2020-02-20 13:12:36 +01:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-06-14 12:10:30 +02:00
|
|
|
import ArdourClient from '/shared/ardour.js';
|
2020-04-11 17:49:34 +02:00
|
|
|
|
2020-04-11 17:43:39 +02:00
|
|
|
import { Switch, DiscreteSlider, ContinuousSlider, LogarithmicSlider,
|
|
|
|
|
StripPanSlider, StripGainSlider, StripMeter } from './widget.js';
|
|
|
|
|
|
2020-02-20 13:12:36 +01:00
|
|
|
(() => {
|
|
|
|
|
|
|
|
|
|
const MAX_LOG_LINES = 1000;
|
2020-04-09 16:34:16 +02:00
|
|
|
|
2020-05-29 11:37:34 +02:00
|
|
|
const ardour = new ArdourClient();
|
2020-04-11 17:49:34 +02:00
|
|
|
|
2020-06-14 12:34:27 +02:00
|
|
|
async function main () {
|
|
|
|
|
ardour.on('connected', (connected) => {
|
|
|
|
|
if (connected) {
|
|
|
|
|
log('Client connected', 'info');
|
|
|
|
|
} else {
|
|
|
|
|
log('Client disconnected', 'error');
|
2020-05-29 11:37:34 +02:00
|
|
|
}
|
2020-06-14 12:34:27 +02:00
|
|
|
});
|
2020-05-29 11:37:34 +02:00
|
|
|
|
2020-06-14 12:34:27 +02:00
|
|
|
ardour.on('message', (msg, inbound) => {
|
|
|
|
|
if (inbound) {
|
|
|
|
|
log(`↙ ${msg}`, 'message-in');
|
|
|
|
|
} else {
|
|
|
|
|
log(`↗ ${msg}`, 'message-out');
|
|
|
|
|
}
|
2020-04-13 11:05:33 +02:00
|
|
|
});
|
|
|
|
|
|
2020-05-29 11:37:34 +02:00
|
|
|
ardour.mixer.on('ready', () => {
|
|
|
|
|
const div = document.getElementById('strips');
|
|
|
|
|
for (const strip of ardour.mixer.strips) {
|
|
|
|
|
createStrip(strip, div);
|
|
|
|
|
}
|
2020-04-13 09:05:30 +02:00
|
|
|
});
|
2020-05-29 11:37:34 +02:00
|
|
|
|
2020-06-14 12:34:27 +02:00
|
|
|
await ardour.connect();
|
|
|
|
|
|
|
|
|
|
const manifest = await ardour.getSurfaceManifest();
|
|
|
|
|
document.getElementById('manifest').innerHTML = manifest.name.toUpperCase()
|
|
|
|
|
+ ' v' + manifest.version + ' — ' + manifest.description;
|
2020-04-11 17:49:34 +02:00
|
|
|
}
|
2020-04-11 17:43:39 +02:00
|
|
|
|
2020-05-29 11:37:34 +02:00
|
|
|
function createStrip (strip, parentDiv) {
|
|
|
|
|
const domId = `strip-${strip.addrId}`;
|
2020-04-14 22:58:44 +02:00
|
|
|
if (document.getElementById(domId) != null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-29 11:37:34 +02:00
|
|
|
const div = createElem(`<div class="strip" id="${domId}"></div>`, parentDiv);
|
|
|
|
|
createElem(`<label class="comp-name" for="${domId}">∿  ${strip.name}</label>`, div);
|
2020-02-20 13:12:36 +01:00
|
|
|
|
|
|
|
|
// meter
|
2020-04-14 22:58:44 +02:00
|
|
|
const meter = new StripMeter();
|
2020-02-20 13:12:36 +01:00
|
|
|
meter.el.classList.add('slider-meter');
|
2020-04-14 22:58:44 +02:00
|
|
|
meter.appendTo(div);
|
2020-05-29 11:37:34 +02:00
|
|
|
bind(strip, 'meter', meter);
|
2020-02-20 13:12:36 +01:00
|
|
|
|
|
|
|
|
// gain
|
|
|
|
|
let holder = createElem(`<div class="strip-slider"></div>`, div);
|
|
|
|
|
createElem(`<label>Gain</label>`, holder);
|
2020-04-14 22:58:44 +02:00
|
|
|
const gain = new StripGainSlider();
|
|
|
|
|
gain.appendTo(holder);
|
2020-05-29 11:37:34 +02:00
|
|
|
bind(strip, 'gain', gain);
|
2020-02-20 13:12:36 +01:00
|
|
|
|
2020-05-29 11:37:34 +02:00
|
|
|
if (!strip.isVca) {
|
2020-04-21 16:20:16 +02:00
|
|
|
// pan
|
|
|
|
|
holder = createElem(`<div class="strip-slider"></div>`, div);
|
|
|
|
|
createElem(`<label>Pan</label>`, holder);
|
|
|
|
|
const pan = new StripPanSlider();
|
|
|
|
|
pan.appendTo(holder);
|
2020-05-29 11:37:34 +02:00
|
|
|
bind(strip, 'pan', pan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const plugin of strip.plugins) {
|
|
|
|
|
createStripPlugin(plugin, div);
|
2020-04-21 16:20:16 +02:00
|
|
|
}
|
2020-02-20 13:12:36 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-29 11:37:34 +02:00
|
|
|
function createStripPlugin (plugin, parentDiv) {
|
|
|
|
|
const domId = `plugin-${plugin.addrId}`;
|
2020-04-14 22:58:44 +02:00
|
|
|
if (document.getElementById(domId) != null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-29 11:37:34 +02:00
|
|
|
const div = createElem(`<div class="plugin" id="${domId}"></div>`, parentDiv);
|
2020-02-20 13:12:36 +01:00
|
|
|
createElem(`<label class="comp-name">⨍  ${name}</label>`, div);
|
2020-04-14 22:58:44 +02:00
|
|
|
|
|
|
|
|
const enable = new Switch();
|
2020-02-20 13:12:36 +01:00
|
|
|
enable.el.classList.add('plugin-enable');
|
2020-04-14 22:58:44 +02:00
|
|
|
enable.appendTo(div);
|
2020-05-29 11:37:34 +02:00
|
|
|
bind(plugin, 'enable', enable);
|
|
|
|
|
|
|
|
|
|
for (const param of plugin.parameters) {
|
|
|
|
|
createStripPluginParam(param, div);
|
|
|
|
|
}
|
2020-02-20 13:12:36 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-29 11:37:34 +02:00
|
|
|
function createStripPluginParam (param, parentDiv) {
|
|
|
|
|
const domId = `param-${param.addrId}`;
|
2020-04-14 22:58:44 +02:00
|
|
|
if (document.getElementById(domId) != null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-29 11:37:34 +02:00
|
|
|
let widget, cssClass;
|
2020-04-14 09:53:25 +02:00
|
|
|
|
2020-05-29 11:37:34 +02:00
|
|
|
if (param.valueType.isBoolean) {
|
2020-04-14 09:53:25 +02:00
|
|
|
cssClass = 'boolean';
|
2020-05-29 11:37:34 +02:00
|
|
|
widget = new Switch();
|
|
|
|
|
} else if (param.valueType.isInteger) {
|
2020-04-14 09:53:25 +02:00
|
|
|
cssClass = 'discrete';
|
2020-05-29 11:37:34 +02:00
|
|
|
widget = new DiscreteSlider(param.min, param.max);
|
|
|
|
|
} else if (param.valueType.isDouble) {
|
2020-04-14 09:53:25 +02:00
|
|
|
cssClass = 'continuous';
|
2020-05-29 11:37:34 +02:00
|
|
|
if (param.isLog) {
|
|
|
|
|
widget = new LogarithmicSlider(param.min, param.max);
|
2020-02-20 13:12:36 +01:00
|
|
|
} else {
|
2020-05-29 11:37:34 +02:00
|
|
|
widget = new ContinuousSlider(param.min, param.max);
|
2020-02-20 13:12:36 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-29 11:37:34 +02:00
|
|
|
const div = createElem(`<div class="plugin-param ${cssClass}" id="${domId}"></div>`, parentDiv);
|
|
|
|
|
createElem(`<label for="${domId}">${param.name}</label>`, div);
|
2020-02-20 13:12:36 +01:00
|
|
|
|
2020-05-29 11:37:34 +02:00
|
|
|
widget.el.name = domId;
|
|
|
|
|
widget.appendTo(div);
|
|
|
|
|
bind(param, 'value', widget);
|
2020-02-20 13:12:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createElem (html, parent) {
|
|
|
|
|
const t = document.createElement('template');
|
|
|
|
|
t.innerHTML = html;
|
|
|
|
|
|
|
|
|
|
const elem = t.content.firstChild;
|
|
|
|
|
|
|
|
|
|
if (parent) {
|
|
|
|
|
parent.appendChild(elem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return elem;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-29 11:37:34 +02:00
|
|
|
function bind (component, property, widget) {
|
|
|
|
|
// ardour → ui
|
|
|
|
|
widget.value = component[property];
|
|
|
|
|
component.on(property, (value) => widget.value = value);
|
|
|
|
|
// ui → ardour
|
|
|
|
|
widget.callback = (value) => component[property] = value;
|
2020-02-20 13:12:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function log (message, className) {
|
|
|
|
|
const output = document.getElementById('log');
|
|
|
|
|
|
|
|
|
|
if (output.childElementCount > MAX_LOG_LINES) {
|
|
|
|
|
output.removeChild(output.childNodes[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const pre = document.createElement('pre');
|
|
|
|
|
pre.innerHTML = message;
|
|
|
|
|
pre.className = className;
|
|
|
|
|
|
|
|
|
|
output.appendChild(pre);
|
|
|
|
|
output.scrollTop = output.scrollHeight;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-29 11:37:34 +02:00
|
|
|
main();
|
|
|
|
|
|
2020-02-20 13:12:36 +01:00
|
|
|
})();
|