Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Components JS HotcueColor integration #2030

Merged
merged 10 commits into from
Jul 10, 2019
52 changes: 51 additions & 1 deletion res/controllers/midi-components-0.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@
print('ERROR: No hotcue number specified for new HotcueButton.');
return;
}
if (options.colors !== undefined || options.sendRGB !== undefined) {
this.colorIdKey = 'hotcue_' + options.number + '_color_id';
if (options.colors === undefined) {
options.colors = color.predefinedColorsList();
}
}
this.number = options.number;
this.outKey = 'hotcue_' + this.number + '_enabled';
Button.call(this, options);
Expand All @@ -301,8 +307,52 @@
shift: function () {
this.inKey = 'hotcue_' + this.number + '_clear';
},
getColor: function() {
if (this.colorIdKey !== undefined) {
return color.predefinedColorFromId(engine.getValue(this.group,this.colorIdKey));
} else {
return null;
}
},
output: function(value) {
var outval = this.outValueScale(value);
// WARNING: outputColor only handles hotcueColors
// and there is no hotcueColor for turning the LED
// off. So the `send()` function is responsible for turning the
// actual LED off.
if (this.colorIdKey !== undefined && outval !== this.off) {
Swiftb0y marked this conversation as resolved.
Show resolved Hide resolved
this.outputColor(engine.getValue(this.group, this.colorIdKey));
Be-ing marked this conversation as resolved.
Show resolved Hide resolved
} else {
this.send(outval);
}
},
outputColor: function (id) {
var color = this.colors[id];
Swiftb0y marked this conversation as resolved.
Show resolved Hide resolved
if (color instanceof Array) {
if (color.length !== 3) {
print("ERROR: invalid color array for id: " + id);
return;
}
if (this.sendRGB === undefined) {
print("ERROR: no function defined for sending RGB colors");
return;
}
this.sendRGB(color);
} else if (typeof color === 'number') {
this.send(color);
}
},
connect: function() {
Button.prototype.connect.call(this); // call parent connect
if (undefined !== this.group && this.colorIdKey !== undefined) {
this.connections[1] = engine.makeConnection(this.group, this.colorIdKey, function (id) {
if (engine.getValue(this.group,this.outKey)) {
this.outputColor(id);
}
});
}
},
});

var SamplerButton = function (options) {
if (options.number === undefined) {
print('ERROR: No sampler number specified for new SamplerButton.');
Expand Down