The ParameterListener Object

The ParameterListener object listens for changes to the value of a named Parameter. When a change occurs, a user-specified function will be called. The object also provides methods for getting and setting the value of the observed Parameter.

ParameterListener Constructor

var pl = new ParameterListener(parameter_name, function);

The parameter_name argument is string specifying a Parameter in the patcher hierarchy of the js object running the script. Parameter names are global to a patcher hierarchy, so there's no need to know the Patcher or Maxobj for the Parameter.

The function argument specifes the function you want to execute. The function should have a single argument, which is a ParameterListenerData object.

Example:

function valuechanged(data) {
  post("parameter value changed: " + data.name + "\n")
  post("new value: " + data.value + "\n")
}

l = new ParameterListener("myParameter", valuechanged)

For convenience, the ParameterListener object is a property of the ParameterListenerData argument to the function. To access the ParameterListener from within its function:

data.listener

ParameterListener Properties

name [string]

The Parameter to observe.

ParameterListener Methods

getvalue

Report the value of the Parameter. List values are reported in a JS Array object.

setvalue

Set the value of the Parameter.

ParameterListenerData

The ParameterListenerData object is the argument to your ParameterListener's function

ParameterListenerData Properties

listener [ParameterListener]

g/s(get)

The ParameterListener which called the function.

name [string]

g/s(get)

The name of the Parameter which changed.

value [value or Array]

g/s(get)

The current value of the Parameter. List values are represented by a JS Array object.

See Also

Name Description
JavaScript Usage JavaScript Usage