2020-06-21 17:29:27 -04:00
|
|
|
/*
|
|
|
|
* Copyright © 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import loadToolkit from './tkloader.js';
|
2020-08-16 09:03:17 -04:00
|
|
|
import { BaseWidget, BaseContainer, BaseDialog, BaseControl } from './widget.js';
|
|
|
|
|
|
|
|
export async function createRootContainer () {
|
|
|
|
await loadToolkit();
|
|
|
|
const root = new Container();
|
2020-07-25 11:45:39 -04:00
|
|
|
root.tk = new TK.Root({id: 'root'});
|
2020-08-16 09:03:17 -04:00
|
|
|
document.body.appendChild(root.element);
|
|
|
|
return root;
|
|
|
|
}
|
2020-07-25 11:45:39 -04:00
|
|
|
|
2020-09-05 07:12:04 -04:00
|
|
|
class TkWidget extends BaseWidget {
|
2020-07-25 11:45:39 -04:00
|
|
|
|
|
|
|
constructor (tk) {
|
|
|
|
super();
|
|
|
|
this.tk = tk;
|
|
|
|
}
|
|
|
|
|
|
|
|
get element () {
|
|
|
|
return this.tk.element;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-09-05 07:12:04 -04:00
|
|
|
class TkControl extends BaseControl {
|
2020-06-21 17:29:27 -04:00
|
|
|
|
2020-07-25 11:45:39 -04:00
|
|
|
constructor (tk) {
|
|
|
|
super();
|
|
|
|
this.tk = tk;
|
|
|
|
}
|
|
|
|
|
2020-06-21 17:29:27 -04:00
|
|
|
get element () {
|
|
|
|
return this.tk.element;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-09-05 07:12:04 -04:00
|
|
|
class TkRangeControl extends TkControl {
|
2020-06-21 17:29:27 -04:00
|
|
|
|
|
|
|
constructor (tk) {
|
2020-07-25 11:45:39 -04:00
|
|
|
super(tk);
|
2020-06-21 17:29:27 -04:00
|
|
|
|
|
|
|
this.tk = tk;
|
|
|
|
this.lastValue = NaN;
|
|
|
|
|
|
|
|
this.tk.add_event('useraction', (name, value) => {
|
|
|
|
if ((name == 'value') && (this.lastValue != value)) {
|
|
|
|
this.lastValue = value;
|
|
|
|
this.callback(value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
get value () {
|
|
|
|
return this.tk.get('value');
|
|
|
|
}
|
|
|
|
|
|
|
|
set value (val) {
|
|
|
|
this.tk.set('value', val);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-09-05 07:12:04 -04:00
|
|
|
class TkKnob extends TkRangeControl {
|
2020-06-21 17:29:27 -04:00
|
|
|
|
|
|
|
constructor (options) {
|
|
|
|
super(new TK.Knob(options));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-09-05 07:12:04 -04:00
|
|
|
class TkFader extends TkRangeControl {
|
|
|
|
|
|
|
|
constructor (options) {
|
|
|
|
super(new TK.Fader(options));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class TkMeter extends TkRangeControl {
|
|
|
|
|
|
|
|
constructor (options) {
|
|
|
|
super(new TK.LevelMeter(options));
|
|
|
|
}
|
|
|
|
|
|
|
|
set value (val) {
|
|
|
|
this.tk.set('value', val);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Label extends TkWidget {
|
|
|
|
|
|
|
|
constructor () {
|
|
|
|
super(new TK.Label());
|
|
|
|
}
|
|
|
|
|
|
|
|
set text (text) {
|
|
|
|
this.tk.set('label', text);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-21 17:29:27 -04:00
|
|
|
export class Container extends BaseContainer {
|
|
|
|
|
|
|
|
constructor () {
|
|
|
|
super();
|
|
|
|
this.tk = new TK.Container();
|
|
|
|
}
|
|
|
|
|
|
|
|
get element () {
|
|
|
|
return this.tk.element;
|
|
|
|
}
|
|
|
|
|
|
|
|
appendChild (child) {
|
|
|
|
super.appendChild(child);
|
|
|
|
this.tk.append_child(child.tk);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-08-16 09:03:17 -04:00
|
|
|
export class Dialog extends BaseDialog {
|
|
|
|
|
|
|
|
constructor () {
|
|
|
|
super();
|
|
|
|
this.tk = new TK.Dialog({
|
|
|
|
anchor: 'center', // center v&h
|
|
|
|
auto_close: true,
|
|
|
|
auto_remove: true,
|
|
|
|
showing_duration: 10,
|
|
|
|
hiding_duration: 10,
|
|
|
|
container: document.getElementById('root')
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
get element () {
|
|
|
|
return this.tk.element;
|
|
|
|
}
|
|
|
|
|
2020-08-22 15:33:49 -04:00
|
|
|
set closeButton (button) {
|
|
|
|
button.callback = () => this.close();
|
|
|
|
this.appendChild(button);
|
|
|
|
}
|
|
|
|
|
2020-08-16 09:03:17 -04:00
|
|
|
appendChild (child) {
|
|
|
|
super.appendChild(child);
|
|
|
|
this.tk.append_child(child.tk);
|
|
|
|
}
|
|
|
|
|
|
|
|
show () {
|
|
|
|
// opening a TK.Dialog with auto_close=true from a TK.Button callback
|
|
|
|
// fails otherwise ev.stopPropagation() is called in the button event
|
|
|
|
// handler or setTimeout() is used here
|
|
|
|
setTimeout(() => {
|
|
|
|
this.tk.set('display_state', 'show');
|
2020-08-22 15:33:49 -04:00
|
|
|
this.tk.add_event('close', (ev) => this.onClose(ev));
|
2020-08-16 09:03:17 -04:00
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
|
2020-08-22 15:33:49 -04:00
|
|
|
close () {
|
|
|
|
this.tk.close();
|
|
|
|
}
|
|
|
|
|
2020-08-16 09:03:17 -04:00
|
|
|
}
|
|
|
|
|
2020-09-05 07:12:04 -04:00
|
|
|
export class Button extends TkControl {
|
2020-08-16 09:03:17 -04:00
|
|
|
|
|
|
|
constructor () {
|
|
|
|
super(new TK.Button());
|
|
|
|
this.tk.add_event('click', (ev) => this.callback(ev));
|
|
|
|
}
|
|
|
|
|
|
|
|
set text (text) {
|
|
|
|
this.tk.set('label', text);
|
|
|
|
}
|
|
|
|
|
2020-08-22 15:33:49 -04:00
|
|
|
set icon (icon) {
|
|
|
|
// see toolkit/styles/Toolkit.html
|
|
|
|
this.tk.set('icon', icon);
|
|
|
|
this.element.style.border = 'none';
|
|
|
|
}
|
|
|
|
|
2020-08-16 09:03:17 -04:00
|
|
|
}
|
|
|
|
|
2020-09-05 07:12:04 -04:00
|
|
|
export class Toggle extends TkControl {
|
2020-06-21 17:29:27 -04:00
|
|
|
|
|
|
|
constructor () {
|
|
|
|
super(new TK.Toggle());
|
|
|
|
this.tk.add_event('toggled', (state) => this.callback(state));
|
|
|
|
}
|
2020-08-16 09:03:17 -04:00
|
|
|
|
|
|
|
set text (text) {
|
|
|
|
this.tk.set('label', text);
|
|
|
|
}
|
2020-06-21 17:29:27 -04:00
|
|
|
|
|
|
|
get value () {
|
|
|
|
return this.tk.get('state');
|
|
|
|
}
|
|
|
|
|
|
|
|
set value (val) {
|
|
|
|
this.tk.set('state', val);
|
|
|
|
}
|
|
|
|
|
2020-08-22 15:33:49 -04:00
|
|
|
setIcons (inactive, active) {
|
|
|
|
this.tk.set('icon', inactive);
|
|
|
|
this.tk.set('icon_active', active);
|
|
|
|
this.element.style.border = 'none';
|
|
|
|
}
|
|
|
|
|
2020-06-21 17:29:27 -04:00
|
|
|
}
|
|
|
|
|
2020-09-05 07:12:04 -04:00
|
|
|
export class AudioStripGainFader extends TkFader {
|
2020-06-21 17:29:27 -04:00
|
|
|
|
|
|
|
constructor () {
|
2020-09-05 07:12:04 -04:00
|
|
|
super({
|
2020-06-21 17:29:27 -04:00
|
|
|
scale: 'decibel',
|
2020-09-05 07:12:04 -04:00
|
|
|
labels: TK.FORMAT("%d"),
|
2020-06-21 17:29:27 -04:00
|
|
|
min: -58.0,
|
|
|
|
max: 6.0
|
2020-09-05 07:12:04 -04:00
|
|
|
});
|
2020-06-21 17:29:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-09-05 07:12:04 -04:00
|
|
|
export class MidiStripGainFader extends TkFader {
|
2020-06-21 17:29:27 -04:00
|
|
|
|
|
|
|
constructor () {
|
2020-09-05 07:12:04 -04:00
|
|
|
super({
|
|
|
|
scale: 'linear',
|
|
|
|
labels: TK.FORMAT("%d"),
|
|
|
|
min: 0,
|
|
|
|
max: 127
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export class AudioStripMeter extends TkMeter {
|
|
|
|
|
|
|
|
constructor () {
|
|
|
|
super({
|
2020-06-21 17:29:27 -04:00
|
|
|
show_scale: false,
|
|
|
|
scale: 'decibel',
|
|
|
|
min: -58.0,
|
|
|
|
max: 6.0
|
2020-09-05 07:12:04 -04:00
|
|
|
});
|
2020-06-21 17:29:27 -04:00
|
|
|
}
|
|
|
|
|
2020-09-05 07:12:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export class MidiStripMeter extends TkMeter {
|
|
|
|
|
|
|
|
constructor () {
|
|
|
|
super({
|
|
|
|
show_scale: false,
|
|
|
|
scale: 'linear',
|
|
|
|
min: 0,
|
|
|
|
max: 127
|
|
|
|
});
|
2020-06-21 17:29:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-09-05 07:12:04 -04:00
|
|
|
export class LinearKnob extends TkKnob {
|
2020-06-21 17:29:27 -04:00
|
|
|
|
|
|
|
constructor (min, max) {
|
|
|
|
super({
|
|
|
|
scale: 'linear',
|
|
|
|
min: min,
|
2020-08-22 15:33:49 -04:00
|
|
|
max: max,
|
|
|
|
hand: {
|
|
|
|
width: 5,
|
|
|
|
length: 15
|
|
|
|
}
|
2020-06-21 17:29:27 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-09-05 07:12:04 -04:00
|
|
|
export class LogKnob extends TkKnob {
|
2020-06-21 17:29:27 -04:00
|
|
|
|
|
|
|
constructor (min, max) {
|
|
|
|
super({
|
2020-08-22 15:33:49 -04:00
|
|
|
scale: 'frequency',
|
2020-06-21 17:29:27 -04:00
|
|
|
min: min,
|
2020-08-22 15:33:49 -04:00
|
|
|
max: max,
|
|
|
|
hand: {
|
|
|
|
width: 5,
|
|
|
|
length: 15
|
|
|
|
}
|
2020-06-21 17:29:27 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-09-05 07:12:04 -04:00
|
|
|
export class DiscreteKnob extends TkKnob {
|
2020-06-21 17:29:27 -04:00
|
|
|
|
|
|
|
constructor (min, max, step) {
|
|
|
|
super({
|
|
|
|
scale: 'linear',
|
|
|
|
min: min,
|
|
|
|
max: max,
|
2020-08-22 15:33:49 -04:00
|
|
|
snap: step || 1,
|
|
|
|
hand: {
|
|
|
|
width: 5,
|
|
|
|
length: 15
|
|
|
|
}
|
2020-06-21 17:29:27 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-09-05 07:12:04 -04:00
|
|
|
export class PanKnob extends TkKnob {
|
2020-06-21 17:29:27 -04:00
|
|
|
|
|
|
|
constructor () {
|
|
|
|
super({
|
2020-07-19 10:31:31 -04:00
|
|
|
//scale: 'linear',
|
|
|
|
scale: (k) => 1.0 - k,
|
|
|
|
min: 0,
|
2020-07-19 17:32:46 -04:00
|
|
|
max: 1.0,
|
|
|
|
hand: {
|
|
|
|
width: 5,
|
|
|
|
length: 15
|
|
|
|
}
|
2020-06-21 17:29:27 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|