NiCMidi 1.1.0
A MIDI library derived from J.D.Koftinoff jdksmidi
MIDIMultiTrackIterator Class Reference

A forward iterator for moving along a MIDIMultiTrack. More...

#include <multitrack.h>

Public Member Functions

 MIDIMultiTrackIterator (MIDIMultiTrack *mlt)
 The constructor creates the object and attaches it to the given MIDIMultiTrack. More...
 
void Reset ()
 Syncs num_tracks with the multitrack and resets time to 0. Does not reset time shift mode. More...
 
MIDIClockTime GetCurrentTime () const
 Gets the current time of the iterator. More...
 
bool GetTimeShiftMode () const
 Returns true if time shifting is on. More...
 
MIDIMultiTrackIteratorStateGetState ()
 Gets the current MIDIMultiTrackIteratorState. More...
 
const MIDIMultiTrackIteratorStateGetState () const
 Gets the current MIDIMultiTrackIteratorState. More...
 
void SetTimeShiftMode (bool f)
 Turns time shifting on and off. More...
 
void SetEnable (unsigned int trk_num, bool f)
 Enable or disable a track. More...
 
void SetState (const MIDIMultiTrackIteratorState &s)
 Sets the given MIDIMultiTrackIteratorState as current state. More...
 
bool GoToTime (MIDIClockTime time)
 Goes to the given time, which becomes the current time, and sets then the current event as the first event (in any track) with time greater or equal to time. More...
 
bool GetNextEvent (int *track, MIDITimedMessage **msg)
 Gets the next event in the multitrack in temporal order and updates the iterator state. More...
 
bool GetNextEventOnTrack (int track, MIDITimedMessage **msg)
 Gets the next event in the multitrack on track track and updates the iterator state. More...
 
bool GetNextEventTime (MIDIClockTime *t) const
 Gets the time of the next event in the multitrack (it can be different from current time if at current time there are not events). More...
 

Detailed Description

A forward iterator for moving along a MIDIMultiTrack.

It defines a current time (initially 0) and a current event, and stores its status in a MIDIMultiTrackIteratorState object. You can jump to any time in the multitrack and get its events in chronological order, starting with the first event with time greater than or equal to the current time, regardless of their track. This class also handles the time shifting of track events. You can set a different time shift amount for every track with the MIDITrack::SetTimeShift() method, and turn time shifting on and off with the SetTimeShiftMode() of this class. See also MIDISequencer::SetTimeShiftMode().

Constructor & Destructor Documentation

◆ MIDIMultiTrackIterator()

MIDIMultiTrackIterator::MIDIMultiTrackIterator ( MIDIMultiTrack mlt)

The constructor creates the object and attaches it to the given MIDIMultiTrack.

Member Function Documentation

◆ Reset()

void MIDIMultiTrackIterator::Reset ( )

Syncs num_tracks with the multitrack and resets time to 0. Does not reset time shift mode.

◆ GetCurrentTime()

MIDIClockTime MIDIMultiTrackIterator::GetCurrentTime ( ) const
inline

Gets the current time of the iterator.

◆ GetTimeShiftMode()

bool MIDIMultiTrackIterator::GetTimeShiftMode ( ) const
inline

Returns true if time shifting is on.

◆ GetState() [1/2]

MIDIMultiTrackIteratorState & MIDIMultiTrackIterator::GetState ( )
inline

Gets the current MIDIMultiTrackIteratorState.

You can save and then restore it for a faster processing in GoTo operations (admitting the contents of the multitrack are not changed).

◆ GetState() [2/2]

const MIDIMultiTrackIteratorState & MIDIMultiTrackIterator::GetState ( ) const
inline

Gets the current MIDIMultiTrackIteratorState.

You can save and then restore it for a faster processing in GoTo operations (admitting the contents of the multitrack are not changed).

◆ SetTimeShiftMode()

void MIDIMultiTrackIterator::SetTimeShiftMode ( bool  f)
inline

Turns time shifting on and off.

If time shifting is off events are sorted according to their time, otherwise an offset (positive or negative) is added to channel and sysex events time (other events time remain unchanged).

◆ SetEnable()

void MIDIMultiTrackIterator::SetEnable ( unsigned int  trk_num,
bool  f 
)

Enable or disable a track.

If you know that a track contains events which you want to ignore you can exclude it for more speed.

Parameters
trk_numthe number of the track
ftrue for enabling, false for disabling.

◆ SetState()

void MIDIMultiTrackIterator::SetState ( const MIDIMultiTrackIteratorState s)
inline

Sets the given MIDIMultiTrackIteratorState as current state.

◆ GoToTime()

bool MIDIMultiTrackIterator::GoToTime ( MIDIClockTime  time)

Goes to the given time, which becomes the current time, and sets then the current event as the first event (in any track) with time greater or equal to time.

If there are more events with same time in different tracks their order is not defined, as the iterator tries to rotate across the tracks rather than to get first all events in a single track. However, temporal order is always granted.

Returns
true if the given time is effectively reached, false otherwise (it is after the end of the multitrack)

◆ GetNextEvent()

bool MIDIMultiTrackIterator::GetNextEvent ( int *  track,
MIDITimedMessage **  msg 
)

Gets the next event in the multitrack in temporal order and updates the iterator state.

If the time shifting mode is on the events are sorted according to their shifted time.

Parameters
trackthe track of the event, if valid.
*msga pointer to the event in the MidiMultiTrack
Returns
true if there is effectively a next event (we are not at the end of the MIDIMultiTrack), false otherwise (and *track and **msg contain undefined values).

◆ GetNextEventOnTrack()

bool MIDIMultiTrackIterator::GetNextEventOnTrack ( int  track,
MIDITimedMessage **  msg 
)

Gets the next event in the multitrack on track track and updates the iterator state.

Parameters
trackthe track of the event, if valid.
*msga pointer to the event in the MidiMultiTrack
Returns
true if there is effectively a next event (we are not at the end of the track), false otherwise (and **msg contains an undefined value).

◆ GetNextEventTime()

bool MIDIMultiTrackIterator::GetNextEventTime ( MIDIClockTime t) const

Gets the time of the next event in the multitrack (it can be different from current time if at current time there are not events).

This does not change the iterator state.

Parameters
there we get the time of next event, if valid. If the time shifting mode is on it is the shifted time.
Returns
true if there is effectively a next event (we aren't at the end of the MIDIMultiTrack, false otherwise (*t doesn't contain a valid time).

The documentation for this class was generated from the following file: