mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-18 04:36:30 +01:00
WebSockets: make mixer-demo use ardour lib and remove duplicated code
This commit is contained in:
parent
40a03e4cf5
commit
ece0bcde8b
4 changed files with 21 additions and 94 deletions
|
|
@ -11,8 +11,6 @@
|
||||||
<div id="strips"></div>
|
<div id="strips"></div>
|
||||||
<div id="log"></div>
|
<div id="log"></div>
|
||||||
</div>
|
</div>
|
||||||
<script src="js/connection.js"></script>
|
<script type="module" src="js/main.js"></script>
|
||||||
<script src="js/widget.js"></script>
|
|
||||||
<script src="js/main.js"></script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -1,77 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2020 Luciano Iam <lucianito@gmail.com>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const JSON_INF = 1.0e+128;
|
|
||||||
|
|
||||||
class Connection {
|
|
||||||
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/URL/host
|
|
||||||
|
|
||||||
constructor (host) {
|
|
||||||
this.socket = new WebSocket(`ws://${host}`);
|
|
||||||
this.socket.onopen = () => this.openCallback();
|
|
||||||
this.socket.onclose = () => this.closeCallback();
|
|
||||||
this.socket.onerror = (error) => this.errorCallback(error);
|
|
||||||
this.socket.onmessage = (event) => this._onMessage(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
openCallback () {
|
|
||||||
// empty
|
|
||||||
}
|
|
||||||
|
|
||||||
closeCallback () {
|
|
||||||
// empty
|
|
||||||
}
|
|
||||||
|
|
||||||
errorCallback (error) {
|
|
||||||
// empty
|
|
||||||
}
|
|
||||||
|
|
||||||
messageCallback (node, addr, val) {
|
|
||||||
// empty
|
|
||||||
}
|
|
||||||
|
|
||||||
send (node, addr, val) {
|
|
||||||
for (const i in val) {
|
|
||||||
if (val[i] == Infinity) {
|
|
||||||
val[i] = JSON_INF;
|
|
||||||
} else if (val[i] == -Infinity) {
|
|
||||||
val[i] = -JSON_INF;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const json = JSON.stringify({node: node, addr: addr, val: val});
|
|
||||||
|
|
||||||
this.socket.send(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
_onMessage (event) {
|
|
||||||
const msg = JSON.parse(event.data);
|
|
||||||
|
|
||||||
for (const i in msg.val) {
|
|
||||||
if (msg.val[i] >= JSON_INF) {
|
|
||||||
msg.val[i] = Infinity;
|
|
||||||
} else if (msg.val[i] <= -JSON_INF) {
|
|
||||||
msg.val[i] = -Infinity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.messageCallback(msg.node, msg.addr || [], msg.val);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -16,16 +16,20 @@
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { Channel } from '/shared/channel.js';
|
||||||
|
import { Switch, DiscreteSlider, ContinuousSlider, LogarithmicSlider,
|
||||||
|
StripPanSlider, StripGainSlider, StripMeter } from './widget.js';
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
|
|
||||||
const MAX_LOG_LINES = 1000;
|
const MAX_LOG_LINES = 1000;
|
||||||
const FEEDBACK_NODES = ['strip_gain', 'strip_pan', 'strip_meter', 'strip_plugin_enable',
|
const FEEDBACK_NODES = ['strip_gain', 'strip_pan', 'strip_meter', 'strip_plugin_enable',
|
||||||
'strip_plugin_param_value'];
|
'strip_plugin_param_value'];
|
||||||
|
|
||||||
const conn = new Connection(location.host);
|
const channel = new Channel(location.host);
|
||||||
const widgets = {};
|
const widgets = {};
|
||||||
|
|
||||||
conn.messageCallback = (node, addr, val) => {
|
channel.messageCallback = (node, addr, val) => {
|
||||||
log(`↙ ${node} (${addr}) = ${val}`, 'message-in');
|
log(`↙ ${node} (${addr}) = ${val}`, 'message-in');
|
||||||
|
|
||||||
if (node == 'strip_desc') {
|
if (node == 'strip_desc') {
|
||||||
|
|
@ -41,14 +45,16 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
conn.closeCallback = () => {
|
channel.closeCallback = () => {
|
||||||
log('Connection dropped', 'error');
|
log('Connection dropped', 'error');
|
||||||
};
|
};
|
||||||
|
|
||||||
conn.errorCallback = () => {
|
channel.errorCallback = () => {
|
||||||
log('Connection error', 'error');
|
log('Connection error', 'error');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
channel.open();
|
||||||
|
|
||||||
function createStrip (addr, name) {
|
function createStrip (addr, name) {
|
||||||
const id = `strip-${addr[0]}`;
|
const id = `strip-${addr[0]}`;
|
||||||
const strips = document.getElementById('strips');
|
const strips = document.getElementById('strips');
|
||||||
|
|
@ -118,7 +124,7 @@
|
||||||
function send (widget) {
|
function send (widget) {
|
||||||
const val = widget.value;
|
const val = widget.value;
|
||||||
log(`↗ ${widget.node} (${widget.addr}) = ${val}`, 'message-out');
|
log(`↗ ${widget.node} (${widget.addr}) = ${val}`, 'message-out');
|
||||||
conn.send(widget.node, widget.addr, [val]);
|
channel.send(widget.node, widget.addr, [val]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createElem (html, parent) {
|
function createElem (html, parent) {
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Widget {
|
export class Widget {
|
||||||
|
|
||||||
constructor (node, addr, html) {
|
constructor (node, addr, html) {
|
||||||
this.node = node;
|
this.node = node;
|
||||||
|
|
@ -44,7 +44,7 @@ class Widget {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Switch extends Widget {
|
export class Switch extends Widget {
|
||||||
|
|
||||||
constructor (node, addr) {
|
constructor (node, addr) {
|
||||||
super (node, addr, `<input type="checkbox" class="widget-switch">`);
|
super (node, addr, `<input type="checkbox" class="widget-switch">`);
|
||||||
|
|
@ -61,7 +61,7 @@ class Switch extends Widget {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Slider extends Widget {
|
export class Slider extends Widget {
|
||||||
|
|
||||||
constructor (node, addr, min, max, step) {
|
constructor (node, addr, min, max, step) {
|
||||||
const html = `<input type="range" class="widget-slider"
|
const html = `<input type="range" class="widget-slider"
|
||||||
|
|
@ -82,7 +82,7 @@ class Slider extends Widget {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class DiscreteSlider extends Slider {
|
export class DiscreteSlider extends Slider {
|
||||||
|
|
||||||
constructor (node, addr, min, max) {
|
constructor (node, addr, min, max) {
|
||||||
super(node, addr, min, max, 1);
|
super(node, addr, min, max, 1);
|
||||||
|
|
@ -90,7 +90,7 @@ class DiscreteSlider extends Slider {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ContinuousSlider extends Slider {
|
export class ContinuousSlider extends Slider {
|
||||||
|
|
||||||
constructor (node, addr, min, max) {
|
constructor (node, addr, min, max) {
|
||||||
super(node, addr, min, max, 0.001);
|
super(node, addr, min, max, 0.001);
|
||||||
|
|
@ -98,7 +98,7 @@ class ContinuousSlider extends Slider {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class LogarithmicSlider extends ContinuousSlider {
|
export class LogarithmicSlider extends ContinuousSlider {
|
||||||
|
|
||||||
constructor (node, addr, min, max) {
|
constructor (node, addr, min, max) {
|
||||||
super(node, addr, 0, 1.0);
|
super(node, addr, 0, 1.0);
|
||||||
|
|
@ -117,7 +117,7 @@ class LogarithmicSlider extends ContinuousSlider {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class StripPanSlider extends ContinuousSlider {
|
export class StripPanSlider extends ContinuousSlider {
|
||||||
|
|
||||||
constructor (node, addr) {
|
constructor (node, addr) {
|
||||||
super(node, addr, -1.0, 1.0);
|
super(node, addr, -1.0, 1.0);
|
||||||
|
|
@ -125,7 +125,7 @@ class StripPanSlider extends ContinuousSlider {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class StripGainSlider extends ContinuousSlider {
|
export class StripGainSlider extends ContinuousSlider {
|
||||||
|
|
||||||
constructor (node, addr) {
|
constructor (node, addr) {
|
||||||
super(node, addr, 0, 1.0)
|
super(node, addr, 0, 1.0)
|
||||||
|
|
@ -144,7 +144,7 @@ class StripGainSlider extends ContinuousSlider {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class StripMeter extends Widget {
|
export class StripMeter extends Widget {
|
||||||
|
|
||||||
constructor (node, addr) {
|
constructor (node, addr) {
|
||||||
super(node, addr, `<label></label>`);
|
super(node, addr, `<label></label>`);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue