Skip to content

Add previous and next scene name to variable #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: feature/companion-v3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/actions/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ export function createCommonActions(self: InstanceBaseExt<WingConfig>): Companio
state.storeDelta(cmd, delta)
if (targetValue != undefined) {
targetValue += delta
console.log('targetValue', targetValue)
ActionUtil.runTransition(cmd, 'gain', event, state, transitions, targetValue)
}
},
Expand Down Expand Up @@ -338,7 +337,6 @@ export function createCommonActions(self: InstanceBaseExt<WingConfig>): Companio
state.storeDelta(cmd, delta)
if (targetValue != undefined) {
targetValue += delta
console.log('targetValue', targetValue)
ActionUtil.runTransition(cmd, 'level', event, state, transitions, targetValue)
}
},
Expand Down Expand Up @@ -430,7 +428,6 @@ export function createCommonActions(self: InstanceBaseExt<WingConfig>): Companio
state.storeDelta(cmd, delta)
if (targetValue != undefined) {
targetValue += delta
console.log('targetValue', targetValue)
ActionUtil.runTransition(cmd, 'pan', event, state, transitions, targetValue)
}
},
Expand Down Expand Up @@ -553,7 +550,6 @@ export function createCommonActions(self: InstanceBaseExt<WingConfig>): Companio
default: 0,
range: true,
isVisible: (options) => {
console.log('options: ', options)
return (options.mode as string) === 'M'
},
},
Expand Down Expand Up @@ -727,7 +723,6 @@ export function createCommonActions(self: InstanceBaseExt<WingConfig>): Companio
state.storeDelta(cmd, delta)
if (targetValue != undefined) {
targetValue += delta
console.log('targetValue', targetValue)
ActionUtil.runTransition(cmd, 'level', event, state, transitions, targetValue)
}
},
Expand Down Expand Up @@ -855,7 +850,6 @@ export function createCommonActions(self: InstanceBaseExt<WingConfig>): Companio
state.storeDelta(cmd, delta)
if (targetValue != undefined) {
targetValue += delta
console.log('targetValue', targetValue)
ActionUtil.runTransition(cmd, 'pan', event, state, transitions, targetValue)
}
},
Expand Down Expand Up @@ -981,7 +975,6 @@ export function createCommonActions(self: InstanceBaseExt<WingConfig>): Companio
state.storeDelta(cmd, delta)
if (targetValue != undefined) {
targetValue += delta
console.log('targetValue', targetValue)
ActionUtil.runTransition(cmd, 'level', event, state, transitions, targetValue)
}
},
Expand All @@ -1003,7 +996,6 @@ export function createCommonActions(self: InstanceBaseExt<WingConfig>): 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
Expand Down
1 change: 0 additions & 1 deletion src/actions/matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ export function createMatrixActions(self: InstanceBaseExt<WingConfig>): Companio
state.storeDelta(cmd, delta)
if (targetValue != undefined) {
targetValue += delta
console.log('targetValue', targetValue)
ActionUtil.runTransition(cmd, 'level', event, state, transitions, targetValue)
}
},
Expand Down
1 change: 0 additions & 1 deletion src/choices/eq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
},
Expand Down
19 changes: 14 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -27,6 +31,7 @@ export class WingInstance extends InstanceBase<WingConfig> implements InstanceBa
model: ModelSpec
osc: osc.UDPPort
subscriptions: WingSubscriptions
connected: boolean = false

private heartbeatTimer: NodeJS.Timeout | undefined
private reconnectTimer: NodeJS.Timeout | undefined
Expand Down Expand Up @@ -211,6 +216,7 @@ export class WingInstance extends InstanceBase<WingConfig> implements InstanceBa
})

this.osc.on('error', (err: Error): void => {
this.connected = false
this.log('error', `Error: ${err.message}`)
this.updateStatus(InstanceStatus.ConnectionFailure, err.message)

Expand Down Expand Up @@ -268,13 +274,16 @@ export class WingInstance extends InstanceBase<WingConfig> 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]
}
Expand Down Expand Up @@ -328,11 +337,11 @@ export class WingInstance extends InstanceBase<WingConfig> 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)
}
}
}
Expand Down
8 changes: 0 additions & 8 deletions src/state/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,14 @@ 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 {
const key = path
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 {
Expand Down
46 changes: 39 additions & 7 deletions src/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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'
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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(/([^/\\]+)[/\\]([^/\\]+)\..*$/)
Expand All @@ -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<string, number>, 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,
})
}