Make sure that 'libardour-config,h' only gets #included when building with waf (as...
[ardour.git] / libs / ardour / ardour / port.h
1 /*
2     Copyright (C) 2009 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 __ardour_port_h__
21 #define __ardour_port_h__
22
23 #ifdef WAF_BUILD
24 #include "libardour-config.h"
25 #endif
26
27 #include <set>
28 #include <string>
29 #include <vector>
30 #include <boost/utility.hpp>
31 #include "pbd/signals.h"
32
33 #include "ardour/data_type.h"
34 #include "ardour/port_engine.h"
35 #include "ardour/libardour_visibility.h"
36 #include "ardour/types.h"
37
38 namespace ARDOUR {
39
40 class AudioEngine;
41 class Buffer;
42
43 class LIBARDOUR_API Port : public boost::noncopyable
44 {
45 public:
46         virtual ~Port ();
47
48         static void set_connecting_blocked( bool yn ) {
49                 _connecting_blocked = yn;
50         }
51         static bool connecting_blocked() {
52                 return _connecting_blocked;
53         }
54
55         /** @return Port short name */
56         std::string name () const {
57                 return _name;
58         }
59
60         /** @return Port human readable name */
61         std::string pretty_name (bool fallback_to_name = false) const;
62         bool set_pretty_name (const std::string&);
63
64         int set_name (std::string const &);
65
66         /** @return flags */
67         PortFlags flags () const {
68                 return _flags;
69         }
70
71         /** @return true if this Port receives input, otherwise false */
72         bool receives_input () const {
73                 return _flags & IsInput;
74         }
75
76         /** @return true if this Port sends output, otherwise false */
77         bool sends_output () const {
78                 return _flags & IsOutput;
79         }
80
81         bool connected () const;
82         int disconnect_all ();
83         int get_connections (std::vector<std::string> &) const;
84
85         /* connection by name */
86         bool connected_to (std::string const &) const;
87         int connect (std::string const &);
88         int disconnect (std::string const &);
89
90         /* connection by Port* */
91         bool connected_to (Port *) const;
92         virtual int connect (Port *);
93         int disconnect (Port *);
94
95         void request_input_monitoring (bool);
96         void ensure_input_monitoring (bool);
97         bool monitoring_input () const;
98         int reestablish ();
99         int reconnect ();
100
101         bool last_monitor() const { return _last_monitor; }
102         void set_last_monitor (bool yn) { _last_monitor = yn; }
103
104         PortEngine::PortHandle port_handle() { return _port_handle; }
105
106         void get_connected_latency_range (LatencyRange& range, bool playback) const;
107
108         void set_private_latency_range (LatencyRange& range, bool playback);
109         const LatencyRange&  private_latency_range (bool playback) const;
110
111         void set_public_latency_range (LatencyRange const& range, bool playback) const;
112         LatencyRange public_latency_range (bool playback) const;
113
114         virtual void reset ();
115
116         virtual DataType type () const = 0;
117         virtual void cycle_start (pframes_t);
118         virtual void cycle_end (pframes_t) = 0;
119         virtual void cycle_split () = 0;
120         virtual Buffer& get_buffer (pframes_t nframes) = 0;
121         virtual void flush_buffers (pframes_t /*nframes*/) {}
122         virtual void transport_stopped () {}
123         virtual void realtime_locate () {}
124
125         bool physically_connected () const;
126         bool externally_connected () const;
127
128         PBD::Signal1<void,bool> MonitorInputChanged;
129         static PBD::Signal2<void,boost::shared_ptr<Port>,boost::shared_ptr<Port> > PostDisconnect;
130         static PBD::Signal0<void> PortDrop;
131         static PBD::Signal0<void> PortSignalDrop;
132
133         static void set_speed_ratio (double s);
134         static void set_cycle_samplecnt (pframes_t n);
135
136         static samplecnt_t port_offset() { return _global_port_buffer_offset; }
137         static void set_global_port_buffer_offset (pframes_t off) {
138                 _global_port_buffer_offset = off;
139         }
140         static void increment_global_port_buffer_offset (pframes_t n) {
141                 _global_port_buffer_offset += n;
142         }
143
144         virtual XMLNode& get_state (void) const;
145         virtual int set_state (const XMLNode&, int version);
146
147         static std::string state_node_name;
148
149         static pframes_t cycle_nframes () { return _cycle_nframes; }
150         static double speed_ratio () { return _speed_ratio; }
151
152 protected:
153
154         Port (std::string const &, DataType, PortFlags);
155
156         PortEngine::PortHandle _port_handle;
157
158         static bool           _connecting_blocked;
159         static pframes_t  _cycle_nframes; /* access only from process() tree */
160
161         static pframes_t  _global_port_buffer_offset; /* access only from process() tree */
162
163         LatencyRange _private_playback_latency;
164         LatencyRange _private_capture_latency;
165
166         static double _speed_ratio;
167         static const uint32_t _resampler_quality; /* also latency of the resampler */
168
169 private:
170         std::string _name;  ///< port short name
171         PortFlags   _flags; ///< flags
172         bool        _last_monitor;
173
174         /** ports that we are connected to, kept so that we can
175             reconnect to the backend when required
176         */
177         std::set<std::string> _connections;
178
179         void port_connected_or_disconnected (boost::weak_ptr<Port>, boost::weak_ptr<Port>, bool);
180         void signal_drop ();
181         void drop ();
182         PBD::ScopedConnection drop_connection;
183         PBD::ScopedConnection engine_connection;
184 };
185
186 }
187
188 #endif /* __ardour_port_h__ */