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 "MIDIEnums.hxx"
00030 #include "InControl.hxx"
00031 
00032 namespace CLAM{
00033 
00034 class MIDIIn;
00035 class MIDIOut;
00036 class MIDIClocker;
00037 class MIDIManager;
00038 
00049 class MIDIDevice
00050 {
00051         friend class MIDIIn;
00052         friend class MIDIOut;
00053         friend class MIDIOutControl;
00054         friend class MIDIClocker;
00055         friend class MIDIManager;
00056 protected:
00060         struct TInfo
00061         {
00062                 std::string mName;
00063                 std::string mArch;
00065                 TInfo() { Reset();}
00066 
00068                 void Reset()
00069                 {
00070                         mName=mArch="";
00071                 }
00072         };
00073 
00074         MIDIIn* target[8][16][128];
00075 
00076         std::vector<MIDIIn*> mInputs;
00077         std::vector<MIDIOut*> mOutputs;
00078 
00079         std::string mName;
00080 
00081         unsigned char mLastStatus;
00082         int mIndex;
00083         int mLength;
00084         unsigned char mData[256];
00085 
00089         MIDIDevice(const std::string& name)
00090         {
00091                 mName = name;
00092                 mLastStatus = 0;
00093                 mIndex = 0;
00094                 mLength = 0;
00095                 mMIDIManager = 0;
00096         }
00097         
00099         virtual ~MIDIDevice() { };
00100 
00102         void Start(void);
00103 
00105         void Stop(void);
00106         
00108         virtual void ConcreteStart(void) throw(Err) = 0;
00109 
00111         virtual void ConcreteStop(void) throw(Err) = 0;
00112 
00116         void GetInfo(TInfo&);
00117 
00118         virtual void SetClock(TControlData val) { }
00119 
00122         virtual void Read(void) throw(Err) = 0;
00123 
00124         virtual void Write(unsigned char* msg,int size) throw(Err) = 0;
00125 
00126 protected:
00127         bool Register(MIDIManager* mm,MIDIIn& in);
00128         bool Register(MIDIManager* mm,MIDIOut& out);
00129         void Unregister(MIDIIn& in);
00130         void Unregister(MIDIOut& out);
00131 
00132         bool Register(MIDIManager* mm,MIDIClocker& in);
00133         void Unregister(MIDIClocker& in);
00134 
00135         int GetMessageLength(unsigned char byte);
00136 
00137         void HandleRawByte(unsigned char byte);
00138 
00139 private:
00140         MIDIManager* mMIDIManager;
00141         MIDIManager& _MIDIManager(void);
00142         void _SetMIDIManager(MIDIManager* mm);
00143 
00144         void SetTarget(
00145                 MIDI::Message msg,
00146                 unsigned char chn,unsigned char firstData,
00147                 MIDIIn* inp);
00148 };
00149 
00150 };//CLAM
00151 
00152 #endif
00153 
Generated by  doxygen 1.6.3