|
| 1 | +import { CompanionActionDefinitions } from '@companion-module/base' |
| 2 | +import { GetFaderInputField, GetDropdown, GetMuteDropdown, GetFaderDeltaInputField } from '../choices/common.js' |
| 3 | +import { getNodeNumber, runTransition } from './utils.js' |
| 4 | +import { CompanionActionWithCallback } from './common.js' |
| 5 | +import { MatrixCommands as Commands } from '../commands/matrix.js' |
| 6 | +import { InstanceBaseExt } from '../types.js' |
| 7 | +import { WingConfig } from '../config.js' |
| 8 | +import * as ActionUtil from './utils.js' |
| 9 | +import { StateUtil } from '../state/index.js' |
| 10 | +import { getMatrixDirectInInputs } from '../choices/matrix.js' |
| 11 | +import { FadeDurationChoice } from '../choices/fades.js' |
| 12 | + |
| 13 | +export enum MatrixActions { |
| 14 | + MatrixDirectInOn = 'matrix_direct_in_level_on', |
| 15 | + MatrixDirectInInput = 'matrix_direct_in_input', |
| 16 | + MatrixDirectInInvert = 'matrix_direct_in_invert', |
| 17 | + MatrixDirectInDeltaFader = 'matrix_direct_in_delta_fader', |
| 18 | + MatrixDirectInUndoDeltaFader = 'matrix_direct_in_undo_delta_fader', |
| 19 | + MatrixDirectInRecallFader = 'matrix_direct_in_recall_fader', |
| 20 | + MatrixDirectInSetFader = 'matrix_direct_in_set_fader', |
| 21 | + MatrixDirectInStoreFader = 'matrix_direct_in_store_fader', |
| 22 | +} |
| 23 | + |
| 24 | +export function createMatrixActions(self: InstanceBaseExt<WingConfig>): CompanionActionDefinitions { |
| 25 | + const send = self.sendCommand |
| 26 | + const ensureLoaded = self.ensureLoaded |
| 27 | + const state = self.state |
| 28 | + const transitions = self.transitions |
| 29 | + |
| 30 | + const actions: { [id in MatrixActions]: CompanionActionWithCallback | undefined } = { |
| 31 | + [MatrixActions.MatrixDirectInOn]: { |
| 32 | + name: 'Set Direct Input Mute', |
| 33 | + description: 'Set or toggle the direct input on a matrix', |
| 34 | + options: [GetDropdown('Selection', 'sel', state.namedChoices.matrices), GetMuteDropdown('mute')], |
| 35 | + callback: async (event) => { |
| 36 | + const cmd = Commands.DirectInputSwitch(getNodeNumber(event, 'sel')) |
| 37 | + const val = ActionUtil.getNumber(event, 'mute') |
| 38 | + |
| 39 | + if (val < 2) { |
| 40 | + if (val === 1) { |
| 41 | + send(cmd, 0) |
| 42 | + } else { |
| 43 | + send(cmd, 1) |
| 44 | + } |
| 45 | + } else { |
| 46 | + const currentVal = StateUtil.getBooleanFromState(cmd, state) |
| 47 | + send(cmd, Number(!currentVal)) |
| 48 | + } |
| 49 | + }, |
| 50 | + subscribe: (event) => { |
| 51 | + ensureLoaded(Commands.DirectInputSwitch(getNodeNumber(event, 'sel'))) |
| 52 | + }, |
| 53 | + }, |
| 54 | + [MatrixActions.MatrixDirectInInput]: { |
| 55 | + name: 'Set Direct Input Source', |
| 56 | + description: 'Set the source of a direct input on a matrix', |
| 57 | + options: [ |
| 58 | + GetDropdown('Selection', 'sel', state.namedChoices.matrices), |
| 59 | + GetDropdown('Source', 'source', getMatrixDirectInInputs()), |
| 60 | + ], |
| 61 | + callback: async (event) => { |
| 62 | + const cmd = Commands.DirectInputIn(getNodeNumber(event, 'sel')) |
| 63 | + send(cmd, event.options.source as string) |
| 64 | + }, |
| 65 | + }, |
| 66 | + [MatrixActions.MatrixDirectInInvert]: { |
| 67 | + name: 'Invert Direct Input', |
| 68 | + description: 'Invert the polarity of a direct input on a matrix', |
| 69 | + options: [ |
| 70 | + GetDropdown('Selection', 'sel', state.namedChoices.matrices), |
| 71 | + { |
| 72 | + type: 'checkbox', |
| 73 | + id: 'invert', |
| 74 | + label: 'Invert', |
| 75 | + default: false, |
| 76 | + }, |
| 77 | + ], |
| 78 | + callback: async (event) => { |
| 79 | + const cmd = Commands.DirectInputInvert(getNodeNumber(event, 'sel')) |
| 80 | + send(cmd, event.options.invert ? 1 : 0) |
| 81 | + }, |
| 82 | + }, |
| 83 | + [MatrixActions.MatrixDirectInDeltaFader]: { |
| 84 | + name: 'Adjust Direct Input Level', |
| 85 | + description: 'Adjust the level of a direct input on a matrix', |
| 86 | + options: [ |
| 87 | + GetDropdown('Selection', 'sel', state.namedChoices.matrices), |
| 88 | + ...GetFaderDeltaInputField('delta', 'Adjust (dB)'), |
| 89 | + ], |
| 90 | + callback: async (event) => { |
| 91 | + const cmd = Commands.DirectInputLevel(getNodeNumber(event, 'sel')) |
| 92 | + let targetValue = StateUtil.getNumberFromState(cmd, state) |
| 93 | + const delta = event.options.delta as number |
| 94 | + state.storeDelta(cmd, delta) |
| 95 | + if (targetValue != undefined) { |
| 96 | + targetValue += delta |
| 97 | + console.log('targetValue', targetValue) |
| 98 | + ActionUtil.runTransition(cmd, 'level', event, state, transitions, targetValue) |
| 99 | + } |
| 100 | + }, |
| 101 | + subscribe: (event) => { |
| 102 | + ensureLoaded(Commands.DirectInputLevel(getNodeNumber(event, 'sel'))) |
| 103 | + }, |
| 104 | + }, |
| 105 | + [MatrixActions.MatrixDirectInUndoDeltaFader]: { |
| 106 | + name: 'Undo Direct Input Level Adjustment', |
| 107 | + description: 'Undo the previous level adjustment of a direct input on a matrix', |
| 108 | + options: [GetDropdown('Selection', 'sel', state.namedChoices.matrices), ...FadeDurationChoice], |
| 109 | + callback: async (event) => { |
| 110 | + const cmd = Commands.DirectInputLevel(getNodeNumber(event, 'sel')) |
| 111 | + let targetValue = StateUtil.getNumberFromState(cmd, state) |
| 112 | + const delta = state.restoreDelta(cmd) |
| 113 | + if (targetValue != undefined) { |
| 114 | + targetValue -= delta |
| 115 | + ActionUtil.runTransition(cmd, 'level', event, state, transitions, targetValue) |
| 116 | + } |
| 117 | + }, |
| 118 | + subscribe: (event) => { |
| 119 | + ensureLoaded(Commands.DirectInputLevel(getNodeNumber(event, 'sel'))) |
| 120 | + }, |
| 121 | + }, |
| 122 | + [MatrixActions.MatrixDirectInRecallFader]: { |
| 123 | + name: 'Recall Direct Input Level', |
| 124 | + description: 'Recall the level of a direct input on a matrix', |
| 125 | + options: [GetDropdown('Selection', 'sel', state.namedChoices.matrices), ...FadeDurationChoice], |
| 126 | + callback: async (event) => { |
| 127 | + const cmd = Commands.DirectInputLevel(getNodeNumber(event, 'sel')) |
| 128 | + const restoreVal = StateUtil.getValueFromKey(cmd, state) |
| 129 | + ActionUtil.runTransition(cmd, 'level', event, state, transitions, restoreVal) |
| 130 | + }, |
| 131 | + subscribe: (event) => { |
| 132 | + ensureLoaded(Commands.DirectInputLevel(getNodeNumber(event, 'sel'))) |
| 133 | + }, |
| 134 | + }, |
| 135 | + [MatrixActions.MatrixDirectInSetFader]: { |
| 136 | + name: 'Set Direct Input Level', |
| 137 | + description: 'Set the level of a direct input on a matrix', |
| 138 | + options: [GetDropdown('Selection', 'sel', state.namedChoices.matrices), ...GetFaderInputField('level')], |
| 139 | + callback: async (event) => { |
| 140 | + const cmd = Commands.DirectInputLevel(getNodeNumber(event, 'sel')) |
| 141 | + runTransition(cmd, 'level', event, state, transitions) |
| 142 | + }, |
| 143 | + subscribe: (event) => { |
| 144 | + ensureLoaded(Commands.DirectInputLevel(getNodeNumber(event, 'sel'))) |
| 145 | + }, |
| 146 | + }, |
| 147 | + [MatrixActions.MatrixDirectInStoreFader]: { |
| 148 | + name: 'Store Direct Input Level', |
| 149 | + description: 'Store the fader level of a direct input on a matrix', |
| 150 | + options: [GetDropdown('Selection', 'sel', state.namedChoices.matrices)], |
| 151 | + callback: async (event) => { |
| 152 | + const cmd = Commands.DirectInputLevel(getNodeNumber(event, 'sel')) |
| 153 | + StateUtil.storeValueForCommand(cmd, state) |
| 154 | + }, |
| 155 | + subscribe: (event) => { |
| 156 | + ensureLoaded(Commands.DirectInputLevel(getNodeNumber(event, 'sel'))) |
| 157 | + }, |
| 158 | + }, |
| 159 | + } |
| 160 | + return actions |
| 161 | +} |
0 commit comments