Button play midi note?

  • Hello everyone!
    Can I assign a Button or a Image to play a midi note with mouse left click?

    I'm sorry if the answer was in my face. I really can't find something about this!

  • Yup

    HiseSnippet 1032.3oc4W0saaaCElz1pXxcIXcnXXWrKDJ1EN.YA1coYEnWzj3XWXr5DinztcyPAiDsMQnH0HoxlQQeR1SvdK1iTuZ2tcn9IRtSKy16OfM4aLO77yGO76bNRSTx.pVKUHr6EKhoH7663uPXl2eNgIPiNAg21YLQanJuLQGuHln0zPDF27YVAX2Vnzm29ziIbhHfVJBgdojEPeNKhYJkN4vujw4CIgzKXQUzd+CGEHE8kbYBfmlNcQwjfqHynmRrp0vAguyfPlQp7MDCUivsNVFtvet76DY5+RllcImZWzC4CNJS7PIOzhX6+Q8my3gSJN2ZDB6LoLKzLKKbemwrP1MxKyFeP5FdkVTMefabavq2FBObE30JCd2ywOPwhMk6Xw1ccFIfKpoD3JnJrxzE03GvN8kfFBydQjqnCUvharnyAc6tq2i51cmmrUa6OlfyDTuoIh.CSJ7jhiSLFonm0GJIuSfLJVJ.usq20DdBcmsZ+5sZ6AOrodcJD4ZEjRo1KlSVbpzXC0tdGruMPtTtllqz.wLHf6Q3bqR5ylNsiUk2jhmBfOiZ5WD2NOHGQOXm8zV4o3pO3fKAdSm2EvVmU4zXCxYhN6z90sca+l1du6V1vWyd4NiSU0tskQqtMC6HRhtjpJxYEJBWsKyctypwcBxxKUTTJFIXlyho4qKYW8pgcgxSrVdVNBAUMorrsyYYYoQDCbhqSdNEkB+pU5nWL5DhgT3HvmPbhoJCydbvmPuF5DjQeccNgpuxHiS0M+1DpCWgv98fZ3OAiPKr+wd.X5wxHvdhBDgaf9sUKPMqLLgSLKWHa6dkuAbCsTEispPnYlEU6tsFU2cqs5t17+JB264LgYBlWOdaTCdg6g+twaduxsbFLcJMvTB1VNC+5Msw3lAksyfxcc7gVHocaRAxGkt16qHWS8dFUPU1jZueuYX+zO+M+3pNCKdkmgcVfAB+EJhPGK0K4XeZD6Bf7qqJ7EZnyL8aO2dKWUdeIQU6Vu8oCgCYs13SLIpT5xQQxDgYI5QyMZX0xUMUzulIWs9WXv5e8kd+46Tzb0f6evre2BL5yhh4zAhqobnAaJF+Pni5TRB2THcYR9XoPFOWJXAUY.mSMJ1rYTUUrW6A5HiAlnVJ49GdNkSIUYye5gOGXgDEjmnaXtn2pmKts6qO1ICtd1JSu+azgu4+O6vetLwvDyFS.hpcx+oIQ9Pi0.JfDg.d2Q6KAzv1bLacW65rNqhvzE+B7juYO6Zb9l8J17ejXDQBTxWEj89UVt76kJAN2hzOswE9FKXs2MuVkM2DA8CeUPfMY+YP1odKd3Zawmu1Vr+ZawiVaKNXss3KVaKd7sXgc3yQIFYTVoGHXxfzWmEiGHH.yMkki9UvVb1vg

  • @d-healey Perfect. Thank you!

  • @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);

  • @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)
            //Play new note
            ids.setValue(noteNumber, Synth.playNote(noteNumber, 60));

  • @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:

    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);
            Synth.noteOffDelayedByEventId(noteID, samples);

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

Log in to reply