How do you use onControl(number,value)?
-
function onControl(number, value) { v = Knob.getValue(); if (v < third) { changeKeyColor(red); } else if(inRange(v,third,third*2)) { changeKeyColor(yellow); } else { changeKeyColor(blue); } }
What's up with the (number, value)? What do you do when you have multiple controls? I would have guessed that number is the control ID and value is the control value, but it doesn't seem to work like that.
-
Sorry, 'number' is a bit outdated as parameter name - it is the actual interface as variable and 'value' is the current value (so you don't need Knob.getValue()). So multiple controls can be used like this:
if(number == Button) { // Do something with button } else if(number == Knob) { // Do something with Knob // Also: Knob.getValue() == value Console.print(value); }
I'll probably change that parameter name to "control" or something…
-
Can somebody please help me with this? I'd like to control the Amp Decay of 2 samplers simultaneously by turning one single knob. From what I understand, this must be scripted in the onControl callback. So I tried:
const var SAMPLER1env = Synth.getModulator("SAMPLER1env"); const var SAMPLER2env = Synth.getModulator("SAMPLER2env"); function onControl(number, value) { switch(number) { case decayKnob: { SAMPLER1env.setAttribute(Decay, value); SAMPLER2env.setAttribute(Decay, value); break;} case sustainKnob //… and other parameters the same way }; }
But it is giving me the error:
! onControl() - Line, column: API call with undefined parameter 0
Am I using the wrong handler by .setAttribute() or is my syntax wrong?
-
@Frankbeat Hi don't use onControl. It's a left over from early versions of HISE. Use a dedicated control callback for your controls instead, I demonstrate this in most videos.
The error could be because you haven't defined
Decay
. But you probably should use a built in constant here, e.g.myModule.Decay
-
@Frankbeat - so as David says - like this:
SAMPLER1env.setAttribute(SAMPLER1env.Decay,value);
But really a giant onControl function is probably a bad way to divide up your code - whats wrong with using the custom callback for each control?
inline function onDecayControl(component, value) { SAMPLER1env.setAttribute(SAMPLER1env.Decay, value); SAMPLER2env.setAttribute(SAMPLER2env.Decay, value); }; Content.getComponent("Decay").setControlCallback(onDecayControl); inline function onReleaseControl(component, value) { SAMPLER1env.setAttribute(SAMPLER1env.Release, value); SAMPLER2env.setAttribute(SAMPLER2env.Release, value); }; Content.getComponent("Release").setControlCallback(onReleaseControl); // etc. etc..
-
@Lindon Thanks, Lindon! That's the way I ended up doing it now after watching David's video Playing with Knobs.