HISE Logo Forum
    • Categories
    • Register
    • Login

    Button play midi note?

    Scheduled Pinned Locked Moved General Questions
    13 Posts 3 Posters 859 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 @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

                        47

                        Online

                        1.7k

                        Users

                        11.7k

                        Topics

                        101.9k

                        Posts