ardour
port.h
Go to the documentation of this file.
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 #include "libardour-config.h"
24 
25 #include <set>
26 #include <string>
27 #include <vector>
28 #include <boost/utility.hpp>
29 #include "pbd/signals.h"
30 
31 #include "ardour/data_type.h"
32 #include "ardour/port_engine.h"
34 #include "ardour/types.h"
35 
36 namespace ARDOUR {
37 
38 class AudioEngine;
39 class Buffer;
40 
41 class LIBARDOUR_API Port : public boost::noncopyable
42 {
43 public:
44  virtual ~Port ();
45 
46  static void set_connecting_blocked( bool yn ) {
47  _connecting_blocked = yn;
48  }
49  static bool connecting_blocked() {
50  return _connecting_blocked;
51  }
52 
54  std::string name () const {
55  return _name;
56  }
57 
59  std::string pretty_name (bool fallback_to_name = false) const;
60 
61  int set_name (std::string const &);
62 
64  PortFlags flags () const {
65  return _flags;
66  }
67 
69  bool receives_input () const {
70  return _flags & IsInput;
71  }
72 
74  bool sends_output () const {
75  return _flags & IsOutput;
76  }
77 
78  bool connected () const;
79  int disconnect_all ();
80  int get_connections (std::vector<std::string> &) const;
81 
82  /* connection by name */
83  bool connected_to (std::string const &) const;
84  int connect (std::string const &);
85  int disconnect (std::string const &);
86 
87  /* connection by Port* */
88  bool connected_to (Port *) const;
89  virtual int connect (Port *);
90  int disconnect (Port *);
91 
92  void request_input_monitoring (bool);
93  void ensure_input_monitoring (bool);
94  bool monitoring_input () const;
95  int reestablish ();
96  int reconnect ();
97 
98  bool last_monitor() const { return _last_monitor; }
99  void set_last_monitor (bool yn) { _last_monitor = yn; }
100 
101  PortEngine::PortHandle port_handle() { return _port_handle; }
102 
103  void get_connected_latency_range (LatencyRange& range, bool playback) const;
104 
105  void set_private_latency_range (LatencyRange& range, bool playback);
106  const LatencyRange& private_latency_range (bool playback) const;
107 
108  void set_public_latency_range (LatencyRange& range, bool playback) const;
109  LatencyRange public_latency_range (bool playback) const;
110 
111  virtual void reset ();
112 
113  virtual DataType type () const = 0;
114  virtual void cycle_start (pframes_t);
115  virtual void cycle_end (pframes_t) = 0;
116  virtual void cycle_split () = 0;
117  virtual Buffer& get_buffer (pframes_t nframes) = 0;
118  virtual void flush_buffers (pframes_t /*nframes*/) {}
119  virtual void transport_stopped () {}
120  virtual void realtime_locate () {}
121 
122  bool physically_connected () const;
123 
124  PBD::Signal1<void,bool> MonitorInputChanged;
125  static PBD::Signal2<void,boost::shared_ptr<Port>,boost::shared_ptr<Port> > PostDisconnect;
126  static PBD::Signal0<void> PortDrop;
127 
128  static void set_cycle_framecnt (pframes_t n) {
129  _cycle_nframes = n;
130  }
131  static framecnt_t port_offset() { return _global_port_buffer_offset; }
133  _global_port_buffer_offset = off;
134  }
136  _global_port_buffer_offset += n;
137  }
138 
139  virtual void increment_port_buffer_offset (pframes_t n);
140 
141  virtual XMLNode& get_state (void) const;
142  virtual int set_state (const XMLNode&, int version);
143 
144  static std::string state_node_name;
145 
146 protected:
147 
148  Port (std::string const &, DataType, PortFlags);
149 
151 
152  static bool _connecting_blocked;
153  static pframes_t _global_port_buffer_offset; /* access only from process() tree */
154  static pframes_t _cycle_nframes; /* access only from process() tree */
155 
156  framecnt_t _port_buffer_offset; /* access only from process() tree */
157 
160 
161 private:
162  std::string _name;
165 
169  std::set<std::string> _connections;
170 
171  void drop ();
173 };
174 
175 }
176 
177 #endif /* __ardour_port_h__ */
static void increment_global_port_buffer_offset(pframes_t n)
Definition: port.h:135
static bool connecting_blocked()
Definition: port.h:49
void set_last_monitor(bool yn)
Definition: port.h:99
PBD::ScopedConnection drop_connection
Definition: port.h:172
static std::string state_node_name
Definition: port.h:144
bool sends_output() const
Definition: port.h:74
std::string _name
port short name
Definition: port.h:162
uint32_t pframes_t
Definition: types.h:61
static PBD::Signal2< void, boost::shared_ptr< Port >, boost::shared_ptr< Port > > PostDisconnect
Definition: port.h:125
static bool _connecting_blocked
Definition: port.h:152
PBD::Signal1< void, bool > MonitorInputChanged
Definition: port.h:124
std::string name() const
Definition: port.h:54
PortEngine::PortHandle port_handle()
Definition: port.h:101
static framecnt_t port_offset()
Definition: port.h:131
static PBD::Signal0< void > PortDrop
Definition: port.h:126
LatencyRange _private_playback_latency
Definition: port.h:158
framecnt_t _port_buffer_offset
Definition: port.h:156
static pframes_t _cycle_nframes
Definition: port.h:154
bool last_monitor() const
Definition: port.h:98
virtual void realtime_locate()
Definition: port.h:120
int64_t framecnt_t
Definition: types.h:76
Definition: amp.h:29
PortFlags flags() const
Definition: port.h:64
PortFlags
Definition: types.h:610
PortEngine::PortHandle _port_handle
Definition: port.h:150
#define LIBARDOUR_API
bool _last_monitor
Definition: port.h:164
virtual void transport_stopped()
Definition: port.h:119
bool receives_input() const
Definition: port.h:69
Definition: xml++.h:95
std::set< std::string > _connections
Definition: port.h:169
static void set_connecting_blocked(bool yn)
Definition: port.h:46
static pframes_t _global_port_buffer_offset
Definition: port.h:153
LIBARDOUR_API uint64_t AudioEngine
Definition: session.h:982
virtual void flush_buffers(pframes_t)
Definition: port.h:118
static void set_global_port_buffer_offset(pframes_t off)
Definition: port.h:132
static void set_cycle_framecnt(pframes_t n)
Definition: port.h:128
LatencyRange _private_capture_latency
Definition: port.h:159
PortFlags _flags
flags
Definition: port.h:163