From 7715d8deefc9ed96ec73f483c5a3190b87e6461c Mon Sep 17 00:00:00 2001 From: Janik Witzig Date: Sun, 13 Apr 2025 17:45:47 +0200 Subject: [PATCH] added previous and next scene number and name --- src/actions/common.ts | 8 -------- src/actions/matrix.ts | 1 - src/choices/eq.ts | 1 - src/index.ts | 19 +++++++++++++----- src/state/state.ts | 8 -------- src/variables.ts | 46 ++++++++++++++++++++++++++++++++++++------- 6 files changed, 53 insertions(+), 30 deletions(-) diff --git a/src/actions/common.ts b/src/actions/common.ts index 71e657b..66f1ce5 100644 --- a/src/actions/common.ts +++ b/src/actions/common.ts @@ -217,7 +217,6 @@ export function createCommonActions(self: InstanceBaseExt): Companio state.storeDelta(cmd, delta) if (targetValue != undefined) { targetValue += delta - console.log('targetValue', targetValue) ActionUtil.runTransition(cmd, 'gain', event, state, transitions, targetValue) } }, @@ -338,7 +337,6 @@ export function createCommonActions(self: InstanceBaseExt): Companio state.storeDelta(cmd, delta) if (targetValue != undefined) { targetValue += delta - console.log('targetValue', targetValue) ActionUtil.runTransition(cmd, 'level', event, state, transitions, targetValue) } }, @@ -430,7 +428,6 @@ export function createCommonActions(self: InstanceBaseExt): Companio state.storeDelta(cmd, delta) if (targetValue != undefined) { targetValue += delta - console.log('targetValue', targetValue) ActionUtil.runTransition(cmd, 'pan', event, state, transitions, targetValue) } }, @@ -553,7 +550,6 @@ export function createCommonActions(self: InstanceBaseExt): Companio default: 0, range: true, isVisible: (options) => { - console.log('options: ', options) return (options.mode as string) === 'M' }, }, @@ -727,7 +723,6 @@ export function createCommonActions(self: InstanceBaseExt): Companio state.storeDelta(cmd, delta) if (targetValue != undefined) { targetValue += delta - console.log('targetValue', targetValue) ActionUtil.runTransition(cmd, 'level', event, state, transitions, targetValue) } }, @@ -855,7 +850,6 @@ export function createCommonActions(self: InstanceBaseExt): Companio state.storeDelta(cmd, delta) if (targetValue != undefined) { targetValue += delta - console.log('targetValue', targetValue) ActionUtil.runTransition(cmd, 'pan', event, state, transitions, targetValue) } }, @@ -981,7 +975,6 @@ export function createCommonActions(self: InstanceBaseExt): Companio state.storeDelta(cmd, delta) if (targetValue != undefined) { targetValue += delta - console.log('targetValue', targetValue) ActionUtil.runTransition(cmd, 'level', event, state, transitions, targetValue) } }, @@ -1003,7 +996,6 @@ export function createCommonActions(self: InstanceBaseExt): Companio const src = event.options.src as string const cmd = ActionUtil.getMainSendLevelCommand(src, getNodeNumber(event, 'src'), getNodeNumber(event, 'dest')) let targetValue = StateUtil.getNumberFromState(cmd, state) - console.log(targetValue) const delta = state.restoreDelta(cmd) if (targetValue != undefined) { targetValue -= delta diff --git a/src/actions/matrix.ts b/src/actions/matrix.ts index 97f6d1d..6417856 100644 --- a/src/actions/matrix.ts +++ b/src/actions/matrix.ts @@ -94,7 +94,6 @@ export function createMatrixActions(self: InstanceBaseExt): Companio state.storeDelta(cmd, delta) if (targetValue != undefined) { targetValue += delta - console.log('targetValue', targetValue) ActionUtil.runTransition(cmd, 'level', event, state, transitions, targetValue) } }, diff --git a/src/choices/eq.ts b/src/choices/eq.ts index ceaf3b4..0971843 100644 --- a/src/choices/eq.ts +++ b/src/choices/eq.ts @@ -52,7 +52,6 @@ export function EqParameterDropdown(id: string, modelId: string, bus?: boolean): choices: StdEqBandChoices(bus), default: 'l', isVisible: (opt) => { - // console.log(opt[modelId]?.toString()) return opt[modelId]?.toString() != 'STD' }, }, diff --git a/src/index.ts b/src/index.ts index ba5d2a0..3cef0aa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,7 +8,11 @@ import { import PQueue from 'p-queue' import { InstanceBaseExt } from './types.js' import { GetConfigFields, WingConfig } from './config.js' -import { UpdateVariables as UpdateAllVariables, UpdateVariableDefinitions } from './variables.js' +import { + UpdateVariables as UpdateAllVariables, + UpdateShowControlVariables, + UpdateVariableDefinitions, +} from './variables.js' import { UpgradeScripts } from './upgrades.js' import { createActions } from './actions/index.js' import { FeedbackId, GetFeedbacksList } from './feedbacks.js' @@ -27,6 +31,7 @@ export class WingInstance extends InstanceBase implements InstanceBa model: ModelSpec osc: osc.UDPPort subscriptions: WingSubscriptions + connected: boolean = false private heartbeatTimer: NodeJS.Timeout | undefined private reconnectTimer: NodeJS.Timeout | undefined @@ -211,6 +216,7 @@ export class WingInstance extends InstanceBase implements InstanceBa }) this.osc.on('error', (err: Error): void => { + this.connected = false this.log('error', `Error: ${err.message}`) this.updateStatus(InstanceStatus.ConnectionFailure, err.message) @@ -268,13 +274,16 @@ export class WingInstance extends InstanceBase implements InstanceBa }) this.osc.on('message', (message): void => { - this.updateStatus(InstanceStatus.Ok) + if (this.connected == false) { + this.updateStatus(InstanceStatus.Ok) + this.connected = true + } const args = message.args as osc.MetaArgument[] - // this.log('debug', `Received ${JSON.stringify(message)}`) + this.log('debug', `Received ${JSON.stringify(message)}`) this.state.set(message.address, args) if (this.inFlightRequests[message.address]) { - // this.log('debug', `Received answer for request ${message.address}`) + this.log('debug', `Received answer for request ${message.address}`) this.inFlightRequests[message.address]() delete this.inFlightRequests[message.address] } @@ -328,11 +337,11 @@ export class WingInstance extends InstanceBase implements InstanceBa if (libRe.test(msg.address)) { const content = String(args[0]?.value ?? '') const scenes = content.match(/\$scenes\s+list\s+\[([^\]]+)\]/) - console.log(scenes) if (scenes) { const sceneList = scenes[1].split(',').map((s) => s.trim()) this.state.namedChoices.scenes = sceneList.map((s) => ({ id: s, label: s })) this.state.sceneNameToIdMap = new Map(sceneList.map((s, i) => [s, i + 1])) + UpdateShowControlVariables(this) } } } diff --git a/src/state/state.ts b/src/state/state.ts index 5e66c9a..fd79ed2 100644 --- a/src/state/state.ts +++ b/src/state/state.ts @@ -86,7 +86,6 @@ export class WingState implements IStoredChannelSubject { } public get(path: string): osc.MetaArgument[] | undefined { - // console.log(`Getting ${path}`) return this.data.get(path) } public set(path: string, data: osc.MetaArgument[]): void { @@ -94,14 +93,7 @@ export class WingState implements IStoredChannelSubject { if (data[0].value == '-oo') { data[0] = { type: 'f', value: -140 } } - // if (data[0].type == 's') { - // const strAsNum = Number(data[0].value) - // console.log(`Setting ${key} to ${strAsNum}`) - // if (strAsNum != undefined) data[0] = { type: 'f', value: strAsNum } - // } - this.data.set(key, data) - // console.log(`Setting ${key}`) } public setPressValue(path: string, value: number): void { diff --git a/src/variables.ts b/src/variables.ts index 7318f03..c8731af 100644 --- a/src/variables.ts +++ b/src/variables.ts @@ -5,7 +5,6 @@ import { ControlCommands } from './commands/control.js' export function UpdateVariableDefinitions(self: WingInstance): void { const model = self.model - // const state = self.state const variables = [] @@ -259,8 +258,12 @@ export function UpdateVariableDefinitions(self: WingInstance): void { } variables.push({ variableId: 'active_show_name', name: 'Active Show Name' }) + variables.push({ variableId: 'previous_scene_number', name: 'Previous Scene Number' }) variables.push({ variableId: 'active_scene_number', name: 'Active Scene Number' }) + variables.push({ variableId: 'next_scene_number', name: 'Next Scene Number' }) + variables.push({ variableId: 'previous_scene_name', name: 'Previous Scene Name' }) variables.push({ variableId: 'active_scene_name', name: 'Active Scene Name' }) + variables.push({ variableId: 'next_scene_name', name: 'Next Scene Name' }) variables.push({ variableId: 'active_scene_folder', name: 'Active Scene Folder' }) self.setVariableDefinitions(variables) @@ -271,8 +274,7 @@ export function UpdateVariables(self: WingInstance, msgs: OscMessage[]): void { const path = msg.address const args = msg.args as OSCMetaArgument[] - // console.log('Updating variable:', path, args) - + self.log('debug', `'Updating variable:', ${path}, ${JSON.stringify(args)}`) UpdateNameVariables(self, path, args[0]?.value as string) UpdateMuteVariables(self, path, args[0]?.value as number) UpdateFaderVariables(self, path, args[0]?.value as number) @@ -323,7 +325,6 @@ function UpdateMuteVariables(self: WingInstance, path: string, value: number): v if (dest == null) { const varName = `${source}${srcnum}_mute` self.setVariableValues({ [varName]: value }) - console.log(varName) } else { if (dest === 'send') { dest = 'bus' @@ -332,7 +333,6 @@ function UpdateMuteVariables(self: WingInstance, path: string, value: number): v } const varName = `${source}${srcnum}_${dest}${destnum}_mute` self.setVariableValues({ [varName]: value }) - console.log(varName) } } @@ -538,8 +538,11 @@ function UpdateControlVariables(self: WingInstance, path: string, args: OSCMetaA const showname = showMatch?.[1] ?? 'N/A' self.setVariableValues({ active_show_name: showname }) } else if (command === '$actidx') { - const index = args.value as number - self.setVariableValues({ active_scene_number: index }) + const index = Number(args.value) + self.setVariableValues({ + active_scene_number: index, + }) + UpdateShowControlVariables(self) } else if (command === '$active') { const fullScenePath = String(args.value) const sceneMatch = fullScenePath.match(/([^/\\]+)[/\\]([^/\\]+)\..*$/) @@ -554,3 +557,32 @@ function UpdateControlVariables(self: WingInstance, path: string, args: OSCMetaA self.sendCommand(ControlCommands.LibraryNode(), '?') } } + +export function UpdateShowControlVariables(self: WingInstance): void { + const index = Number(self.getVariableValue('active_scene_number')) + const nameMap = self.state.sceneNameToIdMap + + const previous_number = index > 0 ? index - 1 : index + const next_number = index < nameMap.size - 1 ? index + 1 : index + self.setVariableValues({ + previous_scene_number: previous_number, + active_scene_number: index, + next_scene_number: next_number, + }) + + function getKeyByValue(map: Map, value: number): string | undefined { + for (const [key, val] of map.entries()) { + if (val === value) return key + } + return undefined + } + + const nextName = getKeyByValue(nameMap, index + 1) + const currentName = getKeyByValue(nameMap, index) + const prevName = getKeyByValue(nameMap, index - 1) + self.setVariableValues({ + previous_scene_name: prevName as string, + active_scene_name: currentName as string, + next_scene_name: nextName as string, + }) +}