HISE Logo Forum
    • Categories
    • Register
    • Login

    Zero-effort sustain controller

    Scheduled Pinned Locked Moved Presets / Scripts / Ideas
    6 Posts 3 Posters 1.6k 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.
    • S
      Skrylar
      last edited by

      I wrote this when testing out the Salamander and Ivy sample sets. Doesn't track which notes were on and properly release them, it just shunts all notes off when the given CC is released.

      Globals.sustain = false;
      
      function onNoteOn()
      {
      	
      }
      
      function onNoteOff()
      {
      	if (Globals.sustain) {
      		Message.ignoreEvent(true);
      	}
      }
      
      function onController()
      {
      	Console.print(Message.getControllerNumber());
      	if (Message.getControllerNumber() == 64) {
      		var newSustain = Message.getControllerValue() > 63;
      		
      		if (newSustain != Globals.sustain) {
      			if (newSustain == false) {
      				Engine.allNotesOff();
      			}
      		}
      		
      		Globals.sustain = newSustain;
      	}
      }
      
      function onTimer()
      {
      	
      }
      
      function onControl(number, value)
      {
      	
      }
      

      Probably good enough to be an example of using the scripting system, if nothing else.

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

        This looks interesting but I don't really get what this is doing

        if (Message.getControllerNumber() == 64) {
        		var newSustain = Message.getControllerValue() > 63;
        

        What is the actual purpose of the script?

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

        1 Reply Last reply Reply Quote 0
        • S
          Skrylar
          last edited by

          It turns that CC in to a poor man's sustain pedal, which is "held" when a CC value of 64-127 is given (high) and "released" when it is 0-63. It's just more forgiving than checking that the CC is exactly 127 or not.

          1 Reply Last reply Reply Quote 1
          • Christoph HartC
            Christoph Hart
            last edited by

            Hi Skrylar,

            and welcome to the forum. This is a neat trick, however I think that the current sustain pedal implementation already interprets values above 63 as "on" (and not only 127).

            This is the C++ code that handles sustain pedal behavior:

            case 0x40:  handleSustainPedal   (midiChannel, controllerValue >= 64); break;
            

            Also, it's recommended to use local variables in callbacks as they are faster and avoid unpredictable memory allocations (but actually I could automatically make var definitions in callbacks local since this is not obvious for people that are used to standard Javascript).

            1 Reply Last reply Reply Quote 0
            • S
              Skrylar
              last edited by Skrylar

              @Christoph-Hart I didn't know there was built-in support for sustains when I wrote that.

              UX Sidebar: I expected there not to be one, since the program didn't show me that one existed. So I looked under the "hard-coded scripts" where things like note transposing is, and thought sustain control would be there. Since there A) exists such a thing as hard-coded scripts and curve editors and B) it didn't include sustain, I naturally assumed it wouldn't do it.

              I don't know how well the "if it's not visible, it isn't happening" assumption holds for users of samplers. The UI probably ought to hint that a sustain pedal is built in to the sampler (discoverability.)

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

                I think most samplers respond to the sustain pedal correctly by default, I'm not sure what you'd put on the UI for this, maybe a sustain pedal on/off indicator? Seems a little unnecessary though and would just take up space. Probably best to just mention it in the manual if it isn't already.

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

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

                29

                Online

                1.7k

                Users

                11.7k

                Topics

                102.0k

                Posts