31#ifndef _NICMIDI_MULTITRACK_H
32#define _NICMIDI_MULTITRACK_H
39class MIDIEditMultiTrack;
70 void Reset(
unsigned int num_tracks = 0);
83 {
return tracks[trk_num]; }
97 {
return (trk_num < tracks.size()); }
165 int tr_end, MIDIEditMultiTrack* edit);
171 void EditInsert(
MIDIClockTime start,
int tr_start,
int times, MIDIEditMultiTrack* edit);
174 void EditReplace(
MIDIClockTime start,
int tr_start,
int times,
175 bool sysex, MIDIEditMultiTrack* edit);
181 std::vector<MIDITrack*> tracks;
204 void SetNumTracks(
unsigned int n);
209 int FindTrackOfFirstEvent();
211 unsigned int num_tracks;
214 std::vector<int> next_event_number;
215 std::vector<MIDIClockTime> next_event_time;
216 std::vector<bool> enabled;
217 bool time_shift_mode;
310 virtual ~MIDIEditMultiTrack() {}
312 void SetStartTrack(
int trk) { start_track = trk; }
313 void SetEndTrack(
int trk) { end_track = trk; }
314 int GetStartTrack()
const {
return start_track; }
315 int GetEndTrack()
const {
return end_track; }
319 int tr_end, MIDIEditMultiTrack* edit) {}
322 void EditInsert(
MIDIClockTime start,
int tr_start,
int times,
323 bool sysex, MIDIEditMultiTrack* edit) {}
324 void EditReplace(
MIDIClockTime start,
int tr_start,
int times,
325 bool sysex, MIDIEditMultiTrack* edit) {}
Holds an array of pointers to MIDITrack objects to be played simultaneously.
Definition: multitrack.h:50
bool IsValidTrackNumber(unsigned int trk_num) const
Returns true if trk_num is in thee range 0 ... GetNumTracks() - 1.
Definition: multitrack.h:96
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 ....
void AssignEventsToTracks(const MIDITrack *src)
This function is useful in dealing with MIDI format 0 files (with all events in an unique track).
const MIDITrack * GetTrack(unsigned int trk_num) const
Returns the pointer to the track.
Definition: multitrack.h:82
int GetTrackNum(MIDITrack *trk) const
Returns the number of the pointed track, -1 if the track is not in the multitrack.
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_pe...
MIDITrack * GetTrack(unsigned int trk_num)
Returns the pointer to the track.
Definition: multitrack.h:79
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 detail...
unsigned int GetClksPerBeat() const
Returns the MIDI clocks per beat of all tracks (i.e. the number of MIDI ticks in a quarter note).
Definition: multitrack.h:76
unsigned int GetNumTracks() const
Returns the number of allocated tracks.
Definition: multitrack.h:87
MIDIMultiTrack(const MIDIMultiTrack &mlt)
The copy constructor.
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 even...
bool DeleteEvent(unsigned int trk_num, const MIDITimedMessage &msg)
Deletes the event msg from the track trk_num. See MIDITrack::DeleteEvent() for details.
unsigned int GetNumTracksWithEvents() const
Returns the number of tracks with events (other than EOT).
MIDIClockTime GetEndTime() const
Returns the end time of the longest track.
bool InsertEvent(unsigned int trk_num, const MIDITimedMessage &msg, tInsMode _ins_mode=INSMODE_DEFAULT)
Inserts the event msg in the track trk_num.
void ClearTracks(bool mantain_end=false)
Clears tracks events but mantains the tracks and their parameters.
bool MoveTrack(int from, int to)
Moves a track from the position from to the position to.
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)...
virtual ~MIDIMultiTrack()
The destructor: The MIDIMultiTrack owns its tracks, so they are destroyed by this.
unsigned int clks_per_beat
The common clock per beat timing parameter for all tracks (this is the number of MIDI ticks for a qua...
Definition: multitrack.h:178
unsigned int GetNumEvents() const
Returns the total number of MIDI events in the multitrack (for every track there is at least the EOT)...
void AssignEventsToTracks(unsigned int trk_num=0)
The same as previous, but argument is the track number in the multitrack object himself.
Definition: multitrack.h:121
bool SetTrack(const MIDITrack *trk, unsigned int trk_num)
Copies the track trk into the position trk_num of the MIDIMultiTrack.
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...
bool DeleteTrack(int trk_num=-1)
Deletes the track trk_num and its events.
bool IsEmpty() const
Returns true if there are no events in the tracks and the end time is 0.
Definition: multitrack.h:99
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...
void ShrinkEndTime()
Sets the time of the data end event equal to the time of the last event of every track.
bool SetEndTime(MIDIClockTime end_time)
Sets the time of the data end event to end_time.
MIDIMultiTrack & operator=(const MIDIMultiTrack &mlt)
The assignment operator.
A forward iterator for moving along a MIDIMultiTrack.
Definition: multitrack.h:230
MIDIMultiTrackIterator(MIDIMultiTrack *mlt)
The constructor creates the object and attaches it to the given MIDIMultiTrack.
void Reset()
Syncs num_tracks with the multitrack and resets time to 0. Does not reset time shift mode.
bool GetTimeShiftMode() const
Returns true if time shifting is on.
Definition: multitrack.h:240
MIDIClockTime GetCurrentTime() const
Gets the current time of the iterator.
Definition: multitrack.h:238
bool GetNextEventOnTrack(int track, MIDITimedMessage **msg)
Gets the next event in the multitrack on track track and updates the iterator state.
bool GetNextEventTime(MIDIClockTime *t) const
Gets the time of the next event in the multitrack (it can be different from current time if at curren...
bool GoToTime(MIDIClockTime time)
Goes to the given time, which becomes the current time, and sets then the current event as the first ...
const MIDIMultiTrackIteratorState & GetState() const
Gets the current MIDIMultiTrackIteratorState.
Definition: multitrack.h:248
bool GetNextEvent(int *track, MIDITimedMessage **msg)
Gets the next event in the multitrack in temporal order and updates the iterator state.
void SetEnable(unsigned int trk_num, bool f)
Enable or disable a track.
void SetTimeShiftMode(bool f)
Turns time shifting on and off.
Definition: multitrack.h:252
MIDIMultiTrackIteratorState & GetState()
Gets the current MIDIMultiTrackIteratorState.
Definition: multitrack.h:244
void SetState(const MIDIMultiTrackIteratorState &s)
Sets the given MIDIMultiTrackIteratorState as current state.
Definition: multitrack.h:259
Used by the MIDIMultiTrackIterator to keep track of the current state of the iterator.
Definition: multitrack.h:192
The MIDITimedMessage class inherits from the MIDIMessage and represents a message associated with a s...
Definition: msg.h:382
Manages a std::vector of MIDITimedMessage objects storing MIDI events, with methods for editing them.
Definition: track.h:86
unsigned long MIDIClockTime
The type of a variable which can hold a time in MIDI ticks.
Definition: midi.h:40
tInsMode
Defines the default behavior of the methods MIDITrack::InsertEvent() and MIDITrack::InsertNote() when...
Definition: track.h:54
const unsigned int DEFAULT_CLKS_PER_BEAT
The default clocks per beat parameter when initializing a MIDIMultiTrack.
Definition: midi.h:51
@ INSMODE_DEFAULT
follow the default behaviour (only used as default argument in methods MIDITrack::InsertEvent() and M...
Definition: track.h:55
Contains the definition of the classes MIDITrack and MIDITrackIterator.