mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-08 15:54:57 +01:00
WebSockets: improve JS client message handling code
This commit is contained in:
parent
176d803a55
commit
8ff4bcfd68
6 changed files with 53 additions and 74 deletions
|
|
@ -31,10 +31,6 @@
|
||||||
|
|
||||||
namespace Node
|
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_description = "strip_description";
|
||||||
const std::string strip_meter = "strip_meter";
|
const std::string strip_meter = "strip_meter";
|
||||||
const std::string strip_gain = "strip_gain";
|
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_enable = "strip_plugin_enable";
|
||||||
const std::string strip_plugin_param_description = "strip_plugin_param_description";
|
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 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
|
} // namespace Node
|
||||||
|
|
||||||
typedef std::vector<uint32_t> AddressVector;
|
typedef std::vector<uint32_t> AddressVector;
|
||||||
|
|
|
||||||
|
|
@ -19,19 +19,19 @@
|
||||||
export const JSON_INF = 1.0e+128;
|
export const JSON_INF = 1.0e+128;
|
||||||
|
|
||||||
export const StateNode = Object.freeze({
|
export const StateNode = Object.freeze({
|
||||||
STRIP_DESCRIPTION: 'strip_description',
|
STRIP_DESCRIPTION : 'strip_description',
|
||||||
STRIP_METER: 'strip_meter',
|
STRIP_METER : 'strip_meter',
|
||||||
STRIP_GAIN: 'strip_gain',
|
STRIP_GAIN : 'strip_gain',
|
||||||
STRIP_PAN: 'strip_pan',
|
STRIP_PAN : 'strip_pan',
|
||||||
STRIP_MUTE: 'strip_mute',
|
STRIP_MUTE : 'strip_mute',
|
||||||
STRIP_PLUGIN_DESCRIPTION: 'strip_plugin_description',
|
STRIP_PLUGIN_DESCRIPTION : 'strip_plugin_description',
|
||||||
STRIP_PLUGIN_ENABLE: 'strip_plugin_enable',
|
STRIP_PLUGIN_ENABLE : 'strip_plugin_enable',
|
||||||
STRIP_PLUGIN_PARAM_DESCRIPTION: 'strip_plugin_param_description',
|
STRIP_PLUGIN_PARAM_DESCRIPTION : 'strip_plugin_param_description',
|
||||||
STRIP_PLUGIN_PARAM_VALUE: 'strip_plugin_param_value',
|
STRIP_PLUGIN_PARAM_VALUE : 'strip_plugin_param_value',
|
||||||
TRANSPORT_TEMPO: 'transport_tempo',
|
TRANSPORT_TEMPO : 'transport_tempo',
|
||||||
TRANSPORT_TIME: 'transport_time',
|
TRANSPORT_TIME : 'transport_time',
|
||||||
TRANSPORT_ROLL: 'transport_roll',
|
TRANSPORT_ROLL : 'transport_roll',
|
||||||
TRANSPORT_RECORD: 'transport_record'
|
TRANSPORT_RECORD : 'transport_record'
|
||||||
});
|
});
|
||||||
|
|
||||||
export class Message {
|
export class Message {
|
||||||
|
|
@ -41,13 +41,13 @@ export class Message {
|
||||||
this.addr = addr;
|
this.addr = addr;
|
||||||
this.val = [];
|
this.val = [];
|
||||||
|
|
||||||
for (const i in val) {
|
for (const v of val) {
|
||||||
if (val[i] >= JSON_INF) {
|
if (v >= JSON_INF) {
|
||||||
this.val.push(Infinity);
|
this.val.push(Infinity);
|
||||||
} else if (val[i] <= -JSON_INF) {
|
} else if (v <= -JSON_INF) {
|
||||||
this.val.push(-Infinity);
|
this.val.push(-Infinity);
|
||||||
} else {
|
} else {
|
||||||
this.val.push(val[i]);
|
this.val.push(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -64,13 +64,13 @@ export class Message {
|
||||||
toJsonText () {
|
toJsonText () {
|
||||||
let val = [];
|
let val = [];
|
||||||
|
|
||||||
for (const i in this.val) {
|
for (const v of this.val) {
|
||||||
if (this.val[i] == Infinity) {
|
if (v == Infinity) {
|
||||||
val.push(JSON_INF);
|
val.push(JSON_INF);
|
||||||
} else if (this.val[i] == -Infinity) {
|
} else if (v == -Infinity) {
|
||||||
val.push(-JSON_INF);
|
val.push(-JSON_INF);
|
||||||
} else {
|
} else {
|
||||||
val.push(this.val[i]);
|
val.push(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,20 +46,18 @@ export class Mixer extends RootComponent {
|
||||||
if (node == StateNode.STRIP_DESCRIPTION) {
|
if (node == StateNode.STRIP_DESCRIPTION) {
|
||||||
this._strips[addr] = new Strip(this, addr, val);
|
this._strips[addr] = new Strip(this, addr, val);
|
||||||
this.notifyObservers('strips');
|
this.notifyObservers('strips');
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
const stripAddr = [addr[0]];
|
const stripAddr = [addr[0]];
|
||||||
if (stripAddr in this._strips) {
|
if (stripAddr in this._strips) {
|
||||||
this._strips[stripAddr].handle(node, addr, val);
|
return this._strips[stripAddr].handle(node, addr, val);
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
// all initial strip description messages have been received at this point
|
// all initial strip description messages have been received at this point
|
||||||
if (!this._ready) {
|
if (!this._ready) {
|
||||||
this.updateLocal('ready', true);
|
this.updateLocal('ready', true);
|
||||||
|
// passthrough by allowing to return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,13 +54,12 @@ export class Plugin extends AddressableComponent {
|
||||||
if (node == StateNode.STRIP_PLUGIN_PARAM_DESCRIPTION) {
|
if (node == StateNode.STRIP_PLUGIN_PARAM_DESCRIPTION) {
|
||||||
this._parameters[addr] = new Parameter(this, addr, val);
|
this._parameters[addr] = new Parameter(this, addr, val);
|
||||||
this.notifyObservers('parameters');
|
this.notifyObservers('parameters');
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if (addr in this._parameters) {
|
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) {
|
} else if (node == StateNode.STRIP_PLUGIN_ENABLE) {
|
||||||
this.updateLocal('enable', val[0]);
|
this.updateLocal('enable', val[0]);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,13 @@ import { AddressableComponent } from '../base/component.js';
|
||||||
import { Plugin } from './plugin.js';
|
import { Plugin } from './plugin.js';
|
||||||
import { StateNode } from '../base/protocol.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 {
|
export class Strip extends AddressableComponent {
|
||||||
|
|
||||||
constructor (parent, addr, desc) {
|
constructor (parent, addr, desc) {
|
||||||
|
|
@ -76,38 +83,18 @@ export class Strip extends AddressableComponent {
|
||||||
handle (node, addr, val) {
|
handle (node, addr, val) {
|
||||||
if (node.startsWith('strip_plugin')) {
|
if (node.startsWith('strip_plugin')) {
|
||||||
if (node == StateNode.STRIP_PLUGIN_DESCRIPTION) {
|
if (node == StateNode.STRIP_PLUGIN_DESCRIPTION) {
|
||||||
|
|
||||||
this._plugins[addr] = new Plugin(this, addr, val);
|
this._plugins[addr] = new Plugin(this, addr, val);
|
||||||
this.notifyObservers('plugins');
|
this.notifyObservers('plugins');
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
const pluginAddr = [addr[0], addr[1]];
|
const pluginAddr = [addr[0], addr[1]];
|
||||||
if (pluginAddr in this._plugins) {
|
if (pluginAddr in this._plugins) {
|
||||||
this._plugins[pluginAddr].handle(node, addr, val);
|
return this._plugins[pluginAddr].handle(node, addr, val);
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (node in NodeToProperty) {
|
||||||
return true;
|
this.updateLocal(NodeToProperty[node], val[0]);
|
||||||
} else {
|
return true;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,13 @@
|
||||||
import { RootComponent } from '../base/component.js';
|
import { RootComponent } from '../base/component.js';
|
||||||
import { StateNode } from '../base/protocol.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 {
|
export class Transport extends RootComponent {
|
||||||
|
|
||||||
constructor (channel) {
|
constructor (channel) {
|
||||||
|
|
@ -58,24 +65,12 @@ export class Transport extends RootComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
handle (node, addr, val) {
|
handle (node, addr, val) {
|
||||||
switch (node) {
|
if (node in NodeToProperty) {
|
||||||
case StateNode.TRANSPORT_TEMPO:
|
this.updateLocal(NodeToProperty[node], val[0]);
|
||||||
this.updateLocal('tempo', val[0]);
|
return true;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue