Skip to content

Commit

Permalink
Allow variables for snapshot and level adjust
Browse files Browse the repository at this point in the history
  • Loading branch information
istnv committed Jul 3, 2023
1 parent 2177634 commit 15859ec
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 120 deletions.
31 changes: 17 additions & 14 deletions actions.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Regex } from '@companion-module/base'
import { Regex, InstanceStatus } from '@companion-module/base'
import { pad0 } from './helpers.js'

export function buildStaticActions(self) {
const sendOSCCmd = async(cmd, arg) => (
await self.sendOSC(cmd, arg)
)
const sendOSCCmd = async (cmd, arg) => await self.sendOSC(cmd, arg)

let actions = {
label: {
Expand Down Expand Up @@ -158,15 +156,21 @@ export function buildStaticActions(self) {
type: 'textinput',
label: 'Snapshot Number 1-64',
id: 'snap',
default: 1,
min: 1,
max: 64,
regex: Regex.NUMBER,
default: '1',
useVariables: true,
},
],
callback: async (action, context) => {
const opt = action.options
await sendOSCCmd('/-snap/load', { type: 'i', value: parseInt(opt.snap) })
const snap = parseInt(await context.parseVariablesInString(action.options.snap))
if (snap < 1 || snap > 64) {
const err = [action.controlId, action.actionId, 'Invalid Snapshot #'].join(' → ')
self.updateStatus(InstanceStatus.BadConfig, err)
self.paramError = true
} else {
self.updateStatus(InstanceStatus.Ok)
self.paramError = false
await sendOSCCmd('/-snap/load', { type: 'i', value: snap })
}
},
},

Expand All @@ -183,7 +187,7 @@ export function buildStaticActions(self) {
name: 'Load Prior Console Snapshot',
options: [],
callback: async (action, context) => {
const snap = Math.max(--self.currentSnapshot,1)
const snap = Math.max(--self.currentSnapshot, 1)
await sendOSCCmd('/-snap/load', { type: 'i', value: snap })
},
},
Expand All @@ -192,8 +196,8 @@ export function buildStaticActions(self) {
name: 'Save Current Console Snapshot',
options: [],
callback: async (action, context) => {
const snap = Math.min(--self.currentSnapshot,1)
await sendOSCCmd('/-snap/save', { type: 'i', value: snap } )
const snap = Math.min(--self.currentSnapshot, 1)
await sendOSCCmd('/-snap/save', { type: 'i', value: snap })
},
},

Expand All @@ -211,7 +215,6 @@ export function buildStaticActions(self) {
const opt = action.options
await sendOSCCmd('/-stat/tape/state', { type: 'i', value: parseInt(opt.tFunc) })
},

},
}
Object.assign(self.actionDefs, actions)
Expand Down
14 changes: 7 additions & 7 deletions buildHADefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ export function buildHADefs(self) {
let haActions = {}
let haVariables = {}

for (let s = 1; s <= 16; s++) {
for (let s = 1; s <= 24; s++) {
let c = pad0(s)
let theID = `/headamp/${c}/`
let fID = 'ha' + c
let baseID = `/headamp/${c}/`
let baseFID = 'ha' + c
let theID = baseID + 'gain'
self.fbToStat[fID] = theID
self.xStat[theID] = {
name: '#' + c,
defaultName: '#' + c,
name: 'ha' + c + '_gain',
valid: false,
fbID: fID,
polled: 0,
}
snapVars.push({
name: 'Snapshot ' + c + ' Name',
haVariables.push({
name: 'Head Amp ' + c ,
variableId: fID,
})
self.snapshot[s] = theID
Expand Down
103 changes: 60 additions & 43 deletions buildStripDefs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'
import { defStrip } from './defStrip.js'
import { combineRgb, Regex } from '@companion-module/base'
import { combineRgb, InstanceStatus } from '@companion-module/base'
import { pad0, unSlash, setToggle, fadeTo } from './helpers.js'

// build the channel strip actions/feedbaks/variables
Expand All @@ -20,13 +20,6 @@ export function buildStripDefs(self) {

let busOpts = []

const levelOpts = [
{ op: '', act: 'Set' },
{ op: '_a', act: 'Adjust' },
{ op: '_s', act: 'Store' },
{ op: '_r', act: 'Recall' },
]

const defProc = {
insert: {
node: 'insert/on',
Expand Down Expand Up @@ -66,7 +59,7 @@ export function buildStripDefs(self) {
}

function makeLevelActions(id, aLabel, aId, theStrip) {
for (let sfx of levelOpts) {
for (let sfx of self.levelOpts) {
const newName = aLabel + ` Level ${sfx.act}`
const newLabel = 'send' != id ? aLabel : sendLabel(theStrip.description, theStrip.min, theStrip.max)
const newId = id + sfx.op
Expand Down Expand Up @@ -114,10 +107,17 @@ export function buildStripDefs(self) {
const aId = action.actionId
const nVal = opt.type == '/ch/' ? pad0(opt.num) : opt.num
const strip = opt.type + nVal + (opt.type == '/dca/' ? '/fader' : '/mix/fader')
let fVal = fadeTo(aId, strip, opt, self)
if ('_s' != aId.slice(-2)) {
// store is local, no console command
self.sendOSC(strip, { type: 'f', value: fVal })
try {
let fVal = await fadeTo(aId, strip, opt, self)

if ('_s' != aId.slice(-2)) {
// store is local, no console command
self.sendOSC(strip, { type: 'f', value: fVal })
}
} catch (error) {
const err = [action.controlId, error.message].join(' → ')
self.updateStatus(InstanceStatus.BadConfig, err)
self.paramError = true
}
}
} else {
Expand All @@ -126,10 +126,19 @@ export function buildStripDefs(self) {
levelActions[newId].callback = async (action, context) => {
const opt = action.options
const aId = action.actionId
const fVal = fadeTo(aId, strip, opt, self)
if ('_s' != aId.slice(-2)) {
// store is local, no console command
self.sendOSC(strip, { type: 'f', value: fVal })
try {
let fVal = await fadeTo(aId, strip, opt, self)
self.updateStatus(InstanceStatus.Ok)
self.paramError = false

if ('_s' != aId.slice(-2)) {
// store is local, no console command
self.sendOSC(strip, { type: 'f', value: fVal })
}
} catch (error) {
const err = [action.controlId, error.message].join(' → ')
self.updateStatus(InstanceStatus.BadConfig, err)
self.paramError = true
}
}
}
Expand All @@ -153,10 +162,17 @@ export function buildStripDefs(self) {
}
const bVal = pad0(opt.busNum)
const strip = opt.type + nVal + 'mix/' + bVal + '/level'
const fVal = fadeTo(aId, strip, opt, self)
if ('_s' != aId.slice(-2)) {
// store is local, no console command
self.sendOSC(strip, { type: 'f', value: fVal })
try {
let fVal = await fadeTo(aId, strip, opt, self)

if ('_s' != aId.slice(-2)) {
// store is local, no console command
self.sendOSC(strip, { type: 'f', value: fVal })
}
} catch (error) {
const err = [action.controlId, error.message].join(' → ')
self.updateStatus(InstanceStatus.BadConfig, err)
self.paramError = true
}
}
}
Expand All @@ -173,13 +189,12 @@ export function buildStripDefs(self) {
break
case '_a':
levelActions[newId].options.push({
type: 'number',
type: 'textinput',
useVariables: true,
tooltip: 'Move fader +/- percent.',
label: 'Adjust By',
id: 'ticks',
min: -100,
max: 100,
default: 1,
default: '1',
})
break
case '_s':
Expand Down Expand Up @@ -217,24 +232,26 @@ export function buildStripDefs(self) {

if (sfx.op != '_s') {
// all but store have a fade time
levelActions[newId].options.push(...[
{
type: 'number',
label: 'Fade Duration (ms)',
id: 'duration',
default: 0,
min: 0,
step: 10,
max: 60000,
},
{
type: 'checkbox',
tooltip: 'This prevents the fader level from going above 0db (75%)',
label: 'Limit fader to 0.0dB',
id: 'faderLim',
default: 0,
},
])
levelActions[newId].options.push(
...[
{
type: 'number',
label: 'Fade Duration (ms)',
id: 'duration',
default: 0,
min: 0,
step: 10,
max: 60000,
},
{
type: 'checkbox',
tooltip: 'This prevents the fader level from going above 0db (75%)',
label: 'Limit fader to 0.0dB',
id: 'faderLim',
default: 0,
},
]
)
}
}
}
Expand Down
13 changes: 10 additions & 3 deletions companion/HELP.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
**Midas MR18 / Behringer XR 12/16/18**

This Module controls the Midas MR series and Behringer XR series of consoles
go over to [Midas](http://www.musictri.be/Categories/Midas/Mixers/Digital/M32/p/P0B3I) or [Behringer](http://www.musictri.be/Categories/Behringer/Mixers/Digital/X32/p/P0ASF)
go over to [Midas](https://www.midasconsoles.com/catalog.html?brandName=midas&catalog=Application&category=C-MIDAS-MIXERS-DIGITALSTAGEBOXMIXERS) or [Behringer](https://www.behringer.com/catalog.html?brandName=behringer&catalog=Application&category=C-BEHRINGER-MIXERS-DIGITALSTAGEBOXMIXERS)
to get additional information about the consoles and their capabilities.

--------
Contributions for development and maintenance of this open source module are always welcome
https://github.com/sponsors/istnv

--------

## Configuration
**Target IP:** Enter the IP address of the Mixer

Expand Down Expand Up @@ -43,11 +49,11 @@ Tape Operation | Stop,Play,PlayPause,Record,RecordPause,Fast Forward,Rewind of t

**Note *mute, solo, processing*:** All mute, solo, and processing actions also have a Toggle option that inverts the current state of the board setting.

**Note *fader adjustment*:** This module stores fader position as a range from 0 (-oo dB) to 100 (+10dB). The conversion from position to dB is explained below. Fader changes also have an optional duration of 0 to 60000 mSec (0 to 60 seconds) to create cross fades. There is an option to limit levels to 0db.
**Note *fader/level adjustment*:** This module stores fader position as a range from 0 (-oo dB) to 100 (+10dB). The conversion from position to dB is explained below. Fader changes also have an optional duration of 0 to 60000 mSec (0 to 60 seconds) to create cross fades. There is an option to limit levels to 0db. The adjustment amount entry will accept a dynamic variable/expression.

**Note *Storage and Recall*:** Each channel or bus send has one save value. Recall will only restore the last value saved. There are also 10 Global slots available to store a value that may be recalled to any channel. Recalling an empty slot will have no effect.

**Note *Snapshots*:** If the Previous/Next numbered Snapshot is empty, the mixer will not change snapshots. The Save snapshot function does NOT ask for confirmation before saving/overwriting.
**Note *Snapshots*:** If the Previous/Next numbered Snapshot is empty, the mixer will not change snapshots. The Save snapshot function does NOT ask for confirmation before saving/overwriting. The Snapshot to load item can be a dynamic variable/expression.

**Note *Presets*:** There are some preset buttons included to show some common button configurations with pre-built actions and feedback indicators. They use channel 1 as a demonstration. There is also a 'Rude Solo' button available.

Expand Down Expand Up @@ -149,3 +155,4 @@ In both representations, 0db maps to 0.75 and 10dB maps to 1.0
![Fader](images/X32-Air-faders.png?raw=true "Fader")

Since the mixer uses 1024 steps per fader, there may be some rounding differences between the mixer display and companion.

26 changes: 22 additions & 4 deletions constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,36 @@ import { combineRgb } from '@companion-module/base'
import { pad0 } from './helpers.js'

export function buildConstants(self) {

// discreet float values for faders (1024)
self.fLevels[1024] = []
for (let i = 0; i < 1024; i++) {
self.fLevels[1024][i] = Math.min(
1.0,
Math.floor((Math.round(self.stepsToFader(i, 1024) * 1023.5) / 1023) * 10000) / 10000
)
}

// discreet float values for sends (161)
for (let i = 0; i < 161; i++) {
self.fLevels[161][i] = self.stepsToFader(i, 161)
self.levelOpts = [
{ op: '', act: 'Set' },
{ op: '_a', act: 'Adjust' },
{ op: '_s', act: 'Store' },
{ op: '_r', act: 'Recall' },
]


// pre-set linear values for various other 'levels'
const lvls = [
161, // sends
101, // pan
145, // trim, headamp gain
65, // aux gain
]

for (let lvl of lvls) {
self.fLevels[lvl] = []
for (let i = 0; i < lvl; i++) {
self.fLevels[lvl][i] = self.stepsToFader(i, lvl)
}
}

self.STORE_LOCATION = []
Expand Down
17 changes: 12 additions & 5 deletions helpers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// helper functions
export function pad0(num, len) {
len = len || 2
return ('00' + num).slice(-len)
export function pad0(num, len = 2) {
const zeros = '0'.repeat(len)
return (zeros + num).slice(-len)
}

export function unSlash(s) {
Expand All @@ -15,12 +15,19 @@ export function setToggle(isOn, opt) {
// calculate new fader/level float
// returns a 'new' float value
// or undefined for a store
export function fadeTo(cmd, strip, opt, self) {
export async function fadeTo(cmd, strip, opt, self) {
const stat = self.xStat[strip]
const node = strip.split('/').pop()
const subAct = cmd.slice(-2)
let opTicks = 1

const opTicks = parseInt(opt.ticks)
if (subAct == '_a') {
opTicks = String(await self.parseVariablesInString(`${opt.ticks}`)).trim()
if (opTicks && self.REGEX_PERCENT && !self.REGEX_PERCENT.test(opTicks)) {
throw new Error('Invalid Adjust Percentage')
}
opTicks = parseInt(opTicks)
}
const faderLim = opt.faderLim
const steps = stat.fSteps
const span = parseFloat(opt.duration)
Expand Down
Loading

0 comments on commit 15859ec

Please sign in to comment.