2 Copyright (C) 2009 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 __ardour_port_h__
21 #define __ardour_port_h__
26 #include <jack/jack.h>
27 #include <sigc++/trackable.h>
28 #include "ardour/data_type.h"
29 #include "ardour/types.h"
36 class Port : public sigc::trackable
40 IsInput = JackPortIsInput,
41 IsOutput = JackPortIsOutput,
46 /** @return Port short name */
47 std::string name () const {
51 int set_name (std::string const &);
54 Flags flags () const {
58 /** @return true if this Port receives input, otherwise false */
59 bool receives_input () const {
60 return _flags & IsInput;
63 /** @return true if this Port sends output, otherwise false */
64 bool sends_output () const {
65 return _flags & IsOutput;
68 /* @return true if this port is visible outside Ardour (via JACK) */
69 bool external () const {
70 return _jack_port != 0;
73 bool connected () const;
74 bool externally_connected () const;
75 int disconnect_all ();
76 int get_connections (std::vector<std::string> &) const;
78 /* connection by name */
79 bool connected_to (std::string const &) const;
80 int connect (std::string const &);
81 int disconnect (std::string const &);
83 /* connection by Port* */
84 bool connected_to (Port *) const;
85 virtual int connect (Port *);
86 int disconnect (Port *);
88 void ensure_monitor_input (bool);
89 bool monitoring_input () const;
90 nframes_t total_latency () const;
93 void set_latency (nframes_t);
94 void request_monitor_input (bool);
95 void make_external ();
97 virtual void reset ();
99 virtual DataType type () const = 0;
100 virtual void cycle_start (nframes_t, nframes_t) = 0;
101 virtual void cycle_end (nframes_t, nframes_t) = 0;
102 virtual Buffer& get_buffer (nframes_t, nframes_t) = 0;
103 virtual void flush_buffers (nframes_t, nframes_t) {}
105 static void set_engine (AudioEngine *);
107 sigc::signal<void, bool> MonitorInputChanged;
111 Port (std::string const &, DataType, Flags, bool);
113 jack_port_t* _jack_port; ///< JACK port, or 0 if we don't have one
114 std::set<Port*> _connections; ///< internal Ports that we are connected to
116 static AudioEngine* _engine; ///< the AudioEngine
118 virtual bool using_internal_data() const { return false; }
119 virtual void use_internal_data () {}
120 virtual void use_external_data () {}
122 void check_buffer_status ();
125 friend class AudioEngine;
127 void recompute_total_latency () const;
128 void do_make_external (DataType);
134 std::string _name; ///< port short name
135 Flags _flags; ///< flags
137 /// list of JACK ports that we are connected to; we only keep this around
138 /// so that we can implement ::reconnect ()
139 std::set<std::string> _named_connections;