Setting ControlCallback w/ Loops ?
-
Or even shorter...
// Don't do this, I'm being silly for (k in Content.getAllComponents("knbVolume")) k.setControlCallback(onSampleVolumeKnobsControl); -
@d-healey
MASTER OF THE UNIVERSE LEVEL! 
-
@Lindon @Oli-Ullmann @d-healey

Thank Yous! ha.

-
@d-healey said in Setting ControlCallback w/ Loops ?:
Or even shorter...
// Don't do this, I'm being silly for (k in Content.getAllComponents("knbVolume")) k.setControlCallback(onSampleVolumeKnobsControl);I always thought there was "no guarantee of ordering" in getAllComponents.....
-
@Lindon I think it grabs them in the order they are in the component list. I never really thought about it though but I haven't ran into any issues.
-
@d-healey yeah..maybe then , however your suggestion makes the callback difficult in that there is no indexOf(component) to show you which one is being called on...unless theres some fu I dont know about...oh I just noticed your "dont do this comment..>"....
-
@Lindon I did put a disclaimer not to use it. :)
-
@Lindon said in Setting ControlCallback w/ Loops ?:
const TheGains = []; const SampleVolumeKnobs = []; const NUM_COMPONENTS = 8; for(i = 0; i< NUM_COMPONENTS; i++) { TheGains[i] = Synth.getEffect("Simple Gain" + (i+1)); SampleVolumeKnobs[i] = Content.getComponent("knbVolume" + (i+1)); SampleVolumeKnobs[i].setControlCallback(onSampleVolumeKnobsControl); }@Chazrox ...and now your call back looks like this:
inline function onSampleVolumeKnobsControl(component, value) { pos = SampleVolumeKnobs.indexOf(component); //tells us which control is being called... TheGains[pos].setAttribute(TheGains[pos].Gain, value); }; -
@Lindon Thank You
Im gonna try this in a bit and get back to you. Appreciate it! Love the energy. 
-
@Lindon
Yes, the components will be added in the order specified in the component list.As for the index, I use a function that I call first in the callback and that returns the index. Something like this:
inline function getIndexAsInt(component) { local index = component.getId().replace("knbVolume", "").getIntValue(); return index; } inline function getIndexAsString(component) { local index = component.getId().replace("knbVolume", ""); return index; }The return value can then be used in the callback to determine the correct component....
-
@Oli-Ullmann said in Setting ControlCallback w/ Loops ?:
local index = component.getId().replace("knbVolume", "").getIntValue();
If you are storing all your components in an array you can get the index directly using
indexOf -
@d-healey
Yes, that's right! Thanks for the tip! :-) -
C Chazrox has marked this topic as solved