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

Holds an array of pointers to MIDITrack objects to be played simultaneously. More...

#include <multitrack.h>

Inherited by MIDIEditMultiTrack.

Public Member Functions

 MIDIMultiTrack (unsigned int num_tracks=0, unsigned int cl_p_b=DEFAULT_CLKS_PER_BEAT)
 The constructor creates an object with given number of tracks (default no track) and base MIDI clocks per beat. More...
 
 MIDIMultiTrack (const MIDIMultiTrack &mlt)
 The copy constructor. More...
 
virtual ~MIDIMultiTrack ()
 The destructor: The MIDIMultiTrack owns its tracks, so they are destroyed by this. More...
 
MIDIMultiTrackoperator= (const MIDIMultiTrack &mlt)
 The assignment operator. More...
 
void Reset (unsigned int num_tracks=0)
 Deletes all the tracks in the Multitrack, resizes it to the given number of tracks and resets clks_per_beat. More...
 
void ClearTracks (bool mantain_end=false)
 Clears tracks events but mantains the tracks and their parameters. More...
 
unsigned int GetClksPerBeat () const
 Returns the MIDI clocks per beat of all tracks (i.e. the number of MIDI ticks in a quarter note). More...
 
MIDITrackGetTrack (unsigned int trk_num)
 Returns the pointer to the track. More...
 
const MIDITrackGetTrack (unsigned int trk_num) const
 Returns the pointer to the track. More...
 
int GetTrackNum (MIDITrack *trk) const
 Returns the number of the pointed track, -1 if the track is not in the multitrack. More...
 
unsigned int GetNumTracks () const
 Returns the number of allocated tracks. More...
 
unsigned int GetNumTracksWithEvents () const
 Returns the number of tracks with events (other than EOT). More...
 
unsigned int GetNumEvents () const
 Returns the total number of MIDI events in the multitrack (for every track there is at least the EOT). More...
 
MIDIClockTime GetEndTime () const
 Returns the end time of the longest track. More...
 
bool IsValidTrackNumber (unsigned int trk_num) const
 Returns true if trk_num is in thee range 0 ... GetNumTracks() - 1. More...
 
bool IsEmpty () const
 Returns true if there are no events in the tracks and the end time is 0. More...
 
void SetClksPerBeat (unsigned int cl_p_b)
 Changes the value of the clock per beat parameter for the tracks, updating the times of all MIDI events. More...
 
bool SetEndTime (MIDIClockTime end_time)
 Sets the time of the data end event to end_time. More...
 
void ShrinkEndTime ()
 Sets the time of the data end event equal to the time of the last event of every track. More...
 
void AssignEventsToTracks (const MIDITrack *src)
 This function is useful in dealing with MIDI format 0 files (with all events in an unique track). More...
 
void AssignEventsToTracks (unsigned int trk_num=0)
 The same as previous, but argument is the track number in the multitrack object himself. More...
 
bool InsertTrack (int trk_num=-1)
 Inserts a new empty track at position trk_num (trk_num must be in the range 0 ... GetNumTracks() - 1). More...
 
bool InsertTrack (const MIDITrack *trk, int trk_num=-1)
 Inserts a copy of the given track at position trk_num (trk_num must be in the range 0 ... GetNumTracks() - 1). More...
 
bool DeleteTrack (int trk_num=-1)
 Deletes the track trk_num and its events. More...
 
bool MoveTrack (int from, int to)
 Moves a track from the position from to the position to. More...
 
bool SetTrack (const MIDITrack *trk, unsigned int trk_num)
 Copies the track trk into the position trk_num of the MIDIMultiTrack. More...
 
bool InsertEvent (unsigned int trk_num, const MIDITimedMessage &msg, tInsMode _ins_mode=INSMODE_DEFAULT)
 Inserts the event msg in the track trk_num. More...
 
bool InsertNote (unsigned int trk_num, const MIDITimedMessage &msg, MIDIClockTime len, tInsMode _ins_mode=INSMODE_DEFAULT)
 Inserts a Note On and a Note Off event into the track trk_num. See MIDITrack::InsertNote() for details. More...
 
bool DeleteEvent (unsigned int trk_num, const MIDITimedMessage &msg)
 Deletes the event msg from the track trk_num. See MIDITrack::DeleteEvent() for details. More...
 
bool DeleteNote (unsigned int trk_num, const MIDITimedMessage &msg)
 Deletes the note msg (msg must be a Note On) from the track _trk_num. See MIDITrack::DeleteNote() for details. More...
 
void EditCopy (MIDIClockTime start, MIDIClockTime end, int tr_start, int tr_end, MIDIEditMultiTrack *edit)
 
void EditCut (MIDIClockTime start, MIDIClockTime end, MIDIEditMultiTrack *edit)
 
void EditClear (MIDIClockTime start, MIDIClockTime end, int tr_start, int tr_end)
 
void EditInsert (MIDIClockTime start, int tr_start, int times, MIDIEditMultiTrack *edit)
 
void EditReplace (MIDIClockTime start, int tr_start, int times, bool sysex, MIDIEditMultiTrack *edit)
 

Protected Attributes

unsigned int clks_per_beat
 The common clock per beat timing parameter for all tracks (this is the number of MIDI ticks for a quarter note). More...
 

Detailed Description

Holds an array of pointers to MIDITrack objects to be played simultaneously.

Every track contains MIDITimedMessage objects representing MIDI events, and all tracks share the same timing (i.e. the events are temporized according to the same MIDI clock per beat). Typically track 0 is the master track and contains only non-channel MIDI events (time, tempo, markers ...) while other tracks contain the channel events. The MIDIMultiTrack object owns its tracks, so deleting it frees them also. You need to embed this into a MIDISequencer for playing the tracks. Moreover, a MIDIMultiTrackIterator class is supplied for moving along events in temporal order regardless the track number.

Examples
test_advancedsequencer.cpp, test_advancedsequencer_noinput.cpp, test_sequencer.cpp, test_stepsequencer.cpp, and test_writefile.cpp.

Constructor & Destructor Documentation

◆ MIDIMultiTrack() [1/2]

MIDIMultiTrack::MIDIMultiTrack ( unsigned int  num_tracks = 0,
unsigned int  cl_p_b = DEFAULT_CLKS_PER_BEAT 
)

The constructor creates an object with given number of tracks (default no track) and base MIDI clocks per beat.

Parameters
num_tracksThe number of tracks of the multitrack. The tracks are created by the constructor and they are are initially empty (contain only the EOT message at time 0). The default is no track
cl_p_bThe number of MIDI ticks per quarter note. All tracks share this to convert the raw MIDIClockTime stored in their MIDITimedMessage objects into musical values.

◆ MIDIMultiTrack() [2/2]

MIDIMultiTrack::MIDIMultiTrack ( const MIDIMultiTrack mlt)

The copy constructor.

◆ ~MIDIMultiTrack()

virtual MIDIMultiTrack::~MIDIMultiTrack ( )
virtual

The destructor: The MIDIMultiTrack owns its tracks, so they are destroyed by this.

Member Function Documentation

◆ operator=()

MIDIMultiTrack & MIDIMultiTrack::operator= ( const MIDIMultiTrack mlt)

The assignment operator.

◆ Reset()

void MIDIMultiTrack::Reset ( unsigned int  num_tracks = 0)

Deletes all the tracks in the Multitrack, resizes it to the given number of tracks and resets clks_per_beat.

◆ ClearTracks()

void MIDIMultiTrack::ClearTracks ( bool  mantain_end = false)

Clears tracks events but mantains the tracks and their parameters.

If mantain_end is true doesn't change the time of EOT events, otherwise sets them to 0.

◆ GetClksPerBeat()

unsigned int MIDIMultiTrack::GetClksPerBeat ( ) const
inline

Returns the MIDI clocks per beat of all tracks (i.e. the number of MIDI ticks in a quarter note).

Examples
test_stepsequencer.cpp.

◆ GetTrack() [1/2]

MIDITrack * MIDIMultiTrack::GetTrack ( unsigned int  trk_num)
inline

Returns the pointer to the track.

Parameters
trk_numThe track number
Examples
test_advancedsequencer_noinput.cpp, test_sequencer.cpp, test_stepsequencer.cpp, and test_writefile.cpp.

◆ GetTrack() [2/2]

const MIDITrack * MIDIMultiTrack::GetTrack ( unsigned int  trk_num) const
inline

Returns the pointer to the track.

Parameters
trk_numThe track number

◆ GetTrackNum()

int MIDIMultiTrack::GetTrackNum ( MIDITrack trk) const

Returns the number of the pointed track, -1 if the track is not in the multitrack.

◆ GetNumTracks()

unsigned int MIDIMultiTrack::GetNumTracks ( ) const
inline

Returns the number of allocated tracks.

Examples
test_stepsequencer.cpp.

◆ GetNumTracksWithEvents()

unsigned int MIDIMultiTrack::GetNumTracksWithEvents ( ) const

Returns the number of tracks with events (other than EOT).

◆ GetNumEvents()

unsigned int MIDIMultiTrack::GetNumEvents ( ) const

Returns the total number of MIDI events in the multitrack (for every track there is at least the EOT).

If you want to know if the MIDIMultiTrack is empty, use GetNumTracksWithEvents() instead.

◆ GetEndTime()

MIDIClockTime MIDIMultiTrack::GetEndTime ( ) const

Returns the end time of the longest track.

Examples
test_stepsequencer.cpp.

◆ IsValidTrackNumber()

bool MIDIMultiTrack::IsValidTrackNumber ( unsigned int  trk_num) const
inline

Returns true if trk_num is in thee range 0 ... GetNumTracks() - 1.

Examples
test_advancedsequencer.cpp, test_sequencer.cpp, and test_stepsequencer.cpp.

◆ IsEmpty()

bool MIDIMultiTrack::IsEmpty ( ) const
inline

Returns true if there are no events in the tracks and the end time is 0.

◆ SetClksPerBeat()

void MIDIMultiTrack::SetClksPerBeat ( unsigned int  cl_p_b)

Changes the value of the clock per beat parameter for the tracks, updating the times of all MIDI events.

This may lead to loss in precision or rounding error if the new clocks per beat is not a multiple of the old, so it's better to call this function before inserting any event in the multitrack.

Parameters
cl_p_bsee the constructor

◆ SetEndTime()

bool MIDIMultiTrack::SetEndTime ( MIDIClockTime  end_time)

Sets the time of the data end event to end_time.

If there are events of other type after end_time the function fails and returns false.

Examples
test_stepsequencer.cpp.

◆ ShrinkEndTime()

void MIDIMultiTrack::ShrinkEndTime ( )

Sets the time of the data end event equal to the time of the last event of every track.

◆ AssignEventsToTracks() [1/2]

void MIDIMultiTrack::AssignEventsToTracks ( const MIDITrack src)

This function is useful in dealing with MIDI format 0 files (with all events in an unique track).

It remakes the MIDIMultiTrack object with 17 tracks (src track can be a member of multitrack object himself), moves src track channel events to tracks 1-16 according their channel, and all other types of events to track 0. This is automatically called when loading a MIDI format 0 file.

◆ AssignEventsToTracks() [2/2]

void MIDIMultiTrack::AssignEventsToTracks ( unsigned int  trk_num = 0)
inline

The same as previous, but argument is the track number in the multitrack object himself.

◆ InsertTrack() [1/2]

bool MIDIMultiTrack::InsertTrack ( int  trk_num = -1)

Inserts a new empty track at position trk_num (trk_num must be in the range 0 ... GetNumTracks() - 1).

If trk_num == -1 appends the track at the end.

Returns
true if the track was effectively inserted.
Warning
if you are using the MIDIMultiTrack into a MIDISequencer class don't call this directly but the corresponding MIDISequencer method (which adjust the MIDISequencer internal values also).

◆ InsertTrack() [2/2]

bool MIDIMultiTrack::InsertTrack ( const MIDITrack trk,
int  trk_num = -1 
)

Inserts a copy of the given track at position trk_num (trk_num must be in the range 0 ... GetNumTracks() - 1).

If trk_num == -1 appends the track at the end.

Returns
true if the track was effectively inserted.
Warning
if you are using the MIDIMultiTrack into a MIDISequencer class don't call this directly but the corresponding MIDISequencer method (which adjust the MIDISequencer internal values also).

◆ DeleteTrack()

bool MIDIMultiTrack::DeleteTrack ( int  trk_num = -1)

Deletes the track trk_num and its events.

(trk_num must be in the range 0 ... GetNumTracks() - 1). If trk_num == -1 deletes the last track.

Returns
true if the track was effectively deleted
See also
warning in the InsertTrack() method

◆ MoveTrack()

bool MIDIMultiTrack::MoveTrack ( int  from,
int  to 
)

Moves a track from the position from to the position to.

( from and to must be in the range 0 ... GetNumTracks() - 1).

Returns
true if the track was effectively moved
See also
warning in the InsertTrack() method

◆ SetTrack()

bool MIDIMultiTrack::SetTrack ( const MIDITrack trk,
unsigned int  trk_num 
)

Copies the track trk into the position trk_num of the MIDIMultiTrack.

Old content is overwritten, and trk_num must be in the range 0 ... GetNumTracks() - 1).

Returns
true if the track was effectively moved.
Warning
this can be used for fast copying of tracks (for example in undo/redo), however if you are using the multitrack into a MIDISequencer class don't forget to call MIDISequencer::UpdateStatus() which updates the attached MIDIMultiTrackIterator status.

◆ InsertEvent()

bool MIDIMultiTrack::InsertEvent ( unsigned int  trk_num,
const MIDITimedMessage msg,
tInsMode  _ins_mode = INSMODE_DEFAULT 
)

Inserts the event msg in the track trk_num.

See MIDITrack::InsertEvent() for details.

Returns
true if the event was effectively inserted

◆ InsertNote()

bool MIDIMultiTrack::InsertNote ( unsigned int  trk_num,
const MIDITimedMessage msg,
MIDIClockTime  len,
tInsMode  _ins_mode = INSMODE_DEFAULT 
)

Inserts a Note On and a Note Off event into the track trk_num. See MIDITrack::InsertNote() for details.

◆ DeleteEvent()

bool MIDIMultiTrack::DeleteEvent ( unsigned int  trk_num,
const MIDITimedMessage msg 
)

Deletes the event msg from the track trk_num. See MIDITrack::DeleteEvent() for details.

◆ DeleteNote()

bool MIDIMultiTrack::DeleteNote ( unsigned int  trk_num,
const MIDITimedMessage msg 
)

Deletes the note msg (msg must be a Note On) from the track _trk_num. See MIDITrack::DeleteNote() for details.

Member Data Documentation

◆ clks_per_beat

unsigned int MIDIMultiTrack::clks_per_beat
protected

The common clock per beat timing parameter for all tracks (this is the number of MIDI ticks for a quarter note).


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