From b879f456b3f6930f2b5532d7e1e3c2b24c67e425 Mon Sep 17 00:00:00 2001 From: John A Knight Jr Date: Mon, 10 Feb 2025 12:05:11 -0800 Subject: [PATCH] Initialize trim value --- buildHADefs.js | 36 +++++++++++++++++++++++++++++++++--- constants.js | 21 ++++++++++++++++----- index.js | 46 +++++++++++++++++++++++++++++++--------------- package.json | 2 +- 4 files changed, 81 insertions(+), 24 deletions(-) diff --git a/buildHADefs.js b/buildHADefs.js index 67bef6f..c06d9c0 100644 --- a/buildHADefs.js +++ b/buildHADefs.js @@ -2,25 +2,32 @@ import { pad0 } from './helpers.js' export function buildHADefs(self) { let haActions = {} + let haFeedbacks = {} let haVariables = [] - let ppRange = [1,4] + let ppRange = [1, 4] const mc = self.config.channels + let haChoices = [] + let ppChoices = [] for (let s = 1; s <= 24; s++) { let c = pad0(s) let baseID = `/headamp/${c}/` let fID = `ha_gain${c}` + let aID = fID let vID = `ha_gain${s}` let theID = baseID + 'gain' self.fbToStat[fID] = theID self.xStat[theID] = { varID: vID, valid: false, + trim: self.HA_CONFIG[s].trim, fbID: fID, + //trim: 0, polled: 0, } if (self.HA_CONFIG[s][mc].has) { - let haName = self.HA_CONFIG[s][mc].name + 'Gain' + let haName = self.HA_CONFIG[s][mc].name + ' Gain' + haChoices.push({ id: s, label: `${s}: ${self.HA_CONFIG[s][mc].name}` }) haVariables.push({ name: haName + ' %', @@ -46,10 +53,33 @@ export function buildHADefs(self) { name: self.HA_CONFIG[s][mc].name + ' Phantom', variableId: vID, }) - ppRange[2] = Math.max(ppRange[2],s) + ppChoices.push({ id: s, label: `${s}: ${self.HA_CONFIG[s][mc].name}` }) + ppRange[2] = Math.max(ppRange[2], s) } } + } + const act = `headamp` + haActions[act] = { + headamp: { + name: `Headamp Level`, + options: [ + { + type: 'dropdown', + label: 'Input', + id: 'input', + choices: haChoices, + }, + { + type: 'dropdown', + label: 'Action', + id: 'act', + choices: self.levelOpts, + default: '', + }, + ], + }, } + self.variableDefs.push(...haVariables) } diff --git a/constants.js b/constants.js index 3fca2bd..5acf6f1 100644 --- a/constants.js +++ b/constants.js @@ -19,10 +19,21 @@ export function buildConstants(self) { ] // pre-set linear values for various other 'levels' + // todo: continue from here + self.LIMITS = { + 1024: { fmin: -100, fmax: 10 }, // main faders + 161: { fmin: -100, fmax: 10 }, // sends, solo level + 101: { fmin: -100, fmax: 100 }, // pan + 145: { fmin: -12, fmax: 60 }, // headamp gain + 73: { fmin: -18, fmax: 18 }, // solo source trim + 65: { fmin: -12, fmax: 20 }, // aux gain + 40: { fmin: -40, fmax: 0 }, // solo dim att/gain + } + const lvls = [ 161, // sends, solo level 101, // pan - 145, // trim, headamp gain + 145, // headamp gain 73, // solo source trim 65, // aux gain 40, // solo dim att/gain @@ -191,8 +202,8 @@ export function buildConstants(self) { break case 17: self.HA_CONFIG[c] = { - 12: { name: `1/4 ${c - 16}`, has: true }, - 16: { name: `1/4 ${c - 16}`, has: true }, + 12: { name: `TRS ${c - 16}`, has: true }, + 16: { name: `TRS ${c - 16}`, has: true }, 18: { name: 'RCA', has: true }, trim: 65, ph: false, @@ -206,8 +217,8 @@ export function buildConstants(self) { case 23: case 24: self.HA_CONFIG[c] = { - 12: { name: `1/4 ${c - 16}`, has: true }, - 16: { name: `1/4 ${c - 16}`, has: true }, + 12: { name: `TRS ${c - 16}`, has: true }, + 16: { name: `TRS ${c - 16}`, has: true }, 18: { name: '', has: false }, trim: 65, ph: false, diff --git a/index.js b/index.js index e061aab..02cd9d7 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,8 @@ import { buildHADefs } from './buildHADefs.js' import { getConfigFields } from './config.js' import { ICON_SOLO } from './icons.js' import { pad0 } from './helpers.js' -import os from 'os' +import os from 'os' +import { runInThisContext } from 'vm' class BAirInstance extends InstanceBase { constructor(internal) { @@ -35,8 +36,9 @@ class BAirInstance extends InstanceBase { this.crossFades = {} this.unitsFound = {} - this.PollCount = 30 - this.PollTimeout = 25 + this.debugLevel = process.env.DEVELOPER ? 2 : 0 + this.PollCount = 10 + this.PollTimeout = 40 this.getConfigFields = getConfigFields buildConstants(this) @@ -472,17 +474,16 @@ class BAirInstance extends InstanceBase { } pollStats() { - let stillNeed = false + let stillNeed = 0 let counter = 0 let timeNow = Date.now() let timeOut = timeNow - this.PollTimeout for (const id in this.xStat) { if (!this.xStat[id].valid) { - stillNeed = true + stillNeed++ if (this.xStat[id].polled < timeOut) { this.sendOSC(id) - // this.log('debug', `sending ${id}`) this.xStat[id].polled = timeNow counter++ // only allow 'PollCount' queries during one cycle @@ -508,7 +509,7 @@ class BAirInstance extends InstanceBase { return } - if (!stillNeed) { + if (0 == stillNeed) { this.updateStatus(InstanceStatus.Ok, 'Console status loaded') const c = Object.keys(this.xStat).length const d = (c / ((timeNow - this.timeStart) / 1000)).toFixed(1) @@ -540,7 +541,18 @@ class BAirInstance extends InstanceBase { } /** - * Calculate logarithmic fader value (0..1) for a given 'step' + * Calculate linear fader dB value for a given 'step' + * depending on total 'steps' + * @param {integer} i - which step + * @param {integer} steps - number of steps for this fader parameter + * @returns {float} + */ + linFaderToDB(f, lim = { fmin: -12, fmax: 20 }) { + return (lim.fmin + (lim.fmax - lim.fmin) * f).toFixed(1) + } + + /** + * Calculate logarithmic fader dB value for a given 'step' * depending on total 'steps' * @param {integer} i - which step * @param {integer} steps - number of steps for this fader parameter @@ -548,7 +560,6 @@ class BAirInstance extends InstanceBase { */ logFaderToDB(f, steps) { let res = i / (steps - 1) - return Math.floor((fmin * exp(log(fmax / fmin) * f)) / 10000) } @@ -601,7 +612,7 @@ class BAirInstance extends InstanceBase { const top = node.split('/')[1] this.hostResponse = true - if ('meters' != top) { + if ('meters' != top && this.debugLevel > 0) { this.log('debug', `received ${node}:` + JSON.stringify(args) + ` from ${info.address}`) } if (this.xStat[node] !== undefined) { @@ -652,10 +663,10 @@ class BAirInstance extends InstanceBase { this.xStat[node].gain = v this.setVariableValues({ [this.xStat[node].varID + '_p']: Math.round(v * 100), - [this.xStat[node].varID + '_d']: this.faderToDB( + [this.xStat[node].varID + '_d']: this.linFaderToDB( v, - this.HA_CONFIG[ha][this.myMixer.channels].trim, - false + this.LIMITS[this.xStat[node].trim] + //{ fmin: this.LIMITS[this.xStat[node].trim].fmin, fmax: this.LIMITS[this.xStat[node].trim].fmax}, ), }) break @@ -664,6 +675,9 @@ class BAirInstance extends InstanceBase { this.setVariableValues({ [this.xStat[node].varID]: !!v, }) + if (this.xStat[node].fbSubs?.size > 0) { + this.checkFeedbacksById(...this.xStat[node].fbSubs) + } break case 'source': this.xStat[node].m_source = v @@ -756,7 +770,7 @@ class BAirInstance extends InstanceBase { this.parseMeters1(args[0].value) break } - if ('meters' != top) { + if ('meters' != top && this.debugLevel > 0) { this.log('debug', message.address, args) } } @@ -945,7 +959,9 @@ class BAirInstance extends InstanceBase { arg = arg ?? [] if (this.oscPort) { - this.log('debug', `OSC > ${node}:` + JSON.stringify(arg)) + if (this.debugLevel > 0) { + this.log('debug', `OSC > ${node}:` + JSON.stringify(arg)) + } this.oscPort.send({ address: node, args: arg, diff --git a/package.json b/package.json index ed27c31..9024395 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "behringer-xair", - "version": "2.6.5", + "version": "2.6.6", "type": "module", "main": "index.js", "scripts": {