diff --git a/libs/surfaces/websockets/state.h b/libs/surfaces/websockets/state.h index 7f34155e19..eecaf16dc3 100644 --- a/libs/surfaces/websockets/state.h +++ b/libs/surfaces/websockets/state.h @@ -31,10 +31,6 @@ namespace Node { - const std::string transport_tempo = "transport_tempo"; - const std::string transport_time = "transport_time"; - const std::string transport_roll = "transport_roll"; - const std::string transport_record = "transport_record"; const std::string strip_description = "strip_description"; const std::string strip_meter = "strip_meter"; const std::string strip_gain = "strip_gain"; @@ -44,6 +40,10 @@ namespace Node const std::string strip_plugin_enable = "strip_plugin_enable"; const std::string strip_plugin_param_description = "strip_plugin_param_description"; const std::string strip_plugin_param_value = "strip_plugin_param_value"; + const std::string transport_tempo = "transport_tempo"; + const std::string transport_time = "transport_time"; + const std::string transport_roll = "transport_roll"; + const std::string transport_record = "transport_record"; } // namespace Node typedef std::vector AddressVector; diff --git a/share/web_surfaces/shared/base/protocol.js b/share/web_surfaces/shared/base/protocol.js index cb6fac0342..d2d487c1cb 100644 --- a/share/web_surfaces/shared/base/protocol.js +++ b/share/web_surfaces/shared/base/protocol.js @@ -19,19 +19,19 @@ export const JSON_INF = 1.0e+128; export const StateNode = Object.freeze({ - STRIP_DESCRIPTION: 'strip_description', - STRIP_METER: 'strip_meter', - STRIP_GAIN: 'strip_gain', - STRIP_PAN: 'strip_pan', - STRIP_MUTE: 'strip_mute', - STRIP_PLUGIN_DESCRIPTION: 'strip_plugin_description', - STRIP_PLUGIN_ENABLE: 'strip_plugin_enable', - STRIP_PLUGIN_PARAM_DESCRIPTION: 'strip_plugin_param_description', - STRIP_PLUGIN_PARAM_VALUE: 'strip_plugin_param_value', - TRANSPORT_TEMPO: 'transport_tempo', - TRANSPORT_TIME: 'transport_time', - TRANSPORT_ROLL: 'transport_roll', - TRANSPORT_RECORD: 'transport_record' + STRIP_DESCRIPTION : 'strip_description', + STRIP_METER : 'strip_meter', + STRIP_GAIN : 'strip_gain', + STRIP_PAN : 'strip_pan', + STRIP_MUTE : 'strip_mute', + STRIP_PLUGIN_DESCRIPTION : 'strip_plugin_description', + STRIP_PLUGIN_ENABLE : 'strip_plugin_enable', + STRIP_PLUGIN_PARAM_DESCRIPTION : 'strip_plugin_param_description', + STRIP_PLUGIN_PARAM_VALUE : 'strip_plugin_param_value', + TRANSPORT_TEMPO : 'transport_tempo', + TRANSPORT_TIME : 'transport_time', + TRANSPORT_ROLL : 'transport_roll', + TRANSPORT_RECORD : 'transport_record' }); export class Message { @@ -41,13 +41,13 @@ export class Message { this.addr = addr; this.val = []; - for (const i in val) { - if (val[i] >= JSON_INF) { + for (const v of val) { + if (v >= JSON_INF) { this.val.push(Infinity); - } else if (val[i] <= -JSON_INF) { + } else if (v <= -JSON_INF) { this.val.push(-Infinity); } else { - this.val.push(val[i]); + this.val.push(v); } } } @@ -64,13 +64,13 @@ export class Message { toJsonText () { let val = []; - for (const i in this.val) { - if (this.val[i] == Infinity) { + for (const v of this.val) { + if (v == Infinity) { val.push(JSON_INF); - } else if (this.val[i] == -Infinity) { + } else if (v == -Infinity) { val.push(-JSON_INF); } else { - val.push(this.val[i]); + val.push(v); } } diff --git a/share/web_surfaces/shared/components/mixer.js b/share/web_surfaces/shared/components/mixer.js index f8fb8252a5..24dac3f1ba 100644 --- a/share/web_surfaces/shared/components/mixer.js +++ b/share/web_surfaces/shared/components/mixer.js @@ -46,20 +46,18 @@ export class Mixer extends RootComponent { if (node == StateNode.STRIP_DESCRIPTION) { this._strips[addr] = new Strip(this, addr, val); this.notifyObservers('strips'); + return true; } else { const stripAddr = [addr[0]]; if (stripAddr in this._strips) { - this._strips[stripAddr].handle(node, addr, val); - } else { - return false; + return this._strips[stripAddr].handle(node, addr, val); } } - - return true; } else { // all initial strip description messages have been received at this point if (!this._ready) { this.updateLocal('ready', true); + // passthrough by allowing to return false } } diff --git a/share/web_surfaces/shared/components/plugin.js b/share/web_surfaces/shared/components/plugin.js index fa9ae5e813..6e2d7f2ad7 100644 --- a/share/web_surfaces/shared/components/plugin.js +++ b/share/web_surfaces/shared/components/plugin.js @@ -54,13 +54,12 @@ export class Plugin extends AddressableComponent { if (node == StateNode.STRIP_PLUGIN_PARAM_DESCRIPTION) { this._parameters[addr] = new Parameter(this, addr, val); this.notifyObservers('parameters'); + return true; } else { if (addr in this._parameters) { - this._parameters[addr].handle(node, addr, val); + return this._parameters[addr].handle(node, addr, val); } } - - return true; } else if (node == StateNode.STRIP_PLUGIN_ENABLE) { this.updateLocal('enable', val[0]); return true; diff --git a/share/web_surfaces/shared/components/strip.js b/share/web_surfaces/shared/components/strip.js index 69ba3a8ad7..dee3ea6f19 100644 --- a/share/web_surfaces/shared/components/strip.js +++ b/share/web_surfaces/shared/components/strip.js @@ -20,6 +20,13 @@ import { AddressableComponent } from '../base/component.js'; import { Plugin } from './plugin.js'; import { StateNode } from '../base/protocol.js'; +const NodeToProperty = Object.freeze({ + [StateNode.STRIP_METER] : 'meter', + [StateNode.STRIP_GAIN] : 'gain', + [StateNode.STRIP_PAN] : 'pan', + [StateNode.STRIP_MUTE] : 'mute' +}); + export class Strip extends AddressableComponent { constructor (parent, addr, desc) { @@ -76,38 +83,18 @@ export class Strip extends AddressableComponent { handle (node, addr, val) { if (node.startsWith('strip_plugin')) { if (node == StateNode.STRIP_PLUGIN_DESCRIPTION) { - this._plugins[addr] = new Plugin(this, addr, val); this.notifyObservers('plugins'); + return true; } else { const pluginAddr = [addr[0], addr[1]]; if (pluginAddr in this._plugins) { - this._plugins[pluginAddr].handle(node, addr, val); - } else { - return false; + return this._plugins[pluginAddr].handle(node, addr, val); } } - - return true; - } else { - switch (node) { - case StateNode.STRIP_METER: - this.updateLocal('meter', val[0]); - break; - case StateNode.STRIP_GAIN: - this.updateLocal('gain', val[0]); - break; - case StateNode.STRIP_PAN: - this.updateLocal('pan', val[0]); - break; - case StateNode.STRIP_MUTE: - this.updateLocal('mute', val[0]); - break; - default: - return false; - } - - return true; + } else if (node in NodeToProperty) { + this.updateLocal(NodeToProperty[node], val[0]); + return true; } return false; diff --git a/share/web_surfaces/shared/components/transport.js b/share/web_surfaces/shared/components/transport.js index d583d2358e..9d6383cfc9 100644 --- a/share/web_surfaces/shared/components/transport.js +++ b/share/web_surfaces/shared/components/transport.js @@ -19,6 +19,13 @@ import { RootComponent } from '../base/component.js'; import { StateNode } from '../base/protocol.js'; +const NodeToProperty = Object.freeze({ + [StateNode.TRANSPORT_TEMPO] : 'tempo', + [StateNode.TRANSPORT_TIME] : 'time', + [StateNode.TRANSPORT_ROLL] : 'roll', + [StateNode.TRANSPORT_RECORD] : 'record' +}); + export class Transport extends RootComponent { constructor (channel) { @@ -58,24 +65,12 @@ export class Transport extends RootComponent { } handle (node, addr, val) { - switch (node) { - case StateNode.TRANSPORT_TEMPO: - this.updateLocal('tempo', val[0]); - break; - case StateNode.TRANSPORT_TIME: - this.updateLocal('time', val[0]); - break; - case StateNode.TRANSPORT_ROLL: - this.updateLocal('roll', val[0]); - break; - case StateNode.TRANSPORT_RECORD: - this.updateLocal('record', val[0]); - break; - default: - return false; + if (node in NodeToProperty) { + this.updateLocal(NodeToProperty[node], val[0]); + return true; } - return true; + return false; } }