HISE Logo Forum
    • Categories
    • Register
    • Login

    Button play midi note?

    Scheduled Pinned Locked Moved General Questions
    13 Posts 3 Posters 862 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      maurodechen
      last edited by

      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!

      1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey
        last edited by

        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
        

        Libre Wave - Freedom respecting instruments and effects
        My Patreon - HISE tutorials
        YouTube Channel - Public HISE tutorials

        M 2 Replies Last reply Reply Quote 1
        • M
          maurodechen @d.healey
          last edited by

          @d-healey Perfect. Thank you!

          1 Reply Last reply Reply Quote 0
          • M
            maurodechen @d.healey
            last edited by

            @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);
            
            d.healeyD 1 Reply Last reply Reply Quote 0
            • d.healeyD
              d.healey @maurodechen
              last edited by

              @maurodechen What do you want it to do?

              Libre Wave - Freedom respecting instruments and effects
              My Patreon - HISE tutorials
              YouTube Channel - Public HISE tutorials

              M 1 Reply Last reply Reply Quote 0
              • M
                maurodechen @d.healey
                last edited by

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

                d.healeyD 1 Reply Last reply Reply Quote 0
                • d.healeyD
                  d.healey @maurodechen
                  last edited by

                  @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?

                  Libre Wave - Freedom respecting instruments and effects
                  My Patreon - HISE tutorials
                  YouTube Channel - Public HISE tutorials

                  M 1 Reply Last reply Reply Quote 0
                  • M
                    maurodechen @d.healey
                    last edited by

                    @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 😆

                    1 Reply Last reply Reply Quote 0
                    • d.healeyD
                      d.healey
                      last edited by

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

                      Libre Wave - Freedom respecting instruments and effects
                      My Patreon - HISE tutorials
                      YouTube Channel - Public HISE tutorials

                      M 1 Reply Last reply Reply Quote 0
                      • M
                        maurodechen @d.healey
                        last edited by

                        @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.

                        1 Reply Last reply Reply Quote 0
                        • d.healeyD
                          d.healey
                          last edited by

                          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.

                          Libre Wave - Freedom respecting instruments and effects
                          My Patreon - HISE tutorials
                          YouTube Channel - Public HISE tutorials

                          1 Reply Last reply Reply Quote 0
                          • ustkU
                            ustk
                            last edited by

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

                            Can't help pressing F5 in the forum...

                            M 1 Reply Last reply Reply Quote 2
                            • M
                              maurodechen @ustk
                              last edited by

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

                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post

                              25

                              Online

                              1.7k

                              Users

                              11.7k

                              Topics

                              102.0k

                              Posts