public class TimeTracker
extends java.lang.Object
TimeTracker
is able to interpret MIDI tempo, key, and time signature change events and keep track
of the song timing in seconds, instead of just using ticks as MIDI events do. It does this by using
a LinkedList of TimeTrackerNode
objects.Modifier and Type | Field and Description |
---|---|
private int |
anacrusisLength
The number of ticks which lie before the first full measure in this song.
|
private long |
lastTick
The last tick for any event in this song, initially 0.
|
private java.util.LinkedList<TimeTrackerNode> |
nodes
The LInkedList of TimeTrackerNodes of this TimeTracker, ordered by time.
|
private double |
PPQ
Pulses (ticks) per Quarter note, as in the current Midi song's header.
|
Constructor and Description |
---|
TimeTracker()
Create a new TimeTracker.
|
Modifier and Type | Method and Description |
---|---|
void |
addKeySignatureChange(long tick,
int keyNumber,
boolean isMajor)
Change the key to the given value.
|
void |
addKeySignatureChange(javax.sound.midi.MidiEvent event,
javax.sound.midi.MetaMessage mm)
A KeySignature event was detected.
|
void |
addTempoChange(long tick,
int qpm)
Change the tempo to the given number of quarter notes per minute.
|
void |
addTempoChange(javax.sound.midi.MidiEvent event,
javax.sound.midi.MetaMessage mm)
A Tempo event was detected.
|
void |
addTimeSignatureChange(long tick,
int numerator,
int denominator)
Change the time signature to the given value.
|
void |
addTimeSignatureChange(javax.sound.midi.MidiEvent event,
javax.sound.midi.MetaMessage mm)
A TimeSignature event was detected.
|
java.util.List<TimeSignature> |
getAllTimeSignatures()
Get a List of all of the time signatures of this TimeTracker, excluding the dummy one.
|
int |
getAnacrusisSubBeats()
Get the anacrusis length of this TimeTracker, in sub beats.
|
int |
getAnacrusisTicks()
Get the anacrusis length of this TimeTracker, in ticks.
|
java.util.List<Beat> |
getBeats()
Get a List of the Beats found by this TimeTracker up until (but not including)
the
lastTick . |
TimeSignature |
getFirstTimeSignature()
Get the first non-dummy time signature in this song.
|
long |
getLastTick()
Get the last tick for this song.
|
private TimeTrackerNode |
getNodeAtTick(long tick)
Get the TimeTrackerNode which is valid at the given tick.
|
TimeTrackerNode |
getNodeAtTime(long time)
Get the TimeTrackerNode which is valid at the given time.
|
java.util.LinkedList<TimeTrackerNode> |
getNodes()
Get a list of the
TimeTrackerNode s tracked by this object. |
double |
getPPQ()
Get the PPQ of this TimeTracker.
|
double |
getQuantizationError(MidiNote note,
int divisions)
Get the quantization error of the given note, with the given number of divisions
per quarter note.
|
long |
getTickAtTime(long time)
Gets the tick number at the given time, measured in microseconds.
|
long |
getTimeAtTick(long tick)
Returns the time in microseconds of a given tick number.
|
void |
setAnacrusis(int length)
Set the anacrusis length of this song to the given number of ticks.
|
void |
setLastTick(long lastTick)
Set the last tick for this song to the given value.
|
void |
setPPQ(double ppq)
Set the PPQ for this TimeTracker.
|
java.lang.String |
toString() |
private double PPQ
private final java.util.LinkedList<TimeTrackerNode> nodes
private int anacrusisLength
private long lastTick
public void addTimeSignatureChange(javax.sound.midi.MidiEvent event, javax.sound.midi.MetaMessage mm)
event
- The event.mm
- The message from the event.public void addTimeSignatureChange(long tick, int numerator, int denominator)
tick
- The tick at which the time signature was changed.numerator
- The numerator.denominator
- The denominator.public void addTempoChange(javax.sound.midi.MidiEvent event, javax.sound.midi.MetaMessage mm)
event
- The event.mm
- The message from the event.public void addTempoChange(long tick, int qpm)
tick
- The tick at which to make the given change.qpm
- The number of quarter notes per minute for the new tempo.public void addKeySignatureChange(javax.sound.midi.MidiEvent event, javax.sound.midi.MetaMessage mm)
event
- The event.mm
- The message from the event.public void addKeySignatureChange(long tick, int keyNumber, boolean isMajor)
tick
- The tick at which to change the key.keyNumber
- The key number to change to.isMajor
- Whether that key is major or minor.public long getTimeAtTick(long tick)
tick
- The tick number to calculate the time ofprivate TimeTrackerNode getNodeAtTick(long tick)
tick
- The tick.public long getTickAtTime(long time)
time
- The time in microseconds whose tick number we want.public TimeTrackerNode getNodeAtTime(long time)
time
- The time.public java.util.List<TimeSignature> getAllTimeSignatures()
public java.util.List<Beat> getBeats()
lastTick
.public double getQuantizationError(MidiNote note, int divisions)
note
- The note whose quantization error we want.divisions
- The number of divisions per quarter note.public TimeSignature getFirstTimeSignature()
public int getAnacrusisSubBeats()
anacrusisLength
, in sub beatspublic int getAnacrusisTicks()
anacrusisLength
public void setAnacrusis(int length)
length
- The anacrusis length of this song, measured in ticks.public java.util.LinkedList<TimeTrackerNode> getNodes()
TimeTrackerNode
s tracked by this object.nodes
public void setLastTick(long lastTick)
lastTick
- lastTick
public long getLastTick()
lastTick
public void setPPQ(double ppq)
ppq
- PPQ
public double getPPQ()
PPQ
public java.lang.String toString()
toString
in class java.lang.Object