load Samplemap and play note
-
@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(); }; Content.getComponent("btnPlay").setControlCallback(onbtnPlayControl);
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); } else { Engine.allNotesOff(); }
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 ofcmbSound
. We saved this value in thesound
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) { Engine.allNotesOff(); }; Content.getComponent("btnPlay").setControlCallback(onbtnPlayControl); inline function oncmbSoundControl(component, value) { Synth.playNote(60+value-1, 64); }; Content.getComponent("cmbSound").setControlCallback(oncmbSoundControl);
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 disablesaveInPreset
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) { Engine.allNotesOff(); Synth.playNote(60+value-1, 64); };
Preset browsers are another issue
-
@d-healey when I do that, it mutes everything, also some I notice is that after selecting from the combo box, it keeps playing the next audio files in sequence
-
when I do that, it mutes everything,
What do you mean everything? In the project I sent there should only be one sound at a time.