PLAY et STOP " Midi Player 1 "
-
@tsempire I'll give the solution to those who need it.
- Copy this code:
// Get a reference to the MIDI processor as MIDI player
const MIDIplayer = Synth.getMidiProcessor("MIDI Player1").asMidiPlayer();// Get a reference to the transport buttons
const grpTranportBtn = [Content.getComponent("btnPlay"),
Content.getComponent("btnStop")];
for(b in grpTranportBtn)
{
// Make sure the buttons are not saved with the presets
b.set("saveInPreset", false);// Assign the control callback to the transport buttons b.setControlCallback(onTransportBtnControl);
}
// Also set the STOP button to be momentary
grpTranportBtn[1].set("isMomentary", true);inline function onTransportBtnControl(component, value)
{
// get which button triggered the callback
local index = grpTranportBtn.indexOf(component);// If it's the PLAY button if(index == 0) { // if the PLAY button is pressed if(value) { // start playing MIDIplayer.play(0); } else { // keep the button's value to 1 if it's still playing grpTranportBtn[0].setValue(1); } } // if it's the STOP button else { // only react if the mouse is clicked (not released) if(!value) return; // stop playing MIDIplayer.stop(0); // set the PLAY button's value to 0 grpTranportBtn[0].setValue(0); }
};
// on compilation, reset the playhead position to the beginning
// comment it out if not needed
MIDIplayer.setPlaybackPosition(0.0);- Create 2 buttons with the ID
btnPlay
btnStop