ardour
port_manager.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 Paul 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 __libardour_port_manager_h__
21 #define __libardour_port_manager_h__
22 
23 #include <vector>
24 #include <string>
25 #include <exception>
26 #include <map>
27 
28 #include <stdint.h>
29 
30 #include <boost/shared_ptr.hpp>
31 
32 #include "pbd/rcu.h"
33 
34 #include "ardour/chan_count.h"
36 #include "ardour/port.h"
37 
38 namespace ARDOUR {
39 
40 class PortEngine;
41 class AudioBackend;
42 
44 {
45  public:
46  typedef std::map<std::string,boost::shared_ptr<Port> > Ports;
47  typedef std::list<boost::shared_ptr<Port> > PortList;
48 
49  PortManager ();
50  virtual ~PortManager() {}
51 
53 
54  uint32_t port_name_size() const;
55  std::string my_name() const;
56 
57  /* Port registration */
58 
59  boost::shared_ptr<Port> register_input_port (DataType, const std::string& portname, bool async = false);
60  boost::shared_ptr<Port> register_output_port (DataType, const std::string& portname, bool async = false);
61  int unregister_port (boost::shared_ptr<Port>);
62 
63  /* Port connectivity */
64 
65  int connect (const std::string& source, const std::string& destination);
66  int disconnect (const std::string& source, const std::string& destination);
67  int disconnect (boost::shared_ptr<Port>);
68  int reestablish_ports ();
69  int reconnect_ports ();
70 
71  bool connected (const std::string&);
72  bool connected_to (const std::string&, const std::string&);
73  bool physically_connected (const std::string&);
74  int get_connections (const std::string&, std::vector<std::string>&);
75 
76  /* Naming */
77 
78  boost::shared_ptr<Port> get_port_by_name (const std::string &);
79  void port_renamed (const std::string&, const std::string&);
80  std::string make_port_name_relative (const std::string& name) const;
81  std::string make_port_name_non_relative (const std::string& name) const;
82  std::string get_pretty_name_by_name (const std::string& portname) const;
83  bool port_is_mine (const std::string& fullname) const;
84 
85  /* other Port management */
86 
87  bool port_is_physical (const std::string&) const;
88  void get_physical_outputs (DataType type, std::vector<std::string>&);
89  void get_physical_inputs (DataType type, std::vector<std::string>&);
90  ChanCount n_physical_outputs () const;
91  ChanCount n_physical_inputs () const;
92 
93  int get_ports (const std::string& port_name_pattern, DataType type, PortFlags flags, std::vector<std::string>&);
94  int get_ports (DataType, PortList&);
95 
96  void remove_all_ports ();
97 
98  /* per-Port monitoring */
99 
100  bool can_request_input_monitoring () const;
101  void request_input_monitoring (const std::string&, bool) const;
102  void ensure_input_monitoring (const std::string&, bool) const;
103 
104  class PortRegistrationFailure : public std::exception {
105  public:
106  PortRegistrationFailure (std::string const & why = "")
107  : reason (why) {}
108 
110 
111  const char *what() const throw () { return reason.c_str(); }
112 
113  private:
114  std::string reason;
115  };
116 
117  /* the port engine will invoke these callbacks when the time is right */
118 
119  void registration_callback ();
120  int graph_order_callback ();
121  void connect_callback (const std::string&, const std::string&, bool connection);
122 
123  bool port_remove_in_progress() const { return _port_remove_in_progress; }
124 
126  PBD::Signal0<void> GraphReordered;
127 
129  PBD::Signal0<void> PortRegisteredOrUnregistered;
130 
136  PBD::Signal5<void, boost::weak_ptr<Port>, std::string, boost::weak_ptr<Port>, std::string, bool> PortConnectedOrDisconnected;
137 
138  protected:
142 
143  boost::shared_ptr<Port> register_port (DataType type, const std::string& portname, bool input, bool async = false);
144  void port_registration_failure (const std::string& portname);
145 
149 
150  void fade_out (gain_t, gain_t, pframes_t);
151  void silence (pframes_t nframes);
152  void silence_outputs (pframes_t nframes);
153  void check_monitoring ();
158  void cycle_start (pframes_t nframes);
159 
165  void cycle_end (pframes_t nframes);
166 };
167 
168 
169 
170 } // namespace
171 
172 #endif /* __libardour_port_manager_h__ */
SerializedRCUManager< Ports > ports
Definition: port_manager.h:140
std::map< std::string, boost::shared_ptr< Port > > Ports
Definition: port_manager.h:46
boost::shared_ptr< Ports > _cycle_ports
Definition: port_manager.h:148
uint32_t pframes_t
Definition: types.h:61
float gain_t
Definition: types.h:58
PBD::Signal0< void > GraphReordered
Definition: port_manager.h:126
bool port_remove_in_progress() const
Definition: port_manager.h:123
std::list< boost::shared_ptr< Port > > PortList
Definition: port_manager.h:47
PBD::Signal5< void, boost::weak_ptr< Port >, std::string, boost::weak_ptr< Port >, std::string, bool > PortConnectedOrDisconnected
Definition: port_manager.h:136
#define port_engine
Definition: amp.h:29
LIBARDOUR_API PBD::PropertyDescriptor< boost::shared_ptr< AutomationList > > fade_out
Definition: audioregion.cc:69
PortFlags
Definition: types.h:610
boost::shared_ptr< AudioBackend > _backend
Definition: port_manager.h:139
PortRegistrationFailure(std::string const &why="")
Definition: port_manager.h:106
#define LIBARDOUR_API
const char * name
PBD::Signal0< void > PortRegisteredOrUnregistered
Definition: port_manager.h:129
virtual ~PortManager()
Definition: port_manager.h:50