Skip to content

Commit

Permalink
Initialize trim value
Browse files Browse the repository at this point in the history
  • Loading branch information
istnv committed Feb 10, 2025
1 parent b96aed3 commit b879f45
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 24 deletions.
36 changes: 33 additions & 3 deletions buildHADefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ' %',
Expand All @@ -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)
}
21 changes: 16 additions & 5 deletions constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
46 changes: 31 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -540,15 +541,25 @@ 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
* @returns {float}
*/
logFaderToDB(f, steps) {
let res = i / (steps - 1)

return Math.floor((fmin * exp(log(fmax / fmin) * f)) / 10000)
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "behringer-xair",
"version": "2.6.5",
"version": "2.6.6",
"type": "module",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit b879f45

Please sign in to comment.