Keyboard to display only active keys?
-
Hi! i'm new here and learning how to use this awesome software!
I'm just wondering if there's a way i can get the keyboard to only show the active keys on a sampler?
For instance;
I have a sampler than only has a one octave range, i would only want it to show that one octave on the keyboard? the rest could be greyed out or simply not shown?Thanks for your time :)
-
Engine.setKeyColour
-
for(i = 0; i < 50; i++) { Engine.setKeyColour(i, 0x88000000); } for(i = 50; i < 90; i++) { Engine.setKeyColour(i, 0x22ffffff); } for(i = 90; i < 128; i++) { Engine.setKeyColour(i, 0x88000000); }
Pick any numbers you want to match your actual range for the loop limits, if you start hotswapping sample maps and have a dynamic keyboard range, you can hook it up to a callback that rebuilds this after you loaded a sample map, but for starters that should be fine.
-
@Christoph-Hart Awesome, thanks guys i'll give this a go!
-
@Christoph-Hart @d-healey I can't seem to make this work using a callback, i think i'm missing some vital functions/have old information, could you offer an example of how this would work please?
-
Show us what you have so far
-
@d-healey Sure!
This is pretty broke as im new to this and have had to find bits from all over the internet here.
Content.makeFrontInterface(670,400); //Sampler const var Sampler1 = Synth.getChildSynth("Sampler1"); const var thesampler = Sampler1.asSampler(); thesampler.enableRoundRobin(false); //Sample maps array const var sampleMaps = Sampler.getSampleMapList(); const var cmbSampleMap = Content.getComponent("cmbSampleMap"); //Combo box cmbSampleMap.set("items", sampleMaps.join("\n")); //AquireKeys const var map = sampler.LoadSampleMap(); const var noteRange = map.getNoteRange(); const var firstKey = Engine.getKeyForNoteNumber(noteRange.getStart()); const var lastKey = Engine.getKeyForNoteNumber(noteRange.getEnd()); for (i = firstKey; i <= lastKey; i++) { if (map.getKeyForNoteNumber(Engine.getNoteNumberForMidiPitch(i)) != -1) { if (Engine.getNoteNumberForMidiPitch(i) < 50) Engine.setKeyColour(i, 0x88000000); else if (Engine.getNoteNumberForMidiPitch(i) < 90) Engine.setKeyColour(i, 0x22ffffff); else Engine.setKeyColour(i, 0x88000000); } } inline function oncmbSampleMapControl(component, value) { //Console.print(value); Sampler1.asSampler().loadSampleMap(sampleMaps[value-1]); }; Content.getComponent("cmbSampleMap").setControlCallback(oncmbSampleMapControl); Synth.addToFront(true);
-
Sample loading is asynchronous. So you need to wait until after the samples have loaded before you can query the mapping and colour the keys. You can use the preloading callback for this. Will your key range change or is it fixed?
-
@d-healey I have several different Sample Maps that have several different key ranges, i just realised i followed your tutorial to learn how to switch between these! Hi! haha.
-
@DailyLlama Then you have two choices.
Use the preload callback as suggested.
Hardcoded the key ranges so that when sample map A is selected key range A is displayed, when sample map B is selected key range B is displayed, etc. -
@d-healey Ah okay, Thanks for your help i'll see if i can figure this out :)
-
@DailyLlama Keep posting code snippets if you need more help.
-
Hi! i've been trying to work on this all day with my friend and i'm not sure where i'm going wrong.
The console is saying getLayerContainer - function not found, and i can't seem to find a replacement for this in the API, am i just working with outdated information and need to learn the new functions? or is it not possible to do what i'm trying to do like this anymore? please help!Content.makeFrontInterface(670,400); //Declarations const var layer; const var numSamples; const var sample; const var rootKey; //Sampler const var GoatScream = Synth.getChildSynth("GoatScream"); const var goatsampler = GoatScream.asSampler(); goatsampler.enableRoundRobin(false); //Sample maps array const var sampleMaps = Sampler.getSampleMapList(); const var cmbSampleMap = Content.getComponent("cmbSampleMap"); //Combo box cmbSampleMap.set("items", sampleMaps.join("\n")); inline function oncmbSampleMapControl(component, value) { //Console.print(value); GoatScream.asSampler().loadSampleMap(sampleMaps[value-1]); }; Content.getComponent("cmbSampleMap").setControlCallback(oncmbSampleMapControl); const var notes = []; // Loop through each layer in the sample map for (var i = 0; i < cmbSampleMap.getLayerContainer().getNumLayers(); i++) { layer = cmbSampleMap.getLayerContainer().getLayer(i); numSamples = layer.getNumSamples(); // Loop through each sample in the layer for (var j = 0; j < numSamples; j++) { sample = layer.getSample(j); if (sample != null) { // Get the root key of the sample rootKey = sample.getRootKey(); // Set the key color of the note to 0x22ffffff cmbSampleMap.setKeyColor(rootKey, 0x22ffffff); // Add the root key to the notes array notes.push(rootKey); } else { // Set the key color of the null sample to 0x88000000 cmbSampleMap.setKeyColor(j, 0x88000000); } } } // Print the notes array to the console Console.print(notes); Synth.addToFront(true);
-
I don't think
Sampler.getSampleMapList()
will work. I think it has to be called on a Sampler object (but I could be wrong). If your combobox contains a list of all the sample maps then it's worked.You don't need
Synth.addToFront
You don't need to declare your loop iterators as
var
. HISE will handle it for you.Comboboxes don't have a function called
getLayerContainer()
and there is no function calledgetNumLayers()
. Where did you find these?You're trying to reassign
const
variables, this won't work.Comboboxes don't have a function called
setKeyColor
. The function (as posted earlier) isEngine.setKeyColour()
. You can use the built in API browser to check this stuff.You're not using the preloading callback anywhere.
-
@d-healey This is what my friend came back with, he has extensive experience with coding languages but obviously not with hise.
I'm not as well versed as you are with this program, i'm still trying to learn and figure this stuff out as i go. -
i'm still trying to learn and figure this stuff out as i go.
Yeah that's we're here for.
I suggest you first learn to colour the keyboard with a fixed range.
All you need is a for loop and the setKeyColour function. All the info has already been posted in this thread but if you need any details just ask.
Also, here is a script I wrote a few years ago for colouring a keyboard range. You might find it useful to study - https://github.com/davidhealey/HiseUtilityScripts/blob/master/modules/KeyRangeColour.js
-
@d-healey Thanks for replying, wow that's a lot of code, i've brough it in to a blank project to try understand your script and go through it with my friend, and i'm getting this error;
Master Chain:! Line 55, column 6: Can't declare var statement in inline function {SW50ZXJmYWNlfG9uSW5pdCgpfDE1ODB8NTV8Ng==}
Is this a problem on my end?
-
@DailyLlama said in Keyboard to display only active keys?:
@d-healey Thanks for replying, wow that's a lot of code, i've brough it in to a blank project to try understand your script and go through it with my friend, and i'm getting this error;
Yeah I wouldn't recommend trying to use it as is. It's old and will need a few fixes to run in the latest version of HISE.
Probably the most relevant part to you is the
updateKeyboardColours
function. But again, don't copy/paste it and expect it to work as is. It's just for guidance. -
@d-healey Hi!
Thanks for all your help so far, here's how i think i understand this.
{ for (i = 0; i < 128; i++) { if (i >=40 && i <=95) Engine.setKeyColour(i, Colours.withAlpha(Colours.white, 0.0)); else Engine.setKeyColour(i, Colours.withAlpha(Colours.black, 0.4)); } }
The for loop iterates through the set 128 note numbers.
For each note it's checking if it falls between the range i set of 40 - 95 it then calls the engine.setKeyColour() function, and makes them white, or in this case, transparent as i've set the value to 0.0, so, normal key colour.
If the note doesn't fall within my set range, it's coloured transparent black?
I've tried this in my project and it works!
I need to figure out how to get this to work with the different samplemaps within my combo box still.
-
@DailyLlama Yep that's the way to do it.
You could use a 2D array for your ranges. Have one array per sample map and each sub array contains the note ranges. Then you just use the value of your combobox to get the index of the correct range array.
And you trigger the colour keys function from the comboboxes control callback. Not quite as elegant as querying the sample mapping in the loading callback but probably a bit easier to implement.
For example:
const myRanges = [[40, 95],[60, 80], [10, 24]];