Skip to content

Commit 24c7601

Browse files
authored
Merge pull request #98 from bitfocus/add-any-solo-feedback
added option to choose 'any' and 'all' for a solo feedback
2 parents d1434c1 + d4335ea commit 24c7601

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed

src/actions/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ export function getSoloCommand(sel: string, val: number): string {
154154
cmd = MatrixCommands.Solo(val)
155155
} else if (sel.startsWith('/main')) {
156156
cmd = MainCommands.Solo(val)
157+
} else if (sel.startsWith('/dca')) {
158+
cmd = DcaCommands.Solo(val)
157159
}
158160
return cmd
159161
}

src/feedbacks.ts

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ export function GetFeedbacksList(
6666
...state.namedChoices.mains,
6767
]
6868

69+
const allChannelsAndDcas = [...allChannels, ...state.namedChoices.dcas]
70+
6971
const feedbacks: { [id in FeedbackId]: CompanionFeedbackWithCallback | undefined } = {
7072
[FeedbackId.Mute]: {
7173
type: 'boolean',
7274
name: 'Mute',
7375
description: "React to a change in a channel's mute state",
7476
options: [
75-
GetDropdown('Selection', 'sel', [...allChannels, ...state.namedChoices.dcas, ...state.namedChoices.mutegroups]),
77+
GetDropdown('Selection', 'sel', [...allChannelsAndDcas, ...state.namedChoices.mutegroups]),
7678
GetMuteDropdown('mute', 'State', false),
7779
],
7880
defaultStyle: {
@@ -261,7 +263,11 @@ export function GetFeedbacksList(
261263
name: 'Solo',
262264
description: "React to a change in a channel's solo state",
263265
options: [
264-
GetDropdown('Selection', 'sel', [...allChannels, ...state.namedChoices.dcas]),
266+
GetDropdown('Selection', 'sel', [
267+
getIdLabelPair('any', 'Any'),
268+
getIdLabelPair('all', 'All'),
269+
...allChannelsAndDcas,
270+
]),
265271
GetDropdown('Solo', 'solo', [getIdLabelPair('1', 'On'), getIdLabelPair('0', 'Off')]),
266272
],
267273
defaultStyle: {
@@ -270,19 +276,51 @@ export function GetFeedbacksList(
270276
},
271277
callback: (event: CompanionFeedbackInfo): boolean => {
272278
const sel = event.options.sel as string
273-
const cmd = ActionUtil.getSoloCommand(sel, getNodeNumber(event, 'sel'))
274-
const currentValue = StateUtil.getNumberFromState(cmd, state)
275-
return typeof currentValue === 'number' && currentValue == event.options.solo
279+
if (sel == 'any') {
280+
return allChannelsAndDcas.some((s) => {
281+
const num = s.id.toString().split('/')[2] as unknown as number
282+
const cmd = ActionUtil.getSoloCommand(s.id as string, num)
283+
const currentValue = StateUtil.getNumberFromState(cmd, state)
284+
return currentValue == event.options.solo
285+
})
286+
} else if (sel == 'all') {
287+
return allChannelsAndDcas.every((s) => {
288+
const num = s.id.toString().split('/')[2] as unknown as number
289+
const cmd = ActionUtil.getSoloCommand(s.id as string, num)
290+
const currentValue = StateUtil.getNumberFromState(cmd, state)
291+
return currentValue == event.options.solo
292+
})
293+
} else {
294+
const cmd = ActionUtil.getSoloCommand(sel, getNodeNumber(event, 'sel'))
295+
const currentValue = StateUtil.getNumberFromState(cmd, state)
296+
return typeof currentValue === 'number' && currentValue == event.options.solo
297+
}
276298
},
277299
subscribe: (event): void => {
278300
const sel = event.options.sel as string
279-
const cmd = ActionUtil.getSoloCommand(sel, getNodeNumber(event, 'sel'))
280-
subscribeFeedback(ensureLoaded, subs, cmd, event)
301+
if (sel == 'any' || sel == 'all') {
302+
allChannelsAndDcas.forEach((s) => {
303+
const num = s.id.toString().split('/')[2] as unknown as number
304+
const cmd = ActionUtil.getSoloCommand(s.id as string, num)
305+
subscribeFeedback(ensureLoaded, subs, cmd, event)
306+
})
307+
} else {
308+
const cmd = ActionUtil.getSoloCommand(sel, getNodeNumber(event, 'sel'))
309+
subscribeFeedback(ensureLoaded, subs, cmd, event)
310+
}
281311
},
282312
unsubscribe: (event: CompanionFeedbackInfo): void => {
283313
const sel = event.options.sel as string
284-
const cmd = ActionUtil.getSoloCommand(sel, getNodeNumber(event, 'sel'))
285-
unsubscribeFeedback(subs, cmd, event)
314+
if (sel == 'any' || sel == 'all') {
315+
allChannelsAndDcas.forEach((s) => {
316+
const num = s.id.toString().split('/')[2] as unknown as number
317+
const cmd = ActionUtil.getSoloCommand(s.id as string, num)
318+
unsubscribeFeedback(subs, cmd, event)
319+
})
320+
} else {
321+
const cmd = ActionUtil.getSoloCommand(sel, getNodeNumber(event, 'sel'))
322+
unsubscribeFeedback(subs, cmd, event)
323+
}
286324
},
287325
},
288326
[FeedbackId.Talkback]: {

0 commit comments

Comments
 (0)