Package heronarts.lx
Class LXEngine
java.lang.Object
heronarts.lx.LXComponent
heronarts.lx.LXEngine
- All Implemented Interfaces:
LXPath,LXSerializable,LXModulationContainer,LXOscComponent,LXParameterListener
The engine is the core class that runs the internal animations. An engine is
comprised of top-level modulators, then a number of channels, each of which
has a set of patterns that it may transition between. These channels are
blended together, and effects are then applied.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic classclassclassclassstatic enumclassA task which runs after an elapsed amount of time, and potentially repeatsNested classes/interfaces inherited from class heronarts.lx.LXComponent
LXComponent.Description, LXComponent.Hidden, LXComponent.Name, LXComponent.Placeholder, LXComponent.PluginRequired, LXComponent.RenamableNested classes/interfaces inherited from interface heronarts.lx.LXSerializable
LXSerializable.Utils -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal LXAudioEnginefinal LXClipEnginefinal LXDmxEnginefinal BoundedParameterfinal BooleanParameterfinal BooleanParameterfinal BooleanParameterfinal LXMappingEnginefinal LXMidiEnginefinal LXMixerEnginefinal LXModulationEnginefinal LXEngine.NetworkThreadlonglongGlobally accessible counter of the current millisecond clockfinal LXOscEnginefinal LXEngine.Outputfinal LXPalettestatic final Stringstatic final Stringfinal BooleanParameterfinal LXEngine.Profilerfinal BooleanParameterfinal LXSnapshotEnginefinal BoundedParameterfinal TempoFields inherited from class heronarts.lx.LXComponent
childArrays, children, internalParameters, KEY_CHILDREN, KEY_CLASS, KEY_COMPONENT_ID, KEY_ID, KEY_INTERNAL, KEY_PARAMETER_PATH, KEY_PARAMETERS, KEY_PATH, KEY_RESET, label, legacyInternalParameters, legacyParameters, lx, modulationColor, modulationControlsExpanded, modulationsExpanded, parameters, presetFileFields inherited from interface heronarts.lx.LXPath
DEFAULT_SEPARATOR, ROOT, ROOT_PREFIX, ROOT_SLASH -
Method Summary
Modifier and TypeMethodDescriptionaddInterval(double intervalMs, Runnable runnable) Add a task to the engine that will run periodically every time the interval has passed, until explicitly canceled.addLoopTask(LXLoopTask loopTask) Add a task to be run on every loop of the engine thread.Sets the output driverAdd a task to be run once on the engine thread.addTimeout(double timerMs, Runnable runnable) Add a task to the engine that will run if the specified duration of milliseconds expires and the timeout has not been canceled.voidUtility method for P4LX mode, invoked from the Processing draw thread to give a chance to change the threading state before the draw loop.voidThis should be used when in threaded mode.voiddispose()Invoked when a component is being removed from the system and will no longer be used at all.floatGets the active frame rate of the engine when in threaded modefloatGets a very rough estimate of the CPU load the engine is using before maxing out.voidNon-thread safe accessor of the render buffer.Get the modulation engine implementation for this componentgetPath()Accessor for the path of this object.booleanhandleOscMessage(OscMessage message, String[] parts, int index) Handles an OSC message sent to this component.booleanisPaused()booleanReturns whether the engine is actively threadedvoidload(LX lx, JsonObject obj) Loads the LX component.voidUtility method to shut down and join the engine thread, only when specifically in P4 mode.voidSubclasses are free to override this if desired.registerComponent(String path, LXComponent component) Register a component with the engine.removeLoopTask(LXLoopTask loopTask) Remove a task from the list run on every loop invocationvoidrun()This is the core run loop of the LXEngine.setFixedDeltaMs(double deltaMs) Utility for when rendering offline videos.setInputDispatch(LXEngine.Dispatch inputDispatch) setPaused(boolean paused) Pause the engine from runningsetSpeed(double speed) Sets a global speed factor on the core animation engine.setThreaded(boolean threaded) Sets the engine to threaded or non-threaded mode.voidstart()Starts the engine thread.voidstop()Stops the engine thread.Methods inherited from class heronarts.lx.LXComponent
addArray, addChild, addInternalParameter, addLegacyInternalParameter, addLegacyParameter, addParameter, addParameter, addParameters, assertDisposed, contains, copyParameters, getCategory, getChild, getComponentDescription, getComponentName, getComponentName, getComponentName, getDescription, getId, getLabel, getLX, getOscAddress, getOscLabel, getOscPath, getParameter, getParameters, getParent, hasParameter, isValidOscParameter, loadParameters, loadPreset, removeParameter, removeParameter, removeParameter, removeParameter, save, savePreset, setDescription, setParent, toOscQuery, toOscQuery, toOscQuery, toString, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface heronarts.lx.modulation.LXModulationContainer
getModulationExpandedMethods inherited from interface heronarts.lx.osc.LXOscComponent
getOscAddressMethods inherited from interface heronarts.lx.LXPath
getCanonicalLabel, getCanonicalLabel, getCanonicalLabel, getCanonicalLabel, getCanonicalLabel, getCanonicalPath, getCanonicalPath, isDescendant
-
Field Details
-
palette
-
tempo
-
clips
-
mixer
-
midi
-
audio
-
mapping
-
osc
-
dmx
-
output
-
framesPerSecond
-
speed
-
performanceMode
-
restricted
-
modulation
-
snapshots
-
profiler
-
isMultithreaded
-
isChannelMultithreaded
-
isNetworkMultithreaded
-
networkThread
-
nowNanoTime
public long nowNanoTimeGlobally accessible counter of the current millisecond clock -
nowMillis
public long nowMillis -
PATH_FRAMERATE
- See Also:
-
PATH_OPEN_PROJECT
- See Also:
-
-
Method Details
-
logProfiler
public void logProfiler() -
getPath
Description copied from class:LXComponentAccessor for the path of this object. Returns the path this component was registered with. Some subclasses may override this if path structure is dynamic.- Specified by:
getPathin interfaceLXPath- Overrides:
getPathin classLXComponent- Returns:
- path of this component relative to its parent
-
setInputDispatch
-
onParameterChanged
Description copied from class:LXComponentSubclasses 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- Overrides:
onParameterChangedin classLXComponent- Parameters:
p- Parameter that has a value change
-
getActualFrameRate
public float getActualFrameRate()Gets the active frame rate of the engine when in threaded mode- Returns:
- How many FPS the engine is running
-
getCpuLoad
public float getCpuLoad()Gets a very rough estimate of the CPU load the engine is using before maxing out.- Returns:
- Estimated CPU load
-
setFixedDeltaMs
Utility for when rendering offline videos. Ignore how much real-time has passed between frames and compute animations based upon the given deltaMs- Parameters:
deltaMs- Fixed deltaMs between rendered frames- Returns:
- this
-
start
public void start()Starts the engine thread. -
stop
public void stop()Stops the engine thread. -
isThreaded
public boolean isThreaded()Returns whether the engine is actively threaded- Returns:
- Whether engine is threaded
-
setThreaded
Sets the engine to threaded or non-threaded mode. Should only be called from the Processing animation thread.- Parameters:
threaded- Whether engine should run on its own thread- Returns:
- this
-
onP4DidDispose
Utility method to shut down and join the engine thread, only when specifically in P4 mode.- Returns:
- this
-
beforeP4LXDraw
public void beforeP4LXDraw()Utility method for P4LX mode, invoked from the Processing draw thread to give a chance to change the threading state before the draw loop. -
setSpeed
Sets a global speed factor on the core animation engine. This does not impact the tempo object.- Parameters:
speed- Global speed multiplier- Returns:
- this
-
setPaused
Pause the engine from running- Parameters:
paused- Whether to pause the engine to pause- Returns:
- this
-
isPaused
public boolean isPaused() -
registerComponent
Register a component with the engine. It will be saved and loaded.- Parameters:
path- Unique path key for saving and loading componentcomponent- Component- Returns:
- this
-
addTask
Add a task to be run once on the engine thread.- Parameters:
runnable- Task to run- Returns:
- this
-
addLoopTask
Add a task to be run on every loop of the engine thread.- Parameters:
loopTask- Task to run on each engine loop- Returns:
- this
-
removeLoopTask
Remove a task from the list run on every loop invocation- Parameters:
loopTask- Task to stop running on every loop- Returns:
- this
-
addTimeout
Add a task to the engine that will run if the specified duration of milliseconds expires and the timeout has not been canceled. The timer is automatically canceled once it has run.- Parameters:
timerMs- Timeout in millisecondsrunnable- Function to run after timeout expires- Returns:
- Timer object which can be stopped via cancel()
-
addInterval
Add a task to the engine that will run periodically every time the interval has passed, until explicitly canceled.- Parameters:
intervalMs- Interval in millisecondsrunnable- Function to run whenever interval has passed- Returns:
- Timer object which can be stopped via cancel()
-
addOutput
Sets the output driver- Parameters:
output- Output driver, or null for no output- Returns:
- this
-
getModulationEngine
Description copied from interface:LXModulationContainerGet the modulation engine implementation for this component- Specified by:
getModulationEnginein interfaceLXModulationContainer- Returns:
- Modulation engine
-
run
public void run()This is the core run loop of the LXEngine. It can be invoked from various places, such as the EngineThread when running in multi-threaded mode, or from a Processing sketch when in P4LX, or from another application framework. Unless you are writing your own new application framework using LX (this is not recommended), you should never call this method directly. It is only public to make it accessible to these other frameworks. -
copyFrameThreadSafe
This should be used when in threaded mode. It synchronizes on the double-buffer and duplicates the internal copy buffer into the provided buffer.- Parameters:
frame- Frame buffer to copy into
-
getFrameNonThreadSafe
Non-thread safe accessor of the render buffer. Directly copies from it, which if in multi-threaded mode could happen during modification. Basically, never call this from the non-engine thread.- Parameters:
frame- Frame buffer to copy into
-
handleOscMessage
Description copied from class:LXComponentHandles 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.- Specified by:
handleOscMessagein interfaceLXOscComponent- Overrides:
handleOscMessagein classLXComponent- 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
-
load
Description copied from class:LXComponentLoads 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- Overrides:
loadin classLXComponent- Parameters:
lx- LX instanceobj- Object to deserialize
-
dispose
public void dispose()Description copied from class:LXComponentInvoked 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.- Overrides:
disposein classLXComponent
-