d8b095351cfb01895d34cc66a218556b6bc777df
[ardour.git] / libs / backends / wavesaudio / waves_dataport.h
1 /*
2     Copyright (C) 2013 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 __libardour_waves_dataport_h__
21 #define __libardour_waves_dataport_h__
22
23 #include "ardour/types.h"
24 #include "memory.h"
25         
26 namespace ARDOUR {
27
28 class WavesDataPort {
29 public:
30
31     virtual ~WavesDataPort ();
32
33     inline const std::string& name () const
34     {
35         return _name;
36     }
37     
38     int set_name (const std::string &name)
39     {
40         _name = name;
41         return 0;
42     }
43
44     virtual DataType type () const = 0;
45
46     inline PortFlags flags () const
47     {
48         return _flags;
49     }
50
51     inline bool is_input () { return flags () & IsInput; }
52     inline bool is_output () { return flags () & IsOutput; }
53     inline bool is_physical () { return flags () & IsPhysical; }
54     inline bool is_terminal () { return flags () & IsTerminal; }
55     inline operator void* () { return (void*)this; }
56
57     inline const LatencyRange& latency_range (bool for_playback) const
58     {
59         return for_playback ? _playback_latency_range : _capture_latency_range;
60     }
61
62     inline void set_latency_range (const LatencyRange &latency_range, bool for_playback)
63     {
64         if (for_playback)
65         {
66             _playback_latency_range = latency_range;
67         }
68         else
69         {
70             _capture_latency_range = latency_range;
71         }
72     }
73
74     int connect (WavesDataPort *port);
75     
76     int disconnect (WavesDataPort *port);
77     
78     void disconnect_all ();
79
80     bool inline is_connected (const WavesDataPort *port) const
81     {
82         return std::find (_connections.begin (), _connections.end (), port) != _connections.end ();
83     }
84
85     bool inline is_connected () const
86     {
87         return _connections.size () != 0;
88     }
89
90     bool is_physically_connected () const;
91
92     inline const std::vector<WavesDataPort *>& get_connections () const { return _connections; }
93
94     virtual void* get_buffer (pframes_t nframes) = 0;
95
96 protected:
97     WavesDataPort (const std::string& inport_name, PortFlags inflags);
98         virtual void _wipe_buffer() = 0;
99
100 private:
101
102     std::string _name;
103     const PortFlags _flags;
104     LatencyRange _capture_latency_range;
105     LatencyRange  _playback_latency_range;
106     std::vector<WavesDataPort*> _connections;
107
108     void _connect (WavesDataPort* port, bool api_call);
109     void _disconnect (WavesDataPort* port, bool api_call);
110 };
111
112 } // namespace
113
114 #endif /* __libardour_waves_dataport_h__ */
115