00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef _JDKMIDI_MSG_H
00035 #define _JDKMIDI_MSG_H
00036
00037 #include "jdkmidi/midi.h"
00038 #include "jdkmidi/tempo.h"
00039 #include "jdkmidi/sysex.h"
00040
00041 namespace jdkmidi
00042 {
00043
00044 class MIDIMessage;
00045 class MIDIBigMessage;
00046
00047 class MIDITimedMessage;
00048 class MIDIDeltaTimedMessage;
00049
00050 class MIDITimedBigMessage;
00051 class MIDIDeltaTimedBigMessage;
00052
00053 class MIDIMessage
00054 {
00055 public:
00056
00057
00058
00059
00060
00061 MIDIMessage();
00062
00063 MIDIMessage( const MIDIMessage &m );
00064
00065 void Clear();
00066
00067 void Copy( const MIDIMessage & m );
00068
00069 char * MsgToText( char *txt ) const;
00070
00071
00072
00073
00074
00075 const MIDIMessage & operator = ( const MIDIMessage &m );
00076
00077
00078
00079
00080
00081 char GetLength() const;
00082
00083 unsigned char GetStatus() const { return (unsigned char)status; }
00084 unsigned char GetChannel() const { return (unsigned char)(status&0x0f); }
00085 unsigned char GetType() const { return (unsigned char)(status&0xf0); }
00086
00087 unsigned char GetMetaType() const { return byte1; }
00088
00089 unsigned char GetByte1() const { return byte1; }
00090 unsigned char GetByte2() const { return byte2; }
00091 unsigned char GetByte3() const { return byte3; }
00092
00093 unsigned char GetNote() const { return byte1; }
00094 unsigned char GetVelocity() const { return byte2; }
00095 unsigned char GetPGValue() const { return byte1; }
00096 unsigned char GetController() const { return byte1; }
00097 unsigned char GetControllerValue() const { return byte2; }
00098
00099 short GetBenderValue() const;
00100
00101 unsigned short GetMetaValue() const;
00102 unsigned char GetTimeSigNumerator() const;
00103 unsigned char GetTimeSigDenominator() const;
00104 signed char GetKeySigSharpFlats() const;
00105 unsigned char GetKeySigMajorMinor() const;
00106
00107 bool IsChannelMsg() const;
00108
00109 bool IsNoteOn() const;
00110
00111
00112 bool IsNoteOff() const;
00113
00114 bool IsPolyPressure() const;
00115
00116 bool IsControlChange() const;
00117
00118 bool IsProgramChange() const;
00119
00120 bool IsChannelPressure() const;
00121
00122 bool IsPitchBend() const;
00123
00124 bool IsSystemMessage() const;
00125
00126 bool IsSysEx() const;
00127
00128 short GetSysExNum() const;
00129
00130 bool IsMTC() const;
00131
00132 bool IsSongPosition() const;
00133
00134 bool IsSongSelect() const;
00135
00136 bool IsTuneRequest() const;
00137
00138 bool IsMetaEvent() const;
00139
00140 bool IsTextEvent() const;
00141
00142 bool IsAllNotesOff() const;
00143
00144
00145 bool IsNoOp() const;
00146
00147
00148 bool IsTempo() const;
00149
00150
00151 bool IsDataEnd() const;
00152
00153
00154 bool IsTimeSig() const;
00155
00156 bool IsKeySig() const;
00157
00158 bool IsBeatMarker() const;
00159
00160
00161
00162
00163
00164 unsigned short GetTempo32() const;
00165
00166 unsigned short GetLoopNumber() const;
00167
00168
00169
00170
00171
00172 void SetStatus( unsigned char s ) { status=s; }
00173 void SetChannel( unsigned char s ) {status=(unsigned char)((status&0xf0)|s);}
00174 void SetType( unsigned char s ) {status=(unsigned char)((status&0x0f)|s);}
00175
00176 void SetByte1( unsigned char b ) { byte1=b; }
00177 void SetByte2( unsigned char b ) { byte2=b; }
00178 void SetByte3( unsigned char b ) { byte3=b; }
00179
00180 void SetNote( unsigned char n ) { byte1=n; }
00181 void SetVelocity(unsigned char v) { byte2=v; }
00182 void SetPGValue(unsigned char v) { byte1=v; }
00183 void SetController(unsigned char c) { byte1=c; }
00184 void SetControllerValue(unsigned char v ) { byte2=v; }
00185
00186 void SetBenderValue( short v);
00187
00188 void SetMetaType( unsigned char t ) ;
00189
00190 void SetMetaValue( unsigned short v );
00191
00192 void SetNoteOn( unsigned char chan, unsigned char note, unsigned char vel );
00193
00194 void SetNoteOff( unsigned char chan, unsigned char note, unsigned char vel );
00195
00196 void SetPolyPressure( unsigned char chan, unsigned char note, unsigned char pres );
00197
00198 void SetControlChange( unsigned char chan, unsigned char ctrl, unsigned char val );
00199
00200 void SetProgramChange( unsigned char chan, unsigned char val );
00201
00202 void SetChannelPressure( unsigned char chan, unsigned char val );
00203
00204 void SetPitchBend( unsigned char chan, short val );
00205
00206 void SetPitchBend( unsigned char chan, unsigned char low, unsigned char high );
00207
00208 void SetSysEx();
00209
00210 void SetMTC( unsigned char field, unsigned char v );
00211
00212 void SetSongPosition( short pos );
00213
00214 void SetSongSelect(unsigned char sng);
00215
00216 void SetTuneRequest();
00217
00218 void SetMetaEvent( unsigned char type, unsigned char v1, unsigned char v2 );
00219
00220 void SetMetaEvent( unsigned char type, unsigned short v );
00221
00222 void SetAllNotesOff( unsigned char chan, unsigned char type=C_ALL_NOTES_OFF );
00223
00224 void SetLocal( unsigned char chan, unsigned char v );
00225
00226 void SetNoOp();
00227
00228 void SetTempo32( unsigned short tempo_times_32 );
00229
00230 void SetText( unsigned short text_num, unsigned char type=META_GENERIC_TEXT );
00231
00232 void SetDataEnd();
00233
00234 void SetTimeSig( unsigned char numerator, unsigned char denominator );
00235
00236 void SetKeySig( signed char sharp_flats, unsigned char major_minor );
00237
00238 void SetBeatMarker();
00239
00240 protected:
00241
00242 static char * chan_msg_name[16];
00243 static char * sys_msg_name[16];
00244
00245 unsigned char status;
00246 unsigned char byte1;
00247 unsigned char byte2;
00248 unsigned char byte3;
00249
00250
00251 };
00252
00254
00255 class MIDIBigMessage : public MIDIMessage
00256 {
00257 public:
00258
00259
00260
00261
00262 MIDIBigMessage();
00263
00264 MIDIBigMessage( const MIDIBigMessage &m );
00265
00266 MIDIBigMessage( const MIDIMessage &m );
00267
00268 void Clear();
00269
00270 void Copy( const MIDIBigMessage &m );
00271
00272 void Copy( const MIDIMessage &m );
00273
00274
00275
00276
00277
00278 ~MIDIBigMessage();
00279
00280
00281
00282
00283
00284 const MIDIBigMessage &operator = ( const MIDIBigMessage &m );
00285
00286 const MIDIBigMessage &operator = ( const MIDIMessage &m );
00287
00288
00289
00290
00291
00292 MIDISystemExclusive *GetSysEx();
00293
00294 const MIDISystemExclusive *GetSysEx() const;
00295
00296
00297
00298
00299
00300 void CopySysEx( const MIDISystemExclusive *e );
00301
00302 void ClearSysEx();
00303
00304
00305 MIDISystemExclusive *sysex;
00306 };
00307
00309
00310 class MIDITimedMessage : public MIDIMessage
00311 {
00312 public:
00313
00314
00315
00316
00317
00318 MIDITimedMessage();
00319
00320 MIDITimedMessage( const MIDITimedMessage &m );
00321
00322 MIDITimedMessage( const MIDIMessage &m );
00323
00324 void Clear();
00325
00326 void Copy( const MIDITimedMessage &m );
00327
00328
00329
00330
00331
00332 const MIDITimedMessage &operator = ( const MIDITimedMessage & m );
00333
00334 const MIDITimedMessage &operator = ( const MIDIMessage & m );
00335
00336
00337
00338
00339
00340 MIDIClockTime GetTime() const;
00341
00342
00343
00344
00345
00346 void SetTime( MIDIClockTime t );
00347
00348
00349
00350
00351
00352
00353 static int CompareEvents(
00354 const MIDITimedMessage &a,
00355 const MIDITimedMessage &b
00356 );
00357
00358 protected:
00359
00360
00361 MIDIClockTime time;
00362 };
00363
00365
00366 class MIDIDeltaTimedMessage : public MIDIMessage
00367 {
00368 public:
00369
00370
00371
00372
00373
00374 MIDIDeltaTimedMessage();
00375
00376 MIDIDeltaTimedMessage( const MIDIDeltaTimedMessage &m );
00377
00378 MIDIDeltaTimedMessage( const MIDIMessage &m );
00379
00380 void Clear();
00381
00382 void Copy( const MIDIDeltaTimedMessage &m );
00383
00384
00385
00386
00387
00388 const MIDIDeltaTimedMessage &operator = ( const MIDIDeltaTimedMessage &m );
00389
00390 const MIDIDeltaTimedMessage &operator = ( const MIDIMessage &m );
00391
00392
00393
00394
00395
00396 MIDIClockTime GetDeltaTime() const;
00397
00398
00399
00400
00401
00402 void SetDeltaTime( MIDIClockTime t );
00403
00404
00405 protected:
00406 MIDIClockTime dtime;
00407 };
00408
00410
00411 class MIDITimedBigMessage : public MIDIBigMessage
00412 {
00413 public:
00414
00415
00416
00417
00418
00419 MIDITimedBigMessage();
00420
00421 MIDITimedBigMessage( const MIDITimedBigMessage &m );
00422
00423 MIDITimedBigMessage( const MIDIBigMessage &m );
00424
00425 MIDITimedBigMessage( const MIDITimedMessage &m );
00426
00427 MIDITimedBigMessage( const MIDIMessage &m );
00428
00429 void Clear();
00430
00431 void Copy( const MIDITimedBigMessage &m );
00432
00433 void Copy( const MIDITimedMessage &m );
00434
00435
00436
00437
00438
00439 const MIDITimedBigMessage &operator = ( const MIDITimedBigMessage & m );
00440
00441 const MIDITimedBigMessage &operator = ( const MIDITimedMessage & m );
00442
00443 const MIDITimedBigMessage &operator = ( const MIDIMessage & m );
00444
00445
00446
00447
00448
00449 MIDIClockTime GetTime() const;
00450
00451
00452
00453
00454
00455 void SetTime( MIDIClockTime t );
00456
00457
00458
00459
00460
00461 static int CompareEvents(
00462 const MIDITimedBigMessage &a,
00463 const MIDITimedBigMessage &b
00464 );
00465
00466 protected:
00467 MIDIClockTime time;
00468 };
00469
00471
00472 class MIDIDeltaTimedBigMessage : public MIDIBigMessage
00473 {
00474 public:
00475
00476
00477
00478
00479 MIDIDeltaTimedBigMessage();
00480
00481 MIDIDeltaTimedBigMessage( const MIDIDeltaTimedBigMessage &m );
00482
00483 MIDIDeltaTimedBigMessage( const MIDIBigMessage &m );
00484
00485 MIDIDeltaTimedBigMessage( const MIDIMessage &m );
00486
00487 MIDIDeltaTimedBigMessage( const MIDIDeltaTimedMessage &m );
00488
00489 void Clear();
00490
00491 void Copy( const MIDIDeltaTimedBigMessage &m );
00492
00493 void Copy( const MIDIDeltaTimedMessage &m );
00494
00495
00496
00497
00498
00499 const MIDIDeltaTimedBigMessage &operator = ( const MIDIDeltaTimedBigMessage &m );
00500
00501 const MIDIDeltaTimedBigMessage &operator = ( const MIDIDeltaTimedMessage &m );
00502
00503 const MIDIDeltaTimedBigMessage &operator = ( const MIDIMessage &m );
00504
00505
00506
00507
00508
00509 MIDIClockTime GetDeltaTime() const;
00510
00511
00512
00513
00514
00515 void SetDeltaTime( MIDIClockTime t );
00516
00517
00518 protected:
00519 MIDIClockTime dtime;
00520 };
00521
00522 }
00523
00524
00525 #endif
00526