Skip to content

Commit 63e481f

Browse files
committed
added basic show control functionality: recall scene
1 parent ffd4fa3 commit 63e481f

File tree

6 files changed

+141
-7
lines changed

6 files changed

+141
-7
lines changed

src/actions/control.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { CompanionActionDefinitions } from '@companion-module/base'
2+
import { CompanionActionWithCallback } from './common.js'
3+
import { InstanceBaseExt } from '../types.js'
4+
import { WingConfig } from '../config.js'
5+
import { ControlCommands } from '../commands/control.js'
6+
import { StateUtil } from '../state/index.js'
7+
import { GetDropdown } from '../choices/common.js'
8+
import { getIdLabelPair } from '../choices/utils.js'
9+
10+
export enum OtherActionId {
11+
RecallScene = 'recall-scene',
12+
SendLibraryAction = 'send-library-action',
13+
}
14+
15+
export function createControlActions(self: InstanceBaseExt<WingConfig>): CompanionActionDefinitions {
16+
const send = self.sendCommand
17+
const state = self.state
18+
const ensureLoaded = self.ensureLoaded
19+
20+
const actions: { [id in OtherActionId]: CompanionActionWithCallback | undefined } = {
21+
[OtherActionId.RecallScene]: {
22+
name: 'Recall Scene',
23+
options: [
24+
{
25+
type: 'number',
26+
id: 'num',
27+
label: 'Argument',
28+
min: 1,
29+
max: 16384,
30+
default: 1,
31+
},
32+
],
33+
callback: async (event) => {
34+
send(ControlCommands.LibrarySceneSelectionIndex(), event.options.num as number)
35+
send(ControlCommands.LibraryAction(), 'GO')
36+
},
37+
subscribe: () => {
38+
const cmd = ControlCommands.LibraryActiveSceneIndex()
39+
ensureLoaded(cmd)
40+
},
41+
learn: () => {
42+
const cmd = ControlCommands.LibraryActiveSceneIndex()
43+
return { num: StateUtil.getNumberFromState(cmd, state) }
44+
},
45+
},
46+
[OtherActionId.SendLibraryAction]: {
47+
name: 'Send Library Action',
48+
description: 'Set the scribble light color of a channel, aux, bus, matrix or main.',
49+
options: [
50+
GetDropdown(
51+
'Action',
52+
'act',
53+
[
54+
getIdLabelPair('GOPREV', 'Select Previous and Go'),
55+
getIdLabelPair('GONEXT', 'Select Next and Go'),
56+
getIdLabelPair('GO', 'Go'),
57+
getIdLabelPair('PREV', 'Select Previous'),
58+
getIdLabelPair('NEXT', 'Select Next'),
59+
// getIdLabelPair('GOTAG', 'G'),
60+
],
61+
'GO',
62+
),
63+
],
64+
callback: async (event) => {
65+
const act = event.options.act as string
66+
const cmd = ControlCommands.LibraryAction()
67+
send(cmd, act)
68+
},
69+
},
70+
}
71+
72+
return actions
73+
}

src/actions/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { createMainActions } from './main.js'
1010
import { createUsbPlayerActions } from './usbplayer.js'
1111
import { createCardsActions } from './cards.js'
1212
import { createCommonActions } from './common.js'
13+
import { createControlActions } from './control.js'
1314

1415
export function createActions(self: InstanceBaseExt<WingConfig>): CompanionActionDefinitions {
1516
const actions = {
@@ -22,6 +23,7 @@ export function createActions(self: InstanceBaseExt<WingConfig>): CompanionActio
2223
...createUsbPlayerActions(self),
2324
...createCardsActions(self),
2425
...createConfigurationActions(self),
26+
...createControlActions(self),
2527
}
2628

2729
return actions

src/actions/other.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { WingConfig } from '../config.js'
66
export enum OtherActionId {
77
SendCommand = 'send-command',
88
SendCommandWithNumber = 'send-command-with-number',
9+
SendCommandWithString = 'send-command-with-string',
910
}
1011

1112
export function GetOtherActions(self: InstanceBaseExt<WingConfig>): CompanionActionDefinitions {
@@ -46,6 +47,24 @@ export function GetOtherActions(self: InstanceBaseExt<WingConfig>): CompanionAct
4647
send(event.options.cmd as string, event.options.num as number)
4748
},
4849
},
50+
[OtherActionId.SendCommandWithString]: {
51+
name: 'Send Command with String',
52+
options: [
53+
{
54+
type: 'textinput',
55+
id: 'cmd',
56+
label: 'Command',
57+
},
58+
{
59+
type: 'textinput',
60+
id: 'val',
61+
label: 'Value',
62+
},
63+
],
64+
callback: async (event) => {
65+
send(event.options.cmd as string, event.options.val as string)
66+
},
67+
},
4968
}
5069

5170
return actions

src/commands/control.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// eslint-disable-next-line @typescript-eslint/no-namespace
2+
export namespace ControlCommands {
3+
export function Node(): string {
4+
return `/$ctl`
5+
}
6+
7+
export function LibraryNode(): string {
8+
return `${Node()}/lib`
9+
}
10+
11+
export function LibraryScenes(): string {
12+
return `${LibraryNode()}/$scenes`
13+
}
14+
15+
export function LibraryActiveSceneIndex(): string {
16+
return `${LibraryNode()}/$actidx`
17+
}
18+
19+
export function LibraryActiveSceneName(): string {
20+
return `${LibraryNode()}/$active`
21+
}
22+
23+
export function LibraryActiveShowName(): string {
24+
return `${LibraryNode()}/$actshow`
25+
}
26+
27+
export function LibraryAction(): string {
28+
return `${LibraryNode()}/$action`
29+
}
30+
31+
export function LibrarySceneSelectionIndex(): string {
32+
return `${LibraryNode()}/$actionidx`
33+
}
34+
}

src/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,11 @@ export class WingInstance extends InstanceBase<WingConfig> implements InstanceBa
271271
this.osc.on('message', (message): void => {
272272
this.updateStatus(InstanceStatus.Ok)
273273
const args = message.args as osc.MetaArgument[]
274-
// this.log('debug', `Received ${JSON.stringify(message)}`)
274+
this.log('debug', `Received ${JSON.stringify(message)}`)
275275
this.state.set(message.address, args)
276276

277277
if (this.inFlightRequests[message.address]) {
278-
this.log('debug', `Received answer for request ${message.address}`)
278+
// this.log('debug', `Received answer for request ${message.address}`)
279279
this.inFlightRequests[message.address]()
280280
delete this.inFlightRequests[message.address]
281281
}
@@ -327,12 +327,14 @@ export class WingInstance extends InstanceBase<WingConfig> implements InstanceBa
327327
const busNameRe = /\/bus\/\d+\/\$name/
328328
const mtxNameRe = /\/mtx\/\d+\/\$name/
329329
const mainNameRe = /\/main\/\d+\/\$name/
330+
const libRe = /\/$ctl\/lib/
330331
if (
331332
channelNameRe.test(msg.address) ||
332333
busNameRe.test(msg.address) ||
333334
auxNameRe.test(msg.address) ||
334335
mtxNameRe.test(msg.address) ||
335-
mainNameRe.test(msg.address)
336+
mainNameRe.test(msg.address) ||
337+
libRe.test(msg.address)
336338
) {
337339
// this.log('info', 'Would update now')
338340

@@ -398,10 +400,10 @@ export class WingInstance extends InstanceBase<WingConfig> implements InstanceBa
398400
args: args,
399401
}
400402
this.osc.send(command)
401-
this.osc.send({ address: cmd, args: [] })
403+
// this.osc.send({ address: cmd, args: [] })
402404
}
403405

404-
ensureLoaded = (path: string): void => {
406+
ensureLoaded = (path: string, arg?: string | number): void => {
405407
this.requestQueue
406408
.add(async () => {
407409
if (this.inFlightRequests[path]) {
@@ -418,7 +420,7 @@ export class WingInstance extends InstanceBase<WingConfig> implements InstanceBa
418420
this.inFlightRequests[path] = resolve
419421
})
420422

421-
this.sendCommand(path, undefined)
423+
this.sendCommand(path, arg ?? undefined)
422424

423425
await p
424426
})

src/state/state.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type NameChoices = {
1313
mains: DropdownChoice[]
1414
dcas: DropdownChoice[]
1515
mutegroups: DropdownChoice[]
16+
scenes: DropdownChoice[]
1617
}
1718

1819
type Names = {
@@ -23,6 +24,7 @@ type Names = {
2324
mains: string[]
2425
dcas: string[]
2526
mutegroups: string[]
27+
scenes: string[]
2628
}
2729
export class WingState implements IStoredChannelSubject {
2830
private readonly data: Map<string, osc.MetaArgument[]>
@@ -37,6 +39,7 @@ export class WingState implements IStoredChannelSubject {
3739
mains: [],
3840
dcas: [],
3941
mutegroups: [],
42+
scenes: [],
4043
}
4144

4245
names: Names = {
@@ -47,6 +50,7 @@ export class WingState implements IStoredChannelSubject {
4750
mains: [],
4851
dcas: [],
4952
mutegroups: [],
53+
scenes: [],
5054
}
5155

5256
constructor(model: ModelSpec) {
@@ -191,7 +195,7 @@ export class WingState implements IStoredChannelSubject {
191195
}
192196
}
193197

194-
public requestNames(model: ModelSpec, ensureLoaded: (path: string) => void): void {
198+
public requestNames(model: ModelSpec, ensureLoaded: (path: string, arg?: string | number) => void): void {
195199
for (let ch = 1; ch <= model.channels; ch++) {
196200
ensureLoaded(Commands.Channel.RealName(ch))
197201
}

0 commit comments

Comments
 (0)