public class Dispatcher
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
Dispatcher.EventHandler
a generic handler for bar start, beat and end
|
static interface |
Dispatcher.NoteEventHandler
a handler for notes starting
|
static class |
Dispatcher.State
the state of the dispatcher
|
Constructor and Description |
---|
Dispatcher(PlayData playData,
java.lang.Runnable playEndHandler)
construct the Dispatcher
|
Modifier and Type | Method and Description |
---|---|
int |
barStartTime(int barIndex)
time in ms from the start of the score to the start of the bar
|
int |
currentBar()
get the last bar which was dispatched
|
void |
setBarStartHandler(Dispatcher.EventHandler handler,
int delay_ms)
register an event handler to be called at the start of each bar
|
void |
setBeatHandler(Dispatcher.EventHandler handler,
int delay_ms)
register an event handler to be called on each beat in the bar
|
void |
setEndHandler(Dispatcher.EventHandler handler,
int delay_ms)
register an event handler to be called on completion of play.
|
void |
setNoteHandler(Dispatcher.NoteEventHandler handler,
int delay_ms)
register an event handler to be called on the start of new note/chord
This can be used to move a cursor onto each note as it is played.
|
void |
startAt(java.util.Date startTime,
int barIndex,
boolean countIn)
start dispatching at the given start time.
|
Dispatcher.State |
state()
the current state of the Dispatcher
|
void |
stop()
stop dispatching
|
public Dispatcher(PlayData playData, java.lang.Runnable playEndHandler)
playData
- the PlayData derived from the scoreplayEndHandler
- a handler to call on true end of play to update state in the caller
NB This is not the same as the registered end handler which may have an associated delaypublic Dispatcher.State state()
public void startAt(java.util.Date startTime, int barIndex, boolean countIn)
startTime
- the time to startbarIndex
- the 0-based bar index to start atcountIn
- if true a count-in bar (copy of the barIndex bar with a maximum of 4 beats and the count-in flag set) is played firstpublic void stop()
public int currentBar()
public int barStartTime(int barIndex)
public void setBarStartHandler(Dispatcher.EventHandler handler, int delay_ms)
handler
- the handler to be called at the start of each bardelay_ms
- a millisecond delay for the handler call, which can be negative to anticipate the bar change eg for an animated cursorpublic void setBeatHandler(Dispatcher.EventHandler handler, int delay_ms)
handler
- the handler to be called on each beatdelay_ms
- a millisecond delay for the handler call, which can be negative to anticipate the eventpublic void setEndHandler(Dispatcher.EventHandler handler, int delay_ms)
handler
- the handler to be called at the end of playdelay_ms
- a millisecond delay for the handler call, which can be negative to anticipate the eventpublic void setNoteHandler(Dispatcher.NoteEventHandler handler, int delay_ms)
handler
- the handler to be called at the start of each notedelay_ms
- a millisecond delay for the handler call, which can be negative to anticipate the event