/**
* Components JS library for Mixxx
* Documentation is on the Mixxx wiki at
* http://mixxx.org/wiki/doku.php/components_js
*
* Copyright (C) 2017 Be <be.0@gmx.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.
*
*
*
* This library depends on Lodash, which is copyright JS Foundation
* and other contributors and licensed under the MIT license. Refer to
* the lodash.mixxx.js file in this directory for details.
**/
(function(global) {
var Component = function(options) {
if (Array.isArray(options) && typeof options[0] === "number") {
this.midi = options;
} else {
_.assign(this, options);
}
if (typeof this.unshift === "function") {
this.unshift();
}
// These cannot be in the prototype; they must be unique to each instance.
this.isShifted = false;
this.connections = [];
if (options !== undefined && typeof options.key === "string") {
this.inKey = options.key;
this.outKey = options.key;
}
if (this.outConnect && this.group !== undefined && this.outKey !== undefined) {
this.connect();
if (this.outTrigger) {
this.trigger();
}
}
};
Component.prototype = {
// default attributes
// You should probably overwrite at least some of these.
inValueScale: function(value) {
// Hack to get exact center of pots to return 0.5
if (value > (this.max / 2)) {
return (value - 1) / (this.max - 1);
} else {
return value / (this.max + 1);
}
},
// map input in the XML file, not inValueScale
input: function(channel, control, value, _status, _group) {
this.inSetParameter(this.inValueScale(value));
},
outValueScale: function(value) { return value * this.max; },
output: function(value, _group, _control) {
this.send(this.outValueScale(value));
},
outConnect: true,
outTrigger: true,
max: 127, // for MIDI. When adapting for HID this may change.
// common functions
// In most cases, you should not overwrite these.
inGetParameter: function() {
return engine.getParameter(this.group, this.inKey);
},
inSetParameter: function(value) {
engine.setParameter(this.group, this.inKey, value);
},
inGetValue: function() {
return engine.getValue(this.group, this.inKey);
},
inSetValue: function(value) {
engine.setValue(this.g