SoftSet:
Filter:
Modality-toolkit/Classes (extension) | Utilities

SoftSet
ExtensionExtension

set process parameters politely.

Description

SoftSet is intended for letting a controller set a numerical parameter of an object politely. The common problem is that when a controller is newly assigned to a process parameter, the physical position can differ widely from the current param value in the process/object, which would create undesirable large parameter jumps when moving the controller.

SoftSet solves this by considering whether the new value is acceptable: if the new value is close enough to the current value in the object, or if the previous value of the controller is close enough to the current value of the process param (which implies that the object was last set from this controller, so the controller conceptually 'owns' it now), it is considered OK to set.

SoftSet returns a boolean whether the set message was accepted.

Class Methods

NOTE: SoftSet only has class methods, to be used as pseudo methods with multiple classes.

.new

SoftSet an object's parameters from a simple value. Convenient with e.g. sliders that use an appropriate parameter range.

Arguments:

obj

the object whose parameter is to be set

paramName

the name of the parameter to be set

value

the unipolar value to set it to, will be mapped by a spec

within

the range within which the value should match the current parameter value to allow the softset

lastVal

the last value which the controller has sent; this helps to determine whether the controller has done the last set of the param in question.

spec

a spec to use for calculation of the unipolar distance within which values should match.

Returns:

a Boolean whether the set has been accepted.

.uni

SoftSet an object's parameters from a unipolar value. Convenient with many controllers that use unipolar values. The mapping spec is done by the receiving object's spec for that param name.

Arguments:

obj

the object whose parameter is to be set

paramName

the name of the parameter to be set

value

the unipolar value to set it to, will be mapped by a spec

within

the range within which the value should match the current parameter value to allow the softset

lastVal

the last value which the controller has sent; this helps to determine whether the controller has done the last set of the param in question.

Returns:

a Boolean whether the set has been accepted.

.nextPair

same as *new, but does not do the setting yet. Instead it returns a pair of values if setting would be accepted, or nil if not. This is intended for collecting multiple name value pairs for a single set message.

Returns:

a pair of values if setting would be accepted, nil if not

.uniNextPair

same as *new, but does not do the setting yet. Instead it returns a pair of values if setting would be accepted, or nil if not. This is intended for collecting multiple name value pairs for a single set message.

Returns:

a pair of unipolar values if setting would be accepted, nil if not

.defaultWithin

gets and set a default value for unipolar distance within which softset is accepted.

.getSpec

ask an object for its spec for a given param name. this is used when no spec is given explicitly, and expects object to answer to getSpec.

Returns:

a spec

Examples