Need a little help with (HISE) loops
-
I am trying to simplify a key-mapping script that colors the keys when notes are set via comboboxes.
This is a portion of the script I have been using:
//Mini Hats Tip inline function onComboBoxMiniHatsTipMidiControl(component, value) { noteTriggers[0] = value - 1; setKeyColours(); }; Content.getComponent("ComboBoxMiniHatsTipMidi").setControlCallback(onComboBoxMiniHatsTipMidiControl); //Mini Hats Edge inline function onComboBoxMiniHatsEdgeMidiControl(component, value) { noteTriggers[1] = value - 1; setKeyColours(); }; Content.getComponent("ComboBoxMiniHatsEdgeMidi").setControlCallback(onComboBoxMiniHatsEdgeMidiControl); //kick const var ComboBoxKickMidi = Content.getComponent("ComboBoxKickMidi"); inline function onComboBoxKickMidiControl(component, value) { noteTriggers[2] = value - 1; setKeyColours(); };
etc etc
I am trying to use a loop to simplify this.
I declared an array of the components, as such:
const var MapCombos = [Content.getComponent("ComboBoxKickMidi"), Content.getComponent("ComboBoxCajonLowMidi"), Content.getComponent("ComboBoxCajonHiMidi"),];
And attempted to do it like this:
Engine.createMidiList(); for (i = 0; i < MapCombos.lenght; i++) { var Box = MapCombos[i]; inline function onBoxControl(component, value) { noteTriggers[i] = value - 1; setKeyColours(); }; Content.getComponent(Box).setControlCallback(onBoxControl); }
But, it is not working.
How do I do this, please?
Thank you.
-
@gorangrooves you mis-spelt length..
MapCombos.lenght
-
@Lindon Thank you. That resolved one bit, but my script is still not working. It compiles, but it doesn't do what I am expecting.
This is the latest:
for (i = 0; i < MapCombos.length; i++) { var Box = MapCombos[i]; inline function onBoxControl(component, value) { noteTriggers[i] = value - 1; setKeyColours(); }; Box.setControlCallback(onBoxControl); }
What am I missing / doing wrong?
-
@gorangrooves What about putting the loop inside your function?
inline function onBoxControl(component, value) { for (i = 0; i < MapCombos.lenght; i++) { var Box = MapCombos[i]; noteTriggers[i] = value - 1; } setKeyColours(); }; Content.getComponent(Box).setControlCallback(onBoxControl);
-
@Dan-Korneff Thanks, Dan. Unfortunately, that doesn't work either. It throws an error
column 21: Argument 0 is undefined!
on this line
Content.getComponent(Box).setControlCallback(onBoxControl);
And If I put it like this:
Content.getComponent("Box").setControlCallback(onBoxControl);
I get this error on that last line:
column 47: Unknown function 'setControlCallback'
O, thou Loop Wizard, @d-healey, could you please enlighten me?
-
@gorangrooves You can't declare an inline function inside a loop, that is just weird :p
Post a snippet and I'll fix it :)
-
@d-healey Ok. Thank you. If I export a HISE snippet from my entire current project, will that work despite missing all of the images for buttons, sliders etc, as well as the actual samples?
-
@gorangrooves Don't make one for your entire project. Just make a minimal one that demonstrates the issue.
-
@d-healey Uh, I'll try. There are several intervened elements.
-
@gorangrooves Often the process of making a simplified snippet will reveal where the true issue is - I do this all the time if I'm trying to solve an issue in a complicated project.
-
@d-healey Got you. I think I'll make a copy of one of the projects, then strip it down naked
-
@gorangrooves You might also want to look at some of my tutorials where I'm building interfaces with controls stored in arrays and how I reference those controls inside the callback.
-
@d-healey I did. I love them. Everything made perfect sense. Then I attempted to make my own...the rest is history
-
@gorangrooves Something like this
for (i = 0; i < MapCombos.length; i++) { MapCombos[i].setControlCallback(onBoxControl); } inline function onBoxControl(component, value) { local index = MapCombos.indexOf(component); noteTriggers[index] = value - 1; setKeyColours(); };
-
@d-healey Thanks so much, you wizard! I think that is the way to go.
The notes and comboboxes are not quite matching at the moment, but I think I need to do some untangling, perhaps. You helped me overcome a major hurdle. Thank you so much!
-
@d-healey Yes, I got it all sorted and implemented another feature to learn MIDI notes using a loop. Thanks so much again for the personal help and for your helpful videos!