Package heronarts.lx
Class LXComponent
java.lang.Object
heronarts.lx.LXComponent
- All Implemented Interfaces:
LXPath
,LXSerializable
,LXParameterListener
- Direct Known Subclasses:
ADM
,ADM.Obj
,ImagePattern.Image
,LXAudioComponent
,LXClipEngine
,LXDmxEngine
,LXEngine
,LXFixture
,LXMidiEngine
,LXMixerEngine
,LXModulatorComponent
,LXOscEngine
,LXOutput
,LXPalette
,LXParameterModulation
,LXRunnableComponent
,LXScheduledProject
,LXScheduler
,LXSnapshot
,LXSnapshotEngine
,LXStructure
,LXSwatch
,LXViewDefinition
,LXViewEngine
,SoundStage
public abstract class LXComponent
extends Object
implements LXPath, LXParameterListener, LXSerializable
Core base class for any component in the LX tree. This class supports the
generic encapsulation of an object with an abstract path, which may
have a variety of parameters. Changes to the parameters can be sent and
received via OSC, and the component can also be serialized and loaded
from JSON files.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic @interface
static interface
A market interface for a Placeholder component that is used when an LXComponent class implementation is missing at runtime.static interface
Marker interface for components which can have their label changed.Nested classes/interfaces inherited from interface heronarts.lx.LXSerializable
LXSerializable.Utils
-
Field Summary
Modifier and TypeFieldDescriptionfinal Map<String,
LXComponent> An immutable view of the map of child components.protected final LXParameter.Collection
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
final StringParameter
The user-facing label of this component.protected final LXParameter.Collection
protected final LXParameter.Collection
protected LX
The LX instance that this component belongs to.final DiscreteColorParameter
A color used to identify this component when it or one of its parameters is used as a modulation source.final BooleanParameter
final BooleanParameter
protected final LXParameter.Collection
final StringParameter
Fields inherited from interface heronarts.lx.LXPath
ROOT, ROOT_PREFIX, ROOT_SLASH
-
Constructor Summary
ModifierConstructorDescriptionprotected
Creates a new component with no ID and not part of the LX hierarchy.protected
LXComponent
(LX lx) Creates a new component as part of an LX hierarchy.protected
LXComponent
(LX lx, int id) Creates a new component as part of the LX hierarchy.protected
LXComponent
(LX lx, int id, String label) Creates a new component as part of the LX hierarchy.protected
LXComponent
(LX lx, String label) Creates a new component as part of the LX hierarchy. -
Method Summary
Modifier and TypeMethodDescriptionprotected LXComponent
addArray
(String path, List<? extends LXComponent> childArray) Registers an array of subcomponents with this component.protected LXComponent
addChild
(String path, LXComponent child) Registers a child component with this component.protected final LXComponent
addInternalParameter
(String path, LXParameter parameter) Internal implementation parameters.protected LXComponent
addLegacyInternalParameter
(String legacyPath, LXParameter parameter) Adds a redundant internal legacy parameter path.protected LXComponent
addLegacyParameter
(String legacyPath, LXParameter parameter) Adds a redundant legacy parameter path.protected final LXComponent
addParameter
(LXParameter parameter) Deprecated.protected LXComponent
addParameter
(String path, LXParameter parameter) Adds a parameter to the component at a fixed path.protected final LXComponent
addParameters
(LXParameter.Collection parameters) Add all parameters from a collection of parametersfinal boolean
Determines whether the given LX object is contained by this parent, at any depth in the tree of child components and parameters.protected LXComponent
copyParameters
(LXComponent that) Utility method to copy all parameter values from another component.void
dispose()
Invoked when a component is being removed from the system and will no longer be used at all.static String
getCategory
(Class<? extends LXComponent> clazz) Accesses the child component object at a given path.static String
getComponentName
(LXComponent component, String suffix) Gets the name of an LXComponent object with suffix removedstatic String
getComponentName
(Class<? extends LXComponent> cls) Gets the name of a component class, automatically removing the suffix of a generic LX superclass, if one is foundstatic String
getComponentName
(Class<? extends LXComponent> component, String suffix) Gets the name of a component class, with a suffix removedReturns a contextual help message explaining the purpose of this parameter or component to the user, or null if none is available.final int
getId()
Accessor for the global id of this component.getLabel()
Accessor for the user-facing label of this component.getLX()
Accessor to the LX instance that this component is part of.Gets the OSC address for this objectGets the OSC-friendly label for this objectAccessor for this component's OSC path relative to its parent.final LXParameter
getParameter
(String path) Accessor for parameter at a given pathfinal Collection<LXParameter>
Returns a read-only view of all the parameters in this component.final LXComponent
Accessor for the parent component.getPath()
Accessor for the path of this object.boolean
handleOscMessage
(OscMessage message, String[] parts, int index) Handles an OSC message sent to this component.final boolean
hasParameter
(String path) Whether this component has a parameter at the given pathboolean
isValidOscParameter
(LXParameter parameter) Whether a parameter is a valid OSC target, this component must be an instance of LXOscComponent and the parameters needs to be in the normal parameters array, e.g.void
load
(LX lx, JsonObject obj) Loads the LX component.protected static void
loadParameters
(LXComponent component, JsonObject obj, Map<String, LXParameter> parameters) Utility function to load a set of parametersvoid
loadPreset
(File file) void
onParameterChanged
(LXParameter parameter) Subclasses are free to override this if desired.protected LXComponent
removeParameter
(LXParameter parameter) Removes a parameter from the component.protected LXComponent
removeParameter
(LXParameter parameter, boolean disposeModulations) protected LXComponent
removeParameter
(String path) Removes a parameter from the component.protected LXComponent
removeParameter
(String path, boolean removeModulations) Removes a parameter from the component.void
save
(LX lx, JsonObject obj) Serializes the LX component.void
savePreset
(File file) protected LXComponent
setDescription
(String description) protected final LXComponent
setParent
(LXComponent parent) Registers this component with a parent object in the hierarchy.toOscQuery
(LXParameter parameter) toOscQuery
(LXParameter parameter, LXParameter parent) toString()
Returns a useful debug string for the component, indicating the class name along with the ID number and the canonical pathtoString
(LXComponent root) Returns a useful debug string for the component, indicating the class name along with the ID number and the canonical pathMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface heronarts.lx.LXPath
getCanonicalLabel, getCanonicalLabel, getCanonicalPath, getCanonicalPath, isDescendant
-
Field Details
-
lx
The LX instance that this component belongs to. -
children
An immutable view of the map of child components. -
label
The user-facing label of this component. May be editable if this LXComponent class implements theLXComponent.Renamable
interface. -
modulationColor
A color used to identify this component when it or one of its parameters is used as a modulation source. -
modulationControlsExpanded
-
modulationsExpanded
-
presetFile
-
parameters
-
internalParameters
-
legacyParameters
-
legacyInternalParameters
-
KEY_ID
- See Also:
-
KEY_CLASS
- See Also:
-
KEY_RESET
- See Also:
-
KEY_PARAMETERS
- See Also:
-
KEY_INTERNAL
- See Also:
-
KEY_CHILDREN
- See Also:
-
KEY_COMPONENT_ID
- See Also:
-
KEY_PARAMETER_PATH
- See Also:
-
KEY_PATH
- See Also:
-
-
Constructor Details
-
LXComponent
protected LXComponent()Creates a new component with no ID and not part of the LX hierarchy. This should very rarely be used, except when creating components that will have to be dynamically loaded later, or may never be part of the hierarchy. -
LXComponent
Creates a new component as part of an LX hierarchy. An ID will be automatically assigned to this component.- Parameters:
lx
- LX instance
-
LXComponent
Creates a new component as part of the LX hierarchy. An ID will be automatically assigned. This component's label will be set to the provided initial value.- Parameters:
lx
- LX instancelabel
- Initial label for the component
-
LXComponent
Creates a new component as part of the LX hierarchy. It will be explicitly registered with the the given pre-existing ID.- Parameters:
lx
- LX instanceid
- Fixed ID value to give this component
-
LXComponent
Creates a new component as part of the LX hierarchy. It will be explicitly registered with the the given pre-existing ID and a given label value.- Parameters:
lx
- LX instanceid
- Fixed ID value to give this componentlabel
- Initial label for the component
-
-
Method Details
-
getComponentName
Gets the name of a component class, with a suffix removed- Parameters:
component
- Component classsuffix
- Suffix to remove- Returns:
- Name of component type
-
getComponentName
Gets the name of a component class, automatically removing the suffix of a generic LX superclass, if one is found- Parameters:
cls
- Component class- Returns:
- Name of component class
-
getComponentName
Gets the name of an LXComponent object with suffix removed- Parameters:
component
- Component instancesuffix
- Suffix to remove- Returns:
- Name of component type
-
getLX
Accessor to the LX instance that this component is part of. Note that this may benull
if this is a dynamic component that has not been registered yet.- Returns:
- LX instance, or
null
if unregistered
-
getCategory
-
addArray
Registers an array of subcomponents with this component. They will be accessible via path and OSC queries at the given path from this component.- Parameters:
path
- Path to register the array atchildArray
- Child objects- Returns:
- this
-
addChild
Registers a child component with this component. It will be accessible via path and OSC queries relative to this component.- Parameters:
path
- Path relative to thischild
- The child component- Returns:
- this
-
getChild
Accesses the child component object at a given path. This method can only be used for direct descendants. It will not return elements out of a child array.- Parameters:
path
- Child path- Returns:
- Child object if exists, or
null
if not found
-
setParent
Registers this component with a parent object in the hierarchy. If this component has not been registered an ID with LX yet but the parent object is,- Parameters:
parent
- Parent component- Returns:
- this
-
getParent
Accessor for the parent component. May benull
if this component has not been registered with any parent. -
getId
public final int getId()Accessor for the global id of this component. May be @{link #ID_UNASSIGNED} if this has not been assigned yet.- Returns:
- Global ID or
ID_UNASSIGNED
-
getOscPath
Accessor for this component's OSC path relative to its parent. This by default is no different fromgetPath()
, but certain subclasses may modify this to support different types of OSC paths that aren't required to match the LX hierarchy.- Returns:
- Path that this object can be accessed via OSC
-
isValidOscParameter
Whether a parameter is a valid OSC target, this component must be an instance of LXOscComponent and the parameters needs to be in the normal parameters array, e.g. not an internal parameter- Parameters:
parameter
- Parameter to check- Returns:
- If this is a valid OSC parameter
-
contains
Determines whether the given LX object is contained by this parent, at any depth in the tree of child components and parameters.- Parameters:
that
- Potential child object- Returns:
true
if a child component or parameter,false
otherwise
-
getOscLabel
Gets the OSC-friendly label for this object- Returns:
- This component's label, sanitized to be OSC-compatible
-
getOscAddress
Gets the OSC address for this object- Returns:
- Full OSC address for this component
-
handleOscMessage
Handles an OSC message sent to this component. By default this method handles registered components and parameters, but subclasses may override this method to handle different types of OSC messages.- Parameters:
message
- Full OSC message objectparts
- The OSC address pattern, broken into an array of partsindex
- Which index into the parts array corresponds to this component's children- Returns:
true
if the OSC message was handled and should be considered consumed,false
otherwise
-
toOscQuery
-
toOscQuery
-
toOscQuery
-
getPath
Accessor for the path of this object. Returns the path this component was registered with. Some subclasses may override this if path structure is dynamic. -
getLabel
Accessor for the user-facing label of this component. Objects that implement theLXComponent.Renamable
interface may allow the user to change this value. -
getDescription
Description copied from interface:LXPath
Returns a contextual help message explaining the purpose of this parameter or component to the user, or null if none is available.- Specified by:
getDescription
in interfaceLXPath
- Returns:
- Contextual help string explaining purpose of the element
-
setDescription
-
toString
Returns a useful debug string for the component, indicating the class name along with the ID number and the canonical path -
toString
Returns a useful debug string for the component, indicating the class name along with the ID number and the canonical path- Parameters:
root
- Component to simplify path relative to- Returns:
- Debug string identifying this component
-
dispose
public void dispose()Invoked when a component is being removed from the system and will no longer be used at all. This unregisters the component and should free up any resources and parameter listeners. Ideally after this method is called the object should be eligible for garbage collection. Subclasses are generally expected to override this method to handle their particular cleanup work. They should also generally callsuper.dispose()
at the appropriate time to perform the basic cleanup, which may need to happen either before or after cleaning up other objects. -
addParameter
Deprecated.Adds a parameter to this component, using its label as the path by default. This method is deprecated and heavily discouraged, it is best always to provide a specific path usingaddParameter(String, LXParameter)
instead.- Parameters:
parameter
- Parameter to add- Returns:
- this
-
addParameters
Add all parameters from a collection of parameters- Parameters:
parameters
- Collection of parameters- Returns:
- this
-
addInternalParameter
Internal implementation parameters. These won't be automatically exposed to the UI or to OSC etc. and will not show up in getParameters() or the general parameter list. They will be saved and loaded however. Subclasses should use this for parameters which manage internal state but should never show up to the end user and will not be available via OSC.- Parameters:
path
- Path to internal parameterparameter
- Parameter- Returns:
- this
-
addParameter
Adds a parameter to the component at a fixed path. The parameter will be registered in the LX hierarchy, and if it is of a listenable type will also send and receive OSC messages. Listenable parameters will also be automatically registered with their parent component as a listener for notifications upon any change of value.- Parameters:
path
- String key path to the parameter, must be uniqueparameter
- Parameter to add to the component- Returns:
- this
-
addLegacyParameter
Adds a redundant legacy parameter path. If a stored file refers to this path which is no longer active, it will load to the new parameter position.- Parameters:
legacyPath
- Legacy parameter path, not used anymoreparameter
- Parameter that should be loaded- Returns:
- this
-
addLegacyInternalParameter
Adds a redundant internal legacy parameter path. If a stored file refers to this path which is no longer active, it will load to the new parameter position.- Parameters:
legacyPath
- Legacy internal parameter path, not used anymoreparameter
- Parameter that should be loaded- Returns:
- this
-
removeParameter
Removes a parameter from the component. The parameter will be automatically disposed and may never be used again.- Parameters:
path
- Parameter path- Returns:
- this
-
removeParameter
Removes a parameter from the component. The parameter will be automatically disposed and may never be used again.- Parameters:
path
- Parameter pathremoveModulations
- Whether to also explicitly remove modulations to this parameter- Returns:
- this
-
removeParameter
Removes a parameter from the component. The parameter will be automatically disposed and may never be used again.- Parameters:
parameter
- Parameter- Returns:
- this
-
removeParameter
-
getParameters
Returns a read-only view of all the parameters in this component.- Returns:
- Unmodifiable collection view of all the parameters
-
hasParameter
Whether this component has a parameter at the given path- Parameters:
path
- Parameter path- Returns:
- whether that parameter path is used
-
getParameter
Accessor for parameter at a given path- Parameters:
path
- Path to parameter- Returns:
- Parameter if it exists, otherwise
null
-
onParameterChanged
Subclasses are free to override this if desired. It will automatically fire for any listenable parameter that is registered with this component.- Specified by:
onParameterChanged
in interfaceLXParameterListener
- Parameters:
parameter
- Parameter that has a value change
-
copyParameters
Utility method to copy all parameter values from another component. The other component is expected to be of the same type or a super-type as this object.- Parameters:
that
- Other component- Returns:
- this
-
loadPreset
-
savePreset
-
loadParameters
protected static void loadParameters(LXComponent component, JsonObject obj, Map<String, LXParameter> parameters) Utility function to load a set of parameters- Parameters:
component
- Component that owns the parametersobj
- JsonObject to serialize toparameters
- Map of parameters to unserialize
-
save
Serializes the LX component. By default, all internal and user-facing parameters are serialized, as well as any explicitly registered child components. Note that child arrays are not serialized, or any other dynamic components. Subclasses may override to perform more saving, and are expected to callsuper.save(lx, obj)
at the appropriate time.- Specified by:
save
in interfaceLXSerializable
- Parameters:
lx
- LX instanceobj
- Object to serialize into
-
load
Loads the LX component. Restores the ID of the component, as well as its internal and user-facing parameters. Any explicitly registered children will be automatically loaded, so long as they are direct descendants. Dynamic arrays will not be automatically loaded, this is left to subclasses to implement.- Specified by:
load
in interfaceLXSerializable
- Parameters:
lx
- LX instanceobj
- Object to deserialize
-