NiCMidi 1.1.0
A MIDI library derived from J.D.Koftinoff jdksmidi
|
A MIDITickComponent which implements a basic sequencer, able to play the MIDI events contained in a MIDIMultiTrack. More...
#include <sequencer.h>
Public Types | |
enum | { FOLLOW_MIDI_TIMESIG_MESSAGE , FOLLOW_TIMESIG_DENOMINATOR , FOLLOW_THEORETIC_VALUE } |
Values for the SetMetronomeMode() method. More... | |
enum | { PLAY_BOUNDED , PLAY_UNBOUNDED } |
Values for the play mode. More... | |
enum | { COUNT_IN_ENABLED = 1 , COUNT_IN_PENDING = 2 , AUTO_STOP_PENDING = 4 } |
Values for count_in_status. More... | |
Public Member Functions | |
MIDISequencer (MIDIMultiTrack *m, MIDISequencerGUINotifier *n=0) | |
The constructor. More... | |
virtual | ~MIDISequencer () |
The destructor. More... | |
virtual void | Reset () |
Resets the MIDISequencer to its initial state. More... | |
MIDIClockTime | GetCurrentMIDIClockTime () const |
Returns current MIDIClockTime in MIDI ticks; it is effective even during playback. More... | |
float | GetCurrentTimeMs () const |
Returns current time in milliseconds; it is effective even during playback. More... | |
unsigned int | GetCurrentMeasure () const |
Returns current measure (1st measure is 0). More... | |
unsigned int | GetCurrentBeat () const |
Returns current beat in the measure (1st beat is 0). More... | |
MIDIClockTime | GetCurrentBeatOffset () const |
Returns the current MIDI time offset respect to current beat. More... | |
unsigned int | GetClksPerBeat () const |
Returns the base MIDI ticks per beat ratio of the internal MIDIMultiTrack. More... | |
MIDIMultiTrack * | GetMultiTrack () |
Returns a pointer to the internal MIDIMultiTrack. More... | |
const MIDIMultiTrack * | GetMultiTrack () const |
Returns a pointer to the internal MIDIMultiTrack. More... | |
MIDITrack * | GetTrack (unsigned int trk_num) |
Returns a pointer to the given track, or 0 if _num_trk is not a valid number. More... | |
unsigned int | GetNumTracks () const |
Returns the number of tracks of the multitrack. More... | |
unsigned int | GetTempoScale () const |
Returns current tempo scale in percentage (100 = no scaling, 200 = twice faster, etc.). More... | |
float | GetTempoWithoutScale () const |
Returns current tempo (BPM) without scaling. More... | |
float | GetTempoWithScale () const |
Returns current tempo (BPM) taking into account scaling (this is the true actual tempo). More... | |
bool | GetRepeatPlay () const |
Returns the repeat play (loop) status on/off. More... | |
unsigned int | GetRepeatPlayStart () const |
Returns the repeat play (loop) start measure. More... | |
unsigned int | GetRepeatPlayEnd () const |
Returns the repeat play (loop) end measure. More... | |
bool | GetCountInEnable () const |
Returns true if the count in is enabled. More... | |
bool | GetCountInPending () const |
Returns true if the count in is pending (the sequencer is counting in). More... | |
bool | GetTimeShiftMode () const |
Returns the time shift mode (on or off). More... | |
MIDISequencerState * | GetState () |
Returns a pointer to the current MIDISequencerState (i.e. More... | |
const MIDISequencerState * | GetState () const |
Returns a pointer to the current MIDISequencerState (i.e. More... | |
bool | GetPlayMode () |
Returns the play mode state (see SetPlayMode()). More... | |
MIDISequencerTrackState * | GetTrackState (unsigned int trk_num) |
Returns a pointer to the MIDISequencerTrackState for a track. More... | |
const MIDISequencerTrackState * | GetTrackState (unsigned int trk_num) const |
Returns a pointer to the MIDISequencerTrackState for a track. More... | |
unsigned int | GetTrackOutPort (unsigned int trk_num) const |
Returns the number of the out port assigned to a track. More... | |
MIDIProcessor * | GetTrackProcessor (unsigned int trk_num) |
Returns a pointer to the MIDISequencerTrackProcessor for a track. More... | |
const MIDIProcessor * | GetTrackProcessor (unsigned int trk_num) const |
Returns a pointer to the MIDISequencerTrackProcessor for a track. More... | |
int | GetTrackTimeShift (unsigned int trk_num) const |
Returns the time offset (in MIDI ticks) assigned to a track. More... | |
virtual bool | SetRepeatPlay (int on_off, int start_meas=-1, int end_meas=-1) |
Sets the repeat play (loop) parameters: you can set the repeat play status on/off, the start and the end measure. More... | |
virtual void | SetCountIn (bool on_off) |
Sets the count in enable or disable. More... | |
virtual bool | SetTempoScale (unsigned int scale) |
Sets the global tempo scale. More... | |
virtual void | SetTimeShiftMode (bool f) |
Sets the time shifting of events on and off. More... | |
virtual void | SetState (MIDISequencerState *s) |
Copies a given MIDISequencerState into the internal sequencer state. More... | |
virtual void | SetPlayMode (int mode) |
Sets the play mode. More... | |
virtual bool | SetTrackOutPort (unsigned int trk_num, unsigned int port) |
Sets the MIDI out port for a track. More... | |
virtual bool | SetTrackProcessor (unsigned int trk_num, MIDIProcessor *p) |
Sets a MIDIProcessor for the given track. More... | |
virtual bool | SetTrackTimeShift (unsigned int trk_num, int offset) |
Sets the time shift offset (in MIDI ticks) for a track. More... | |
virtual bool | InsertTrack (int trk_num=-1) |
Inserts into the internal MIDIMultiTrack a new empty track with default track parameters (transpose, time offset, etc.). More... | |
virtual bool | DeleteTrack (int trk_num=-1) |
Deletes a track and all its events from the internal MIDIMultiTrack. More... | |
virtual bool | MoveTrack (int from, int to) |
Moves a track from one position to another in the internal MIDIMultiTrack. More... | |
virtual void | GoToZero () |
Sets the current time to the beginning of the song, updating the internal status. More... | |
virtual bool | GoToTime (MIDIClockTime time_clk) |
Sets the current time to a given the MIDI time, updating the internal status. More... | |
virtual bool | GoToTimeMs (float time_ms) |
Same as GoToTime(), but the time is given in milliseconds. More... | |
virtual bool | GoToMeasure (unsigned int measure, unsigned int beat=0) |
Sets the current time to the given measure and beat, updating the internal status. More... | |
virtual bool | GetNextEvent (int *trk_num, MIDITimedMessage *msg) |
Gets the next event (respect current position). More... | |
virtual bool | GetNextEventTime (MIDIClockTime *time_clk) |
Gets the time of the next event (it can be different from current time if at current time there are not events). More... | |
virtual bool | GetNextEventTimeMs (float *time_ms) |
Same of GetNextEventTime(), but time is returned in milliseconds from the beginning. More... | |
float | MIDItoMs (MIDIClockTime time_clk) |
Converts a time from MIDI ticks into milliseconds, taking into account all tempo changes from the beginning of the song to the given time. More... | |
MIDIClockTime | MeasToMIDI (unsigned int meas, unsigned int beat=0, unsigned int offset=0) |
TODO. More... | |
virtual void | UpdateStatus () |
This is equivalent of GoToTime(state.cur_clock) and should be used to update the sequencer state after an edit in the multitrack (adding, deleting or editing events, for changes in the track structure see InsertTrack(), DeleteTrack() and MoveTrack()). More... | |
virtual void | Start () |
Starts the sequencer playing from the current time. More... | |
virtual void | Stop () |
Stops the sequencer playing. More... | |
virtual void | Play () |
This is an alias of Start(). More... | |
![]() | |
MIDITickComponent (tPriority pr, MIDITick func) | |
The constructor. More... | |
virtual | ~MIDITickComponent () |
The destructor. More... | |
MIDITick * | GetFunc () const |
Returns the address of the StaticTickProc() method, which will be called by the MIDIManager at every clock tick. More... | |
tPriority | GetPriority () const |
Returns the priority. More... | |
tMsecs | GetDevOffset () const |
Returns the user time offset parameter (see SetDevOffset()). More... | |
bool | IsPlaying () const |
Returns true if the callback procedure is active. More... | |
void | SetDevOffset (tMsecs dev_offs) |
Sets an user defined time offset, which will be added to every time calculation. More... | |
Static Public Member Functions | |
static void | SetMetronomeMode (int mode) |
Selects the way the sequencer calculates metronome beat. More... | |
Protected Member Functions | |
virtual void | TickProc (tMsecs sys_time) |
Implements the pure virtual method inherited from MIDITickComponent (you must not call it directly). More... | |
Static Protected Member Functions | |
static void | StaticTickProc (tMsecs sys_time, void *pt) |
Implements the static method inherited by MIDITickComponent and called at every timer tick. More... | |
static void | StaticStopProc (MIDISequencer *p) |
Internal use for auto stop. More... | |
![]() | |
static void | StaticTickProc (tMsecs sys_time, void *pt) |
This is the static callback procedure which the MIDIManager will call at every MIDITimer tick. More... | |
Additional Inherited Members | |
![]() | |
const MIDITick * | tick_proc |
The pointer to the static callback (set by the constructor to StaticTickProc()). More... | |
tMsecs | dev_time_offset |
A time offset set by the user and which you can use for your calculations. More... | |
tMsecs | sys_time_offset |
The system time of the last call of Start(). More... | |
std::recursive_mutex | proc_lock |
A mutex you can use for implementing thread safe methods. More... | |
A MIDITickComponent which implements a basic sequencer, able to play the MIDI events contained in a MIDIMultiTrack.
It embeds:
You can call Start() (aliased by Play()) and Stop() to start and stop a separate thread which takes care of playing. All methods are thread safe and can be called during playback. Moreover the class allows the user to:
anonymous enum |
Values for the SetMetronomeMode() method.
anonymous enum |
Values for the play mode.
Enumerator | |
---|---|
PLAY_BOUNDED | See SetPlayMode() |
PLAY_UNBOUNDED | See SetPlayMode() |
anonymous enum |
MIDISequencer::MIDISequencer | ( | MIDIMultiTrack * | m, |
MIDISequencerGUINotifier * | n = 0 |
||
) |
The constructor.
It raises an exception if in your system there are no MIDI out ports.
m | a pointer to a MIDIMultiTrack that will hold MIDI messages |
n | a pointer to a MIDISequencerGUINotifier. If you leave 0 the sequencer will not notify the GUI. |
RtMidiError::INVALID_DEVICE | if in the system are not present MIDI out ports |
|
virtual |
The destructor.
The MIDIMultiTrack and the MIDISequencerGUINotifier are not owned by the MIDISequencer; the MIDIProcessor objects, instead, (if you have set them with SetProcessor()) are deleted.
|
virtual |
Resets the MIDISequencer to its initial state.
Moves the time to 0 updating the state (see MIDISequencerState::Reset()), deletes all the track processors (if you have set them with SetProcessor()), sets all the tracks to MIDI out 0 and no time offset, sets tempo scale to 100.
Implements MIDITickComponent.
Reimplemented in AdvancedSequencer.
MIDIClockTime MIDISequencer::GetCurrentMIDIClockTime | ( | ) | const |
Returns current MIDIClockTime in MIDI ticks; it is effective even during playback.
float MIDISequencer::GetCurrentTimeMs | ( | ) | const |
Returns current time in milliseconds; it is effective even during playback.
|
inline |
Returns current measure (1st measure is 0).
|
inline |
Returns current beat in the measure (1st beat is 0).
|
inline |
Returns the current MIDI time offset respect to current beat.
|
inline |
Returns the base MIDI ticks per beat ratio of the internal MIDIMultiTrack.
Default value is 120 clocks per quarter beat. However, loading a MIDIFile into the MIDIMultiTrack can change this according to the file clock.
|
inline |
Returns a pointer to the internal MIDIMultiTrack.
|
inline |
Returns a pointer to the internal MIDIMultiTrack.
|
inline |
Returns a pointer to the given track, or 0 if _num_trk is not a valid number.
|
inline |
Returns the number of tracks of the multitrack.
|
inline |
Returns current tempo scale in percentage (100 = no scaling, 200 = twice faster, etc.).
|
inline |
Returns current tempo (BPM) without scaling.
|
inline |
Returns current tempo (BPM) taking into account scaling (this is the true actual tempo).
|
inline |
Returns the repeat play (loop) status on/off.
|
inline |
Returns the repeat play (loop) start measure.
|
inline |
Returns the repeat play (loop) end measure.
|
inline |
Returns true if the count in is enabled.
|
inline |
Returns true if the count in is pending (the sequencer is counting in).
|
inline |
|
inline |
Returns a pointer to the current MIDISequencerState (i.e.
the global sequencer state at current time). You can easily jump from a time to another saving and retrieving sequencer states.
|
inline |
Returns a pointer to the current MIDISequencerState (i.e.
the global sequencer state at current time). You can easily jump from a time to another saving and retrieving sequencer states.
|
inline |
Returns the play mode state (see SetPlayMode()).
|
inline |
Returns a pointer to the MIDISequencerTrackState for a track.
trk_num | the track number |
|
inline |
Returns a pointer to the MIDISequencerTrackState for a track.
trk_num | the track number |
|
inline |
Returns the number of the out port assigned to a track.
trk_num | the track number |
|
inline |
Returns a pointer to the MIDISequencerTrackProcessor for a track.
trk_num | the track number |
|
inline |
Returns a pointer to the MIDISequencerTrackProcessor for a track.
trk_num | the track number |
|
inline |
Returns the time offset (in MIDI ticks) assigned to a track.
trk_num | the track number |
|
virtual |
Sets the repeat play (loop) parameters: you can set the repeat play status on/off, the start and the end measure.
When the repeat play mode is on, the sequencer will start playing from its current position if it is before the end measure, or from the start measure otherwise. When it reaches the end of the loop it jumps to the start.
on_off | can be 0 (repeat play off), 1 (repeat play on) or -1 (leave the state unchanged). The latter can be useful if you only want to change the start or stop measure |
start_meas,end_meas | you can set the start and end measures (remember that measure numbers start with 0). If you set an end measure lesser or equal to the start the loop is automatically disabled. If you leave the default values the measures are left unchanged (useful if you only want to turn on or off the loop). |
|
virtual |
Sets the count in enable or disable.
|
virtual |
Sets the global tempo scale.
scale | the percentage: 100 = no scaling, 200 = twice faster, 50 = twice slower, etc. |
|
virtual |
Sets the time shifting of events on and off.
If you are editing the multitrack events you probably want to see the original (not shifted) MIDI time of events, while during playback you want them shifted. So you can turn time shifting on and off (and all the time related methods of the sequencer will return the shifted or the original time of events). The Start() method sets time shifting on, while the Stop() resets it to your choice, so usually you can leave time shifting off.
|
virtual |
Copies a given MIDISequencerState into the internal sequencer state.
This method is thread-safe and can be called during playback. Notifies the GUI a GROUP_ALL event to signify a full GUI reset.
s | a pointer to the new state. |
|
virtual |
Sets the play mode.
mode | an enum value with the following meaning:
|
|
virtual |
Sets the MIDI out port for a track.
This method is thread-safe and can be called during playback (in this case the sequencer will send a MIDI AllNotesOff message to the old port).
trk_num | the track number |
port | the id number of the port (see MIDIManager::GetOutPorts()) |
|
virtual |
Sets a MIDIProcessor for the given track.
This can't be done while the sequencer is playing so it stops it.
trk_num | the track number |
p | a pointer to a MIDIProcessor; calling this with p = 0 sets the track to no processor |
|
virtual |
Sets the time shift offset (in MIDI ticks) for a track.
The offset can be positive or negative; events shifted include all channel messages and sysex messages (others remain at their time). If you select a negative offset, be sure not to have shifted events at lesser time than the offset (they won't be shifted). This method is thread-safe and can be called during playback.
trk_num | the track number |
offset | the offset in MIDI ticks |
|
virtual |
Inserts into the internal MIDIMultiTrack a new empty track with default track parameters (transpose, time offset, etc.).
This method is thread-safe and can be called during playback. Notifies the GUI a GROUP_ALL event to signify a full GUI reset.
trk_num | the track number (it must be in the range 0 ... GetNumTracks() - 1). If you leave the default value the track will be appended as last. |
|
virtual |
Deletes a track and all its events from the internal MIDIMultiTrack.
This method is thread-safe and can be called during playback (in this case the sequencer will send a MIDI AllNotesOff message to the old track port). Notifies the GUI a GROUP_ALL event to signify a full GUI reset.
trk_num | the track number (must be in the range 0 ... GetNumTracks() - 1). If you leave he default value the last track wil be deleted. |
|
virtual |
Moves a track from one position to another in the internal MIDIMultiTrack.
This method is thread-safe and can be called during playback (in this case the sequencer will send a MIDI AllNotesOff message to the involved ports). Notifies the GUI a GROUP_ALL event to signify a full GUI reset.
from,to | the start and destination track numbers (both must be in the range 0 ... GetNumTracks() - 1). |
|
virtual |
Sets the current time to the beginning of the song, updating the internal status.
This method is thread-safe and can be called during playback. Notifies the GUI a GROUP_ALL event to signify a full GUI reset.
Reimplemented in AdvancedSequencer.
|
virtual |
Sets the current time to a given the MIDI time, updating the internal status.
This method is thread-safe and can be called during playback. Notifies the GUI a GROUP_ALL event to signify a full GUI reset
time_clk | the new time in MIDI ticks |
Reimplemented in AdvancedSequencer.
|
virtual |
Same as GoToTime(), but the time is given in milliseconds.
Reimplemented in AdvancedSequencer.
|
virtual |
Sets the current time to the given measure and beat, updating the internal status.
This method is thread-safe and can be called during playback. Notifies the GUI a GROUP_ALL event to signify a GUI reset. See Numbering conventions.
|
virtual |
Gets the next event (respect current position).
This queries the state for the next event in the multitrack, then processes it with the corresponding track processor (if you have set it with SetProcessor)) and updates the state. Moreover it notifies the GUI with appropriate messages. If there are no events before the next metronome click you will get a Beat Marker internal event.
[out] | trk_num | will return the track number of the next event |
[out] | msg | will return the MIDI event |
|
virtual |
Gets the time of the next event (it can be different from current time if at current time there are not events).
[out] | time_clk | will return the requested time in MIDI ticks from the beginning |
|
virtual |
Same of GetNextEventTime(), but time is returned in milliseconds from the beginning.
float MIDISequencer::MIDItoMs | ( | MIDIClockTime | time_clk | ) |
Converts a time from MIDI ticks into milliseconds, taking into account all tempo changes from the beginning of the song to the given time.
time_clk | the time to convert |
MIDIClockTime MIDISequencer::MeasToMIDI | ( | unsigned int | meas, |
unsigned int | beat = 0 , |
||
unsigned int | offset = 0 |
||
) |
TODO.
|
inlinevirtual |
This is equivalent of GoToTime(state.cur_clock) and should be used to update the sequencer state after an edit in the multitrack (adding, deleting or editing events, for changes in the track structure see InsertTrack(), DeleteTrack() and MoveTrack()).
If you have edited the multitrack, call this before moving time, getting events or playing.
Reimplemented in AdvancedSequencer.
|
virtual |
Starts the sequencer playing from the current time.
Reimplemented from MIDITickComponent.
Reimplemented in AdvancedSequencer.
|
virtual |
Stops the sequencer playing.
Reimplemented from MIDITickComponent.
Reimplemented in AdvancedSequencer.
|
inlinevirtual |
This is an alias of Start().
|
inlinestatic |
Selects the way the sequencer calculates metronome beat.
You have three choices:
Don't use this while the sequencer is playing.
|
staticprotected |
Implements the static method inherited by MIDITickComponent and called at every timer tick.
It only calls the member TickProc().
|
protectedvirtual |
Implements the pure virtual method inherited from MIDITickComponent (you must not call it directly).
Implements MIDITickComponent.
|
inlinestaticprotected |
Internal use for auto stop.