load Samplemap and play note

  • I think the samplemap system is overkill for you needs 😛

    So if samplemap = C you want every switch to trigger C3?

  • @d-healey what can I use instead?

  • @Jay You could just put all the samples in one sample map and only allow the notes to be played that you want by ignoring the others in the on note callback. But I still don't know what you're trying to do 😛

  • @d-healey yes I was thinking of doing that but don't know how, can you share a little snippet?

  • Yes I will post a snippet but it would be better if I understand exactly what behaviour you need so I can create a more complete snippet. I still don't understand exactly what you want the instrument to do.

  • @d-healey ok here is the idea I have.

    Let's say I got an audio file that I want to incorporate into my songs as a background noise like the old LP, I want to create a plugin with that audio playing, I insert that plugin in my master bus and voila the old LP noise is now part of my song, make sense now?

  • I know exactly what you want now. I'll send you a snippet soon 🙂

  • I've made a little demo project for you. It should explain things a little more clearly than just a snippet.

    The file is actually a .zip but the forum doesn't allow such files. So when you download it just change the extension to .zip and it should open.


  • @d-healey Thank you brother I'll read through it and try to learn as much as I can, I appreciate it

  • @d-healey is Good, but is there a way of no having to press the Play Button?, but when selecting any of the option in this case the notes it start automatically?

  • @Jay said in load Samplemap and play note:

    no having to press the Play Button?, but when selecting any of the opti

    Yeah of course, just put it in the combo box callback instead.

  • @d-healey said in load Samplemap and play note:

    Yeah of course, just put it in the combo box callback instead.

    Don't know what to change

  • @Jay Ok, I'll walk you through it because if I just change it it won't explain why.

    So this is the whole script (except for the one line in the on note callback)

    Content.makeFrontInterface(600, 500);
    //Combo box
    const var cmbSound = Content.getComponent("cmbSound");
    //Play button
    inline function onbtnPlayControl(component, value)
    	var sound = cmbSound.getValue()-1; //Get combobox value (-1 to start at 0)
    	value ? Synth.playNote(60+sound, 64) : Engine.allNotesOff();

    The first line Content.makeFrontInterface(600, 500); Just sets the width and height of the main interface. Nothing special here, HISE adds this for us automatically.

    In this line const var cmbSound = Content.getComponent("cmbSound"); We are getting a reference to the combo box that is on the interface. The combo box has an id of cmbSound and we are saving it in a variable with the same name.

    Next we have the callback function for the play button. This is like when you use a switch statement in the generic on control callback. But this callback is only triggered when the play button btnPlay is pressed.

    var sound = cmbSound.getValue()-1; //Get combobox value (-1 to start at 0) This line gets the current value of the combo box. We use the reference we saved earlier - cmbSound. The first item in a combo box always has an index of 1 but we want it to be 0 so we subtract 1.

    value ? Synth.playNote(60+sound, 64) : Engine.allNotesOff(); This uses the ternary operator ?. It's a way of making a 1 line if/else statement. We can understand it better if we write it out in full.

    if (value)
        Synth.playNote(60+sound, 64);

    Let's go through this.

    So firstly we only play a note when the value is 1 - if (value)

    Then we play the note Synth.playNote(60+sound, 64); We use 60 as the note number because the first sample is mapped to middle C which is MIDI note 60. We add to this the current value of cmbSound. We saved this value in the sound variable earlier. So if the first sound is selected then the note that triggers will be 60, if the second sound is selected then the triggered note will be 61, etc.

    In the else clause (it the button value is 0) we just turn off all playing notes. That way we don't have to keep track of individual note IDs. There will only ever be one note playing at a time.

    Ok so to get this to play when selecting from the comboBox instead of by pressing the play button we add a callback function for the combo box. The callback function is auto-generated by HISE if we right click on the control in the widget list and select create custom callback definition then paste into the script editor.

    Now our script will look like this:

    Content.makeFrontInterface(600, 500);
    //Play button
    inline function onbtnPlayControl(component, value)
    inline function oncmbSoundControl(component, value)
    	Synth.playNote(60+value-1, 64);

    The play button is now a stop button - you'll probably want to rename it and set it to be momentary.

    The note is played in the cmbSound callback. We no longer need to store this control or its value in a separate variable. We can just use the value directly in the Synth.playNote() function. You'll want to disable saveInPreset for the combo box otherwise it will always play when you hit compile.

  • @d-healey got it up to here, but every time I select any of the other notes it play on top of the one already playing, how do I mute the last note playing and start playing the new select it one?

  • @Jay Oh yeah I didn't think of that. Well you know how to turn the note off, right 😉 so just do that before you play a note.

  • @d-healey yeah cool, but I would like to be able to do it automatically, I will be trying to do it myself to see if I can pull it off, wish me luck.

    Thanks man

  • Just use the same code from the stop button - Engine.allNotesOff();

  • @d-healey I'll try when I get home from work

  • @d-healey I couldn't get it to work, maybe I'm going the old route of doing a samplemap per audio file.

    Also can't get the text to update when calling the preset using this:

    Content.getComponent("presetLbl").set("text", Engine.getCurrentUserPresetName());

  • inline function oncmbSoundControl(component, value)
    	Synth.playNote(60+value-1, 64);

    Preset browsers are another issue

Log in to reply