Pilcrow Records

Scripter Javascript Tutorial

javascriptmusiclogicscripterbookexcerpttutorial

74 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:

  1. Which parameter to be accessed as the index in the PluginParameters array.

  2. The changed parameter’s value.

In the following example, changes to two controls are captured:

var PluginParameters = [];

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});
function 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:

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.