Skip to content

Commit 644c387

Browse files
committed
WIP: restructured variable definitions to include paths for these variables
1 parent ea72f3c commit 644c387

File tree

16 files changed

+201
-209
lines changed

16 files changed

+201
-209
lines changed

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ export class WingInstance extends InstanceBase<WingConfig> implements InstanceBa
129129

130130
this.connection?.on('ready', () => {
131131
this.updateStatus(InstanceStatus.Connecting, 'waiting for response from console...')
132+
this.stateHandler?.state?.requestNames(this)
133+
if (this.config.prefetchVariablesOnStartup) {
134+
void this.stateHandler?.state?.requestAllVariables(this)
135+
}
132136
void this.connection?.sendCommand('/*', undefined, undefined, true) // send something to trigger response from console
133137
})
134138

@@ -151,10 +155,6 @@ export class WingInstance extends InstanceBase<WingConfig> implements InstanceBa
151155
this.logger?.info('OSC connection established')
152156

153157
this.feedbackHandler?.startPolling()
154-
this.stateHandler?.state?.requestNames(this)
155-
if (this.config.prefetchVariablesOnStartup) {
156-
this.stateHandler?.state?.requestAllVariables(this)
157-
}
158158
this.stateHandler?.requestUpdate()
159159
}
160160
this.feedbackHandler?.clearPollTimeout()

src/state/state.ts

Lines changed: 19 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { DropdownChoice } from '@companion-module/base'
55
import { ModelSpec } from '../models/types.js'
66
import { getIdLabelPair } from '../choices/utils.js'
77
import * as Commands from '../commands/index.js'
8+
import { getAllVariables } from '../variables/index.js'
89

910
type NameChoices = {
1011
channels: DropdownChoice[]
@@ -231,10 +232,27 @@ export class WingState implements IStoredChannelSubject {
231232
}
232233
}
233234

234-
public requestAllVariables(self: WingInstance): void {
235+
public async requestAllVariables(self: WingInstance): Promise<void> {
235236
const model = self.model
236237
const sendCommand = self.connection!.sendCommand.bind(self.connection)
237238

239+
const vars = getAllVariables(model)
240+
241+
const chunkSize = 1000
242+
const chunkWait = 50
243+
for (let i = 0; i < vars.length; i += 1) {
244+
const v = vars[i]
245+
const p = v.path
246+
const wait = Math.floor(i / chunkSize) * chunkWait
247+
248+
if (p === undefined) continue
249+
250+
setTimeout(() => {
251+
void sendCommand(p)
252+
}, wait)
253+
}
254+
// Separate Stuff
255+
// TODO: eventually this should be unified in the main variable definitions
238256
// Desk/system status
239257
void sendCommand(Commands.Io.MainAltSwitch())
240258

@@ -277,134 +295,6 @@ export class WingState implements IStoredChannelSubject {
277295
void sendCommand(Commands.Cards.WLiveCardSessionLength(card))
278296
void sendCommand(Commands.Cards.WLiveCardSDFree(card))
279297
}
280-
281-
// GPIO states
282-
for (let gpio = 1; gpio <= model.gpio; gpio++) {
283-
void sendCommand(Commands.Control.GpioReadState(gpio))
284-
}
285-
286-
// Talkback assigns (A and B)
287-
for (let bus = 1; bus <= model.busses; bus++) {
288-
void sendCommand(Commands.Configuration.TalkbackBusAssign('A', bus))
289-
void sendCommand(Commands.Configuration.TalkbackBusAssign('B', bus))
290-
}
291-
for (let mtx = 1; mtx <= model.matrices; mtx++) {
292-
void sendCommand(Commands.Configuration.TalkbackMatrixAssign('A', mtx))
293-
void sendCommand(Commands.Configuration.TalkbackMatrixAssign('B', mtx))
294-
}
295-
for (let main = 1; main <= model.mains; main++) {
296-
void sendCommand(Commands.Configuration.TalkbackMainAssign('A', main))
297-
void sendCommand(Commands.Configuration.TalkbackMainAssign('B', main))
298-
}
299-
300-
// Names are requested elsewhere via state.requestNames
301-
302-
// Channel strips
303-
for (let ch = 1; ch <= model.channels; ch++) {
304-
void sendCommand(Commands.Channel.InputGain(ch))
305-
void sendCommand(Commands.Channel.Color(ch))
306-
void sendCommand(Commands.Channel.Mute(ch))
307-
void sendCommand(Commands.Channel.Fader(ch))
308-
void sendCommand(Commands.Channel.Pan(ch))
309-
310-
for (let bus = 1; bus <= model.busses; bus++) {
311-
void sendCommand(Commands.Channel.SendOn(ch, bus))
312-
void sendCommand(Commands.Channel.SendLevel(ch, bus))
313-
void sendCommand(Commands.Channel.SendPan(ch, bus))
314-
}
315-
for (let main = 1; main <= model.mains; main++) {
316-
void sendCommand(Commands.Channel.MainSendOn(ch, main))
317-
void sendCommand(Commands.Channel.MainSendLevel(ch, main))
318-
}
319-
for (let mtx = 1; mtx <= model.matrices; mtx++) {
320-
void sendCommand(Commands.Channel.MatrixSendOn(ch, mtx))
321-
void sendCommand(Commands.Channel.MatrixSendLevel(ch, mtx))
322-
void sendCommand(Commands.Channel.MatrixSendPan(ch, mtx))
323-
}
324-
}
325-
326-
// Auxes
327-
for (let aux = 1; aux <= model.auxes; aux++) {
328-
void sendCommand(Commands.Aux.InputGain(aux))
329-
void sendCommand(Commands.Aux.Color(aux))
330-
void sendCommand(Commands.Aux.Mute(aux))
331-
void sendCommand(Commands.Aux.Fader(aux))
332-
void sendCommand(Commands.Aux.Pan(aux))
333-
334-
for (let main = 1; main <= model.mains; main++) {
335-
void sendCommand(Commands.Aux.MainSendOn(aux, main))
336-
void sendCommand(Commands.Aux.MainSendLevel(aux, main))
337-
}
338-
for (let bus = 1; bus <= model.busses; bus++) {
339-
void sendCommand(Commands.Aux.SendOn(aux, bus))
340-
void sendCommand(Commands.Aux.SendLevel(aux, bus))
341-
void sendCommand(Commands.Aux.SendPan(aux, bus))
342-
}
343-
for (let mtx = 1; mtx <= model.matrices; mtx++) {
344-
void sendCommand(Commands.Aux.MatrixSendOn(aux, mtx))
345-
void sendCommand(Commands.Aux.MatrixSendLevel(aux, mtx))
346-
void sendCommand(Commands.Aux.MatrixSendPan(aux, mtx))
347-
}
348-
}
349-
350-
// Busses
351-
for (let bus = 1; bus <= model.busses; bus++) {
352-
void sendCommand(Commands.Bus.Mute(bus))
353-
void sendCommand(Commands.Bus.Fader(bus))
354-
void sendCommand(Commands.Bus.Pan(bus))
355-
void sendCommand(Commands.Bus.Color(bus))
356-
357-
for (let main = 1; main <= model.mains; main++) {
358-
void sendCommand(Commands.Bus.MainSendOn(bus, main))
359-
void sendCommand(Commands.Bus.MainSendLevel(bus, main))
360-
}
361-
for (let other = 1; other <= model.busses; other++) {
362-
if (other === bus) continue
363-
void sendCommand(Commands.Bus.SendOn(bus, other))
364-
void sendCommand(Commands.Bus.SendLevel(bus, other))
365-
void sendCommand(Commands.Bus.SendPan(bus, other))
366-
}
367-
for (let mtx = 1; mtx <= model.matrices; mtx++) {
368-
void sendCommand(Commands.Bus.MatrixSendOn(bus, mtx))
369-
void sendCommand(Commands.Bus.MatrixSendLevel(bus, mtx))
370-
void sendCommand(Commands.Bus.MatrixSendPan(bus, mtx))
371-
}
372-
}
373-
374-
// Matrices
375-
for (let mtx = 1; mtx <= model.matrices; mtx++) {
376-
void sendCommand(Commands.Matrix.Mute(mtx))
377-
void sendCommand(Commands.Matrix.Fader(mtx))
378-
void sendCommand(Commands.Matrix.Pan(mtx))
379-
void sendCommand(Commands.Matrix.Color(mtx))
380-
}
381-
382-
// Mains
383-
for (let main = 1; main <= model.mains; main++) {
384-
void sendCommand(Commands.Main.Mute(main))
385-
void sendCommand(Commands.Main.Fader(main))
386-
void sendCommand(Commands.Main.Pan(main))
387-
void sendCommand(Commands.Main.Color(main))
388-
389-
for (let mtx = 1; mtx <= model.matrices; mtx++) {
390-
void sendCommand(Commands.Main.MatrixSendOn(main, mtx))
391-
void sendCommand(Commands.Main.MatrixSendLevel(main, mtx))
392-
void sendCommand(Commands.Main.MatrixSendPan(main, mtx))
393-
}
394-
}
395-
396-
// DCAs
397-
for (let dca = 1; dca <= model.dcas; dca++) {
398-
void sendCommand(Commands.Dca.Mute(dca))
399-
void sendCommand(Commands.Dca.Fader(dca))
400-
void sendCommand(Commands.Dca.Color(dca))
401-
}
402-
403-
// Mute Groups
404-
for (let mgrp = 1; mgrp <= model.mutegroups; mgrp++) {
405-
// Mute group variables are handled via RE_MUTE
406-
void sendCommand(Commands.MuteGroup.Mute(mgrp))
407-
}
408298
}
409299

410300
public setStoredChannel(channel: number): void {

src/variables/auxiliary.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,87 @@
1-
import { CompanionVariableDefinition } from '@companion-module/base'
21
import { ModelSpec } from '../models/types.js'
2+
import { VariableDefinition } from './index.js'
3+
import * as Commands from '../commands/index.js'
34

4-
export function getAuxVariables(model: ModelSpec): CompanionVariableDefinition[] {
5-
const variables: CompanionVariableDefinition[] = []
5+
export function getAuxVariables(model: ModelSpec): VariableDefinition[] {
6+
const variables: VariableDefinition[] = []
67

78
for (let aux = 1; aux <= model.auxes; aux++) {
89
variables.push({
910
variableId: `aux${aux}_name`,
1011
name: `Aux ${aux} Name`,
12+
path: Commands.Aux.Name(aux),
1113
})
1214
variables.push({
1315
variableId: `aux${aux}_gain`,
1416
name: `Aux ${aux} Gain`,
17+
path: Commands.Aux.InputGain(aux),
1518
})
1619
variables.push({
1720
variableId: `aux${aux}_mute`,
1821
name: `Aux ${aux} Mute`,
22+
path: Commands.Aux.Mute(aux),
1923
})
2024
variables.push({
2125
variableId: `aux${aux}_level`,
2226
name: `Aux ${aux} Level`,
27+
path: Commands.Aux.Fader(aux),
2328
})
2429
variables.push({
2530
variableId: `aux${aux}_pan`,
2631
name: `Aux ${aux} Pan`,
32+
path: Commands.Aux.Pan(aux),
2733
})
2834
for (let main = 1; main <= model.mains; main++) {
2935
variables.push({
3036
variableId: `aux${aux}_main${main}_mute`,
3137
name: `Aux ${aux} to Main ${main} Mute`,
38+
path: Commands.Aux.MainSendOn(aux, main),
3239
})
3340
variables.push({
3441
variableId: `aux${aux}_main${main}_level`,
3542
name: `Aux ${aux} to Main ${main} Level`,
43+
path: Commands.Aux.MainSendLevel(aux, main),
3644
})
3745
}
3846
for (let bus = 1; bus <= model.busses; bus++) {
3947
variables.push({
4048
variableId: `aux${aux}_bus${bus}_mute`,
4149
name: `Aux ${aux} to Bus ${bus} Mutes`,
50+
path: Commands.Aux.SendOn(aux, bus),
4251
})
4352
variables.push({
4453
variableId: `aux${aux}_bus${bus}_level`,
4554
name: `Aux ${aux} to Bus ${bus} Level`,
55+
path: Commands.Aux.SendLevel(aux, bus),
4656
})
4757
variables.push({
4858
variableId: `aux${aux}_bus${bus}_pan`,
4959
name: `Aux ${aux} to Bus ${bus} Pan`,
60+
path: Commands.Aux.SendPan(aux, bus),
5061
})
5162
}
5263
for (let mtx = 1; mtx <= model.matrices; mtx++) {
5364
variables.push({
5465
variableId: `aux${aux}_mtx${mtx}_mute`,
5566
name: `Aux ${aux} to Matrix ${mtx} Mute`,
67+
path: Commands.Aux.MatrixSendOn(aux, mtx),
5668
})
5769
variables.push({
5870
variableId: `aux${aux}_mtx${mtx}_level`,
5971
name: `Aux ${aux} to Matrix ${mtx} Level`,
72+
path: Commands.Aux.MatrixSendLevel(aux, mtx),
6073
})
6174
variables.push({
6275
variableId: `aux${aux}_mtx${mtx}_pan`,
6376
name: `Aux ${aux} to Matrix ${mtx} Pan`,
77+
path: Commands.Aux.MatrixSendPan(aux, mtx),
6478
})
6579
}
6680

6781
variables.push({
6882
variableId: `aux${aux}_color`,
6983
name: `Aux ${aux} Color`,
84+
path: Commands.Aux.Color(aux),
7085
})
7186
}
7287

src/variables/bus.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { CompanionVariableDefinition } from '@companion-module/base'
21
import { ModelSpec } from '../models/types.js'
2+
import { VariableDefinition } from './index.js'
33

4-
export function getBusVariables(model: ModelSpec): CompanionVariableDefinition[] {
5-
const variables: CompanionVariableDefinition[] = []
4+
export function getBusVariables(model: ModelSpec): VariableDefinition[] {
5+
const variables: VariableDefinition[] = []
66

77
for (let bus = 1; bus <= model.busses; bus++) {
88
variables.push({

src/variables/channel.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,87 @@
1-
import { CompanionVariableDefinition } from '@companion-module/base'
21
import { ModelSpec } from '../models/types.js'
2+
import { VariableDefinition } from './index.js'
3+
import * as Commands from '../commands/index.js'
34

4-
export function getChannelVariables(model: ModelSpec): CompanionVariableDefinition[] {
5-
const variables: CompanionVariableDefinition[] = []
5+
export function getChannelVariables(model: ModelSpec): VariableDefinition[] {
6+
const variables: VariableDefinition[] = []
67

78
for (let ch = 1; ch <= model.channels; ch++) {
89
variables.push({
910
variableId: `ch${ch}_name`,
1011
name: `Channel ${ch} Name`,
12+
path: Commands.Channel.Name(ch),
1113
})
1214
variables.push({
1315
variableId: `ch${ch}_gain`,
1416
name: `Channel ${ch} Gain`,
17+
path: Commands.Channel.InputGain(ch),
1518
})
1619
variables.push({
1720
variableId: `ch${ch}_mute`,
1821
name: `Channel ${ch} Mute`,
22+
path: Commands.Channel.Mute(ch),
1923
})
2024
variables.push({
2125
variableId: `ch${ch}_level`,
2226
name: `Channel ${ch} Level`,
27+
path: Commands.Channel.Fader(ch),
2328
})
2429
variables.push({
2530
variableId: `ch${ch}_pan`,
2631
name: `Channel ${ch} Pan`,
32+
path: Commands.Channel.Pan(ch),
2733
})
2834
for (let bus = 1; bus <= model.busses; bus++) {
2935
variables.push({
3036
variableId: `ch${ch}_bus${bus}_mute`,
3137
name: `Channel ${ch} to Bus ${bus} Mute`,
38+
path: Commands.Channel.SendOn(ch, bus),
3239
})
3340
variables.push({
3441
variableId: `ch${ch}_bus${bus}_level`,
3542
name: `Channel ${ch} to Bus ${bus} Level`,
43+
path: Commands.Channel.SendLevel(ch, bus),
3644
})
3745
variables.push({
3846
variableId: `ch${ch}_bus${bus}_pan`,
3947
name: `Channel ${ch} to Bus ${bus} Pan`,
48+
path: Commands.Channel.SendPan(ch, bus),
4049
})
4150
}
4251
for (let main = 1; main <= model.mains; main++) {
4352
variables.push({
4453
variableId: `ch${ch}_main${main}_mute`,
4554
name: `Channel ${ch} to Main ${main} Mute`,
55+
path: Commands.Channel.MainSendOn(ch, main),
4656
})
4757
variables.push({
4858
variableId: `ch${ch}_main${main}_level`,
4959
name: `Channel ${ch} to Main ${main} Level`,
60+
path: Commands.Channel.MainSendLevel(ch, main),
5061
})
5162
}
5263
for (let mtx = 1; mtx <= model.matrices; mtx++) {
5364
variables.push({
5465
variableId: `ch${ch}_mtx${mtx}_mute`,
5566
name: `Channel ${ch} to Matrix ${mtx} Mute`,
67+
path: Commands.Channel.MatrixSendOn(ch, mtx),
5668
})
5769
variables.push({
5870
variableId: `ch${ch}_mtx${mtx}_level`,
5971
name: `Channel ${ch} to Matrix ${mtx} Level`,
72+
path: Commands.Channel.MatrixSendLevel(ch, mtx),
6073
})
6174
variables.push({
6275
variableId: `ch${ch}_mtx${mtx}_pan`,
6376
name: `Channel ${ch} to Matrix ${mtx} Pan`,
77+
path: Commands.Channel.MatrixSendPan(ch, mtx),
6478
})
6579
}
6680

6781
variables.push({
6882
variableId: `ch${ch}_color`,
6983
name: `Channel ${ch} Color`,
84+
path: Commands.Channel.Color(ch),
7085
})
7186
}
7287

0 commit comments

Comments
 (0)