Button play midi note?



  • @d-healey My sampler is set to Oneshot. It plays normal on the keyboard but using this code I need to hold the "Button1" to play the entire sample.

    If I cut the "else" part it will play the note forever so probably not the best idea.

    Any tips?

    inline function onButton1Control(component, value)
    {
        if (value)
    	    Synth.playNote(80, 56);
    	else
    	    Engine.allNotesOff();
    };
    
    Content.getComponent("Button1").setControlCallback(onButton1Control);
    


  • @maurodechen What do you want it to do?



  • @d-healey The button is working in "normal" playback mode. I want it to play oneshot mode like the sampler.



  • @maurodechen But in oneshot mode the sample will continue to play until the end which you already achieved by removing the else... or am I misunderstanding what oneshot mode is?



  • @d-healey Yes. If I remove the else it will play oneshot. But the midi note will keep playing infinitely even if I release the mouse button. The Sine Wave Generator confirmed that 😆



  • Oh I get it.

    Try this code. It turns off the old note before playing a new one. Of course the last note won't be turned off though. If you want to to turn the last note off I think you'd need a timer that checks to see what the voice count is and turns the MIDI note off when the voice count is 0.

    const var ids = Engine.createMidiList();
    
    inline function onButton1Control(component, value)
    {
        local noteNumber = 60;
        
        if (value)
        {
            //Turn off old note
            if (ids.getValue(noteNumber) != -1)
                Synth.noteOffByEventId(ids.getValue(noteNumber));
            
            //Play new note
            ids.setValue(noteNumber, Synth.playNote(noteNumber, 60));
        }	    
    };
    
    Content.getComponent("Button1").setControlCallback(onButton1Control);
    


  • @d-healey Actually the voice count seems like an excellent idea!

    I found "getNumVoices" in the ApiCollection.

    A function that keeps counting the voices and when it's 0:
    Engine.allNotesOff();

    I'm asking because I understand the logic but I'm a little lost in the coding yet.
    You think that's the direction?

    Something like this certainly sounds better than a never ending midi note even if there's no sound being produced.



  • Yeah that's what I was thinking. You'll need to use the timer callback too. However I wonder if there is something automatically built in to HISE that turns notes off when the samples they trigger reach the end. I'm not sure how to test this but @Christoph-Hart will know.



  • @maurodechen @d-healey I never did it with samples length, but in one of my projects I am using the sum of different time parameter of an AHDSR (summing the get.attribute for attack, hold, decay...)
    If it can help...

    time = Synth1AHDSREnvelope.getAttribute(2) + Synth1AHDSREnvelope.getAttribute(4) + Synth1AHDSREnvelope.getAttribute(5);
            samples = Engine.getSamplesForMilliSeconds(time);
            
            noteID = Synth.addNoteOn(ch, noteNb, noteVel, 0);
            Message.makeArtificial();
            Synth.noteOffDelayedByEventId(noteID, samples);
    


  • @ustk Yes. Maybe this last line is what I need. Gonna try to code something! Thanks!


Log in to reply
 

2
Online

491
Users

1.7k
Topics

13.0k
Posts