CLAM-Development  1.4.0
MIDIDevice.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #ifndef __MIDIDevice__
23 #define __MIDIDevice__
24 
25 
26 #include <string>
27 #include <vector>
28 #include "Err.hxx"
29 #include "MIDIEnums.hxx"
30 #include "InControl.hxx"
31 
32 namespace CLAM{
33 
34 class MIDIIn;
35 class MIDIOut;
36 class MIDIClocker;
37 class MIDIManager;
38 
50 {
51  friend class MIDIIn;
52  friend class MIDIOut;
53  friend class MIDIOutControl;
54  friend class MIDIClocker;
55  friend class MIDIManager;
56 protected:
60  struct TInfo
61  {
62  std::string mName;
63  std::string mArch;
65  TInfo() { Reset();}
66 
68  void Reset()
69  {
70  mName=mArch="";
71  }
72  };
73 
74  MIDIIn* target[8][16][128];
75 
76  std::vector<MIDIIn*> mInputs;
77  std::vector<MIDIOut*> mOutputs;
78 
79  std::string mName;
80 
81  unsigned char mLastStatus;
82  int mIndex;
83  int mLength;
84  unsigned char mData[256];
85 
89  MIDIDevice(const std::string& name)
90  {
91  mName = name;
92  mLastStatus = 0;
93  mIndex = 0;
94  mLength = 0;
95  mMIDIManager = 0;
96  }
97 
99  virtual ~MIDIDevice() { };
100 
102  void Start(void);
103 
105  void Stop(void);
106 
108  virtual void ConcreteStart(void) throw(Err) = 0;
109 
111  virtual void ConcreteStop(void) throw(Err) = 0;
112 
116  void GetInfo(TInfo&);
117 
118  virtual void SetClock(TControlData val) { }
119 
122  virtual void Read(void) throw(Err) = 0;
123 
124  virtual void Write(unsigned char* msg,int size) throw(Err) = 0;
125 
126 protected:
127  bool Register(MIDIManager* mm,MIDIIn& in);
128  bool Register(MIDIManager* mm,MIDIOut& out);
129  void Unregister(MIDIIn& in);
130  void Unregister(MIDIOut& out);
131 
132  bool Register(MIDIManager* mm,MIDIClocker& in);
133  void Unregister(MIDIClocker& in);
134 
135  int GetMessageLength(unsigned char byte);
136 
137  void HandleRawByte(unsigned char byte);
138 
139 private:
140  MIDIManager* mMIDIManager;
141  MIDIManager& _MIDIManager(void);
142  void _SetMIDIManager(MIDIManager* mm);
143 
144  void SetTarget(
145  MIDI::Message msg,
146  unsigned char chn,unsigned char firstData,
147  MIDIIn* inp);
148 };
149 
150 };//CLAM
151 
152 #endif
153