Skip to content

Commit

Permalink
feat: Implement a sceneRecalledTrigger variable whose value changes…
Browse files Browse the repository at this point in the history
… every time a scene is recalled, enabling it to be used in a scene-recalled trigger. (#69)
  • Loading branch information
jswalden committed Nov 18, 2024
1 parent 7154d4d commit 534ced5
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
16 changes: 16 additions & 0 deletions companion/HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ Controls the Allen & Heath SQ.
- Talkback macro
- Scene step increment

New in v.2.1.0

- Fix scene recalling if the mixer MIDI channel isn't 1
- Add Step +/-0.1dB choices for setting signal levels
- Permit setting signal levels between -85dB and -40dB
- Make assigning the LR mix to matrixes work correctly
- Allow setting the pan/balance of matrix 3 used as an output
- Add an action to make active/inactive an FX return in LR/mixes
- Define pan/balance variables on-demand as pan/balance change messages are sent by the mixer
- Restart module instances in response to configuration changes only if absolutely required
- Add a `sceneRecalledTrigger` variable whose value changes every time a scene is recalled, suitable for use in user-defined triggers

New in v.2.0.0 (not released)

- Convert to Companion v3 format

New in v.1.1.0

- Add listener for MIDI inbound data
Expand Down
6 changes: 4 additions & 2 deletions src/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getFeedbacks } from './feedbacks/feedbacks.js'
import { Mixer } from './mixer/mixer.js'
import { canUpdateOptionsWithoutRestarting, noConnectionOptions, optionsFromConfig } from './options.js'
import { getPresets } from './presets.js'
import { getVariables } from './variables.js'
import { CurrentSceneId, getVariables, SceneRecalledTriggerId } from './variables.js'

import api from './api.js'

Expand Down Expand Up @@ -97,10 +97,12 @@ export class sqInstance extends InstanceBase {
this.setVariableDefinitions(getVariables(this, model))

this.setVariableValues({
[SceneRecalledTriggerId]: 0,

// This value may very well be wrong, but there's no defined way to
// query what the current scene is, nor to be updated if it changes
// and this module didn't do it.
currentScene: 1,
[CurrentSceneId]: 1,
})
}

Expand Down
7 changes: 6 additions & 1 deletion src/midi/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { MixerMessageParser } from './parse/parse.js'
import { MidiTokenizer } from './tokenize/tokenize.js'
import { prettyByte, prettyBytes } from '../utils/pretty.js'
import { asyncSleep, sleep } from '../utils/sleep.js'
import { CurrentSceneId, SceneRecalledTriggerId } from '../variables.js'

/**
* The port number used for MIDI-over-TCP connections to SQ mixers.
Expand Down Expand Up @@ -147,10 +148,14 @@ export class MidiSession {
verboseLog(`Scene changed: ${newScene}`)

mixer.currentScene = newScene

const sceneRecalledTrigger = Number(instance.getVariableValue(SceneRecalledTriggerId)!)
instance.setVariableValues({
[SceneRecalledTriggerId]: sceneRecalledTrigger + 1,

// The currentScene variable is 1-indexed, consistent with how
// the current scene is displayed to users in mixer UI.
currentScene: newScene + 1,
[CurrentSceneId]: newScene + 1,
})
})
mixerChannelParser.on('mute', (msb: number, lsb: number, vf: number) => {
Expand Down
28 changes: 22 additions & 6 deletions src/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,29 @@ import type { CompanionVariableDefinition } from '@companion-module/base'
import type { SQInstanceInterface as sqInstance } from './instance-interface.js'
import type { Model } from './mixer/model.js'

export function getVariables(instance: sqInstance, model: Model): CompanionVariableDefinition[] {
const variables: CompanionVariableDefinition[] = []
/**
* The variable ID for the variable containing the last recalled scene
* (1-indexed).
*/
export const CurrentSceneId = 'currentScene'

/**
* The variable ID for the variable updated every time a scene is recalled
* intended for use in triggers.
*/
export const SceneRecalledTriggerId = 'sceneRecalledTrigger'

variables.push({
name: 'Scene - Current',
variableId: 'currentScene',
})
export function getVariables(instance: sqInstance, model: Model): CompanionVariableDefinition[] {
const variables: CompanionVariableDefinition[] = [
{
name: 'Scene - Scene Recalled',
variableId: SceneRecalledTriggerId,
},
{
name: 'Scene - Current',
variableId: CurrentSceneId,
},
]

model.forEachInputChannel((channel, channelLabel) => {
model.forEachMixAndLR((mix, _mixLabel, mixDesc) => {
Expand Down

0 comments on commit 534ced5

Please sign in to comment.