2020-05-29 05:37:34 -04:00
|
|
|
/*
|
2021-06-13 19:07:40 -04:00
|
|
|
* Copyright © 2020 Luciano Iam <oss@lucianoiam.com>
|
2020-05-29 05:37:34 -04:00
|
|
|
*
|
|
|
|
* 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 07:04:43 -04:00
|
|
|
import { ChildComponent } from '../base/component.js';
|
2020-05-29 05:37:34 -04:00
|
|
|
import { StateNode } from '../base/protocol.js';
|
|
|
|
|
2020-06-01 05:11:01 -04:00
|
|
|
const NodeToProperty = Object.freeze({
|
|
|
|
[StateNode.TRANSPORT_TEMPO] : 'tempo',
|
|
|
|
[StateNode.TRANSPORT_TIME] : 'time',
|
|
|
|
[StateNode.TRANSPORT_ROLL] : 'roll',
|
|
|
|
[StateNode.TRANSPORT_RECORD] : 'record'
|
|
|
|
});
|
|
|
|
|
2020-06-14 07:04:43 -04:00
|
|
|
export default class Transport extends ChildComponent {
|
2020-05-29 05:37:34 -04:00
|
|
|
|
2020-06-14 07:04:43 -04:00
|
|
|
constructor (parent) {
|
|
|
|
super(parent);
|
2020-05-29 05:37:34 -04:00
|
|
|
this._time = 0;
|
|
|
|
this._tempo = 0;
|
|
|
|
this._roll = false;
|
|
|
|
this._record = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
get time () {
|
|
|
|
return this._time;
|
|
|
|
}
|
|
|
|
|
|
|
|
get tempo () {
|
|
|
|
return this._tempo;
|
|
|
|
}
|
|
|
|
|
|
|
|
set tempo (bpm) {
|
2020-05-30 13:08:27 -04:00
|
|
|
this.updateRemote('tempo', bpm, StateNode.TRANSPORT_TEMPO);
|
2020-05-29 05:37:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
get roll () {
|
|
|
|
return this._roll;
|
|
|
|
}
|
|
|
|
|
|
|
|
set roll (value) {
|
|
|
|
this.updateRemote('roll', value, StateNode.TRANSPORT_ROLL);
|
|
|
|
}
|
|
|
|
|
|
|
|
get record () {
|
|
|
|
return this._record;
|
|
|
|
}
|
|
|
|
|
|
|
|
set record (value) {
|
2020-05-30 13:08:27 -04:00
|
|
|
this.updateRemote('record', value, StateNode.TRANSPORT_RECORD);
|
2020-05-29 05:37:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
handle (node, addr, val) {
|
2020-06-01 05:11:01 -04:00
|
|
|
if (node in NodeToProperty) {
|
|
|
|
this.updateLocal(NodeToProperty[node], val[0]);
|
|
|
|
return true;
|
2020-05-29 05:37:34 -04:00
|
|
|
}
|
|
|
|
|
2020-06-01 05:11:01 -04:00
|
|
|
return false;
|
2020-05-29 05:37:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|