MIDIDevice.hxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 #ifndef __MIDIDevice__
00023 #define __MIDIDevice__
00024 
00025 
00026 #include <string>
00027 #include <vector>
00028 #include "Err.hxx"
00029 #include "InControl.hxx"
00030 #include "MIDIEnums.hxx"
00031 
00032 
00033 namespace CLAM{
00034 
00035 class MIDIIn;
00036 class MIDIOut;
00037 class MIDIClocker;
00038 class MIDIManager;
00039 
00050 class MIDIDevice
00051 {
00052         friend class MIDIIn;
00053         friend class MIDIOut;
00054         friend class MIDIOutControl;
00055         friend class MIDIClocker;
00056         friend class MIDIManager;
00057 protected:
00061         struct TInfo
00062         {
00063                 std::string mName;
00064                 std::string mArch;
00066                 TInfo() { Reset();}
00067 
00069                 void Reset()
00070                 {
00071                         mName=mArch="";
00072                 }
00073         };
00074 
00075         MIDIIn* target[8][16][128];
00076 
00077         std::vector<MIDIIn*> mInputs;
00078         std::vector<MIDIOut*> mOutputs;
00079 
00080         std::string mName;
00081 
00082         unsigned char mLastStatus;
00083         int mIndex;
00084         int mLength;
00085         unsigned char mData[256];
00086 
00090         MIDIDevice(const std::string& name)
00091         {
00092                 mName = name;
00093                 mLastStatus = 0;
00094                 mIndex = 0;
00095                 mLength = 0;
00096                 mMIDIManager = 0;
00097         }
00098         
00100         virtual ~MIDIDevice() { };
00101 
00103         void Start(void);
00104 
00106         void Stop(void);
00107         
00109         virtual void ConcreteStart(void) throw(Err) = 0;
00110 
00112         virtual void ConcreteStop(void) throw(Err) = 0;
00113 
00117         void GetInfo(TInfo&);
00118 
00119         virtual void SetClock(TControlData val) { }
00120 
00123         virtual void Read(void) throw(Err) = 0;
00124 
00125         virtual void Write(unsigned char* msg,int size) throw(Err) = 0;
00126 
00127 protected:
00128         bool Register(MIDIManager* mm,MIDIIn& in);
00129         bool Register(MIDIManager* mm,MIDIOut& out);
00130         void Unregister(MIDIIn& in);
00131         void Unregister(MIDIOut& out);
00132 
00133         bool Register(MIDIManager* mm,MIDIClocker& in);
00134         void Unregister(MIDIClocker& in);
00135 
00136         int GetMessageLength(unsigned char byte);
00137 
00138         void HandleRawByte(unsigned char byte);
00139 
00140 private:
00141         MIDIManager* mMIDIManager;
00142         MIDIManager& _MIDIManager(void);
00143         void _SetMIDIManager(MIDIManager* mm);
00144 
00145         void SetTarget(
00146                 MIDI::Message msg,
00147                 unsigned char chn,unsigned char firstData,
00148                 MIDIIn* inp);
00149 };
00150 
00151 };//CLAM
00152 
00153 #endif
00154 

Generated on Tue Aug 12 22:33:43 2008 for CLAM by  doxygen 1.5.5