Skip to content

Commit

Permalink
fix(ci): silence eslint complaints for common-controller-scripts.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Swiftb0y committed Jun 4, 2023
1 parent 67e51ad commit 6fb61a6
Showing 1 changed file with 39 additions and 29 deletions.
68 changes: 39 additions & 29 deletions res/controllers/common-controller-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
};
Expand All @@ -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 {
Expand All @@ -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 + " ")
Expand All @@ -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;
Expand All @@ -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)
+ ":"
Expand All @@ -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; }
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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() {
};

Expand All @@ -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
Expand All @@ -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<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");
Expand All @@ -534,11 +539,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 = [];
Expand All @@ -547,8 +554,8 @@ var Controller = function() {

Controller.prototype.addButton = function(buttonName, button, eventHandler) {
if (eventHandler) {
var executionEnvironment = this;
var handler = function(value) {
const executionEnvironment = this;
const handler = function(value) {
button.state = value;
executionEnvironment[eventHandler](value);
};
Expand All @@ -562,6 +569,7 @@ Controller.prototype.setControlValue = function(control, value) {
};

// Button

var Button = function(controlId) {
this.controlId = controlId;
this.state = ButtonState.released;
Expand All @@ -571,6 +579,7 @@ Button.prototype.handleEvent = function(value) {
};

// Control

var Control = function(mappedFunction, softMode) {
// These defaults are for MIDI controllers
this.minInput = 0;
Expand All @@ -587,7 +596,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))
Expand All @@ -598,8 +607,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))
Expand All @@ -619,6 +628,7 @@ Control.prototype.setValue = function(group, inputValue) {
};

// Deck

var Deck = function(deckNumber, group) {
this.deckNumber = deckNumber;
this.group = group;
Expand Down

0 comments on commit 6fb61a6

Please sign in to comment.