Mark notes that contain samples by coloring keyboard keys
-
@Jerems134 sorry you already have sample map selection in a callback so just place your code after that, no need for another panel…
-
@ustk Key color code is working, but I use 1 sampler with 2 sample maps, I would like color each sample maps on the same sampler when I switch sample maps
-
@Jerems134 You mean you want to color blue keys to match the range of the loaded sample map? If so I'd use two hidden knobs, or a range slider, to set the range of keys to be colored and save this with your preset.
-
@d-healey I’ve to set the range with knob or it’s just for saving preset ?
Its possible to make it automatic ?
I already have the code to save a preset. For now just the first samplemaps color the keys, when I change samplemap/preset, keyboard stay coloured like samplemap1, it dosent match with samplemap2. -
Oh I get it now. You're only coloring the keys in on init, you need to recolour them each time a preset is loaded, try moving the loop into the combo box callback.
-
@d-healey Trying this doesn't work, now all sample maps color keys at same time, no matter I change sample map
//Combo box const var cmbSampleMap = Content.getComponent("cmbSampleMap"); cmbSampleMap.set("items", sampleMaps.join("\n")); inline function oncmbSampleMapControl(component, value) { Sampler1.asSampler().loadSampleMap(sampleMaps[value-1]); }; reg i; for (i = 0; i < 127; i++) { if (Sampler1.asSampler().isNoteNumberMapped(i)) Engine.setKeyColour(i, Colours.withAlpha(Colours.blue, 0.3)); } Content.getComponent("cmbSampleMap").setControlCallback(oncmbSampleMapControl);
-
As I said, try putting the loop inside the combobox callback function.
-
@d-healey That's what I did ?! Maybe in the wrong place?
Look code sample//Combo box const var cmbSampleMap = Content.getComponent("cmbSampleMap"); cmbSampleMap.set("items", sampleMaps.join("\n")); inline function oncmbSampleMapControl(component, value) { Sampler1.asSampler().loadSampleMap(sampleMaps[value-1]); }; //-> reg i; for (i = 0; i < 127; i++) { if (Sampler1.asSampler().isNoteNumberMapped(i)) Engine.setKeyColour(i, Colours.withAlpha(Colours.blue, 0.3)); } Content.getComponent("cmbSampleMap").setControlCallback(oncmbSampleMapControl);
-
@Jerems134 nope it is not what you did, you closed the callback right before
reg i;
;)
Also you need to reset the previous colour for all keys before applying the new one (especially if the range is not the same). Use any colour with an alpha value of 0 -
@ustk is correct, you need to place the loop between the braces
{}
of the function. You have placed it after the closing brace. Also youreg i
isn't necessary here, so you can remove that. -
@ustk @d-healey Ok, I've put code in right place now, but all keys stay coloured.
How to reset the previous colour ?
Sorry I'm noob//Combo box const var cmbSampleMap = Content.getComponent("cmbSampleMap"); cmbSampleMap.set("items", sampleMaps.join("\n")); inline function oncmbSampleMapControl(component, value) { Sampler1.asSampler().loadSampleMap(sampleMaps[value-1]); if (Sampler1.asSampler().isNoteNumberMapped(i)) Engine.setKeyColour(i, Colours.withAlpha(Colours.blue, 0.3)); }; Content.getComponent("cmbSampleMap").setControlCallback(oncmbSampleMapControl);
-
@Jerems134 It is the entire for loop you need to move inside ;)
-
@ustk You also need to reset the key colors before the if statement in the for loop with an alpha colour value of 0
-
@ustk @d-healey Ok it's working, thanks for your help !
Solved with this code ://Combo box const var cmbSampleMap = Content.getComponent("cmbSampleMap"); cmbSampleMap.set("items", sampleMaps.join("\n")); inline function oncmbSampleMapControl(component, value) { Sampler1.asSampler().loadSampleMap(sampleMaps[value-1]); for (i = 0; i < 127; i++) if (Sampler1.asSampler().isNoteNumberMapped(i)) Engine.setKeyColour(i, Colours.withAlpha(Colours.blue, 0.3)); else Engine.setKeyColour(i, Colours.withAlpha(Colours.white, 0.0)); };
-
just to thank you guys, I did this code above of my reply and did some editing for 4 samplers and 4 keyboards, I hope it help a newbie like me.
const var Sampler1 = Synth.getChildSynth("Sampler1");
reg i;
for (i = 0; i < 127; i++)
{
if (Sampler1.asSampler().isNoteNumberMapped(i))
Engine.setKeyColour(i, Colours.withAlpha(Colours.blue, 0.2));
}const var Sampler2 = Synth.getChildSynth("Sampler2");
reg i2;
for (i = 0; i < 127; i++)
{
if (Sampler2.asSampler().isNoteNumberMapped(i))
Engine.setKeyColour(i, Colours.withAlpha(Colours.yellow, 0.3));
}
const var Sampler3 = Synth.getChildSynth("Sampler3");reg i3;
for (i = 0; i < 127; i++)
{
if (Sampler3.asSampler().isNoteNumberMapped(i))
Engine.setKeyColour(i, Colours.withAlpha(Colours.orange, 0.3));
}const var Sampler4 = Synth.getChildSynth("Sampler4");
reg i4;
for (i = 0; i < 127; i++)
{
if (Sampler4.asSampler().isNoteNumberMapped(i))
Engine.setKeyColour(i, Colours.withAlpha(Colours.red, 0.3));
}