[SOLVED] Changing Key Colors with Samplemaps
-
Hi, I have an Instrument with different Samplemaps that change with Radio Buttons, these Buttons Change the Samplemap and the image, I try to colour the Keyboard putting the code in this Callback but I have to double click the button to make this function work on the Keys. I tried putting the code in a hidden Slider, Panel but have the same result, I also tried a timer and it works but I don't like that timer running and sometimes glitching the Key Colours, some ideas?
This is my code
inline function changeInst(component, value) { if (value) { local idx = instButtons.indexOf(component); for (i = 0; i < insts.length; i++) { insts[i].showControl(false); Sampler1.loadSampleMap(Samplemap[idx]); } for (i = 0; i < 127; i++) { Engine.setKeyColour(i, Colours.withAlpha(Colours.black, 0.6)); if (Sampler.asSampler().isNoteNumberMapped(i)) { Engine.setKeyColour(i, Colours.withAlpha(Colours.dodgerblue, 0.4)); } } insts[idx].showControl(true); } }
I have "Sampler" Referencing Child Synth and "Sampler1" Referencing Sampler in order to make this work.
-
@Soundavid My first guess (without any investigation) is that your re-colouring triggers before the new sample map has finished loading, therefore it won't detect the note numbers as being mapped/unmapped at the point your loop runs. If you put the key colouring code in a preload callback you might get better results.
-
@d-healey You were Right! I tried this code in a hidden Panel and works Perfectly! Thanks man.
ScriptPanel1.setLoadingCallback(function(isPreloading) { if(!isPreloading) for (i = 0; i < 127; i++) { Engine.setKeyColour(i, Colours.withAlpha(Colours.black, 0.6)); if (Sampler.asSampler().isNoteNumberMapped(i)) Engine.setKeyColour(i, Colours.withAlpha(Colours.dodgerblue, 0.4)); } });