Mark notes that contain samples by coloring keyboard keys

  • Hey guys,
    does anyone have a script willing to share that would color the keys on the floating keyboard only for notes that are being used by the sampler instrument? To be clear, I don't want to just label a range, but rather automatically mark every key that has a sample loaded to it.

    On a related subject, how do I go about specifying the range a floating keyboard displays? How do I change the keyboard style to flat?

    Thank you!

  • @gorangrooves The data object of the floating tile is accessible in the interface designer and allows you to change the key range and the keyboard style

      "KeyWidth": 14,
      "DisplayOctaveNumber": false,
      "LowKey": 9,
      "HiKey": 127,
      "CustomGraphics": false,
      "DefaultAppearance": true,
      "BlackKeyRatio": 0.69999999,
      "ToggleMode": false,
      "MidiChannel": 1,
      "UseVectorGraphics": false,
      "UseFlatStyle": false,
      "MPEKeyboard": false,
      "MPEStartChannel": 2,
      "MPEEndChannel": 16

    I haven't written a script to automatically colour keys that are mapped but it shouldn't be hard to do. You would need to use the Sampler.isNoteNumberMapped() function.

  • I decided to write it anyway. Just replace "Sampler1" with the name of your sampler

    const var Sampler1 = Synth.getChildSynth("Sampler1");
    reg i;
    for (i = 0; i < 127; i++)
        if (Sampler1.asSampler().isNoteNumberMapped(i))
            Engine.setKeyColour(i, Colours.withAlpha(, 0.3));

  • @d-healey Hey man, thanks for much for the script! It is greatly appreciated. Can't wait to try it 🙂

    I am aware of the settings for the keyboard in the interface designer. However, I am not able to change anything. Actually, I make an edit, but as soon as I rebuild the interface the changes revert to default. Not sure what the deal is. Am supposed to do something else as well?

    Thank you.

  • @gorangrooves You need to press F5 once you've edited the data

  • @d-healey Thank you!

  • Ok this was one time too much that people stumble over this. I‘ll add a button and a discard warning 😉

  • @gorangrooves I tested the script and it works for a sampler 🙂 Yay!

    Is there a way to specify that it uses the master container that contains all of the samples instead of a single sampler? Or do I need to replicate the script for each sampler?

  • @gorangrooves If there is more than one sampler you will need to modify the code. Put all of the samplers in an array and loop through all of them, test if any of them have a sample mapped to i and if so colour the key - so you will have a loop inside another loop.

  • @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(, 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 😉

Log in to reply