Mark notes that contain samples by coloring keyboard keys
-
@d-healey Thank you! I spent the last couple of days thinking of your answer. While I understand every word individually, I can't say I do when they are combined in such a way I am sorry.
Could you please give me some pointers with regards to "array and loop"? I assume I am supposed to do this with code and not with the way they are arranged within sampler container, no? -
@gorangrooves Yes code.
So you need to use this part of the code which gets the sampler
const var Sampler1 = Synth.getChildSynth("Sampler1");
But instead of storing one sampler in one variable you need to store all of the samplers you are interested in using in an array. There are several ways to do this but the simplest is manually one line at a time.
const var samplers = []; //Declare the array samplers[0] = Synth.getChildSynth("Sampler1"); //Add sampler 1 to the array (index is 0) samplers[1] = Synth.getChildSynth("Sampler2"); //Add sampler 2 to the array (index is 1) samplers[2] = Synth.getChildSynth("Sampler3"); //Add sampler 3 to the array (index is 2)
Then you need to loop through all of the samplers. Again there is more than one way to do this, here is how I would probably do it.
for (s in samplers) { }
Then inside this loop you have the original loop I posted that checks every key and colours the right one, only this time it will do this for every sampler in the
samplers
array.reg i; for (s in samplers) { for (i = 0; i < 127; i++) { if (s.asSampler().isNoteNumberMapped(i)) //s is the sampler being checked, we get s from the outer loop Engine.setKeyColour(i, Colours.withAlpha(Colours.blue, 0.3)); } }
-
@d-healey Thanks so much for your kindness and for teaching me! I will be playing around with this and hopefully will manage to get it going :) I'll report back.
-
@d-healey I got it working! Thank you sooo much! I still don't fully understand how you came up with the logic for the code. Good on you. Quite simple and most importantly, it works :) Thank you. Thank you. Thank you!
-
@gorangrooves No problemo
I still don't fully understand how you came up with the logic for the code.
By reading lots of code and writing lots of code ;)
-
@d-healey I've many sample maps on one sampler and all keys are coloured at the same time, have an idea to do with sample map ?
//I've try replace 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.3)); } //by const var Sampler1 = Synth.getChildSynth("Sampler1"); const var sampleMaps = Sampler.getSampleMapList(); reg i; for (i = 0; i < 127; i++) { if (Sampler.getSampleMapList().isNoteNumberMapped(i)) Engine.setKeyColour(i, Colours.withAlpha(Colours.blue, 0.3)); }
Not working
-
@Jerems134 I don't understand the question, could you rephrase it?
-
@Jerems134 It is not the SampleMap you need to check but the sampler itself
Sampler1.asSampler()
assuming your sampler is called "Sampler1"
Perform this each time you load a new sampleMap -
@d-healey @ustk On Sampler1 I have 2 sample maps loaded and I switch with presets/combo box.
How to color keys only for samplemap1 and match coloured keys on samplemaps2 when I switch presets ?
Actualy all keys from all sample maps are coloured no matter different sample maps mapping.
They are layered.Full code :
Content.makeFrontInterface(1200, 370); const var Panel1 = Content.getComponent("Panel1"); const var Panel2 = Content.getComponent("Panel2"); const var Button1 = Content.getComponent("Button1"); //Tab button callback function inline function onButton1Control(component, value) { if (value == 1) Panel2.showControl(true); else Panel2.showControl(false); }; Content.getComponent("Button1").setControlCallback(onButton1Control); //Presets ComboBox Function //Sampler const var Sampler1 = Synth.getChildSynth("Sampler1"); //Sample maps array const var sampleMaps = Sampler.getSampleMapList(); //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]); }; Content.getComponent("cmbSampleMap").setControlCallback(oncmbSampleMapControl); //Coloured Keys //const var Sampler1 = Synth.getChildSynth("Sampler1");//(Repetiton) reg i; for (i = 0; i < 127; i++) { if (Sampler1.asSampler().isNoteNumberMapped(i)) Engine.setKeyColour(i, Colours.withAlpha(Colours.blue, 0.3)); }
-
Add a hidden panel on the interface. Wrap your key colour code in the panel callback.
Don't forget to enable saveInPreset so when you change preset the callback is called -
@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.