Strip trailing whitespace and fix other whitespace errors (e.g. space/tab mixing...
[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 #include <set>
24 #include <string>
25 #include <vector>
26 #include <jack/jack.h>
27 #include <boost/utility.hpp>
28 #include <sigc++/trackable.h>
29 #include "ardour/data_type.h"
30 #include "ardour/types.h"
31
32 namespace ARDOUR {
33
34 class AudioEngine;
35 class Buffer;
36
37 class Port : public sigc::trackable, public boost::noncopyable
38 {
39 public:
40         enum Flags {
41                 IsInput = JackPortIsInput,
42                 IsOutput = JackPortIsOutput,
43         };
44
45         virtual ~Port ();
46
47         static nframes_t port_offset() { return _port_offset; }
48
49         static void set_port_offset (nframes_t off) {
50                 _port_offset = off;
51         }
52         static void increment_port_offset (nframes_t n) {
53                 _port_offset += n;
54         }
55         static void set_buffer_size (nframes_t sz) {
56                 _buffer_size = sz;
57         }
58
59         /** @return Port short name */
60         std::string name () const {
61                 return _name;
62         }
63
64         int set_name (std::string const &);
65
66         /** @return flags */
67         Flags 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 ensure_monitor_input (bool);
96         bool monitoring_input () const;
97         nframes_t total_latency () const;
98         int reestablish ();
99         int reconnect ();
100         void request_monitor_input (bool);
101         void set_latency (nframes_t);
102
103         virtual void reset ();
104
105         /** @return the size of the raw buffer (bytes) for duration @a nframes (audio frames) */
106         virtual size_t raw_buffer_size(jack_nframes_t nframes) const = 0;
107
108         virtual DataType type () const = 0;
109         virtual void cycle_start (nframes_t) = 0;
110         virtual void cycle_end (nframes_t) = 0;
111         virtual void cycle_split () = 0;
112         virtual Buffer& get_buffer (nframes_t nframes, nframes_t offset = 0) = 0;
113         virtual void flush_buffers (nframes_t, nframes_t offset = 0) {
114                 (void) offset;
115         }
116
117         static void set_engine (AudioEngine *);
118
119         sigc::signal<void, bool> MonitorInputChanged;
120
121 protected:
122
123         Port (std::string const &, DataType, Flags);
124
125         jack_port_t* _jack_port; ///< JACK port
126
127         static nframes_t _port_offset;
128         static nframes_t _buffer_size;
129
130         static AudioEngine* _engine; ///< the AudioEngine
131
132 private:
133         friend class AudioEngine;
134
135         void recompute_total_latency () const;
136
137         /* XXX */
138         bool _last_monitor;
139
140         std::string _name;  ///< port short name
141         Flags       _flags; ///< flags
142
143         /** ports that we are connected to, kept so that we can
144             reconnect to JACK when required */
145         std::set<std::string> _connections;
146 };
147
148 }
149
150 #endif /* __ardour_port_h__ */