perhaps, just possibly, a working solo model. needs to be fixed so that connections...
[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 "pbd/signals.h"
29
30 #include "ardour/data_type.h"
31 #include "ardour/types.h"
32
33 namespace ARDOUR {
34
35 class AudioEngine;
36 class Buffer;
37
38 class Port : public boost::noncopyable
39 {
40 public:
41         enum Flags {
42                 IsInput = JackPortIsInput,
43                 IsOutput = JackPortIsOutput,
44         };
45
46         virtual ~Port ();
47
48         static nframes_t port_offset() { return _port_offset; }
49
50         static void set_port_offset (nframes_t off) {
51                 _port_offset = off;
52         }
53         static void increment_port_offset (nframes_t n) {
54                 _port_offset += n;
55         }
56         static void set_buffer_size (nframes_t sz) {
57                 _buffer_size = sz;
58         }
59
60         /** @return Port short name */
61         std::string name () const {
62                 return _name;
63         }
64
65         int set_name (std::string const &);
66
67         /** @return flags */
68         Flags flags () const {
69                 return _flags;
70         }
71
72         /** @return true if this Port receives input, otherwise false */
73         bool receives_input () const {
74                 return _flags & IsInput;
75         }
76
77         /** @return true if this Port sends output, otherwise false */
78         bool sends_output () const {
79                 return _flags & IsOutput;
80         }
81
82         bool connected () const;
83         int disconnect_all ();
84         int get_connections (std::vector<std::string> &) const;
85
86         /* connection by name */
87         bool connected_to (std::string const &) const;
88         int connect (std::string const &);
89         int disconnect (std::string const &);
90
91         /* connection by Port* */
92         bool connected_to (Port *) const;
93         virtual int connect (Port *);
94         int disconnect (Port *);
95
96         void ensure_monitor_input (bool);
97         bool monitoring_input () const;
98         nframes_t total_latency () const;
99         int reestablish ();
100         int reconnect ();
101         void request_monitor_input (bool);
102         void set_latency (nframes_t);
103
104         virtual void reset ();
105
106         /** @return the size of the raw buffer (bytes) for duration @a nframes (audio frames) */
107         virtual size_t raw_buffer_size(jack_nframes_t nframes) const = 0;
108
109         virtual DataType type () const = 0;
110         virtual void cycle_start (nframes_t) = 0;
111         virtual void cycle_end (nframes_t) = 0;
112         virtual void cycle_split () = 0;
113         virtual Buffer& get_buffer (nframes_t nframes, nframes_t offset = 0) = 0;
114         virtual void flush_buffers (nframes_t nframes, nframes64_t /*time*/, nframes_t offset = 0) {
115                 assert(offset < nframes);
116         }
117         virtual void transport_stopped () {}
118
119         bool physically_connected () const;
120
121         static void set_engine (AudioEngine *);
122
123         PBD::Signal1<void,bool> MonitorInputChanged;
124
125 protected:
126
127         Port (std::string const &, DataType, Flags);
128
129         jack_port_t* _jack_port; ///< JACK port
130
131         static nframes_t _port_offset;
132         static nframes_t _buffer_size;
133         
134         static AudioEngine* _engine; ///< the AudioEngine
135
136 private:
137         friend class AudioEngine;
138
139         void recompute_total_latency () const;
140
141         /* XXX */
142         bool _last_monitor;
143
144         std::string _name;  ///< port short name
145         Flags       _flags; ///< flags
146
147         /** ports that we are connected to, kept so that we can
148             reconnect to JACK when required */
149         std::set<std::string> _connections;
150 };
151
152 }
153
154 #endif /* __ardour_port_h__ */