Package heronarts.lx.modulator
Class LXPeriodicModulator
java.lang.Object
heronarts.lx.LXComponent
heronarts.lx.LXRunnableComponent
heronarts.lx.modulator.LXModulator
heronarts.lx.modulator.LXPeriodicModulator
- All Implemented Interfaces:
LXComponent.Renamable
,LXLoopTask
,LXPath
,LXSerializable
,LXParameter
,LXParameterListener
- Direct Known Subclasses:
Click
,Interval
,LXRangeModulator
,Randomizer
,StepSequencer
An LXPeriodicModulator is a modulator that moves through a cycle in a given
amount of time. It may then repeat the cycle, or perform it once. The values
are computed based upon a position in the cycle, internally referred to as a
basis, which moves from 0 to 1. This can be thought of as equivalent to an
angle moving from 0 to two times pi. The period itself is a parameter which
may be a modulator or otherwise.
-
Nested Class Summary
Nested classes/interfaces inherited from class heronarts.lx.modulator.LXModulator
LXModulator.Device, LXModulator.Global, LXModulator.Placeholder
Nested classes/interfaces inherited from class heronarts.lx.LXComponent
LXComponent.Hidden, LXComponent.Renamable
Nested classes/interfaces inherited from interface heronarts.lx.parameter.LXParameter
LXParameter.Collection, LXParameter.Formatter, LXParameter.Monitor, LXParameter.MultiMonitor, LXParameter.Polarity, LXParameter.Units
Nested classes/interfaces inherited from interface heronarts.lx.LXSerializable
LXSerializable.Utils
-
Field Summary
Modifier and TypeFieldDescriptionfinal BooleanParameter
Whether this modulator runs continuously looping.final EnumParameter<Tempo.Division>
final BooleanParameter
final BooleanParameter
Fields inherited from class heronarts.lx.modulator.LXModulator
crashed, midiFilter
Fields inherited from class heronarts.lx.LXRunnableComponent
runMs, running, trigger
Fields inherited from class heronarts.lx.LXComponent
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, presetFile
Fields inherited from interface heronarts.lx.LXPath
ROOT, ROOT_PREFIX, ROOT_SLASH
-
Constructor Summary
ModifierConstructorDescriptionprotected
LXPeriodicModulator
(String label, LXParameter period) Utility constructor with period -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract double
computeBasis
(double basis, double value) Implementation method to compute the appropriate basis for a modulator given its current basis and value.protected final double
computeValue
(double deltaMs) Implementation method to advance the modulator's internal state.protected abstract double
computeValue
(double deltaMs, double basis) Implementation method to compute the value of a modulator given its basis.final boolean
finished()
For envelope modulators, which are not looping, this returns true if they finished on this frame.final double
getBasis()
Accessor for the current basisfinal float
Accessor for basis as a floatfinal double
final float
void
load
(LX lx, JsonObject object) Loads the LX component.final boolean
loop()
Returns true once each time this modulator loops through its starting position.void
loop
(double deltaMs) final int
numLoops()
Returns the number of times the modulator looped on the last cycle; should be 0 or 1 unless the period's extremely short and/or the machine is overworked.void
Subclasses are free to override this if desired.protected void
onReset()
Optional subclass method when reset happens.void
onSetValue
(double value) Set the modulator to a certain value in its cycle.final LXPeriodicModulator
Sets the basis to a random positionvoid
save
(LX lx, JsonObject object) Serializes the LX component.final LXPeriodicModulator
setBasis
(double basis) Set the modulator to a certain basis position in its cycle.setLooping
(boolean looping) Sets whether the modulator should loop after it completes a cycle or halt at the end position.final LXPeriodicModulator
setPeriod
(double periodMs) Modify the period of this modulatorfinal LXPeriodicModulator
setPeriod
(LXParameter period) Sets a parameter to the period of this modulatorprotected final void
updateBasis
(double value) Updates the basis of the modulator based on present values.Methods inherited from class heronarts.lx.modulator.LXModulator
autostart, disableAutoStart, getCrash, getCrashStackTrace, getFormatter, getIndex, getOscAddress, getOscPath, getPath, getPolarity, getUnits, getValue, isMappingSource, run, setComponent, setFormatter, setIndex, setMappingSource, setPolarity, setUnits, setValue, setValue, updateValue
Methods inherited from class heronarts.lx.LXRunnableComponent
isRunning, onStart, onStop, onTrigger, postRun, reset, start, stop, toggle, trigger
Methods inherited from class heronarts.lx.LXComponent
addArray, addChild, addInternalParameter, addLegacyInternalParameter, addLegacyParameter, addParameter, addParameter, addParameters, contains, copyParameters, dispose, getCategory, getChild, getComponentName, getComponentName, getComponentName, getDescription, getId, getLabel, getLX, getOscLabel, getParameter, getParameters, getParent, handleOscMessage, hasParameter, isValidOscParameter, loadParameters, loadPreset, removeParameter, removeParameter, removeParameter, removeParameter, savePreset, setDescription, setParent, toOscQuery, toOscQuery, toOscQuery, toString, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface heronarts.lx.parameter.LXParameter
dispose, getBaseValue, getBaseValuef, getLabel, getParentParameter, getValuef, isMappable, reset, setMappable
Methods inherited from interface heronarts.lx.LXPath
getCanonicalLabel, getCanonicalLabel, getCanonicalPath, getCanonicalPath, getDescription, getParent, isDescendant
-
Field Details
-
looping
Whether this modulator runs continuously looping. -
tempoSync
-
tempoDivision
-
tempoLock
-
-
Constructor Details
-
LXPeriodicModulator
Utility constructor with period- Parameters:
label
- Labelperiod
- Parameter for period
-
-
Method Details
-
onParameterChanged
Description copied from class:LXComponent
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
- Overrides:
onParameterChanged
in classLXRunnableComponent
- Parameters:
p
- Parameter that has a value change
-
setLooping
Sets whether the modulator should loop after it completes a cycle or halt at the end position.- Parameters:
looping
- Whether to loop- Returns:
- this, for method chaining
-
disableAutoReset
-
getBasis
public final double getBasis()Accessor for the current basis- Returns:
- The basis of the modulator
-
getBasisf
public final float getBasisf()Accessor for basis as a float- Returns:
- basis as float
-
onReset
protected void onReset()Description copied from class:LXRunnableComponent
Optional subclass method when reset happens.- Overrides:
onReset
in classLXRunnableComponent
-
randomBasis
Sets the basis to a random position- Returns:
- this
-
setBasis
Set the modulator to a certain basis position in its cycle.- Parameters:
basis
- Basis of modulator, from 0-1- Returns:
- this
-
onSetValue
public void onSetValue(double value) Set the modulator to a certain value in its cycle.- Overrides:
onSetValue
in classLXModulator
- Parameters:
value
- The value to apply
-
updateBasis
protected final void updateBasis(double value) Updates the basis of the modulator based on present values.- Parameters:
value
- New value of the modulator
-
setPeriod
Modify the period of this modulator- Parameters:
periodMs
- New period, in milliseconds- Returns:
- Modulator, for method chaining;
-
getPeriod
public final double getPeriod()- Returns:
- The period of this modulator
-
getPeriodf
public final float getPeriodf()- Returns:
- The period of this modulator as a floating point
-
setPeriod
Sets a parameter to the period of this modulator- Parameters:
period
- Parameter for period value- Returns:
- This modulator, for method chaining
-
loop
public void loop(double deltaMs) - Specified by:
loop
in interfaceLXLoopTask
- Overrides:
loop
in classLXModulator
-
computeValue
protected final double computeValue(double deltaMs) Description copied from class:LXModulator
Implementation method to advance the modulator's internal state. Subclasses must provide and update value appropriately.- Specified by:
computeValue
in classLXModulator
- Parameters:
deltaMs
- Number of milliseconds to advance by- Returns:
- Computed value
-
loop
public final boolean loop()Returns true once each time this modulator loops through its starting position.- Returns:
- true if the modulator just looped
-
numLoops
public final int numLoops()Returns the number of times the modulator looped on the last cycle; should be 0 or 1 unless the period's extremely short and/or the machine is overworked.- Returns:
- number of loops on the last cycle
-
finished
public final boolean finished()For envelope modulators, which are not looping, this returns true if they finished on this frame.- Returns:
- true if the modulator just finished its operation on this frame
-
computeValue
protected abstract double computeValue(double deltaMs, double basis) Implementation method to compute the value of a modulator given its basis.- Parameters:
deltaMs
- Milliseconds elapsedbasis
- Basis of the modulator- Returns:
- Value of modulator
-
computeBasis
protected abstract double computeBasis(double basis, double value) Implementation method to compute the appropriate basis for a modulator given its current basis and value.- Parameters:
basis
- Last basis of modulatorvalue
- Current value of modulator- Returns:
- Basis of modulator
-
save
Description copied from class:LXComponent
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
- Overrides:
save
in classLXComponent
- Parameters:
lx
- LX instanceobject
- Object to serialize into
-
load
Description copied from class:LXComponent
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
- Overrides:
load
in classLXComponent
- Parameters:
lx
- LX instanceobject
- Object to deserialize
-