00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _JDKMIDI_SEQUENCER_H
00025 #define _JDKMIDI_SEQUENCER_H
00026
00027 #include "jdkmidi/track.h"
00028 #include "jdkmidi/multitrack.h"
00029 #include "jdkmidi/tempo.h"
00030 #include "jdkmidi/matrix.h"
00031 #include "jdkmidi/process.h"
00032
00033 namespace jdkmidi
00034 {
00035
00036 class MIDISequencerGUIEvent;
00037 class MIDISequencerGUIEventNotifier;
00038 class MIDISequencerTrackState;
00039 class MIDISequencer;
00040
00041 class MIDISequencerGUIEvent
00042 {
00043 public:
00044 MIDISequencerGUIEvent()
00045 {
00046 bits=0;
00047 }
00048
00049 MIDISequencerGUIEvent( unsigned long bits_ )
00050 : bits(bits_)
00051 {
00052 }
00053
00054 MIDISequencerGUIEvent( const MIDISequencerGUIEvent &e )
00055 : bits(e.bits)
00056 {
00057 }
00058
00059 MIDISequencerGUIEvent( int group, int subgroup, int item=0 )
00060 {
00061 bits = ((group&0xff)<<24)
00062 | ((subgroup&0xfff)<<12)
00063 | ((item&0xfff)<<0);
00064 }
00065
00066 operator unsigned long () const
00067 {
00068 return bits;
00069 }
00070
00071 void SetEvent( int group, int subgroup = 0, int item = 0 )
00072 {
00073 bits = ((group&0xff)<<24)
00074 | ((subgroup&0xfff)<<12)
00075 | ((item&0xfff)<<0);
00076 }
00077
00078 int GetEventGroup() const
00079 {
00080 return (int)((bits>>24)&0xff);
00081 }
00082
00083 int GetEventSubGroup() const
00084 {
00085 return (int)((bits>>12)&0xfff);
00086 }
00087
00088 int GetEventItem() const
00089 {
00090 return (int)((bits>>0)&0xfff);
00091 }
00092
00093
00094 enum
00095 {
00096 GROUP_ALL = 0,
00097 GROUP_CONDUCTOR,
00098 GROUP_TRANSPORT,
00099 GROUP_TRACK
00100 };
00101
00102
00103 enum
00104 {
00105 GROUP_CONDUCTOR_ALL = 0,
00106 GROUP_CONDUCTOR_TEMPO,
00107 GROUP_CONDUCTOR_TIMESIG
00108 };
00109
00110
00111 enum
00112 {
00113 GROUP_TRANSPORT_ALL = 0,
00114 GROUP_TRANSPORT_MODE,
00115 GROUP_TRANSPORT_MEASURE,
00116 GROUP_TRANSPORT_BEAT,
00117 GROUP_TRANSPORT_ENDOFSONG
00118 };
00119
00120
00121 enum
00122 {
00123 GROUP_TRACK_ALL = 0,
00124 GROUP_TRACK_NAME,
00125 GROUP_TRACK_PG,
00126 GROUP_TRACK_NOTE,
00127 GROUP_TRACK_VOLUME
00128 };
00129
00130 private:
00131 unsigned long bits;
00132 };
00133
00134
00135 class MIDISequencerGUIEventNotifier
00136 {
00137 public:
00138 MIDISequencerGUIEventNotifier();
00139
00140 virtual ~MIDISequencerGUIEventNotifier();
00141
00142 virtual void Notify( const MIDISequencer *seq, MIDISequencerGUIEvent e ) = 0;
00143 virtual bool GetEnable() const = 0;
00144 virtual void SetEnable( bool f ) = 0;
00145 };
00146
00147
00148 class MIDISequencerGUIEventNotifierText :
00149 public MIDISequencerGUIEventNotifier
00150 {
00151 public:
00152 MIDISequencerGUIEventNotifierText(FILE *f);
00153
00154 virtual ~MIDISequencerGUIEventNotifierText();
00155
00156 virtual void Notify( const MIDISequencer *seq, MIDISequencerGUIEvent e );
00157 virtual bool GetEnable() const;
00158 virtual void SetEnable( bool f );
00159
00160 private:
00161
00162 FILE *f;
00163 bool en;
00164 };
00165
00166 class MIDISequencerTrackNotifier : public MIDIProcessor
00167 {
00168 public:
00169 MIDISequencerTrackNotifier(
00170 MIDISequencer *seq_,
00171 int trk,
00172 MIDISequencerGUIEventNotifier *n
00173 );
00174
00175 virtual ~MIDISequencerTrackNotifier();
00176
00177 void SetNotifier(
00178 MIDISequencer *seq_,
00179 int trk,
00180 MIDISequencerGUIEventNotifier *n
00181 )
00182 {
00183 seq = seq_;
00184 track_num = trk;
00185 notifier=n;
00186 }
00187
00188
00189 void Notify( int item );
00190 void NotifyConductor( int item );
00191
00192 private:
00193 MIDISequencer *seq;
00194 int track_num;
00195 MIDISequencerGUIEventNotifier *notifier;
00196 };
00197
00198 class MIDISequencerTrackProcessor : public MIDIProcessor
00199 {
00200 public:
00201 MIDISequencerTrackProcessor();
00202 virtual ~MIDISequencerTrackProcessor();
00203
00204 virtual void Reset();
00205 virtual bool Process( MIDITimedBigMessage *msg );
00206
00207 bool mute;
00208 bool solo;
00209 int velocity_scale;
00210 int rechannel;
00211 int transpose;
00212
00213 MIDIProcessor *extra_proc;
00214 };
00215
00216 class MIDISequencerTrackState : public MIDISequencerTrackNotifier
00217 {
00218 public:
00219
00220 MIDISequencerTrackState(
00221 MIDISequencer *seq_,
00222 int trk,
00223 MIDISequencerGUIEventNotifier *n
00224 );
00225 virtual ~MIDISequencerTrackState();
00226
00227 virtual void GoToZero();
00228 virtual void Reset();
00229 virtual bool Process( MIDITimedBigMessage *msg );
00230
00231 float tempobpm;
00232 int pg;
00233 int volume;
00234 int timesig_numerator;
00235 int timesig_denominator;
00236 int bender_value;
00237 char track_name[256];
00238 bool got_good_track_name;
00239
00240 bool notes_are_on;
00241 MIDIMatrix note_matrix;
00242
00243
00244 };
00245
00246
00247 class MIDISequencerState
00248 {
00249 public:
00250 MIDISequencerState( MIDISequencer *s,
00251 MIDIMultiTrack *multitrack_,
00252 MIDISequencerGUIEventNotifier *n );
00253
00254 MIDISequencerState( const MIDISequencerState &s );
00255 ~MIDISequencerState();
00256
00257 const MIDISequencerState & operator = ( const MIDISequencerState &s );
00258
00259 MIDISequencerGUIEventNotifier *notifier;
00260 MIDIMultiTrack *multitrack;
00261 int num_tracks;
00262
00263 MIDISequencerTrackState *track_state[64];
00264 MIDIMultiTrackIterator iterator;
00265 MIDIClockTime cur_clock;
00266 float cur_time_ms;
00267 int cur_beat;
00268 int cur_measure;
00269 MIDIClockTime next_beat_time;
00270 };
00271
00272 class MIDISequencer
00273 {
00274 public:
00275
00276 MIDISequencer(
00277 MIDIMultiTrack *m,
00278 MIDISequencerGUIEventNotifier *n=0
00279 );
00280
00281 virtual ~MIDISequencer();
00282
00283 void ResetTrack( int trk );
00284 void ResetAllTracks();
00285
00286 MIDIClockTime GetCurrentMIDIClockTime() const;
00287 double GetCurrentTimeInMs() const;
00288 int GetCurrentBeat() const;
00289 int GetCurrentMeasure() const;
00290
00291 double GetCurrentTempoScale() const;
00292 double GetCurrentTempo() const;
00293
00294 MIDISequencerState *GetState();
00295 const MIDISequencerState *GetState() const;
00296
00297 void SetState( MIDISequencerState * );
00298
00299 MIDISequencerTrackState * GetTrackState( int trk );
00300 const MIDISequencerTrackState * GetTrackState( int trk ) const;
00301
00302 MIDISequencerTrackProcessor * GetTrackProcessor( int trk );
00303 const MIDISequencerTrackProcessor * GetTrackProcessor( int trk ) const;
00304
00305 int GetNumTracks() const { return state.num_tracks; }
00306
00307 bool GetSoloMode() const;
00308
00309 void SetCurrentTempoScale( float scale );
00310 void SetSoloMode( bool m, int trk=-1 );
00311
00312 void GoToZero();
00313 bool GoToTime( MIDIClockTime time_clk );
00314 bool GoToTimeMs( float time_ms );
00315 bool GoToMeasure( int measure, int beat=0 );
00316
00317 bool GetNextEventTimeMs( float *t );
00318 bool GetNextEventTime( MIDIClockTime *t );
00319 bool GetNextEvent( int *tracknum, MIDITimedBigMessage *msg );
00320
00321 void ScanEventsAtThisTime();
00322
00323 protected:
00324
00325 MIDITimedBigMessage beat_marker_msg;
00326
00327 bool solo_mode;
00328 int tempo_scale;
00329
00330 int num_tracks;
00331 MIDISequencerTrackProcessor *track_processors[64];
00332
00333 MIDISequencerState state;
00334
00335 } ;
00336 }
00337
00338 #endif