r269@gandalf: fugalh | 2006-08-03 20:18:05 -0600
[ardour.git] / libs / midi++2 / midi++ / manager.h
1 /*
2     Copyright (C) 1998 Paul Barton-Davis
3     
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18     $Id$
19 */
20
21 #ifndef __midi_manager_h__
22 #define __midi_manager_h__
23
24 #include <map>
25 #include <string>
26
27 #include <midi++/types.h>
28 #include <midi++/port.h>
29
30 namespace MIDI {
31
32 class Manager {
33   public:
34         ~Manager ();
35         
36         Port *add_port (PortRequest &);
37         int   remove_port (std::string port);
38
39         Port *port (std::string name);
40         Port *port (size_t number);
41
42         size_t    nports () { return ports_by_device.size(); }
43
44         /* defaults for clients who are not picky */
45         
46         Port *inputPort;
47         Port *outputPort;
48         channel_t inputChannelNumber;
49         channel_t outputChannelNumber;
50
51         int set_input_port (size_t port);
52         int set_input_port (std::string);
53         int set_output_port (size_t port);
54         int set_output_port (std::string);
55         int set_input_channel (channel_t);
56         int set_output_channel (channel_t);
57
58         int foreach_port (int (*func)(const Port &, size_t n, void *), 
59                           void *arg);
60
61         typedef std::map<std::string, Port *> PortMap;
62
63         const PortMap& get_midi_ports() const { return ports_by_tag; } 
64
65         static Manager *instance () {
66                 if (theManager == 0) {
67                         theManager = new Manager;
68                 }
69                 return theManager;
70         }
71
72         static int parse_port_request (std::string str, Port::Type type);
73
74   private:
75         /* This is a SINGLETON pattern */
76         
77         Manager ();
78
79         static Manager *theManager;
80         PortMap         ports_by_device; /* canonical */
81         PortMap         ports_by_tag;    /* may contain duplicate Ports */
82
83         void close_ports ();
84 };
85
86 } // namespace MIDI
87
88 #endif  // __midi_manager_h__