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 __MIDIManager__ 00023 #define __MIDIManager__ 00024 00025 #include <vector> 00026 00027 #include "MIDIDevice.hxx" 00028 #include "MIDIDeviceList.hxx" 00029 00030 #ifdef WIN32 00031 #define DEFAULT_MIDI_ARCH "portmidi" 00032 #else 00033 #define DEFAULT_MIDI_ARCH "alsa" 00034 #endif 00035 00036 namespace CLAM{ 00037 00045 class MIDIManager 00046 { 00047 friend class MIDIIn; 00048 friend class MIDIClocker; 00049 friend class MIDIOut; 00050 friend class MIDIDeviceList; 00051 private: 00052 std::vector<MIDIDevice*> mDevices; 00053 00055 static std::vector<MIDIDeviceList*>& DeviceLists(void) 00056 { 00057 static std::vector<MIDIDeviceList*> sDeviceLists; 00058 return sDeviceLists; 00059 } 00060 00061 static MIDIManager* _Current(bool set = 0,MIDIManager* m = 0) 00062 { 00063 static MIDIManager* sCurrent = 0; 00064 if (set) 00065 { 00066 if (m) 00067 { 00068 if (sCurrent) throw Err("Can only have one MIDIManager at a time"); 00069 } 00070 sCurrent = m; 00071 } 00072 return sCurrent; 00073 } 00074 public: 00075 typedef std::vector<MIDIDevice*>::const_iterator device_iterator; 00076 typedef std::vector<MIDIDeviceList*>::const_iterator list_iterator; 00077 00079 MIDIManager() throw(Err); 00080 00082 ~MIDIManager(); 00083 00084 static MIDIManager& Current() 00085 { 00086 MIDIManager* p = _Current(); 00087 00088 if (p==0) throw Err("No MIDIManager current"); 00089 00090 return *p; 00091 } 00092 00097 MIDIDevice* FindDevice(const std::string& name); 00098 00103 MIDIDevice* FindOrCreateDevice(const std::string& name); 00104 00106 void Start(void) throw(Err); 00107 00109 void Stop(void) throw(Err); 00110 00112 void Check(void); 00113 00121 MIDIDeviceList* FindList(const std::string& arch = "default"); 00122 00127 list_iterator lists_begin() const {return DeviceLists().begin();} 00128 00133 list_iterator lists_end() const {return DeviceLists().end();} 00134 00139 device_iterator used_devices_begin() const {return mDevices.begin();} 00144 device_iterator used_devices_end() const {return mDevices.end();} 00145 00146 protected: 00149 bool Register(MIDIIn& in); 00150 00154 bool Register(MIDIClocker& cl); 00155 00158 bool Register(MIDIOut& out); 00159 00160 /* flag to check if the MIDIManager has been started properly*/ 00161 bool mStarted; 00162 }; 00163 00164 00165 };//CLAM 00166 00167 #endif 00168