CLAM-Development  1.4.0
MIDIMessage.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * MIDIFileReader C++ classes
20  * This code is part of the CLAM library, but also usable stand-alone.
21  * Maarten de Boer <mdeboer@iua.upf.es>
22  *
23  */
24 #ifndef __MIDIMessage__
25 #define __MIDIMessage__
26 
27 #include "MIDIDataTypes.hxx"
28 #include <iostream>
29 
30 namespace MIDI
31 {
32 
33  class Message
34  /* an ordinary MIDI message contains between 2 and 4 bytes. reserve
35  ** space for the maximum, 4. */
36  {
37  friend class Event;
38  public:
40  {
41  mData.mStatus = 0;
42  mData.mData1 = 0;
43  mData.mData2 = 0;
44  mData.mData3 = 0;
45  }
46 
47  Message(Byte status,Byte data1,Byte data2 = 0,Byte data3 = 0)
48  {
49  mData.mStatus = status;
50  mData.mData1 = data1;
51  mData.mData2 = data2;
52  mData.mData3 = data3;
53  }
54 
55  Byte operator [] (int i) const { return mVal[i]; }
56 
57  bool operator== (Message message) const {
58  return (( mData.mStatus == message[0] ) && ( mData.mData1 == message[1] ) && ( mData.mData2 == message[2] ) && ( mData.mData3 == message[3] ));
59  };
60 
61  bool operator!= (Message message) const {
62  return ( ( message[0] != mData.mStatus) || ( message[1] != mData.mData1 ) || ( message[2] != mData.mData2 ) || ( message[3] != mData.mData3 ) );
63  };
64 
65  void Update(Byte status = 0,Byte data1 = 0,Byte data2 = 0,Byte data3 = 0)
66  {
67  if(status) {mData.mStatus = status;}
68  if(data1) {mData.mData1 = data1;}
69  if(data2) {mData.mData2 = data2;}
70  if(data3) {mData.mData3 = data3;}
71  }
72 
73  private:
74  union
75  {
76  struct
77  {
82  } mData;
83 
84  Byte mVal[4];
85  };
86  };
87 
88  std::ostream& operator<< (std::ostream &os, const Message& m);
89 }
90 #endif
91