HISE Logo Forum
    • Categories
    • Register
    • Login

    Sample stops playing when key is released

    Scheduled Pinned Locked Moved Scripting
    4 Posts 3 Posters 39 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.
    • pcs800P
      pcs800
      last edited by

      I would like to alter this code so that the entire sample gets played once a key is pressed, regardless if the user releases the key before the sample is done playing.

      const var ids = Engine.createMidiList();
      
      inline function onButton1Control(component, value)
      {
          local noteNumber = 36;
          
          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, 36));
          }	    
      };
      
      Content.getComponent("Button1").setControlCallback(onButton1Control);
      
      d.healeyD 1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey @pcs800
        last edited by

        @pcs800 If you enable one-shot mode in the sampler's playback settings it will do this without any scripting.

        4912e2e6-4116-40bc-936a-74b8962538fe-image.png

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

        1 Reply Last reply Reply Quote 1
        • rglidesR
          rglides
          last edited by

          David is of course right, but if you do want to script this, perhaps to be able to let the user switch between one shot and normal you can easily use this

          Sampler1AsChild.setAttribute(Sampler1AsChild.OneShot, true);
          

          just make sure to use the as child refence

          rglidesR 1 Reply Last reply Reply Quote 0
          • rglidesR
            rglides @rglides
            last edited by

            @rglides and false if you want Normal mode

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

            31

            Online

            1.9k

            Users

            12.2k

            Topics

            106.5k

            Posts