CLAM-Development  1.4.0
MIDIManager.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 __MIDIManager__
23 #define __MIDIManager__
24 
25 #include <vector>
26 
27 #include "MIDIDevice.hxx"
28 #include "MIDIDeviceList.hxx"
29 
30 #ifdef WIN32
31 #define DEFAULT_MIDI_ARCH "portmidi"
32 #else
33 #define DEFAULT_MIDI_ARCH "alsa"
34 #endif
35 
36 namespace CLAM{
37 
46 {
47  friend class MIDIIn;
48  friend class MIDIClocker;
49  friend class MIDIOut;
50  friend class MIDIDeviceList;
51 private:
52  std::vector<MIDIDevice*> mDevices;
53 
55  static std::vector<MIDIDeviceList*>& DeviceLists(void)
56  {
57  static std::vector<MIDIDeviceList*> sDeviceLists;
58  return sDeviceLists;
59  }
60 
61  static MIDIManager* _Current(bool set = 0,MIDIManager* m = 0)
62  {
63  static MIDIManager* sCurrent = 0;
64  if (set)
65  {
66  if (m)
67  {
68  if (sCurrent) throw Err("Can only have one MIDIManager at a time");
69  }
70  sCurrent = m;
71  }
72  return sCurrent;
73  }
74 public:
75  typedef std::vector<MIDIDevice*>::const_iterator device_iterator;
76  typedef std::vector<MIDIDeviceList*>::const_iterator list_iterator;
77 
79  MIDIManager() throw(Err);
80 
82  ~MIDIManager();
83 
84  static MIDIManager& Current()
85  {
86  MIDIManager* p = _Current();
87 
88  if (p==0) throw Err("No MIDIManager current");
89 
90  return *p;
91  }
92 
97  MIDIDevice* FindDevice(const std::string& name);
98 
103  MIDIDevice* FindOrCreateDevice(const std::string& name);
104 
106  void Start(void) throw(Err);
107 
109  void Stop(void) throw(Err);
110 
112  void Check(void);
113 
121  MIDIDeviceList* FindList(const std::string& arch = "default");
122 
127  list_iterator lists_begin() const {return DeviceLists().begin();}
128 
133  list_iterator lists_end() const {return DeviceLists().end();}
134 
139  device_iterator used_devices_begin() const {return mDevices.begin();}
144  device_iterator used_devices_end() const {return mDevices.end();}
145 
146 protected:
149  bool Register(MIDIIn& in);
150 
154  bool Register(MIDIClocker& cl);
155 
158  bool Register(MIDIOut& out);
159 
160  /* flag to check if the MIDIManager has been started properly*/
161  bool mStarted;
162 };
163 
164 
165 };//CLAM
166 
167 #endif
168