Zero-effort sustain controller



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



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



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


  • administrators

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



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



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


Log in to reply

Looks like your connection to Zero-effort sustain controller was lost, please wait while we try to reconnect.