summaryrefslogtreecommitdiff
path: root/share/web_surfaces/shared
diff options
context:
space:
mode:
Diffstat (limited to 'share/web_surfaces/shared')
-rw-r--r--share/web_surfaces/shared/ardour.js55
-rw-r--r--share/web_surfaces/shared/callback.js28
-rw-r--r--share/web_surfaces/shared/control.js12
-rw-r--r--share/web_surfaces/shared/message.js24
4 files changed, 82 insertions, 37 deletions
diff --git a/share/web_surfaces/shared/ardour.js b/share/web_surfaces/shared/ardour.js
index a7e6978ba2..63a548e174 100644
--- a/share/web_surfaces/shared/ardour.js
+++ b/share/web_surfaces/shared/ardour.js
@@ -16,17 +16,19 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-import { MetadataMixin } from './metadata.js';
import { ControlMixin } from './control.js';
+import { MetadataMixin } from './metadata.js';
import { Message } from './message.js';
import { MessageChannel } from './channel.js';
-// See *Mixin for the available APIs
+// See ControlMixin and MetadataMixin for available APIs
+// See ArdourCallback for an example callback implementation
class BaseArdourClient {
constructor () {
this._callbacks = [];
+ this._connected = false;
this._pendingRequest = null;
this._channel = new MessageChannel(location.host);
@@ -39,21 +41,30 @@ class BaseArdourClient {
};
}
- addCallback (callback) {
- this._callbacks.push(callback);
+ addCallbacks (callbacks) {
+ this._callbacks.push(callbacks);
}
- async open () {
- this._channel.onClose = () => {
- this._fireCallbacks('error', new Error('Message channel unexpectedly closed'));
+ async connect (autoReconnect) {
+ this._channel.onClose = async () => {
+ if (this._connected) {
+ this._fireCallbacks('disconnected');
+ this._connected = false;
+ }
+
+ if ((autoReconnect == null) || autoReconnect) {
+ await this._sleep(1000);
+ await this._connect();
+ }
};
- await this._channel.open();
+ this._connect();
}
- close () {
+ disconnect () {
this._channel.onClose = () => {};
this._channel.close();
+ this._connected = false;
}
send (msg) {
@@ -61,6 +72,12 @@ class BaseArdourClient {
}
// Private methods
+
+ async _connect () {
+ await this._channel.open();
+ this._connected = true;
+ this._fireCallbacks('connected');
+ }
_send (node, addr, val) {
const msg = new Message(node, addr, val);
@@ -75,6 +92,10 @@ class BaseArdourClient {
});
}
+ async _sendRecvSingle (node, addr, val) {
+ return await this._sendAndReceive (node, addr, val)[0];
+ }
+
_onChannelMessage (msg) {
if (this._pendingRequest && (this._pendingRequest.hash == msg.hash)) {
this._pendingRequest.resolve(msg.val);
@@ -91,9 +112,9 @@ class BaseArdourClient {
return s[0].toUpperCase() + s.slice(1).toLowerCase();
}).join('');
- for (const callback of this._callbacks) {
- if (method in callback) {
- callback[method](...args)
+ for (const callbacks of this._callbacks) {
+ if (method in callbacks) {
+ callbacks[method](...args)
}
}
}
@@ -102,15 +123,19 @@ class BaseArdourClient {
return new Error(`HTTP response status ${status}`);
}
+ async _sleep (t) {
+ return new Promise(resolve => setTimeout(resolve, 1000));
+ }
+
}
export class ArdourClient extends mixin(BaseArdourClient, ControlMixin, MetadataMixin) {}
function mixin (dstClass, ...classes) {
for (const srcClass of classes) {
- for (const methName of Object.getOwnPropertyNames(srcClass.prototype)) {
- if (methName != 'constructor') {
- dstClass.prototype[methName] = srcClass.prototype[methName];
+ for (const propName of Object.getOwnPropertyNames(srcClass.prototype)) {
+ if (propName != 'constructor') {
+ dstClass.prototype[propName] = srcClass.prototype[propName];
}
}
}
diff --git a/share/web_surfaces/shared/callback.js b/share/web_surfaces/shared/callback.js
index a510b118cf..9da8b420d2 100644
--- a/share/web_surfaces/shared/callback.js
+++ b/share/web_surfaces/shared/callback.js
@@ -20,14 +20,34 @@
export class ArdourCallback {
+ // Connection status
+ onConnected () {}
+ onDisconnected () {}
+
+ // All messages and errors
+ onMessage (msg) {}
+ onError (error) {}
+
+ // Globals
onTempo (bpm) {}
+
+ // Strips
+ onStripDesc (stripId, name) {}
+ onStripMeter (stripId, db) {}
onStripGain (stripId, db) {}
onStripPan (stripId, value) {}
onStripMute (stripId, value) {}
+
+ // Strip plugins
+ onStripPluginDesc (stripId, pluginId, name) {}
onStripPluginEnable (stripId, pluginId, value) {}
- onStripPluginParamValue (stripId, pluginId, paramId, value) {}
- onMessage (msg) {}
- onError (error) {}
+ // Strip plugin parameters
+ // valueType
+ // 'b' : boolean
+ // 'i' : integer
+ // 'd' : double
+ onStripPluginParamDesc (stripId, pluginId, paramId, name, valueType, min, max, isLog) {}
+ onStripPluginParamValue (stripId, pluginId, paramId, value) {}
- }
+}
diff --git a/share/web_surfaces/shared/control.js b/share/web_surfaces/shared/control.js
index 19116bf4c7..94ffa0a83d 100644
--- a/share/web_surfaces/shared/control.js
+++ b/share/web_surfaces/shared/control.js
@@ -23,27 +23,27 @@ import { ANode } from './message.js';
export class ControlMixin {
async getTempo () {
- return (await this._sendAndReceive(ANode.TEMPO))[0];
+ return await this._sendRecvSingle(ANode.TEMPO);
}
async getStripGain (stripId) {
- return (await this._sendAndReceive(ANode.STRIP_GAIN, [stripId]))[0];
+ return await this._sendRecvSingle(ANode.STRIP_GAIN, [stripId]);
}
async getStripPan (stripId) {
- return (await this._sendAndReceive(ANode.STRIP_PAN, [stripId]))[0];
+ return await this._sendRecvSingle(ANode.STRIP_PAN, [stripId]);
}
async getStripMute (stripId) {
- return (await this._sendAndReceive(ANode.STRIP_MUTE, [stripId]))[0];
+ return await this._sendRecvSingle(ANode.STRIP_MUTE, [stripId]);
}
async getStripPluginEnable (stripId, pluginId) {
- return (await this._sendAndReceive(ANode.STRIP_PLUGIN_ENABLE, [stripId, pluginId]))[0];
+ return await this._sendRecvSingle(ANode.STRIP_PLUGIN_ENABLE, [stripId, pluginId]);
}
async getStripPluginParamValue (stripId, pluginId, paramId) {
- return (await this._sendAndReceive(ANode.STRIP_PLUGIN_PARAM_VALUE, [stripId, pluginId, paramId]))[0];
+ return await this._sendRecvSingle(ANode.STRIP_PLUGIN_PARAM_VALUE, [stripId, pluginId, paramId]);
}
setTempo (bpm) {
diff --git a/share/web_surfaces/shared/message.js b/share/web_surfaces/shared/message.js
index 6c81cd972f..0252c9fa63 100644
--- a/share/web_surfaces/shared/message.js
+++ b/share/web_surfaces/shared/message.js
@@ -19,15 +19,15 @@
export const JSON_INF = 1.0e+128;
export const ANode = Object.freeze({
- TEMPO: 'tempo',
- STRIP_DESC: 'strip_desc',
- STRIP_METER: 'strip_meter',
- STRIP_GAIN: 'strip_gain',
- STRIP_PAN: 'strip_pan',
- STRIP_MUTE: 'strip_mute',
- STRIP_PLUGIN_DESC: 'strip_plugin_desc',
- STRIP_PLUGIN_ENABLE: 'strip_plugin_enable',
- STRIP_PLUGIN_PARAM_DESC: 'strip_plugin_param_desc',
+ TEMPO: 'tempo',
+ STRIP_DESC: 'strip_desc',
+ STRIP_METER: 'strip_meter',
+ STRIP_GAIN: 'strip_gain',
+ STRIP_PAN: 'strip_pan',
+ STRIP_MUTE: 'strip_mute',
+ STRIP_PLUGIN_DESC: 'strip_plugin_desc',
+ STRIP_PLUGIN_ENABLE: 'strip_plugin_enable',
+ STRIP_PLUGIN_PARAM_DESC: 'strip_plugin_param_desc',
STRIP_PLUGIN_PARAM_VALUE: 'strip_plugin_param_value'
});
@@ -49,7 +49,7 @@ export class Message {
}
}
- static hash (node, addr) {
+ static nodeAddrId (node, addr) {
return [node].concat(addr || []).join('_');
}
@@ -74,8 +74,8 @@ export class Message {
return JSON.stringify({node: this.node, addr: this.addr, val: val});
}
- get hash () {
- return Message.hash(this.node, this.addr);
+ get nodeAddrId () {
+ return Message.nodeAddrId(this.node, this.addr);
}
toString () {