MIDIMessage.hxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  * UNIVERSITAT POMPEU FABRA
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00018  *
00019  * MIDIFileReader C++ classes
00020  * This code is part of the CLAM library, but also usable stand-alone.
00021  * Maarten de Boer <mdeboer@iua.upf.es>
00022  *
00023  */
00024 #ifndef __MIDIMessage__
00025 #define __MIDIMessage__
00026 
00027 #include "MIDIDataTypes.hxx"
00028 #include <iostream>
00029 
00030 namespace MIDI
00031 {
00032 
00033         class Message
00034         /* an ordinary MIDI message contains between 2 and 4 bytes. reserve
00035         ** space for the maximum, 4. */
00036         {
00037         friend class Event;
00038         public:
00039                 Message()
00040                 {
00041                         mData.mStatus = 0;
00042                         mData.mData1 = 0;
00043                         mData.mData2 = 0;
00044                         mData.mData3 = 0;
00045                 }
00046 
00047                 Message(Byte status,Byte data1,Byte data2 = 0,Byte data3 = 0)
00048                 {
00049                         mData.mStatus = status;
00050                         mData.mData1 = data1;
00051                         mData.mData2 = data2;
00052                         mData.mData3 = data3;
00053                 }
00054 
00055                 Byte operator [] (int i) const { return mVal[i]; }
00056 
00057                 bool operator== (Message message) const { 
00058                         return (( mData.mStatus == message[0] ) && ( mData.mData1 == message[1] ) && ( mData.mData2 == message[2] ) && ( mData.mData3 == message[3] ));
00059                 };
00060         
00061                 bool operator!= (Message message) const { 
00062                         return ( ( message[0] != mData.mStatus) || ( message[1] != mData.mData1 ) || ( message[2] != mData.mData2 ) || ( message[3] != mData.mData3 ) );
00063                 };
00064 
00065                 void Update(Byte status = 0,Byte data1 = 0,Byte data2 = 0,Byte data3 = 0)
00066                 {
00067                         if(status) {mData.mStatus = status;}
00068                         if(data1) {mData.mData1 = data1;}
00069                         if(data2) {mData.mData2 = data2;}
00070                         if(data3) {mData.mData3 = data3;}
00071                 }
00072                 
00073         private:
00074                 union
00075                 {
00076                         struct
00077                         {
00078                                 Byte mStatus;
00079                                 Byte mData1;
00080                                 Byte mData2;
00081                                 Byte mData3;
00082                         } mData;
00083 
00084                         Byte mVal[4];
00085                 };
00086         };
00087 
00088         std::ostream& operator<< (std::ostream &os, const Message& m);
00089 }
00090 #endif
00091 
Generated by  doxygen 1.6.3