ParameterBindings

The parameters of objects, bound by labels: their values are read, set, randomized, saved and loaded by the label of an object and the name of a parameter. This is what a GUI shows, without a GUI: programs that run without one, and other front ends, like remote controls or MIDI controllers, use it in the same way.

Objects are added with add, under a label that is unique. The objects held by properties with a NestedParameter annotation are bound too, labeled <label of the parent>/<label of the nested parameter>; when such a property holds another object, rebindNested binds that object.

val bindings = ParameterBindings()
val settings = bindings.add(Settings(), "settings")
bindings.load(File("parameters.json"))
bindings["settings", "radius"] = 20.0

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
class Binding

The binding of obj, an object with parameters, under label

Link copied to clipboard
class Change(val binding: ParameterBindings.Binding, val parameter: Parameter, val value: Any?)

a change of the value of parameter of binding, or of the object of a nested parameter

Link copied to clipboard

The binding of the object held by the property of a ParameterType.Nested parameter of parent

Properties

Link copied to clipboard

an object was added

Link copied to clipboard

the bindings of the objects that are added, in the order they are added

Link copied to clipboard

Values were changed through the bindings: by set, invoke, randomize, fromObject or load; for nested parameters by rebindNested. Front ends trigger it for the changes they make, like the GUI of orx-gui for its controls. Changes made to the objects directly are not noticed.

Link copied to clipboard

the values were loaded, by fromObject or load

Link copied to clipboard

the property of a nested parameter holds another object, which is bound, see rebindNested

Link copied to clipboard

an object was removed

Functions

Link copied to clipboard
fun add(obj: Any, label: String? = obj.title()): ParameterBindings.Binding?

Adds obj under label, or the title of its Description annotation; the label is made unique. Objects without parameters are not bound.

Link copied to clipboard

the bindings of the objects and of the objects nested in them, parents before the objects nested in them

Link copied to clipboard

the binding of obj

the binding with label, of an object or a nested object

Link copied to clipboard

the value of parameter of binding when its object was bound, null when it has no value

Link copied to clipboard
fun fromJson(json: String)

sets the values of the parameters to the values in json, see fromObject

Link copied to clipboard
fun fromObject(labeledValues: Map<String, Map<String, ParameterValue>>)

Sets the values of the parameters of the objects to labeledValues, by the label of the object and the name of the parameter; values of objects or parameters that are not bound are ignored. Complements toObject.

Link copied to clipboard
operator fun get(label: String, name: String): Any?

the value of the parameter with name of the object with label

Link copied to clipboard
fun invoke(label: String, name: String)

calls the action with name of the object with label

Link copied to clipboard
fun load(file: File)

loads the values of the parameters from the JSON in file

Link copied to clipboard

the value of parameter of binding as it is saved, a copy that does not change with the parameter

Link copied to clipboard
fun randomize(strength: Double = 0.05, random: Random = Random.Default, filter: (ParameterBindings.Binding, Parameter) -> Boolean = { _, _ -> true })

Moves the values of the numeric, vector and color parameters towards random values in their ranges by strength, 0 keeps the values, 1 sets random values

Link copied to clipboard

Binds the objects that the properties of nested parameters hold when they hold other objects than the ones that are bound, with the objects nested in them

Link copied to clipboard
fun remove(obj: Any)

removes obj, an object that was added

Link copied to clipboard
fun reset(binding: ParameterBindings.Binding, parameter: Parameter)

sets parameter of binding to the value it had when its object was bound

Link copied to clipboard
fun resetAll()

sets all parameters of all objects to the values they had when their objects were bound

Link copied to clipboard
fun save(file: File)

saves the values of all parameters to file as JSON

Link copied to clipboard
operator fun set(label: String, name: String, value: Any?)

sets the parameter with name of the object with label to value

fun set(binding: ParameterBindings.Binding, parameter: Parameter, value: Any?)

Sets parameter of binding to value. For list parameters value selects an element: an Int is the index of the element, any other value is the element. For mutable list parameters a List replaces the elements.

Link copied to clipboard

sets parameter of binding to value, a value as it is saved

Link copied to clipboard
fun toJson(): String

the values of all parameters as JSON, see toObject

Link copied to clipboard

The values of the parameters of all objects, by the label of the object and the name of the parameter, to be saved; complements fromObject. This allows the values to be saved together with other data.