Optimize plugin-processing for non-automated params
[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         uint32_t externally_connected () const { return _externally_connected; }
127
128         void increment_external_connections() { _externally_connected++; }
129         void decrement_external_connections() { if (_externally_connected) _externally_connected--; }
130
131         PBD::Signal1<void,bool> MonitorInputChanged;
132         static PBD::Signal2<void,boost::shared_ptr<Port>,boost::shared_ptr<Port> > PostDisconnect;
133         static PBD::Signal0<void> PortDrop;
134         static PBD::Signal0<void> PortSignalDrop;
135
136         static void set_speed_ratio (double s);
137         static void set_cycle_samplecnt (pframes_t n);
138
139         static samplecnt_t port_offset() { return _global_port_buffer_offset; }
140         static void set_global_port_buffer_offset (pframes_t off) {
141                 _global_port_buffer_offset = off;
142         }
143         static void increment_global_port_buffer_offset (pframes_t n) {
144                 _global_port_buffer_offset += n;
145         }
146
147         virtual XMLNode& get_state (void) const;
148         virtual int set_state (const XMLNode&, int version);
149
150         static std::string state_node_name;
151
152         static pframes_t cycle_nframes () { return _cycle_nframes; }
153         static double speed_ratio () { return _speed_ratio; }
154
155 protected:
156
157         Port (std::string const &, DataType, PortFlags);
158
159         PortEngine::PortHandle _port_handle;
160
161         static bool           _connecting_blocked;
162         static pframes_t  _cycle_nframes; /* access only from process() tree */
163
164         static pframes_t  _global_port_buffer_offset; /* access only from process() tree */
165
166         LatencyRange _private_playback_latency;
167         LatencyRange _private_capture_latency;
168
169         static double _speed_ratio;
170         static const uint32_t _resampler_quality; /* also latency of the resampler */
171
172 private:
173         std::string _name;  ///< port short name
174         PortFlags   _flags; ///< flags
175         bool        _last_monitor;
176         uint32_t    _externally_connected;
177
178         /** ports that we are connected to, kept so that we can
179             reconnect to the backend when required
180         */
181         std::set<std::string> _connections;
182
183         void port_connected_or_disconnected (boost::weak_ptr<Port>, boost::weak_ptr<Port>, bool);
184         void signal_drop ();
185         void drop ();
186         PBD::ScopedConnectionList drop_connection;
187         PBD::ScopedConnection engine_connection;
188 };
189
190 }
191
192 #endif /* __ardour_port_h__ */