jdkmidi class library documentation

Copyright © 2004 J.D. Koftinoff Software, Ltd.

Released under the GNU General Public License (GPL)




Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

src/jdkmidi_msg.cpp

Go to the documentation of this file.
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 #include "jdkmidi/world.h"
00035 
00036 #include "jdkmidi/sysex.h"
00037 #include "jdkmidi/msg.h"
00038 
00039 namespace jdkmidi
00040 {
00041   
00042   
00043   
00044   char *  MIDIMessage::chan_msg_name[16] = 
00045   {
00046     "ERROR 00    ",   // 0x00
00047     "ERROR 10    ",   // 0x10
00048     "ERROR 20    ",   // 0x20
00049     "ERROR 30    ",       // 0x30
00050     "ERROR 40    ",       // 0x40
00051     "ERROR 50    ",       // 0x50
00052     "ERROR 60    ",       // 0x60
00053     "ERROR 70    ",       // 0x70
00054     "NOTE OFF    ",   // 0x80
00055     "NOTE ON     ",   // 0x90
00056     "POLY PRES.  ",   // 0xa0
00057     "CTRL CHANGE ",   // 0xb0
00058     "PG CHANGE   ",   // 0xc0
00059     "CHAN PRES.  ",   // 0xd0
00060     "BENDER      ",   // 0xe0
00061     "SYSTEM      "    // 0xf0
00062   }; 
00063   
00064   char *  MIDIMessage::sys_msg_name[16] = 
00065   {
00066     "SYSEX       ",   // 0xf0
00067     "MTC         ",   // 0xf1
00068     "SONG POS    ",   // 0xf2
00069     "SONG SELECT ",   // 0xf3
00070     "ERR - F4    ",   // 0xf4
00071     "ERR - F5    ",   // 0xf5
00072     "TUNE REQ.   ",   // 0xf6
00073     "SYSEX END   ",   // 0xf7
00074     "CLOCK       ",   // 0xf8
00075     "MEASURE END ",   // 0xf9
00076     "START       ",   // 0xfa
00077     "CONTINUE    ",   // 0xfb
00078     "STOP        ",         // 0xfc
00079     "ERR - FD    ",         // 0xfd
00080     "SENSE       ",   // 0xfe
00081     "META-EVENT  "    // 0xff
00082   }; 
00083   
00084   
00085   char *  MIDIMessage::MsgToText( char *txt ) const 
00086   {
00087     char buf[64];
00088     int len=GetLength();
00089     
00090     *txt=0;
00091     
00092     if( IsAllNotesOff() )
00093     {
00094       sprintf( buf, "Ch %2d  All Notes Off  (ctrl=%3d)", (int)GetChannel()+1, (int)byte1 );
00095       
00096       strcat( txt, buf );
00097     }
00098     else
00099     {
00100       int type=(status&0xf0)>>4;
00101       
00102       //
00103       // if it is a note on with vel=0, call it a NOTE OFF
00104       //
00105       
00106       if( type==9 && byte2==0 )
00107         type=8;
00108       
00109       if( type!=0xf )
00110       {
00111         sprintf( buf, "Ch %2d  ", (int)GetChannel()+1 );
00112         strcat( txt, buf  );
00113       }
00114       
00115       
00116       strcat( txt, chan_msg_name[type] );
00117       
00118       if( status>=0xf0 )
00119       {
00120         strcat( txt, sys_msg_name[status-0xf0] );
00121         
00122         if( len>1 )
00123         {
00124           sprintf( buf,"%02x", (int)byte1 );
00125           strcat( txt, buf );
00126         }
00127         
00128         if( len>2 )
00129         {     
00130           sprintf( buf,",%02x", (int)byte2 );
00131           strcat( txt, buf );
00132         }
00133         
00134         if( len>3 )
00135         {       
00136           sprintf( buf,",%02x", (int)byte3 );       
00137           strcat( txt, buf );
00138         }
00139         
00140       }
00141       else
00142       {
00143         char *endtxt = txt+strlen(txt);
00144         
00145         switch( status&0xf0 )
00146         {
00147         case NOTE_ON:
00148           if( byte2==0 )
00149             sprintf( endtxt, "Note %3d", (int)byte1 );
00150           else
00151             sprintf( endtxt, "Note %3d  Vel  %3d  ", (int)byte1, (int)byte2 );
00152           break;
00153         case NOTE_OFF:
00154           sprintf( endtxt, "Note %3d  Vel  %3d  ", (int)byte1, (int)byte2 );
00155           break;
00156         case POLY_PRESSURE:
00157           sprintf( endtxt, "Note %3d  Pres %3d  ", (int)byte1, (int)byte2 );
00158           break;
00159         case CONTROL_CHANGE:
00160           sprintf( endtxt, "Ctrl %3d  Val  %3d  ", (int)byte1, (int)byte2 );
00161           break;
00162         case PROGRAM_CHANGE:
00163           sprintf( endtxt, "PG   %3d  ", (int)byte1 );
00164           break;
00165         case CHANNEL_PRESSURE:
00166           sprintf( endtxt, "Pres %3d  ", (int)byte1 );
00167           break;
00168         case PITCH_BEND:
00169           sprintf( endtxt, "Val %5d", (int)GetBenderValue() );
00170           break;
00171         }
00172       }
00173     }
00174     
00175     //
00176     // pad the rest with spaces
00177     //
00178     
00179     {
00180       int len=strlen(txt);
00181       char *p=txt+len;
00182       
00183       while( len<45 )
00184       {
00185         *p++=' ';
00186         ++len;
00187       }
00188       *p++='\0';
00189     }
00190     
00191     return txt;
00192   } 
00193   
00194   
00195   MIDIMessage::MIDIMessage() 
00196   { 
00197     status=0;
00198     byte1=0; 
00199     byte2=0;
00200     byte3=0;  
00201   } 
00202   
00203   
00204   MIDIMessage::MIDIMessage( const MIDIMessage &m ) 
00205   {
00206     status=m.status;
00207     byte1=m.byte1;
00208     byte2=m.byte2;
00209     byte3=m.byte3;
00210   } 
00211   
00212   
00213   void  MIDIMessage::Clear() 
00214   {
00215     status=0;
00216     byte1=0;
00217     byte2=0;
00218     byte3=0;
00219   } 
00220   
00221   
00222   void  MIDIMessage::Copy( const MIDIMessage & m ) 
00223   {
00224     status=m.status;
00225     byte1=m.byte1;
00226     byte2=m.byte2;
00227     byte3=m.byte3;
00228   } 
00229   
00230   
00231   
00232 //
00233 // The equal operator
00234 //
00235   
00236   const MIDIMessage & MIDIMessage::operator = ( const MIDIMessage &m ) 
00237   {
00238     status=m.status;
00239     byte1=m.byte1;
00240     byte2=m.byte2;
00241     byte3=m.byte3;
00242     return *this;
00243   } 
00244   
00245   
00246   char  MIDIMessage::GetLength() const 
00247   {
00248     if( (status&0xf0)==0xf0 )
00249     {
00250       return GetSystemMessageLength( status );
00251     }
00252     else
00253     {
00254       return GetMessageLength( status );
00255     }
00256   } 
00257   
00258   
00259   
00260   short MIDIMessage::GetBenderValue() const 
00261   { 
00262     return (short)(((byte2<<7) | byte1)-8192);  
00263   } 
00264   
00265   
00266   unsigned short  MIDIMessage::GetMetaValue() const 
00267   { 
00268     return (unsigned short)((byte3<<8) | byte2);  
00269   } 
00270   
00271   unsigned char MIDIMessage::GetTimeSigNumerator() const 
00272   {
00273     return byte2; 
00274   } 
00275   
00276   
00277   unsigned char MIDIMessage::GetTimeSigDenominator() const 
00278   {
00279     return byte3;
00280   } 
00281   
00282   
00283   signed char MIDIMessage::GetKeySigSharpFlats() const
00284   {
00285     return (signed char)byte2;
00286   }
00287 
00288   unsigned char MIDIMessage::GetKeySigMajorMinor() const
00289   {
00290     return byte3;
00291   }
00292   
00293   
00294   bool  MIDIMessage::IsChannelMsg() const 
00295   {
00296     return (status>=0x80) && (status<0xf0);
00297   } 
00298   
00299   
00300   bool  MIDIMessage::IsNoteOn() const 
00301   {
00302     return ((status&0xf0)==NOTE_ON) && byte2;
00303   } 
00304   
00305   
00306   bool  MIDIMessage::IsNoteOff() const 
00307   {
00308     return ((status&0xf0)==NOTE_OFF) ||
00309       (((status&0xf0)==NOTE_ON) && byte2==0 );
00310   } 
00311   
00312   
00313   bool  MIDIMessage::IsPolyPressure() const 
00314   {
00315     return ((status&0xf0)==POLY_PRESSURE );
00316   } 
00317   
00318   
00319   bool  MIDIMessage::IsControlChange() const 
00320   {
00321     return ((status&0xf0)==CONTROL_CHANGE);
00322   } 
00323   
00324   
00325   bool  MIDIMessage::IsProgramChange() const 
00326   {
00327     return ((status&0xf0)==PROGRAM_CHANGE);
00328   } 
00329   
00330   
00331   bool  MIDIMessage::IsChannelPressure() const 
00332   {
00333     return ((status&0xf0)==CHANNEL_PRESSURE);
00334   } 
00335   
00336   
00337   bool  MIDIMessage::IsPitchBend() const 
00338   {
00339     return ((status&0xf0)==PITCH_BEND);
00340   } 
00341   
00342   
00343   bool  MIDIMessage::IsSystemMessage() const 
00344   {
00345     return (status&0xf0)==0xf0;
00346   } 
00347   
00348   
00349   bool  MIDIMessage::IsSysEx() const 
00350   {
00351     return (status==SYSEX_START);
00352   } 
00353   
00354   
00355   short MIDIMessage::GetSysExNum() const 
00356   {
00357     return (short)((byte3<<8) | byte2);
00358   } 
00359   
00360   
00361   bool  MIDIMessage::IsMTC() const 
00362   {
00363     return (status==MTC);
00364   } 
00365   
00366   
00367   bool  MIDIMessage::IsSongPosition() const 
00368   {
00369     return (status==SONG_POSITION);
00370   } 
00371   
00372   
00373   bool  MIDIMessage::IsSongSelect() const 
00374   {
00375     return (status==SONG_SELECT);
00376   } 
00377   
00378   
00379   bool  MIDIMessage::IsTuneRequest() const 
00380   {
00381     return (status==TUNE_REQUEST);
00382   } 
00383   
00384   
00385   bool  MIDIMessage::IsMetaEvent() const 
00386   {
00387     return (status==META_EVENT);
00388   } 
00389   
00390   
00391   bool  MIDIMessage::IsTextEvent() const 
00392   {
00393     return (status==META_EVENT) &&
00394       (byte1>=0x1 && byte1<=0xf);
00395   } 
00396   
00397   
00398   bool  MIDIMessage::IsAllNotesOff() const 
00399   {
00400     return ((status&0xf0)==CONTROL_CHANGE )
00401       && (byte1>=C_ALL_NOTES_OFF);
00402   } 
00403   
00404   
00405   bool  MIDIMessage::IsNoOp() const 
00406   {
00407     return (status==META_EVENT)
00408       && (byte1==META_NO_OPERATION);
00409   } 
00410   
00411   
00412   bool  MIDIMessage::IsTempo() const 
00413   {
00414     return (status==META_EVENT)
00415       && (byte1==META_TEMPO);
00416   } 
00417   
00418   
00419   bool  MIDIMessage::IsDataEnd() const 
00420   {
00421     return (status==META_EVENT)
00422       && (byte1==META_DATA_END );
00423   } 
00424   
00425   bool  MIDIMessage::IsTimeSig() const 
00426   {
00427     return (status==META_EVENT)
00428       && (byte1==META_TIMESIG );
00429   }
00430 
00431   bool  MIDIMessage::IsKeySig() const 
00432   {
00433     return (status==META_EVENT)
00434       && (byte1==META_KEYSIG );
00435   }
00436   
00437   bool  MIDIMessage::IsBeatMarker() const 
00438   {
00439     return (status==META_EVENT)
00440       && (byte1==META_BEAT_MARKER);
00441   }
00442   
00443   
00444   
00445   unsigned short  MIDIMessage::GetTempo32() const 
00446   {
00447     return GetMetaValue();
00448   } 
00449   
00450   
00451   unsigned short  MIDIMessage::GetLoopNumber() const 
00452   {
00453     return GetMetaValue();
00454   } 
00455   
00456   
00457   void  MIDIMessage::SetBenderValue( short v) 
00458   {
00459     short x=(short)(v+8192);
00460     byte1=(unsigned char)(x&0x7f);
00461     byte2=(unsigned char)((x>>7)&0x7f);
00462   } 
00463   
00464   
00465   void  MIDIMessage::SetMetaType( unsigned char t ) 
00466   { 
00467     byte1=t;    
00468   } 
00469   
00470   
00471   
00472   void  MIDIMessage::SetMetaValue( unsigned short v ) 
00473   {
00474     byte2=(unsigned char)(v&0xff);
00475     byte3=(unsigned char)((v>>8)&0xff);
00476   } 
00477   
00478   
00479   void  MIDIMessage::SetNoteOn( unsigned char chan, unsigned char note, unsigned char vel ) 
00480   {
00481     status=(unsigned char)(chan | NOTE_ON);
00482     byte1=note;
00483     byte2=vel;
00484     byte3=0;
00485   } 
00486   
00487   
00488   void  MIDIMessage::SetNoteOff( unsigned char chan, unsigned char note, unsigned char vel ) 
00489   {
00490     status=(unsigned char)(chan | NOTE_OFF);
00491     byte1=note;
00492     byte2=vel;
00493     byte3=0;
00494   } 
00495   
00496   
00497   void  MIDIMessage::SetPolyPressure( unsigned char chan, unsigned char note, unsigned char pres ) 
00498   {
00499     status=(unsigned char)(chan | POLY_PRESSURE);
00500     byte1=note;
00501     byte2=pres;
00502     byte3=0;
00503   } 
00504   
00505   
00506   void  MIDIMessage::SetControlChange( unsigned char chan, unsigned char ctrl, unsigned char val ) 
00507   {
00508     status=(unsigned char)(chan | CONTROL_CHANGE);
00509     byte1=ctrl;
00510     byte2=val;
00511     byte3=0;
00512   } 
00513   
00514   
00515   void  MIDIMessage::SetProgramChange( unsigned char chan, unsigned char val ) 
00516   {
00517     status=(unsigned char)(chan | PROGRAM_CHANGE);
00518     byte1=val;
00519     byte2=0;
00520     byte3=0;
00521   } 
00522   
00523   
00524   void  MIDIMessage::SetChannelPressure( unsigned char chan, unsigned char val ) 
00525   {
00526     status=(unsigned char)(chan | CHANNEL_PRESSURE);
00527     byte1=val;
00528     byte2=0;
00529     byte3=0;
00530   } 
00531   
00532   
00533   void  MIDIMessage::SetPitchBend( unsigned char chan, short val ) 
00534   {
00535     status=(unsigned char)(chan | PITCH_BEND);
00536     val+=(short)0x2000; // center value
00537     byte1=(unsigned char)(val&0x7f); // 7 bit bytes
00538     byte2=(unsigned char)((val>>7)&0x7f);
00539     byte3=0;
00540   } 
00541   
00542   
00543   void  MIDIMessage::SetPitchBend( unsigned char chan, unsigned char low, unsigned char high ) 
00544   {
00545     status=(unsigned char)(chan | PITCH_BEND);
00546     byte1=(unsigned char)(low);
00547     byte2=(unsigned char)(high);
00548     byte3=0;
00549   } 
00550   
00551   
00552   void  MIDIMessage::SetSysEx() 
00553   {
00554     status=SYSEX_START;
00555     byte1=0;
00556     
00557     int num=0;
00558     byte2=(unsigned char)(num&0xff);
00559     byte3=(unsigned char)((num>>8)&0xff);
00560   } 
00561   
00562   
00563   void  MIDIMessage::SetMTC( unsigned char field, unsigned char v ) 
00564   {
00565     status=MTC;
00566     byte1=(unsigned char)((field<<4) | v);
00567     byte2=0;
00568     byte3=0;
00569   } 
00570   
00571   
00572   void  MIDIMessage::SetSongPosition( short pos ) 
00573   {
00574     status=SONG_POSITION;
00575     byte1=(unsigned char)(pos&0x7f);
00576     byte2=(unsigned char)((pos>>7)&0x7f);
00577     byte3=0;
00578   } 
00579   
00580   
00581   void  MIDIMessage::SetSongSelect(unsigned char sng) 
00582   {
00583     status=SONG_SELECT;
00584     byte1=sng;
00585     byte2=0;
00586     byte3=0;
00587   } 
00588   
00589   
00590   void  MIDIMessage::SetTuneRequest() 
00591   {
00592     status=TUNE_REQUEST;
00593     byte1=0;
00594     byte2=0;
00595     byte3=0;
00596   } 
00597   
00598   
00599   void  MIDIMessage::SetMetaEvent( unsigned char type, unsigned char v1, unsigned char v2 ) 
00600   {
00601     status=META_EVENT;
00602     byte1=type;
00603     byte2=v1;
00604     byte3=v2;
00605   } 
00606   
00607   
00608   void  MIDIMessage::SetMetaEvent( unsigned char type, unsigned short v ) 
00609   {
00610     status=META_EVENT;
00611     byte1=type;
00612     byte2=(unsigned char)(v&0xff);
00613     byte3=(unsigned char)((v>>8)&0xff);
00614   } 
00615   
00616   
00617   void  MIDIMessage::SetAllNotesOff(
00618     unsigned char chan,
00619     unsigned char type
00620     ) 
00621   {
00622     status=(unsigned char)(chan|CONTROL_CHANGE);
00623     byte1=type;
00624     byte2=0x7f;
00625     byte3=0;
00626   } 
00627   
00628   
00629   void  MIDIMessage::SetLocal( unsigned char chan, unsigned char v ) 
00630   {
00631     status=(unsigned char)(chan|CONTROL_CHANGE);
00632     byte1=C_LOCAL;
00633     byte2=v;
00634     byte3=0;
00635   } 
00636   
00637   
00638   void  MIDIMessage::SetNoOp() 
00639   {
00640     status=META_EVENT;
00641     byte1=META_NO_OPERATION;
00642     byte2=0;
00643     byte3=0;
00644   } 
00645   
00646   
00647   void  MIDIMessage::SetTempo32( unsigned short tempo_times_32 ) 
00648   {
00649     SetMetaEvent( META_TEMPO, tempo_times_32 );
00650   } 
00651   
00652   
00653   void  MIDIMessage::SetText( unsigned short text_num, unsigned char type) 
00654   {
00655     SetMetaEvent( type, text_num );
00656   } 
00657   
00658   
00659   void  MIDIMessage::SetDataEnd() 
00660   {
00661     SetMetaEvent( META_DATA_END,0 );
00662   } 
00663   
00664   void  MIDIMessage::SetTimeSig( unsigned char num, unsigned char den) 
00665   {
00666     SetMetaEvent( META_TIMESIG,num,den );
00667   } 
00668 
00669   void  MIDIMessage::SetKeySig( signed char sharp_flats, unsigned char major_minor) 
00670   {
00671     SetMetaEvent( META_KEYSIG,sharp_flats,major_minor);
00672   }   
00673   
00674   
00675   void  MIDIMessage::SetBeatMarker() 
00676   {
00677     SetMetaEvent( META_BEAT_MARKER,0,0 );
00678   } 
00679   
00680   
00681   
00682   MIDIBigMessage::MIDIBigMessage() 
00683     :
00684     sysex(0)
00685   {
00686   } 
00687   
00688   MIDIBigMessage::MIDIBigMessage( const MIDIBigMessage &m ) 
00689     :
00690     MIDIMessage( m ),
00691     sysex( 0 )
00692   {
00693     if( m.sysex )
00694     {
00695       sysex = new MIDISystemExclusive( *m.sysex );
00696     }
00697   } 
00698   
00699   MIDIBigMessage::MIDIBigMessage( const MIDIMessage &m ) 
00700     :
00701     MIDIMessage( m ),
00702     sysex( 0 )
00703   {
00704   } 
00705   
00706   void  MIDIBigMessage::Clear() 
00707   {
00708     if( sysex )
00709     {
00710       delete sysex;
00711     }
00712     sysex=0;
00713     MIDIMessage::Clear();
00714   } 
00715   
00716   void  MIDIBigMessage::Copy( const MIDIBigMessage &m ) 
00717   {
00718     delete sysex;
00719     if( m.sysex )
00720     {
00721       sysex = new MIDISystemExclusive( *m.sysex );
00722     }
00723     else
00724     {
00725       sysex = 0;
00726     }
00727     MIDIMessage::Copy( m );
00728   } 
00729   
00730   void  MIDIBigMessage::Copy( const MIDIMessage &m ) 
00731   {
00732     delete sysex;
00733     sysex = 0;
00734     MIDIMessage::Copy( m );
00735   } 
00736   
00737 //
00738 // destructors
00739 //
00740   
00741   MIDIBigMessage::~MIDIBigMessage() 
00742   {
00743     if( sysex )
00744     {
00745       delete sysex;
00746       sysex=0;
00747     }
00748   } 
00749   
00750 //
00751 // operator =
00752 //
00753   
00754   const MIDIBigMessage &MIDIBigMessage::operator = ( const MIDIBigMessage &m ) 
00755   {
00756     delete sysex;
00757     if( m.sysex )
00758     {
00759       sysex = new MIDISystemExclusive( *m.sysex );
00760     }
00761     else
00762     {
00763       sysex = 0;
00764     }
00765     MIDIMessage::operator = (m);
00766     return *this;
00767   } 
00768   
00769   const MIDIBigMessage &MIDIBigMessage::operator = ( const MIDIMessage &m ) 
00770   {   
00771     delete sysex;
00772     sysex = 0;    
00773     
00774     MIDIMessage::operator = (m);
00775     return *this;
00776   } 
00777   
00778 //
00779 // 'Get' methods
00780 //
00781   
00782   MIDISystemExclusive *MIDIBigMessage::GetSysEx() 
00783   {
00784     return sysex;
00785   } 
00786   
00787   const MIDISystemExclusive *MIDIBigMessage::GetSysEx() const 
00788   {
00789     return sysex;
00790   } 
00791   
00792 //
00793 // 'Set' methods
00794 //
00795   
00796   void MIDIBigMessage::CopySysEx( const MIDISystemExclusive *e ) 
00797   {
00798     delete sysex;
00799     sysex=0;
00800     if( e )
00801     {
00802       sysex = new MIDISystemExclusive( *e );
00803     }
00804   } 
00805   
00806   
00807 #if 0
00808   void MIDIBigMessage::SetSysEx( MIDISystemExclusive *e ) 
00809   {
00810     delete sysex;
00811     sysex = e;
00812   } 
00813 #endif
00814   
00815   void MIDIBigMessage::ClearSysEx()  
00816   {
00817     delete sysex;
00818     sysex = 0;
00819   } 
00820   
00821   
00822   
00823   
00824   
00825   
00826 //
00827 // Constructors
00828 //
00829   
00830   MIDITimedMessage::MIDITimedMessage()  
00831     : time(0)
00832   {
00833   } 
00834   
00835   MIDITimedMessage::MIDITimedMessage( const MIDITimedMessage &m )  
00836     : MIDIMessage( m ), time(m.GetTime())
00837   {
00838   } 
00839   
00840   MIDITimedMessage::MIDITimedMessage( const MIDIMessage &m )  
00841     : MIDIMessage( m ), time(0)
00842   {
00843   } 
00844   
00845   void  MIDITimedMessage::Clear() 
00846   {
00847     time=0;
00848     MIDIMessage::Clear();
00849   } 
00850   
00851   void  MIDITimedMessage::Copy( const MIDITimedMessage &m ) 
00852   {
00853     time=m.GetTime();
00854     MIDIMessage::Copy( m );
00855   } 
00856   
00857 //
00858 // operator =
00859 //
00860   
00861   const MIDITimedMessage &MIDITimedMessage::operator = ( const MIDITimedMessage & m ) 
00862   {
00863     time=m.GetTime();
00864     MIDIMessage::operator = (m);
00865     return *this;
00866   } 
00867   
00868   const MIDITimedMessage &MIDITimedMessage::operator = ( const MIDIMessage & m ) 
00869   {
00870     time=0;
00871     MIDIMessage::operator = (m);
00872     return *this;
00873   } 
00874   
00875 //
00876 // 'Get' methods
00877 //
00878   
00879   MIDIClockTime MIDITimedMessage::GetTime() const
00880   {
00881     return time;
00882   }
00883   
00884 //
00885 // 'Set' methods
00886 //
00887   
00888   void  MIDITimedMessage::SetTime( MIDIClockTime t )
00889   {
00890     time=t;
00891   }
00892   
00893   
00894   
00895   int   MIDITimedMessage::CompareEvents(
00896     const MIDITimedMessage &m1,
00897     const MIDITimedMessage &m2
00898     ) 
00899   {
00900     bool n1 = m1.IsNoOp();
00901     bool n2 = m2.IsNoOp();
00902       
00903       // NOP's always are larger.
00904       
00905       if( n1 && n2 )
00906                       return 0; // same, do not care.
00907       
00908       if( n2 )
00909                 return 2; // m2 is larger
00910       
00911       if( n1 )
00912                 return 1; // m1 is larger
00913       
00914       if( m1.GetTime() > m2.GetTime() )
00915                                          return 1;  // m1 is larger
00916       
00917       if( m2.GetTime() > m1.GetTime() )
00918                                          return 2;  // m2 is larger
00919       
00920       // if times are the same, a note off is always larger
00921       
00922       if(     m1.byte1 == m2.byte1
00923               && m1.GetStatus()==NOTE_ON
00924               &&  ((m2.GetStatus()==NOTE_ON && m2.byte2==0) || (m2.GetStatus()==NOTE_OFF))
00925         )
00926            return 2;  // m2 is larger
00927       
00928       if(   m1.byte1 == m2.byte1
00929                 && m2.GetStatus()==NOTE_ON
00930                 &&  ((m1.GetStatus()==NOTE_ON && m1.byte2==0) || (m1.GetStatus()==NOTE_OFF))
00931         )
00932            return 1;  // m1 is larger
00933       
00934       
00935       return 0;   // both are equal.
00936       
00937   } 
00938   
00939   
00940   
00941   
00942   
00943   MIDIDeltaTimedMessage::MIDIDeltaTimedMessage() 
00944     : dtime(0)
00945   {
00946   } 
00947   
00948   MIDIDeltaTimedMessage::MIDIDeltaTimedMessage( const MIDIDeltaTimedMessage &m ) 
00949     : MIDIMessage( m ), dtime(m.GetDeltaTime())
00950   {
00951   } 
00952   
00953   MIDIDeltaTimedMessage::MIDIDeltaTimedMessage( const MIDIMessage &m )  
00954     : MIDIMessage( m ), dtime(0)
00955   {
00956   } 
00957   
00958   void  MIDIDeltaTimedMessage::Clear() 
00959   {
00960     dtime=0;
00961     MIDIMessage::Clear();
00962   } 
00963   
00964   void  MIDIDeltaTimedMessage::Copy( const MIDIDeltaTimedMessage &m ) 
00965   {
00966     dtime=m.GetDeltaTime();
00967     MIDIMessage::Copy( m );
00968   } 
00969   
00970 //
00971 // operator =
00972 //
00973   
00974   const MIDIDeltaTimedMessage &MIDIDeltaTimedMessage::operator = ( const MIDIDeltaTimedMessage &m ) 
00975   {
00976     dtime=m.GetDeltaTime();
00977     MIDIMessage::operator = (m);
00978     return *this;
00979   } 
00980   
00981   const MIDIDeltaTimedMessage &MIDIDeltaTimedMessage::operator = ( const MIDIMessage &m ) 
00982   {
00983     dtime=0;
00984     MIDIMessage::operator = (m);
00985     return *this;
00986   } 
00987   
00988 //
00989 // 'Get' methods
00990 //
00991   
00992   MIDIClockTime MIDIDeltaTimedMessage::GetDeltaTime() const 
00993   { 
00994     return dtime; 
00995   }
00996   
00997 //
00998 // 'Set' methods
00999 //
01000   
01001   void  MIDIDeltaTimedMessage::SetDeltaTime( MIDIClockTime t )
01002   { 
01003     dtime=t;  
01004   }
01005   
01006   
01007   
01008   
01009   
01010   
01011 //
01012 // Constructors
01013 //
01014   
01015   MIDITimedBigMessage::MIDITimedBigMessage() 
01016     : time(0)
01017   {
01018   } 
01019   
01020   MIDITimedBigMessage::MIDITimedBigMessage( const MIDITimedBigMessage &m )  
01021     : MIDIBigMessage( m ),
01022       time(m.GetTime())
01023   {
01024   } 
01025   
01026   MIDITimedBigMessage::MIDITimedBigMessage( const MIDIBigMessage &m )   
01027     : MIDIBigMessage( m ),
01028       time(0)
01029   {
01030   } 
01031   
01032   MIDITimedBigMessage::MIDITimedBigMessage( const MIDITimedMessage &m ) 
01033     : MIDIBigMessage( m ),
01034       time(m.GetTime())
01035   {
01036   } 
01037   
01038   MIDITimedBigMessage::MIDITimedBigMessage( const MIDIMessage &m )  
01039     : MIDIBigMessage( m ),
01040       time(0)
01041   {
01042   } 
01043   
01044   void  MIDITimedBigMessage::Clear() 
01045   {
01046     time=0;
01047     MIDIBigMessage::Clear();
01048   } 
01049   
01050   void  MIDITimedBigMessage::Copy( const MIDITimedBigMessage &m ) 
01051   {
01052     time=m.GetTime();
01053     MIDIBigMessage::Copy( m );
01054   } 
01055   
01056   void  MIDITimedBigMessage::Copy( const MIDITimedMessage &m ) 
01057   {
01058     time=m.GetTime();
01059     MIDIBigMessage::Copy( m );
01060   } 
01061   
01062 //
01063 // operator =
01064 //
01065   
01066   const MIDITimedBigMessage &MIDITimedBigMessage::operator = ( const MIDITimedBigMessage & m ) 
01067   {
01068     time=m.GetTime();
01069     MIDIBigMessage::operator = (m);
01070     return *this;
01071   } 
01072   
01073   const MIDITimedBigMessage &MIDITimedBigMessage::operator = ( const MIDITimedMessage & m ) 
01074   {
01075     time=m.GetTime();
01076     MIDIBigMessage::operator = (m);
01077     return *this;
01078   } 
01079   
01080   const MIDITimedBigMessage &MIDITimedBigMessage::operator = ( const MIDIMessage & m ) 
01081   {
01082     time=0;
01083     MIDIBigMessage::operator = (m);
01084     return *this;
01085   } 
01086   
01087 //
01088 // 'Get' methods
01089 //
01090   
01091   MIDIClockTime MIDITimedBigMessage::GetTime() const    
01092   { 
01093     return time;  
01094   }
01095   
01096 //
01097 // 'Set' methods
01098 //
01099   
01100   void  MIDITimedBigMessage::SetTime( MIDIClockTime t )
01101   {
01102     time=t;
01103   }
01104   
01105   
01106   
01107   int   MIDITimedBigMessage::CompareEvents(
01108     const MIDITimedBigMessage &m1,
01109     const MIDITimedBigMessage &m2
01110     ) 
01111   {
01112     bool n1 = m1.IsNoOp();
01113     bool n2 = m2.IsNoOp();
01114       
01115       // NOP's always are larger.
01116       
01117       if( n1 && n2 )
01118                       return 0; // same, do not care.
01119       
01120       if( n2 )
01121                 return 2; // m2 is larger
01122       
01123       if( n1 )
01124                 return 1; // m1 is larger
01125       
01126       if( m1.GetTime() > m2.GetTime() )
01127                                          return 1;  // m1 is larger
01128       
01129       if( m2.GetTime() > m1.GetTime() )
01130                                          return 2;  // m2 is larger
01131       
01132       // if times are the same, a note off is always larger
01133       
01134       if(     m1.byte1 == m2.byte1
01135               && m1.GetStatus()==NOTE_ON
01136               &&  ((m2.GetStatus()==NOTE_ON && m2.byte2==0) || (m2.GetStatus()==NOTE_OFF))
01137         )
01138            return 2;  // m2 is larger
01139       
01140       if(   m1.byte1 == m2.byte1
01141                 && m2.GetStatus()==NOTE_ON
01142                 &&  ((m1.GetStatus()==NOTE_ON && m1.byte2==0) || (m1.GetStatus()==NOTE_OFF))
01143         )
01144            return 1;  // m1 is larger
01145       
01146       
01147       return 0;   // both are equal.
01148       
01149   } 
01150   
01151   
01152   
01153 //
01154 // Constructors
01155 //
01156   
01157   MIDIDeltaTimedBigMessage::MIDIDeltaTimedBigMessage() 
01158     : dtime(0)
01159   {
01160   } 
01161   
01162   MIDIDeltaTimedBigMessage::MIDIDeltaTimedBigMessage( const MIDIDeltaTimedBigMessage &m ) 
01163     : MIDIBigMessage( m ), dtime(m.GetDeltaTime())
01164   {   
01165   } 
01166   
01167   MIDIDeltaTimedBigMessage::MIDIDeltaTimedBigMessage( const MIDIBigMessage &m )   
01168     : MIDIBigMessage( m ), dtime(0)
01169   {
01170   } 
01171   
01172   MIDIDeltaTimedBigMessage::MIDIDeltaTimedBigMessage( const MIDIMessage &m ) 
01173     : MIDIBigMessage( m ), dtime(0)
01174   {
01175   } 
01176   
01177   MIDIDeltaTimedBigMessage::MIDIDeltaTimedBigMessage( const MIDIDeltaTimedMessage &m ) 
01178     : MIDIBigMessage( m ), dtime(m.GetDeltaTime())
01179   {
01180   } 
01181   
01182   void  MIDIDeltaTimedBigMessage::Clear() 
01183   {
01184     dtime=0;
01185     MIDIBigMessage::Clear();
01186   } 
01187   
01188   void  MIDIDeltaTimedBigMessage::Copy( const MIDIDeltaTimedBigMessage &m ) 
01189   {
01190     dtime=m.GetDeltaTime();
01191     MIDIBigMessage::Copy( m );
01192   } 
01193   
01194   void  MIDIDeltaTimedBigMessage::Copy( const MIDIDeltaTimedMessage &m ) 
01195   {
01196     dtime=m.GetDeltaTime();
01197     MIDIBigMessage::Copy( m );
01198   } 
01199   
01200 //
01201 // operator =
01202 //
01203   
01204   const MIDIDeltaTimedBigMessage &MIDIDeltaTimedBigMessage::operator = ( const MIDIDeltaTimedBigMessage &m ) 
01205   {
01206     dtime=m.GetDeltaTime();
01207     MIDIBigMessage::operator = (m);
01208     return *this;
01209   } 
01210   
01211   const MIDIDeltaTimedBigMessage &MIDIDeltaTimedBigMessage::operator = ( const MIDIDeltaTimedMessage &m ) 
01212   {
01213     dtime=m.GetDeltaTime();
01214     MIDIBigMessage::operator = (m);
01215     return *this;
01216   } 
01217   
01218   const MIDIDeltaTimedBigMessage &MIDIDeltaTimedBigMessage::operator = ( const MIDIMessage &m ) 
01219   {
01220     dtime=0;
01221     MIDIBigMessage::operator = (m);
01222     return *this;
01223   } 
01224   
01225 //
01226 // 'Get' methods
01227 //
01228   
01229   MIDIClockTime MIDIDeltaTimedBigMessage::GetDeltaTime() const  
01230   { 
01231     return dtime; 
01232   }
01233   
01234 //
01235 // 'Set' methods
01236 //
01237   
01238   void  MIDIDeltaTimedBigMessage::SetDeltaTime( MIDIClockTime t ) 
01239   { 
01240     dtime=t;    
01241   }
01242   
01243   
01244   
01245   
01246   
01247   
01248   
01249   
01250   
01251   
01252   
01253   
01254   
01255   
01256   
01257 }