2 Copyright (C) 2013 Paul Davis
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.
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.
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.
20 #ifndef __libardour_port_manager_h__
21 #define __libardour_port_manager_h__
30 #include <boost/shared_ptr.hpp>
33 #include "pbd/ringbuffer.h"
35 #include "ardour/chan_count.h"
36 #include "ardour/midiport_manager.h"
37 #include "ardour/port.h"
45 class LIBARDOUR_API PortManager
48 typedef std::map<std::string,boost::shared_ptr<Port> > Ports;
49 typedef std::list<boost::shared_ptr<Port> > PortList;
52 virtual ~PortManager() {}
54 PortEngine& port_engine();
56 uint32_t port_name_size() const;
57 std::string my_name() const;
59 /* Port registration */
61 boost::shared_ptr<Port> register_input_port (DataType, const std::string& portname, bool async = false, PortFlags extra_flags = PortFlags (0));
62 boost::shared_ptr<Port> register_output_port (DataType, const std::string& portname, bool async = false, PortFlags extra_flags = PortFlags (0));
63 int unregister_port (boost::shared_ptr<Port>);
65 /* Port connectivity */
67 int connect (const std::string& source, const std::string& destination);
68 int disconnect (const std::string& source, const std::string& destination);
69 int disconnect (boost::shared_ptr<Port>);
70 int disconnect (std::string const &);
71 int reestablish_ports ();
72 int reconnect_ports ();
74 bool connected (const std::string&);
75 bool physically_connected (const std::string&);
76 int get_connections (const std::string&, std::vector<std::string>&);
80 boost::shared_ptr<Port> get_port_by_name (const std::string &);
81 void port_renamed (const std::string&, const std::string&);
82 std::string make_port_name_relative (const std::string& name) const;
83 std::string make_port_name_non_relative (const std::string& name) const;
84 std::string get_pretty_name_by_name (const std::string& portname) const;
85 bool port_is_mine (const std::string& fullname) const;
87 static bool port_is_control_only (std::string const &);
89 /* other Port management */
91 bool port_is_physical (const std::string&) const;
92 void get_physical_outputs (DataType type, std::vector<std::string>&,
93 MidiPortFlags include = MidiPortFlags (0),
94 MidiPortFlags exclude = MidiPortFlags (0));
95 void get_physical_inputs (DataType type, std::vector<std::string>&,
96 MidiPortFlags include = MidiPortFlags (0),
97 MidiPortFlags exclude = MidiPortFlags (0));
98 ChanCount n_physical_outputs () const;
99 ChanCount n_physical_inputs () const;
101 int get_ports (const std::string& port_name_pattern, DataType type, PortFlags flags, std::vector<std::string>&);
102 int get_ports (DataType, PortList&);
104 void remove_all_ports ();
105 void clear_pending_port_deletions ();
106 virtual void add_pending_port_deletion (Port*) = 0;
107 RingBuffer<Port*>& port_deletions_pending () { return _port_deletions_pending; }
109 /* per-Port monitoring */
111 bool can_request_input_monitoring () const;
112 void request_input_monitoring (const std::string&, bool) const;
113 void ensure_input_monitoring (const std::string&, bool) const;
115 class PortRegistrationFailure : public std::exception {
117 PortRegistrationFailure (std::string const & why = "")
120 ~PortRegistrationFailure () throw () {}
122 const char *what() const throw () { return reason.c_str(); }
128 /* the port engine will invoke these callbacks when the time is right */
130 void registration_callback ();
131 int graph_order_callback ();
132 void connect_callback (const std::string&, const std::string&, bool connection);
134 bool port_remove_in_progress() const { return _port_remove_in_progress; }
136 struct MidiPortInformation {
137 std::string pretty_name;
139 MidiPortFlags properties;
141 MidiPortInformation () : input (false) , properties (MidiPortFlags (0)) {}
144 void fill_midi_port_info ();
146 MidiPortInformation midi_port_information (std::string const&);
147 void get_known_midi_ports (std::vector<std::string>&);
148 void get_midi_selection_ports (std::vector<std::string>&);
149 void add_midi_port_flags (std::string const&, MidiPortFlags);
150 void remove_midi_port_flags (std::string const&, MidiPortFlags);
151 void set_midi_port_pretty_name (std::string const&, std::string const&);
153 /** Emitted if the list of ports to be used for MIDI selection tracking changes */
154 PBD::Signal0<void> MidiSelectionPortsChanged;
155 /** Emitted if anything other than the selection property for a MIDI port changes */
156 PBD::Signal0<void> MidiPortInfoChanged;
158 /** Emitted if the backend notifies us of a graph order event */
159 PBD::Signal0<void> GraphReordered;
161 /** Emitted if a Port is registered or unregistered */
162 PBD::Signal0<void> PortRegisteredOrUnregistered;
164 /** Emitted if a Port is connected or disconnected.
165 * The Port parameters are the ports being connected / disconnected, or 0 if they are not known to Ardour.
166 * The std::string parameters are the (long) port names.
167 * The bool parameter is true if ports were connected, or false for disconnected.
169 PBD::Signal5<void, boost::weak_ptr<Port>, std::string, boost::weak_ptr<Port>, std::string, bool> PortConnectedOrDisconnected;
172 boost::shared_ptr<AudioBackend> _backend;
173 SerializedRCUManager<Ports> ports;
174 bool _port_remove_in_progress;
175 RingBuffer<Port*> _port_deletions_pending;
177 boost::shared_ptr<Port> register_port (DataType type, const std::string& portname, bool input, bool async = false, PortFlags extra_flags = PortFlags (0));
178 void port_registration_failure (const std::string& portname);
180 /** List of ports to be used between ::cycle_start() and ::cycle_end()
182 boost::shared_ptr<Ports> _cycle_ports;
184 void fade_out (gain_t, gain_t, pframes_t);
185 void silence (pframes_t nframes, Session *s = 0);
186 void silence_outputs (pframes_t nframes);
187 void check_monitoring ();
188 /** Signal the start of an audio cycle.
189 * This MUST be called before any reading/writing for this cycle.
192 void cycle_start (pframes_t nframes);
194 /** Signal the end of an audio cycle.
195 * This signifies that the cycle began with @ref cycle_start has ended.
196 * This MUST be called at the end of each cycle.
199 void cycle_end (pframes_t nframes);
201 typedef std::map<std::string,MidiPortInformation> MidiPortInfo;
203 mutable Glib::Threads::Mutex midi_port_info_mutex;
204 MidiPortInfo midi_port_info;
206 static std::string midi_port_info_file ();
207 bool midi_info_dirty;
208 void save_midi_port_info ();
209 void load_midi_port_info ();
210 void fill_midi_port_info_locked ();
212 void filter_midi_ports (std::vector<std::string>&, MidiPortFlags, MidiPortFlags);
219 #endif /* __libardour_port_manager_h__ */