Return silence from read_from_sources() if we try to read a channel that our source...
[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 <list>
24
25 #include <string>
26
27 #include "pbd/rcu.h"
28
29 #include "midi++/types.h"
30 #include "midi++/port.h"
31
32 namespace MIDI {
33
34 class MachineControl;   
35
36 class Manager {
37   public:
38         ~Manager ();
39         
40         /** Signal the start of an audio cycle.
41          * This MUST be called before any reading/writing for this cycle.
42          * Realtime safe.
43          */
44         void cycle_start (pframes_t nframes);
45         
46         /** Signal the end of an audio cycle.
47          * This signifies that the cycle began with @ref cycle_start has ended.
48          * This MUST be called at the end of each cycle.
49          * Realtime safe.
50          */
51         void cycle_end ();
52
53         MachineControl* mmc () const { return _mmc; }
54         Port *mtc_input_port() const { return _mtc_input_port; }
55         Port *mtc_output_port() const { return _mtc_output_port; }
56         Port *midi_input_port() const { return _midi_input_port; }
57         Port *midi_output_port() const { return _midi_output_port; }
58         Port *midi_clock_input_port() const { return _midi_clock_input_port; }
59         Port *midi_clock_output_port() const { return _midi_clock_output_port; }
60
61         Port* add_port (Port *);
62         void remove_port (Port *);
63
64         Port* port (std::string const &);
65
66         void set_port_states (std::list<XMLNode*>);
67
68         typedef std::list<Port *> PortList;
69
70         boost::shared_ptr<const PortList> get_midi_ports() const { return _ports.reader (); } 
71
72         static void create (jack_client_t* jack);
73         
74         static Manager *instance () {
75                 return theManager;
76         }
77         static void destroy ();
78
79         void reestablish (jack_client_t *);
80         void reconnect ();
81
82         PBD::Signal0<void> PortsChanged;
83
84   private:
85         /* This is a SINGLETON pattern */
86         
87         Manager (jack_client_t *);
88         static Manager *theManager;
89
90         MIDI::MachineControl*   _mmc;
91         MIDI::Port*         _mtc_input_port;
92         MIDI::Port*         _mtc_output_port;
93         MIDI::Port*         _midi_input_port;
94         MIDI::Port*         _midi_output_port;
95         MIDI::Port*         _midi_clock_input_port;
96         MIDI::Port*         _midi_clock_output_port;
97
98         SerializedRCUManager<PortList> _ports;
99 };
100
101 } // namespace MIDI
102
103 #endif  // __midi_manager_h__