From 6fb61a62ba3f4d49b6948e3ba6c2784353653adb Mon Sep 17 00:00:00 2001 From: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> Date: Sun, 4 Jun 2023 14:53:12 +0200 Subject: fix(ci): silence eslint complaints for common-controller-scripts.js --- res/controllers/common-controller-scripts.js | 68 ++++++++++++++++------------ 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/res/controllers/common-controller-scripts.js b/res/controllers/common-controller-scripts.js index c20a54908b..f0d19253ee 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 = new Array(); + 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; } @@ -149,7 +153,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 +177,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 +259,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 +286,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 +311,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 +394,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; }; @@ -460,6 +464,7 @@ script.softStart = function(channel, control, value, status, group, factor) { }; // bpm - Used for tapping the desired BPM for a deck + var bpm = function() { }; @@ -477,8 +482,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 +506,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