Scripter Javascript Tutorial
javascriptmusiclogicscripterbookexcerpttutorial74 Capturing Parameter Control Updates
The ParameterChanged()
function is how all parameter
control changes are captured in the script, either by the user or in
code. The function is optional and is not required for a working script.
The function accepts two values:
Which parameter to be accessed as the index in the
PluginParameters
array.The changed parameter’s value.
In the following example, changes to two controls are captured:
var PluginParameters = [];
.push({name:"Linear Slider 1", type:"lin", unit:"%", minValue:0, maxValue:100, numberOfSteps:100, defaultValue:50});
PluginParameters.push({name:"Linear Slider 2", type:"lin", unit:"%", minValue:0, maxValue:100, numberOfSteps:100, defaultValue:50});
PluginParametersfunction HandleMIDI ( event ) {
if ( event instanceof NoteOff ) {
SetParameter("Linear Slider 1", 50);
SetParameter("Linear Slider 2", 50);
}
}
function ParameterChanged( param, value ) {
switch( param ) {
case 0:
Trace("Linear Slider 1: " + value );
break;
case 1:
Trace("Linear Slider 2: " + value );
break;
default:
Trace("ERROR: ParameterChanged");
} }
In the above example:
Lines 1–4: Two linear slider controls are created.
Lines 7–10: When a
NoteOff
event is encountered by the playhead, the controls are reset to their default values (50).Lines 13–24: As the controls are changed by the user or reset in code, the
ParameterChanged()
function is called by Scripter and the value changes are then managed from there (or not).Line 13: The two arguments are passed: the parameter control’s
index
in the PluginParameter array and thevalue
to which the control was set.Lines 14–23: A
switch
statement is used to test which index was passed and the resulting code block is executed.
Note that the ParameterChanged()
function does not
provide the source of the change, either by the user or by any code. All
changes are handled the same.