Pilcrow Records

Scripter Javascript Tutorial

javascriptmusiclogicscripterbookexcerpttutorial

72 Update Control Values

To update the value of any control, use the global SetParameter() function, which accepts two arguments:

  1. Which parameter to be accessed, which can be done either as the parameter name or the index in the PluginParameters array. The parameter name must be exactly the same.

  2. The value to be set for the control, which is always a number.

var PluginParameters = [];
PluginParameters.push({name:"Linear Slider 1", type:"lin", unit:"%", minValue:0, maxValue:100, numberOfSteps:100, defaultValue:50});
SetParameter("Linear Slider 1", 0);
SetParameter(0, 0);

In the above example:

When SetParameter() is called with a name or an index which does not exist in PluginParameters, then the following error is shown:

SetParameter() called with an argument: (Linear Slider 2) that does not equal any registered parameter name.

SetParameter() only works when called from either HandleMIDI() or ProcessMIDI(), so the track must be playing in order for the callback to make any changes. All changes to parameter controls either by SetParameter() or by the user are captured in the ParameterChanged() function.