rollback to 3428, before the mysterious removal of libs/* at 3431/3432
[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 */
19
20 #ifndef __midi_manager_h__
21 #define __midi_manager_h__
22
23 #include <map>
24 #include <vector>
25
26 #include <string>
27
28 #include <midi++/types.h>
29 #include <midi++/port.h>
30
31 namespace MIDI {
32
33 class Manager {
34   public:
35         ~Manager ();
36         
37         void set_api_data(void* data) { api_data = data; }
38         
39         /** Signal the start of an audio cycle.
40          * This MUST be called before any reading/writing for this cycle.
41          * Realtime safe.
42          */
43         void cycle_start(nframes_t nframes);
44         
45         /** Signal the end of an audio cycle.
46          * This signifies that the cycle began with @ref cycle_start has ended.
47          * This MUST be called at the end of each cycle.
48          * Realtime safe.
49          */
50         void cycle_end();
51
52         Port *add_port (const XMLNode& node);
53         int   remove_port (Port*);
54
55         Port *port (std::string name);
56
57         size_t    nports () { return ports_by_device.size(); }
58
59         /* defaults for clients who are not picky */
60         
61         Port *inputPort;
62         Port *outputPort;
63         channel_t inputChannelNumber;
64         channel_t outputChannelNumber;
65
66         int set_input_port (std::string);
67         int set_output_port (std::string);
68         int set_input_channel (channel_t);
69         int set_output_channel (channel_t);
70
71         int foreach_port (int (*func)(const Port &, size_t n, void *), 
72                           void *arg);
73
74         typedef std::map<std::string, Port *> PortMap;
75
76         const PortMap& get_midi_ports() const { return ports_by_tag; } 
77
78         static Manager *instance () {
79                 if (theManager == 0) {
80                         theManager = new Manager;
81                 }
82                 return theManager;
83         }
84
85         int get_known_ports (std::vector<PortSet>&);
86
87   private:
88         /* This is a SINGLETON pattern */
89         
90         Manager ();
91
92         static Manager *theManager;
93         PortMap         ports_by_device; /* canonical */
94         PortMap         ports_by_tag;    /* may contain duplicate Ports */
95
96         void* api_data;
97
98         void close_ports ();
99 };
100
101 } // namespace MIDI
102
103 #endif  // __midi_manager_h__