Script to link/unlink knobs, update with callback help
-
Hey guys,
I'm trying to link Gain of 2 SimpleGain effects with one Knob via a Button.When Button = 1 , both effects Gain controls are linked to Knob
When Button = 0 , Gain1 is controlled by Knob, Gain2 is set to -100
Here's what I got so far, which works... But the gain of Gain2 does not update until the "Level" Knob is turned.
Do I need to add a callback to my Button?// get value of Button inline function onButtonControl(component, value) { var w = Button.getValue(); }; Content.getComponent("Button").setControlCallback(onButtonControl); inline function onLevelControl(component, value) { if (w == 1) { Gain1.setAttribute(Gain1..Gain, value); local g =Gain1.getAttribute(0); Gain2.setAttribute(Gain2.Gain, g); } else if (w == 0) { Gain1.setAttribute(Gain1.Gain, value); Gain2.setAttribute(Gain2.Gain, -100); } }; Content.getComponent("Level").setControlCallback(onLevelControl);
-
What you need to do here is to call the same function for both control callbacks. The prettiest way to do this is to reuse the inline function for both controls:
const var SimpleGain = Synth.getEffect("Simple Gain"); const var SimpleGain2 = Synth.getEffect("Simple Gain2"); const var Button1 = Content.getComponent("Button1"); const var Knob1 = Content.getComponent("Knob1"); inline function update(unusedComponentParameter, unusedValueParameter) { local value = Knob1.getValue(); local mode = Button1.getValue(); if(mode) { SimpleGain.setAttribute(SimpleGain.Gain, value); SimpleGain2.setAttribute(SimpleGain2.Gain, value); } else { SimpleGain.setAttribute(SimpleGain.Gain, value); SimpleGain2.setAttribute(SimpleGain2.Gain, -100); } } Button1.setControlCallback(update); Knob1.setControlCallback(update);
As you can see, we ignore the parameters of the function (it still needs 2 parameters to compile) and grab the actual values directly from the components.
-
@Christoph-Hart Super clean solution!