public class Tempo extends LXModulatorComponent implements LXOscComponent
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.Modifier and Type | Class and Description |
---|---|
static class |
Tempo.ClockSource |
static class |
Tempo.Division |
static interface |
Tempo.Listener |
LXModulatorComponent.Profiler
LXComponent.Placeholder, LXComponent.Renamable
LXSerializable.Utils
Modifier and Type | Field and Description |
---|---|
DiscreteParameter |
beatsPerMeasure |
BoundedParameter |
bpm |
EnumParameter<Tempo.ClockSource> |
clockSource |
BooleanParameter |
enabled |
static double |
MAX_BPM |
static double |
MIN_BPM |
BooleanParameter |
nudgeDown |
BooleanParameter |
nudgeUp |
MutableParameter |
period |
BooleanParameter |
tap |
BooleanParameter |
trigger |
modulators, profiler
controlSurfaceSemaphore, KEY_CLASS, KEY_COMPONENT_ID, KEY_ID, KEY_PARAMETER_PATH, KEY_PATH, label, lx, modulationColor
Modifier and Type | Method and Description |
---|---|
Tempo |
addListener(Tempo.Listener listener) |
Tempo |
adjustBpm(double amount)
Adjust the BPM by the given amount
|
double |
basis()
Indicates phase of the current beat.
|
double |
basisf() |
boolean |
beat()
Method to indicate when we are on-beat, assuming quarter-notes being given
one beat.
|
int |
beatCount()
Gets the count of the current beat we are on
|
double |
bpm()
Returns the current tempo in Beats Per Minute
|
float |
bpmf()
Returns the tempo in floating point
|
double |
getBasis(Tempo.Division division)
Gets the basis of the tempo, relative to a tempo division.
|
double |
getBasis(Tempo.Division division,
boolean mod)
Gets the basis of the tempo, relative to a division.
|
double |
getCompositeBasis()
Gets the composite basis of the tempo, which is the beatCount combined with the current
basis cycle.
|
String |
getLabel()
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.
|
void |
loop(double deltaMs) |
boolean |
measure()
Method to indicate the start of a measure.
|
void |
onParameterChanged(LXParameter p)
Subclasses are free to override this if desired.
|
double |
ramp()
Deprecated.
|
float |
rampf()
Deprecated.
|
Tempo |
removeListener(Tempo.Listener listener) |
Tempo |
setBpm(double bpm)
Sets the BPM to the given value
|
Tempo |
setPeriod(double beatMillis)
Sets the period of one beat
|
void |
tap()
Adjusts the tempo in realtime by tapping.
|
void |
tap(long now)
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 count
|
void |
trigger(int beat)
Triggers the metronome, setting the beat count to the given explicit value
|
addModulator, addModulator, addModulator, constructProfiler, dispose, getModulator, getModulators, moveModulator, removeModulator, startModulator
addArray, addChild, addInternalParameter, addParameter, addParameter, contains, copyParameters, getChild, getComponentName, getComponentName, getComponentName, getId, getLX, getOscAddress, getOscLabel, getOscPath, getParameter, getParameters, getParent, getPath, load, loadParameters, removeParameter, removeParameter, save, saveParameters, setParent, toString, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getOscAddress
get, get, getCanonicalLabel, getCanonicalLabel, getCanonicalPath, getCanonicalPath, getComponent, getComponent, getParameter, getParameter
public static final double MIN_BPM
public static final double MAX_BPM
public final EnumParameter<Tempo.ClockSource> clockSource
public final DiscreteParameter beatsPerMeasure
public final BoundedParameter bpm
public final BooleanParameter trigger
public final BooleanParameter enabled
public final BooleanParameter tap
public final BooleanParameter nudgeUp
public final BooleanParameter nudgeDown
public final MutableParameter period
public Tempo(LX lx)
public boolean handleOscMessage(OscMessage message, String[] parts, int index)
LXComponent
handleOscMessage
in interface LXOscComponent
handleOscMessage
in class LXComponent
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 childrentrue
if the OSC message was handled and should be considered consumed, false
otherwisepublic String getLabel()
LXComponent
LXComponent.Renamable
interface may allow the user to change this value.getLabel
in interface LXPath
getLabel
in class LXComponent
public void onParameterChanged(LXParameter p)
LXComponent
onParameterChanged
in interface LXParameterListener
onParameterChanged
in class LXComponent
p
- Parameter that has a value changepublic Tempo addListener(Tempo.Listener listener)
public Tempo removeListener(Tempo.Listener listener)
public boolean beat()
public int beatCount()
public double getCompositeBasis()
public double getBasis(Tempo.Division division, boolean mod)
division
- Tempo divisionmod
- Whether to take modulus against 1public double getBasis(Tempo.Division division)
division
- Tempo divisionpublic boolean measure()
public double basis()
public double basisf()
@Deprecated public double ramp()
basis()
instead.@Deprecated public float rampf()
basisf()
instead.public double bpm()
public float bpmf()
public Tempo setBpm(double bpm)
bpm
- Number of beats per minutepublic Tempo adjustBpm(double amount)
amount
- Amount to adjust BPM bypublic Tempo setPeriod(double beatMillis)
beatMillis
- Milliseconds in a beatpublic void trigger()
public void trigger(int beat)
beat
- Beat countpublic void trigger(boolean resetBeat)
resetBeat
- True if the beat count should be reset to 0public void tap()
public void tap(long now)
now
- Timestamp of event, should be equivalent to System.currentTimeMillis()public void loop(double deltaMs)
loop
in interface LXLoopTask
loop
in class LXModulatorComponent
LX library by Mark C. Slee. © 2012-2020