|
| 1 | +import { CompanionActionDefinition } from '@companion-module/base' |
| 2 | +import { SetRequired } from 'type-fest' // eslint-disable-line n/no-missing-import |
| 3 | + |
| 4 | +export type CompanionActionWithCallback = SetRequired<CompanionActionDefinition, 'callback'> |
| 5 | + |
| 6 | +import { CompanionActionDefinitions } from '@companion-module/base' |
| 7 | +import { GetDropdown, GetMuteDropdown } from '../choices/common.js' |
| 8 | +import { InstanceBaseExt } from '../types.js' |
| 9 | +import { WingConfig } from '../config.js' |
| 10 | +import * as ActionUtil from './utils.js' |
| 11 | +import { ConfigurationCommands } from '../commands/config.js' |
| 12 | +import { StateUtil } from '../state/index.js' |
| 13 | +import { getIdLabelPair } from '../choices/utils.js' |
| 14 | + |
| 15 | +export enum CommonActions { |
| 16 | + // Solo |
| 17 | + SetSoloMute = 'set-solo-mute', |
| 18 | + SetSoloDim = 'set-solo-dim', |
| 19 | + SetSoloMono = 'set-solo-mono', |
| 20 | + SetSoloLRSwap = 'set-solo-swap', |
| 21 | +} |
| 22 | + |
| 23 | +export function createConfigurationActions(self: InstanceBaseExt<WingConfig>): CompanionActionDefinitions { |
| 24 | + const send = self.sendCommand |
| 25 | + const ensureLoaded = self.ensureLoaded |
| 26 | + const state = self.state |
| 27 | + |
| 28 | + const actions: { [id in CommonActions]: CompanionActionWithCallback | undefined } = { |
| 29 | + //////////////////////////////////////////////////////////////// |
| 30 | + // Solo |
| 31 | + //////////////////////////////////////////////////////////////// |
| 32 | + [CommonActions.SetSoloMute]: { |
| 33 | + name: 'Set Solo Mute', |
| 34 | + description: 'Set or toggle the mute state of the solo output.', |
| 35 | + options: [GetMuteDropdown('mute')], |
| 36 | + callback: async (event) => { |
| 37 | + const cmd = ConfigurationCommands.SoloMute() |
| 38 | + const val = ActionUtil.getNumber(event, 'mute') |
| 39 | + const currentVal = StateUtil.getBooleanFromState(cmd, state) |
| 40 | + if (val >= 2) { |
| 41 | + send(cmd, Number(!currentVal)) |
| 42 | + } else { |
| 43 | + send(cmd, val) |
| 44 | + } |
| 45 | + }, |
| 46 | + subscribe: (_) => { |
| 47 | + const cmd = ConfigurationCommands.SoloMute() |
| 48 | + ensureLoaded(cmd) |
| 49 | + }, |
| 50 | + }, |
| 51 | + [CommonActions.SetSoloDim]: { |
| 52 | + name: 'Set Solo Dim', |
| 53 | + description: 'Set or toggle the dim state of the solo output.', |
| 54 | + options: [ |
| 55 | + GetDropdown( |
| 56 | + 'Dim', |
| 57 | + 'dim', |
| 58 | + [getIdLabelPair('1', 'On'), getIdLabelPair('0', 'Off'), getIdLabelPair('2', 'Toggle')], |
| 59 | + '1', |
| 60 | + ), |
| 61 | + ], |
| 62 | + callback: async (event) => { |
| 63 | + const cmd = ConfigurationCommands.SoloDim() |
| 64 | + const val = ActionUtil.getNumber(event, 'dim') |
| 65 | + const currentVal = StateUtil.getBooleanFromState(cmd, state) |
| 66 | + if (val >= 2) { |
| 67 | + send(cmd, Number(!currentVal)) |
| 68 | + } else { |
| 69 | + send(cmd, val) |
| 70 | + } |
| 71 | + }, |
| 72 | + subscribe: (_) => { |
| 73 | + const cmd = ConfigurationCommands.SoloDim() |
| 74 | + ensureLoaded(cmd) |
| 75 | + }, |
| 76 | + }, |
| 77 | + [CommonActions.SetSoloMono]: { |
| 78 | + name: 'Set Solo Mono', |
| 79 | + description: 'Set or toggle the mono state of the solo output.', |
| 80 | + options: [ |
| 81 | + GetDropdown( |
| 82 | + 'Mono', |
| 83 | + 'mono', |
| 84 | + [getIdLabelPair('1', 'On'), getIdLabelPair('0', 'Off'), getIdLabelPair('2', 'Toggle')], |
| 85 | + '1', |
| 86 | + ), |
| 87 | + ], |
| 88 | + callback: async (event) => { |
| 89 | + const cmd = ConfigurationCommands.SoloMono() |
| 90 | + const val = ActionUtil.getNumber(event, 'mono') |
| 91 | + const currentVal = StateUtil.getBooleanFromState(cmd, state) |
| 92 | + if (val >= 2) { |
| 93 | + send(cmd, Number(!currentVal)) |
| 94 | + } else { |
| 95 | + send(cmd, val) |
| 96 | + } |
| 97 | + }, |
| 98 | + subscribe: (_) => { |
| 99 | + const cmd = ConfigurationCommands.SoloMono() |
| 100 | + ensureLoaded(cmd) |
| 101 | + }, |
| 102 | + }, |
| 103 | + [CommonActions.SetSoloLRSwap]: { |
| 104 | + name: 'Set Solo LR Swap', |
| 105 | + description: 'Set the left-right channel swap of the solo channel.', |
| 106 | + options: [ |
| 107 | + GetDropdown( |
| 108 | + 'Swap', |
| 109 | + 'swap', |
| 110 | + [getIdLabelPair('1', 'Swap'), getIdLabelPair('0', "Don't Swap"), getIdLabelPair('2', 'Toggle')], |
| 111 | + '1', |
| 112 | + ), |
| 113 | + ], |
| 114 | + callback: async (event) => { |
| 115 | + const cmd = ConfigurationCommands.SoloLRSwap() |
| 116 | + const val = ActionUtil.getNumber(event, 'swap') |
| 117 | + const currentVal = StateUtil.getBooleanFromState(cmd, state) |
| 118 | + if (val >= 2) { |
| 119 | + send(cmd, Number(!currentVal)) |
| 120 | + } else { |
| 121 | + send(cmd, val) |
| 122 | + } |
| 123 | + }, |
| 124 | + subscribe: (_) => { |
| 125 | + const cmd = ConfigurationCommands.SoloLRSwap() |
| 126 | + ensureLoaded(cmd) |
| 127 | + }, |
| 128 | + }, |
| 129 | + } |
| 130 | + return actions |
| 131 | +} |
0 commit comments