summaryrefslogtreecommitdiffstats
path: root/res/controllers/common-controller-scripts.js
diff options
context:
space:
mode:
Diffstat (limited to 'res/controllers/common-controller-scripts.js')
-rw-r--r--res/controllers/common-controller-scripts.js99
1 files changed, 70 insertions, 29 deletions
diff --git a/res/controllers/common-controller-scripts.js b/res/controllers/common-controller-scripts.js
index c20a54908b..68eed58954 100644
--- a/res/controllers/common-controller-scripts.js
+++ b/res/controllers/common-controller-scripts.js
@@ -21,8 +21,8 @@
// Returns an ASCII byte array for the string
String.prototype.toInt = function() {
- var a = new Array();
- for (var i = 0; i < this.length; i++) {
+ const a = [];
+ for (let i = 0; i < this.length; i++) {
a[i] = this.charCodeAt(i);
}
return a;
@@ -32,9 +32,11 @@ String.prototype.toInt = function() {
/**
* Prints a message to the terminal and the log file.
+ *
* @param {string} message - The log message.
* @deprecated Use console.log()/console.warn()/console.debug() instead.
*/
+
var print = function(message) {
console.log(message);
};
@@ -44,6 +46,7 @@ var printObject = function(obj, maxdepth) {
print(stringifyObject(obj, maxdepth));
};
+
var stringifyObject = function(obj, maxdepth, checked, prefix) {
if (!maxdepth) { maxdepth = 2; }
try {
@@ -54,9 +57,9 @@ var stringifyObject = function(obj, maxdepth, checked, prefix) {
if (maxdepth > 0 && typeof obj === "object" && obj !== null &&
Object.getPrototypeOf(obj) !== "" && !arrayContains(checked, obj)) {
checked.push(obj);
- var output = "{\n";
- for (var property in obj) {
- var value = obj[property];
+ let output = "{\n";
+ for (const property in obj) {
+ const value = obj[property];
if (typeof value === "function") { continue; }
output += prefix + property + ": "
+ stringifyObject(value, maxdepth - 1, checked, prefix + " ")
@@ -68,8 +71,9 @@ var stringifyObject = function(obj, maxdepth, checked, prefix) {
return obj;
};
+
var arrayContains = function(array, elem) {
- for (var i = 0; i < array.length; i++) {
+ for (let i = 0; i < array.length; i++) {
if (array[i] === elem) { return true; }
}
return false;
@@ -79,7 +83,7 @@ var arrayContains = function(array, elem) {
// eslint-disable-next-line no-unused-vars
var secondstominutes = function(secs) {
- var m = (secs / 60) | 0;
+ const m = (secs / 60) | 0;
return (m < 10 ? "0" + m : m)
+ ":"
@@ -88,9 +92,9 @@ var secondstominutes = function(secs) {
// eslint-disable-next-line no-unused-vars
var msecondstominutes = function(msecs) {
- var m = (msecs / 60000) | 0;
+ const m = (msecs / 60000) | 0;
msecs %= 60000;
- var secs = (msecs / 1000) | 0;
+ const secs = (msecs / 1000) | 0;
msecs %= 1000;
msecs = Math.round(msecs * 100 / 1000);
if (msecs === 100) { msecs = 99; }
@@ -120,9 +124,40 @@ var colorCodeToObject = function(colorCode) {
};
};
+/* eslint @typescript-eslint/no-empty-function: "off" */
var script = function() {
};
+// ----------------- Mapping constants ---------------------
+
+// Library column value, which can be used to interact with the CO for "[Library] sort_column"
+script.LIBRARY_COLUMNS = Object.freeze({
+ ARTIST: 1,
+ TITLE: 2,
+ ALBUM: 3,
+ ALBUM_ARTIST: 4,
+ YEAR: 5,
+ GENRE: 6,
+ COMPOSER: 7,
+ GROUPING: 8,
+ TRACK_NUMBER: 9,
+ FILETYPE: 10,
+ NATIVE_LOCATION: 11,
+ COMMENT: 12,
+ DURATION: 13,
+ BITRATE: 14,
+ BPM: 15,
+ REPLAY_GAIN: 16,
+ DATETIME_ADDED: 17,
+ TIMES_PLAYED: 18,
+ RATING: 19,
+ KEY: 20,
+ PREVIEW: 21,
+ COVERART: 22,
+ TRACK_COLOR: 30,
+ LAST_PLAYED: 31,
+});
+
// DEPRECATED -- use script.midiDebug() instead
script.debug = function(channel, control, value, status, group) {
print("Warning: script.debug() is deprecated. Use script.midiDebug() instead.");
@@ -149,7 +184,7 @@ script.midiDebug = function(channel, control, value, status, group) {
// Returns the deck number of a "ChannelN" or "SamplerN" group
script.deckFromGroup = function(group) {
- var deck = 0;
+ let deck = 0;
if (group.substring(2, 8) === "hannel") {
// Extract deck number from the group text
deck = group.substring(8, group.length - 1);
@@ -173,7 +208,7 @@ script.deckFromGroup = function(group) {
Output: none
-------- ------------------------------------------------------ */
script.bindConnections = function(group, controlsToFunctions, remove) {
- var control;
+ let control;
remove = (remove === undefined) ? false : remove;
for (control in controlsToFunctions) {
@@ -255,7 +290,7 @@ script.absoluteLinInverse = function(value, low, high, min, max) {
if (!max) {
max = 127;
}
- var result = (((value - low) * (max - min)) / (high - low)) + min;
+ const result = (((value - low) * (max - min)) / (high - low)) + min;
if (result < min) {
return min;
} else if (result > max) {
@@ -282,7 +317,7 @@ script.absoluteNonLin = function(value, low, mid, high, min, max) {
if (!max) {
max = 127;
}
- var center = (max - min) / 2;
+ const center = (max - min) / 2;
if (value === center || value === Math.round(center)) {
return mid;
} else if (value < center) {
@@ -307,8 +342,8 @@ script.absoluteNonLinInverse = function(value, low, mid, high, min, max) {
if (!max) {
max = 127;
}
- var center = (max - min) / 2;
- var result;
+ const center = (max - min) / 2;
+ let result;
if (value === mid) {
return center;
@@ -390,9 +425,9 @@ script.midiPitch = function(LSB, MSB, status) {
print("Script.midiPitch: Error, not a MIDI pitch (0xEn) message: " + status);
return false;
}
- var value = (MSB << 7) | LSB; // Construct the 14-bit number
+ const value = (MSB << 7) | LSB; // Construct the 14-bit number
// Range is 0x0000..0x3FFF center @ 0x2000, i.e. 0..16383 center @ 8192
- var rate = (value - 8192) / 8191;
+ const rate = (value - 8192) / 8191;
// print("Script.Pitch: MSB="+MSB+", LSB="+LSB+", value="+value+", rate="+rate);
return rate;
};
@@ -477,8 +512,8 @@ bpm.tap = []; // Tap sample values
Output: -
-------- ------------------------------------------------------ */
bpm.tapButton = function(deck) {
- var now = new Date() / 1000; // Current time in seconds
- var tapDelta = now - bpm.tapTime;
+ const now = new Date() / 1000; // Current time in seconds
+ const tapDelta = now - bpm.tapTime;
bpm.tapTime = now;
// assign tapDelta in cases where the button has not been pressed previously
@@ -501,19 +536,19 @@ bpm.tapButton = function(deck) {
bpm.tap.push(60 / tapDelta);
// Keep the last 8 samples for averaging
if (bpm.tap.length > 8) { bpm.tap.shift(); }
- var sum = 0;
- for (var i=0; i<bpm.tap.length; i++) {
+ let sum = 0;
+ for (let i=0; i<bpm.tap.length; i++) {
sum += bpm.tap[i];
}
- var average = sum / bpm.tap.length;
+ const average = sum / bpm.tap.length;
- var group = "[Channel" + deck + "]";
+ const group = "[Channel" + deck + "]";
// "bpm" was changed in 1.10 to reflect the *adjusted* bpm, but I presume it
// was supposed to return the tracks bpm (which it did before the change).
// "file_bpm" is supposed to return the set BPM of the loaded track of the
// channel.
- var fRateScale = average/engine.getValue(group, "file_bpm");
+ let fRateScale = average/engine.getValue(group, "file_bpm");
// Adjust the rate:
fRateScale = (fRateScale - 1.) / engine.getValue(group, "rateRange");
@@ -534,11 +569,13 @@ script.individualEffectRegEx = /^\[EffectRack1_EffectUnit(\d+)_Effect(\d+)\]$/;
// ----------------- Object definitions --------------------------
+
var ButtonState = {"released": 0x00, "pressed": 0x7F};
// eslint-disable-next-line no-unused-vars
var LedState = {"off": 0x00, "on": 0x7F};
// Controller
+
var Controller = function() {
this.group = "[Master]";
this.Controls = [];
@@ -547,8 +584,9 @@ var Controller = function() {
Controller.prototype.addButton = function(buttonName, button, eventHandler) {
if (eventHandler) {
- var executionEnvironment = this;
- var handler = function(value) {
+ /* eslint @typescript-eslint/no-this-alias: "off" */
+ const executionEnvironment = this;
+ const handler = function(value) {
button.state = value;
executionEnvironment[eventHandler](value);
};
@@ -562,6 +600,7 @@ Controller.prototype.setControlValue = function(control, value) {
};
// Button
+
var Button = function(controlId) {
this.controlId = controlId;
this.state = ButtonState.released;
@@ -571,6 +610,7 @@ Button.prototype.handleEvent = function(value) {
};
// Control
+
var Control = function(mappedFunction, softMode) {
// These defaults are for MIDI controllers
this.minInput = 0;
@@ -587,7 +627,7 @@ var Control = function(mappedFunction, softMode) {
};
Control.prototype.setValue = function(group, inputValue) {
- var outputValue = 0;
+ let outputValue = 0;
if (inputValue <= this.midInput) {
outputValue = this.minOutput
+ ((inputValue - this.minInput) / (this.midInput - this.minInput))
@@ -598,8 +638,8 @@ Control.prototype.setValue = function(group, inputValue) {
* (this.maxOutput - this.midOutput);
}
if (this.softMode) {
- var currentValue = engine.getValue(group, this.mappedFunction);
- var currentRelative = 0.0;
+ const currentValue = engine.getValue(group, this.mappedFunction);
+ let currentRelative = 0.0;
if (currentValue <= this.midOutput) {
currentRelative = this.minInput
+ ((currentValue - this.minOutput) / (this.midOutput - this.minOutput))
@@ -619,6 +659,7 @@ Control.prototype.setValue = function(group, inputValue) {
};
// Deck
+
var Deck = function(deckNumber, group) {
this.deckNumber = deckNumber;
this.group = group;