Controller Value To Note On Velocity



  • A simple little script to convert a selected controller's value to note on velocity. Handy if you want to control staccato sample dynamics with a CC instead of velocity for example. Or you could bypass the script to switch back to the default velocity based control.

    /**
     * Title: Controller Value To Note On Velocity v1.0.1
     * Author: David Healey
     * Date: 30/06/2017
     * Modified: 30/06/2017
     * License: Public Domain
    */
    
    Content.setHeight(50);
    
    const var knbCC = Content.addKnob("CC Number", 0, 0);
    knbCC.setRange(1, 127, 1);
    
    reg lastCCValue = 1;
    
    function onNoteOn()
    {
    	Message.setVelocity(lastCCValue);
    }
    
    function onNoteOff()
    {
    }
    
    function onController()
    {
    	if (Message.getControllerNumber() == knbCC.getValue())
    	{
    		lastCCValue = Math.max(1, Message.getControllerValue());
    	}
    }
    
    function onTimer()
    {
    }
    
    function onControl(number, value)
    {
    }
    

  • administrators

    I'd recommend using a reg variable for the lastCCValue. Also you can use

    lastCCValue = Math.max(1, Message.getControllerValue();
    

    to remove the if branch (shorter and slightly faster).



  • Oh I'd completely forgotten Math.max(). Good idea! I'll update my original post


Log in to reply
 

2
Online

339
Users

1.0k
Topics

7.1k
Posts

Looks like your connection to Forum was lost, please wait while we try to reconnect.