00001 /* 00002 * libjdkmidi-2004 C++ Class Library for MIDI 00003 * 00004 * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. 00005 * www.jdkoftinoff.com 00006 * jeffk@jdkoftinoff.com 00007 * 00008 * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** 00009 * 00010 * This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License 00021 * along with this program; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 */ 00024 /* 00025 ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. 00026 ** 00027 ** All rights reserved. 00028 ** 00029 ** No one may duplicate this source code in any form for any reason 00030 ** without the written permission given by J.D. Koftinoff Software, Ltd. 00031 ** 00032 */ 00033 00034 #ifndef _JDKMIDI_MULTITRACK_H 00035 #define _JDKMIDI_MULTITRACK_H 00036 00037 #include "jdkmidi/track.h" 00038 00039 namespace jdkmidi 00040 { 00041 00042 class MIDIMultiTrack; 00043 class MIDIMultiTrackIteratorState; 00044 class MIDIMultiTrackIterator; 00045 00046 class MIDIMultiTrack 00047 { 00048 public: 00049 00050 MIDIMultiTrack( int max_num_tracks_=64, bool deletable_=true ); 00051 virtual ~MIDIMultiTrack(); 00052 00053 void SetTrack( int trk, MIDITrack *t ); 00054 MIDITrack *GetTrack( int trk ); 00055 const MIDITrack *GetTrack( int trk ) const; 00056 int GetNumTracks() { return num_tracks; } 00057 00058 00059 void Clear(); 00060 00061 int GetClksPerBeat() 00062 { 00063 return clks_per_beat; 00064 } 00065 00066 void SetClksPerBeat( int c ) 00067 { 00068 clks_per_beat = c; 00069 } 00070 00071 protected: 00072 00073 MIDITrack **tracks; 00074 const int num_tracks; 00075 bool deletable; 00076 00077 int clks_per_beat; 00078 00079 private: 00080 00081 }; 00082 00083 class MIDIMultiTrackIteratorState 00084 { 00085 public: 00086 00087 MIDIMultiTrackIteratorState( int num_tracks_=64); 00088 MIDIMultiTrackIteratorState( const MIDIMultiTrackIteratorState &m ); 00089 virtual ~MIDIMultiTrackIteratorState(); 00090 00091 const MIDIMultiTrackIteratorState & operator = ( const MIDIMultiTrackIteratorState &m ); 00092 00093 int GetNumTracks() { return num_tracks; } 00094 int GetCurEventTrack() { return cur_event_track; } 00095 MIDIClockTime GetCurrentTime() { return cur_time; } 00096 00097 void Reset(); 00098 int FindTrackOfFirstEvent(); 00099 00100 MIDIClockTime cur_time; 00101 int cur_event_track; 00102 int num_tracks; 00103 int *next_event_number; 00104 MIDIClockTime *next_event_time; 00105 }; 00106 00107 class MIDIMultiTrackIterator 00108 { 00109 public: 00110 00111 MIDIMultiTrackIterator( MIDIMultiTrack *mlt ); 00112 virtual ~MIDIMultiTrackIterator(); 00113 00114 00115 void GoToTime( MIDIClockTime time ); 00116 00117 bool GetCurEventTime( MIDIClockTime *t); 00118 bool GetCurEvent( int *track, MIDITimedBigMessage **msg ); 00119 bool GoToNextEvent(); 00120 00121 bool GoToNextEventOnTrack( int track ); 00122 00123 const MIDIMultiTrackIteratorState &GetState() const 00124 { 00125 return state; 00126 } 00127 00128 MIDIMultiTrackIteratorState &GetState() 00129 { 00130 return state; 00131 } 00132 00133 void SetState( const MIDIMultiTrackIteratorState &s ) 00134 { 00135 state = s; 00136 } 00137 00138 MIDIMultiTrack * GetMultiTrack() { return multitrack; } 00139 const MIDIMultiTrack * GetMultiTrack() const { return multitrack; } 00140 00141 protected: 00142 00143 MIDIMultiTrack *multitrack; 00144 MIDIMultiTrackIteratorState state; 00145 }; 00146 00147 } 00148 00149 #endif 00150 00151