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,LXClipEngine.Grid,LXClipLane,LXDmxEngine,LXEngine,LXFixture,LXMidiEngine,LXMidiSurface,LXMidiTemplate,LXMixerEngine,LXModulatorComponent,LXOscConnection,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
Nested ClassesModifier and TypeClassDescriptionstatic @interfaceAn annotation which provides a user-friendly description of the function of the component, which may be shown in a UI tool tipstatic @interfacestatic @interfaceAn annotation to be applied to classes giving them a name in the UI different from their classnamestatic interfaceA market interface for a Placeholder component that is used when an LXComponent class implementation is missing at runtime.static @interfaceSpecifies that this component requires the given plugin to operate properlystatic interfaceMarker interface for components which can have their label changed.Nested classes/interfaces inherited from interface heronarts.lx.LXSerializable
LXSerializable.Utils -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal Map<String, List<? extends LXComponent>> An immutable view of the map of child array componentsfinal Map<String, LXComponent> An immutable view of the map of child components.protected final LXParameter.Collectionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringfinal StringParameterThe user-facing label of this component.protected final LXParameter.Collectionprotected final LXParameter.Collectionprotected LXThe LX instance that this component belongs to.final DiscreteColorParameterA color used to identify this component when it or one of its parameters is used as a modulation source.final BooleanParameterfinal BooleanParameterprotected final LXParameter.Collectionfinal StringParameterFields inherited from interface heronarts.lx.LXPath
DEFAULT_SEPARATOR, ROOT, ROOT_PREFIX, ROOT_SLASH -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a new component with no ID and not part of the LX hierarchy.protectedLXComponent(LX lx) Creates a new component as part of an LX hierarchy.protectedLXComponent(LX lx, int id) Creates a new component as part of the LX hierarchy.protectedLXComponent(LX lx, int id, String label) Creates a new component as part of the LX hierarchy.protectedLXComponent(LX lx, String label) Creates a new component as part of the LX hierarchy. -
Method Summary
Modifier and TypeMethodDescriptionprotected LXComponentaddArray(String path, List<? extends LXComponent> childArray) Registers an array of subcomponents with this component.protected LXComponentaddChild(String path, LXComponent child) Registers a child component with this component.protected final LXComponentaddInternalParameter(String path, LXParameter parameter) Internal implementation parameters.protected LXComponentaddLegacyInternalParameter(String legacyPath, LXParameter parameter) Adds a redundant internal legacy parameter path.protected LXComponentaddLegacyParameter(String legacyPath, LXParameter parameter) Adds a redundant legacy parameter path.protected final LXComponentaddParameter(LXParameter parameter) Deprecated.protected LXComponentaddParameter(String path, LXParameter parameter) Adds a parameter to the component at a fixed path.protected final LXComponentaddParameters(LXParameter.Collection parameters) Add all parameters from a collection of parametersstatic voidassertDisposed(LXComponent component) A checked version of dispose used by internal engine implementation to ensure that the base class LXComponent.dispose() is always called.final booleanDetermines whether the given LX object is contained by this parent, at any depth in the tree of child components and parameters.protected LXComponentcopyParameters(LXComponent that) Utility method to copy all parameter values from another component.voiddispose()Invoked when a component is being removed from the system and will no longer be used at all.static StringgetCategory(Class<? extends LXComponent> clazz) Accesses the child component object at a given path.static StringgetComponentDescription(Class<? extends LXComponent> cls) Gets the description for a component class, if one is available and provided by the description annotationstatic StringgetComponentName(LXComponent component, String suffix) Gets the name of an LXComponent object with suffix removedstatic StringgetComponentName(Class<? extends LXComponent> cls) Gets the name of a component class, automatically removing the suffix of a generic LX superclass, if one is foundstatic StringgetComponentName(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 intgetId()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 LXParametergetParameter(String path) Accessor for parameter at a given pathfinal Collection<LXParameter> Returns a read-only view of all the parameters in this component.final LXComponentAccessor for the parent component.getPath()Accessor for the path of this object.booleanhandleOscMessage(OscMessage message, String[] parts, int index) Handles an OSC message sent to this component.final booleanhasParameter(String path) Whether this component has a parameter at the given pathbooleanisValidOscParameter(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.voidload(LX lx, JsonObject obj) Loads the LX component.protected static voidloadParameters(LXComponent component, JsonObject obj, Map<String, LXParameter> parameters) Utility function to load a set of parametersvoidloadPreset(File file) voidonParameterChanged(LXParameter parameter) Subclasses are free to override this if desired.protected LXComponentremoveParameter(LXParameter parameter) Removes a parameter from the component.protected LXComponentremoveParameter(LXParameter parameter, boolean disposeModulations) protected LXComponentremoveParameter(String path) Removes a parameter from the component.protected LXComponentremoveParameter(String path, boolean removeModulations) Removes a parameter from the component.voidsave(LX lx, JsonObject obj) Serializes the LX component.voidsavePreset(File file) protected LXComponentsetDescription(String description) protected final LXComponentsetParent(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, waitMethods inherited from interface heronarts.lx.LXPath
getCanonicalLabel, getCanonicalLabel, getCanonicalLabel, 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. -
childArrays
An immutable view of the map of child array components -
label
The user-facing label of this component. May be editable if this LXComponent class implements theLXComponent.Renamableinterface. -
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
-
getComponentDescription
Gets the description for a component class, if one is available and provided by the description annotation- Parameters:
cls- Component class- Returns:
- Description 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 benullif this is a dynamic component that has not been registered yet.- Returns:
- LX instance, or
nullif 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
nullif 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 benullif 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:
trueif a child component or parameter,falseotherwise
-
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:
trueif the OSC message was handled and should be considered consumed,falseotherwise
-
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.Renamableinterface may allow the user to change this value. -
getDescription
Description copied from interface:LXPathReturns a contextual help message explaining the purpose of this parameter or component to the user, or null if none is available.- Specified by:
getDescriptionin 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
-
assertDisposed
A checked version of dispose used by internal engine implementation to ensure that the base class LXComponent.dispose() is always called.- Parameters:
component- Component to dispose
-
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:
onParameterChangedin 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:
savein 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:
loadin interfaceLXSerializable- Parameters:
lx- LX instanceobj- Object to deserialize
-