2020-02-20 07:12:36 -05: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-04-12 06:07:10 -04:00
|
|
|
import { nodeAddressHash } from '/shared/channel.js';
|
|
|
|
|
2020-04-11 11:43:39 -04:00
|
|
|
export class Widget {
|
2020-02-20 07:12:36 -05:00
|
|
|
|
|
|
|
constructor (node, addr, html) {
|
|
|
|
this.node = node;
|
|
|
|
this.addr = addr;
|
|
|
|
const template = document.createElement('template');
|
|
|
|
template.innerHTML = html;
|
|
|
|
this.el = template.content.firstChild;
|
|
|
|
}
|
|
|
|
|
|
|
|
attach (parent, callback) {
|
|
|
|
parent.appendChild(this.el);
|
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
this.callback = callback;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
callback (value) {
|
|
|
|
// do nothing by default
|
|
|
|
}
|
|
|
|
|
|
|
|
get hash () {
|
2020-04-12 06:07:10 -04:00
|
|
|
return nodeAddressHash(this.node, this.addr);
|
2020-02-20 07:12:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-11 11:43:39 -04:00
|
|
|
export class Switch extends Widget {
|
2020-02-20 07:12:36 -05:00
|
|
|
|
|
|
|
constructor (node, addr) {
|
|
|
|
super (node, addr, `<input type="checkbox" class="widget-switch">`);
|
|
|
|
this.el.addEventListener('input', (ev) => this.callback(this.value));
|
|
|
|
}
|
|
|
|
|
|
|
|
get value () {
|
|
|
|
return this.el.checked;
|
|
|
|
}
|
|
|
|
|
|
|
|
set value (val) {
|
|
|
|
this.el.checked = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-11 11:43:39 -04:00
|
|
|
export class Slider extends Widget {
|
2020-02-20 07:12:36 -05:00
|
|
|
|
|
|
|
constructor (node, addr, min, max, step) {
|
|
|
|
const html = `<input type="range" class="widget-slider"
|
|
|
|
min="${min}" max="${max}" step="${step}">`;
|
|
|
|
super(node, addr, html);
|
|
|
|
this.min = min;
|
|
|
|
this.max = max;
|
|
|
|
this.el.addEventListener('input', (ev) => this.callback(this.value));
|
|
|
|
}
|
|
|
|
|
|
|
|
get value () {
|
|
|
|
return parseFloat(this.el.value)
|
|
|
|
}
|
|
|
|
|
|
|
|
set value (val) {
|
|
|
|
this.el.value = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-11 11:43:39 -04:00
|
|
|
export class DiscreteSlider extends Slider {
|
2020-02-20 07:12:36 -05:00
|
|
|
|
|
|
|
constructor (node, addr, min, max) {
|
|
|
|
super(node, addr, min, max, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-11 11:43:39 -04:00
|
|
|
export class ContinuousSlider extends Slider {
|
2020-02-20 07:12:36 -05:00
|
|
|
|
|
|
|
constructor (node, addr, min, max) {
|
|
|
|
super(node, addr, min, max, 0.001);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-11 11:43:39 -04:00
|
|
|
export class LogarithmicSlider extends ContinuousSlider {
|
2020-02-20 07:12:36 -05:00
|
|
|
|
|
|
|
constructor (node, addr, min, max) {
|
|
|
|
super(node, addr, 0, 1.0);
|
|
|
|
this.minVal = Math.log(min);
|
|
|
|
this.maxVal = Math.log(max);
|
|
|
|
this.scale = this.maxVal - this.minVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
get value () {
|
|
|
|
return Math.exp(this.minVal + this.scale * super.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
set value (val) {
|
|
|
|
this.el.value = (Math.log(val) - this.minVal) / this.scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-11 11:43:39 -04:00
|
|
|
export class StripPanSlider extends ContinuousSlider {
|
2020-02-20 07:12:36 -05:00
|
|
|
|
|
|
|
constructor (node, addr) {
|
|
|
|
super(node, addr, -1.0, 1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-11 11:43:39 -04:00
|
|
|
export class StripGainSlider extends ContinuousSlider {
|
2020-02-20 07:12:36 -05:00
|
|
|
|
|
|
|
constructor (node, addr) {
|
|
|
|
super(node, addr, 0, 1.0)
|
|
|
|
this.minVal = -58.0;
|
|
|
|
this.maxVal = 6.0;
|
|
|
|
this.scale = (this.maxVal - this.minVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
get value () {
|
|
|
|
return this.maxVal + Math.log10(super.value) * this.scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
set value (val) {
|
|
|
|
this.el.value = Math.pow(10.0, (val - this.maxVal) / this.scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-11 11:43:39 -04:00
|
|
|
export class StripMeter extends Widget {
|
2020-02-20 07:12:36 -05:00
|
|
|
|
|
|
|
constructor (node, addr) {
|
|
|
|
super(node, addr, `<label></label>`);
|
|
|
|
}
|
|
|
|
|
|
|
|
set value (val) {
|
|
|
|
this.el.innerHTML = val == -Infinity ? '-∞' : `${Math.round(val)} dB`;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|