Getting error message "Execution timed-out"
-
Well, this is overly complicated because it needs to keep track of the parent relation ship. Having one function per element makes the control callback execution even faster than it is right now. There are still a lot ways to make this automatically (you can store inline functions in an array for each rack and pass it on to it's child components on creation etc).
-
Alright, I committed this feature:
const var Knob = Content.addKnob("Knob", 0, 0); inline function x(component, value) { // component == Knob Console.print(value); } Knob.setControlCallback(x);
setControlCallback
can be called at any time so you can implement the dynamic behaviour. There are some rules:Two Parameter
The inline function must have two parameters, the first being the component that caused the callback and the second the value (just like the
onControl
callback).No anonymous Inline functions
the argument for
setControllCallback
must be a inline function. However, there is nothing like a anonymous inline function, so this won't work:Knob.setControlCallback(inline function(c, value){ Console.print(value); });
Instead, you need to define the inline function up front and pass it to the callback with its name. But this should not be a real restriction as you might want to write all callbacks up front anyway.
Resetting the component
When a custom callback is set, the
onControl
callback of the script will not be executed if the respective component was moved. In order to restore this behaviour, simply passundefined
as parameter tosetControlCallback
Let me know if this works for you. You can group inline functions in arrays and pass them to arrays of knobs to automate things:
inline function p1(component, value) {Console.print("P1");}; inline function p2(component, value) {Console.print("P2");}; inline function p3(component, value) {Console.print("P3");}; inline function p4(component, value) {Console.print("P4");}; inline function p5(component, value) {Console.print("P5");}; inline function p6(component, value) {Console.print("P6");}; inline function p7(component, value) {Console.print("P7");}; // Some random combinations of callbacks const var pSet1 = [p1, p4, p6, p2]; const var pSet2 = [p3, p2, p7, p5]; const var knobs = []; knobs[0] = Content.addKnob("Knob1", 0, 0); knobs[1] = Content.addKnob("Knob2", 130, 0); knobs[2] = Content.addKnob("Knob3", 260, 0); knobs[3] = Content.addKnob("Knob4", 390, 0); const var ComboBox = Content.addComboBox("ComboBox", 550, 10); // [JSON ComboBox] Content.setPropertiesFromJSON("ComboBox", { "items": "Set 1\nSet 2" }); // [/JSON ComboBox] function onNoteOn() { } function onNoteOff() { } function onController() { } function onTimer() { } function onControl(number, value) { if(number == ComboBox) { local setToUse = value == 1 ? pSet1 : pSet2; for(i = 0; i < 4; i++) { knobs[i].setControlCallback(setToUse[i]); } } }
-
That looks sweet!
-
this is nice _ i'll definitely be using it....
-
NIEECE! thanks