Package heronarts.lx
Class Tempo
java.lang.Object
heronarts.lx.LXComponent
heronarts.lx.LXModulatorComponent
heronarts.lx.Tempo
- All Implemented Interfaces:
LXLoopTask
,LXPath
,LXSerializable
,LXTriggerSource
,LXOscComponent
,LXParameterListener
Class to represent a musical tempo at which patterns are operating. This can
be updated in real-time via invoking the
tap()
method. Note there is no automatic beat detection -
the Tempo object must be explicitly tap()
'd to learn the tempo.
"Beats" are indicated by the return value of beat()
. ramp()
returns the current beat phase
from 0 to 1
The bpm
parameter indicates the current BPM, and period
can be used to invert the beat
frequency (BPM) into a listenable period (ms per beat).
Additional utility functions are available that assume beats represent the tempo:
- measure()
can be polled to check measure beats, respectively.
- Tempo.Listener
's can be added to trigger on beats or measures without polling the Tempo object.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
static enum
static interface
Nested classes/interfaces inherited from class heronarts.lx.LXModulatorComponent
LXModulatorComponent.Profiler
Nested classes/interfaces inherited from class heronarts.lx.LXComponent
LXComponent.Hidden, LXComponent.Placeholder, LXComponent.Renamable
Nested classes/interfaces inherited from interface heronarts.lx.LXSerializable
LXSerializable.Utils
-
Field Summary
Modifier and TypeFieldDescriptionfinal DiscreteParameter
final BoundedParameter
final EnumParameter<Tempo.ClockSource>
static final double
static final double
final BooleanParameter
final BooleanParameter
final BooleanParameter
final MutableParameter
final BooleanParameter
final TriggerParameter
Fields inherited from class heronarts.lx.LXModulatorComponent
modulators, profiler
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
-
Method Summary
Modifier and TypeMethodDescriptionaddListener
(Tempo.Listener listener) adjustBpm
(double amount) Adjust the BPM by the given amountboolean
bar()
Method to indicate the start of a bar.int
barCount()
Returns the count of what bar number we are ondouble
basis()
Indicates phase of the current beat.float
basisf()
boolean
beat()
Method to indicate when we are on-beat, assuming quarter-notes being given one beat.int
Gets the count of the current beat we are on, 0-indexed and absoluteint
Gets the count of the current beat we are on, 0-indexed and within the range [0, beatsPerBar-1]double
bpm()
Returns the current tempo in Beats Per Minutefloat
bpmf()
Returns the tempo in floating pointdouble
getBasis
(Tempo.Division division) Gets the basis of the tempo, relative to a tempo division.double
Gets the composite basis of the tempo, which is the beatCount combined with the current basis cycle.int
getCycleCount
(Tempo.Division division) Gets the cycle count at this tempo divisiongetLabel()
Accessor for the user-facing label of this component.boolean
handleOscMessage
(OscMessage message, String[] parts, int index) Handles an OSC message sent to this component.boolean
isValidOscBpm
(double bpm) void
loop
(double deltaMs) boolean
measure()
Deprecated.Use bar()void
Subclasses are free to override this if desired.double
ramp()
Deprecated.float
rampf()
Deprecated.removeListener
(Tempo.Listener listener) When in internal clock mode, the next beat will reset the beat count to 0.setBpm
(double bpm) Sets the BPM to the given valuesetOscBpmRange
(double min, double max) setPeriod
(double beatMillis) Sets the period of one beatvoid
stop()
Stop the metronome runningvoid
tap()
Adjusts the tempo in realtime by tapping.void
tap
(long nanoTime) Adjusts the tempo, specifying an exact timestamp in milliseconds of when the tap event occurred.void
trigger()
Re-triggers the metronome, so that it immediately beats.void
trigger
(boolean resetBeat) Triggers a beat, optionally resetting the beat countvoid
trigger
(int beat) Triggers the metronome, setting the beat count to the given explicit valuevoid
trigger
(int beat, long nanoTime) Triggers the metronome, setting the beat count to the given value with a specified offset into the beat.void
trigger
(int beat, OscMessage message) Triggers the metronome, setting the beat count to the given value with a specified offset into the beat.void
triggerBarAndBeat
(int bar, int beat) Trigger the given bar and beat position, both 1-indexedvoid
triggerBarAndBeat
(int bar, int beat, long nanoTime) Trigger the given bar and beat position, both 1-indexedvoid
triggerBarAndBeat
(int bar, int beat, OscMessage message) Trigger the given bar and beat position, both 1-indexedvoid
triggerBeatWithinBar
(int beatWithinBar, long nanoTime) Triggers the given beat within bar, keeping count over subsequent bars if desired.void
triggerBeatWithinBar
(int beatWithinBar, OscMessage message) Triggers the given beat within bar, keeping count over subsequent bars if desired.Methods inherited from class heronarts.lx.LXModulatorComponent
addModulator, addModulator, addModulator, addModulator, addModulator, constructProfiler, dispose, getModulator, getModulators, moveModulator, removeModulator, startModulator
Methods inherited from class heronarts.lx.LXComponent
addArray, addChild, addInternalParameter, addLegacyInternalParameter, addLegacyParameter, addParameter, addParameter, addParameters, contains, copyParameters, getCategory, getChild, getComponentName, getComponentName, getComponentName, getDescription, getId, getLX, getOscAddress, getOscLabel, getOscPath, getParameter, getParameters, getParent, getPath, hasParameter, isValidOscParameter, load, loadParameters, loadPreset, removeParameter, removeParameter, removeParameter, removeParameter, save, 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.osc.LXOscComponent
getOscAddress
Methods inherited from interface heronarts.lx.LXPath
getCanonicalLabel, getCanonicalLabel, getCanonicalPath, getCanonicalPath, isDescendant
-
Field Details
-
DEFAULT_MIN_BPM
public static final double DEFAULT_MIN_BPM- See Also:
-
DEFAULT_MAX_BPM
public static final double DEFAULT_MAX_BPM- See Also:
-
clockSource
-
beatsPerBar
-
bpm
-
trigger
-
enabled
-
tap
-
nudgeUp
-
nudgeDown
-
period
-
-
Constructor Details
-
Tempo
-
-
Method Details
-
setOscBpmRange
-
isValidOscBpm
public boolean isValidOscBpm(double bpm) -
handleOscMessage
Description copied from class:LXComponent
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.- Specified by:
handleOscMessage
in interfaceLXOscComponent
- Overrides:
handleOscMessage
in 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:
true
if the OSC message was handled and should be considered consumed,false
otherwise
-
getLabel
Description copied from class:LXComponent
Accessor for the user-facing label of this component. Objects that implement theLXComponent.Renamable
interface may allow the user to change this value.- Specified by:
getLabel
in interfaceLXPath
- Overrides:
getLabel
in classLXComponent
- Returns:
- Label for this component
-
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 classLXComponent
- Parameters:
p
- Parameter that has a value change
-
addListener
-
removeListener
-
beat
public boolean beat()Method to indicate when we are on-beat, assuming quarter-notes being given one beat.- Returns:
- true if we are on a quarter-note beat
-
barCount
public int barCount()Returns the count of what bar number we are on- Returns:
- Bar count
-
beatCount
public int beatCount()Gets the count of the current beat we are on, 0-indexed and absolute- Returns:
- Beat count
-
beatCountWithinBar
public int beatCountWithinBar()Gets the count of the current beat we are on, 0-indexed and within the range [0, beatsPerBar-1]- Returns:
- Beat count within bar
-
getCompositeBasis
public double getCompositeBasis()Gets the composite basis of the tempo, which is the beatCount combined with the current basis cycle.- Returns:
- Number of full beats completed since beginning of tempo
-
getCycleCount
Gets the cycle count at this tempo division- Parameters:
division
- Division level- Returns:
- Measure count
-
getBasis
Gets the basis of the tempo, relative to a tempo division. The result is between 0 and strictly less than 1- Parameters:
division
- Tempo division- Returns:
- Relative tempo division cycle basis from 0-1
-
measure
Deprecated.Use bar()Method to indicate the start of a measure.- Returns:
- true if we are on a measure-beat
-
bar
public boolean bar()Method to indicate the start of a bar.- Returns:
- true if we are on a bar-beat
-
basis
public double basis()Indicates phase of the current beat. On the beat the value will be 0, then ramp up to 1 before the next beat triggers.- Returns:
- value from 0-1 indicating phase of beat
-
basisf
public float basisf() -
ramp
Deprecated.Indicates phase of the current beat. On the beat the value will be 0, then ramp up to 1 before the next beat triggers. This is deprecated, should usebasis()
instead.- Returns:
- value from 0-1 indicating phase of beat
-
rampf
Deprecated.Indicates beat phase in floating point. This is deprecated, should usebasisf()
instead.- Returns:
- value from 0-1 indicating phase of beat
-
bpm
public double bpm()Returns the current tempo in Beats Per Minute- Returns:
- Current tempo
-
bpmf
public float bpmf()Returns the tempo in floating point- Returns:
- Current tempo in float
-
setBpm
Sets the BPM to the given value- Parameters:
bpm
- Number of beats per minute- Returns:
- this
-
adjustBpm
Adjust the BPM by the given amount- Parameters:
amount
- Amount to adjust BPM by- Returns:
- this
-
setPeriod
Sets the period of one beat- Parameters:
beatMillis
- Milliseconds in a beat- Returns:
- this
-
resetOnNextBeat
When in internal clock mode, the next beat will reset the beat count to 0. -
trigger
public void trigger()Re-triggers the metronome, so that it immediately beats. Also resetting the beat count to be at the beginning of a measure. -
triggerBeatWithinBar
Triggers the given beat within bar, keeping count over subsequent bars if desired.- Parameters:
beatWithinBar
- Beat within bar, 1-indexedmessage
- OSC message that triggered the beat, for timing adjustment
-
triggerBeatWithinBar
public void triggerBeatWithinBar(int beatWithinBar, long nanoTime) Triggers the given beat within bar, keeping count over subsequent bars if desired.- Parameters:
beatWithinBar
- Beat within bar, 1-indexednanoTime
- System.nanoTime() value for the event causing trigger
-
triggerBarAndBeat
public void triggerBarAndBeat(int bar, int beat) Trigger the given bar and beat position, both 1-indexed- Parameters:
bar
- Bar number, 1-indexedbeat
- Beat number, 1-indexed
-
triggerBarAndBeat
Trigger the given bar and beat position, both 1-indexed- Parameters:
bar
- Bar number, 1-indexedbeat
- Beat number, 1-indexedmessage
- Source message, for timing adjustment
-
triggerBarAndBeat
public void triggerBarAndBeat(int bar, int beat, long nanoTime) Trigger the given bar and beat position, both 1-indexed- Parameters:
bar
- Bar number, 1-indexedbeat
- Beat number, 1-indexednanoTime
- System.nanoTime() value of the event that caused the trigger
-
trigger
public void trigger(boolean resetBeat) Triggers a beat, optionally resetting the beat count- Parameters:
resetBeat
- True if the beat count should be reset to 0
-
trigger
public void trigger(int beat) Triggers the metronome, setting the beat count to the given explicit value- Parameters:
beat
- Beat count, 0-indexed
-
trigger
Triggers the metronome, setting the beat count to the given value with a specified offset into the beat.- Parameters:
beat
- Beat count, 0-indexedmessage
- OSC message that caused the trigger, for timing adjustment
-
trigger
public void trigger(int beat, long nanoTime) Triggers the metronome, setting the beat count to the given value with a specified offset into the beat.- Parameters:
beat
- Beat count, 0-indexednanoTime
- System.nanoTime() value of event that caused the trigger
-
tap
public void tap()Adjusts the tempo in realtime by tapping. Whenever tap() is invoked the time between previous taps is averaged to compute a new tempo. At least three taps are required to compute a tempo. Otherwise, tapping just re-triggers the beat. It is better to use the trigger() method directly if this is all that is desired. -
tap
public void tap(long nanoTime) Adjusts the tempo, specifying an exact timestamp in milliseconds of when the tap event occurred.- Parameters:
nanoTime
- Timestamp of event, should be equivalent to System.nanoTime()
-
stop
public void stop()Stop the metronome running -
loop
public void loop(double deltaMs) - Specified by:
loop
in interfaceLXLoopTask
- Overrides:
loop
in classLXModulatorComponent
-
getTriggerSource
- Specified by:
getTriggerSource
in interfaceLXTriggerSource
-