remove unnecessary files from native audio backend
[ardour.git] / libs / backends / wavesaudio / waves_dataport.cc
1 /*\r
2     Copyright (C) 2014 Waves Audio Ltd.\r
3 \r
4     This program is free software; you can redistribute it and/or modify\r
5     it under the terms of the GNU General Public License as published by\r
6     the Free Software Foundation; either version 2 of the License, or\r
7     (at your option) any later version.\r
8 \r
9     This program is distributed in the hope that it will be useful,\r
10     but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
12     GNU General Public License for more details.\r
13 \r
14     You should have received a copy of the GNU General Public License\r
15     along with this program; if not, write to the Free Software\r
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
17 \r
18 */\r
19 \r
20 #include "waves_dataport.h"\r
21 \r
22 using namespace ARDOUR;\r
23 \r
24 WavesDataPort::WavesDataPort (const std::string& inport_name, PortFlags inflags)\r
25     : _name (inport_name)\r
26     , _flags (inflags)\r
27 {\r
28     _capture_latency_range.min = \r
29     _capture_latency_range.max = \r
30     _playback_latency_range.min = \r
31     _playback_latency_range.max = 0;\r
32 }\r
33 \r
34 \r
35 WavesDataPort::~WavesDataPort ()\r
36 {\r
37     disconnect_all ();\r
38 }\r
39 \r
40 \r
41 int WavesDataPort::connect (WavesDataPort *port)\r
42 {\r
43     if (!port) {\r
44         std::cerr << "WavesDataPort::connect (): invalid (null) port to connect to!" << std::endl;\r
45         return -1;\r
46     }\r
47 \r
48     if (type () != port->type ())    {\r
49         std::cerr << "WavesDataPort::connect (): wrong type of the port to connect to!" << std::endl;\r
50         return -1;\r
51     }\r
52 \r
53     if (is_output () && port->is_output ()) {\r
54         std::cerr << "WavesDataPort::connect (): attempt to connect output port to output port!" << std::endl;\r
55         return -1;\r
56     }\r
57 \r
58     if (is_input () && port->is_input ()) {\r
59         std::cerr << "WavesDataPort::connect (): attempt to connect input port to input port!" << std::endl;\r
60         return -1;\r
61     }\r
62 \r
63     if (this == port) {\r
64         std::cerr << "WavesDataPort::connect (): attempt to connect port to itself!" << std::endl;\r
65         return -1; \r
66     }\r
67 \r
68     if (is_connected (port)) {\r
69         std::cerr << "WavesDataPort::connect (): the ports are already connected!" << std::endl;\r
70         return -1;\r
71     }\r
72 \r
73     _connect (port, true);\r
74     return 0;\r
75 }\r
76 \r
77 \r
78 void WavesDataPort::_connect (WavesDataPort *port, bool api_call)\r
79 {\r
80     _connections.push_back (port);\r
81     if (api_call) {\r
82         port->_connect (this, false);\r
83     }\r
84 }\r
85 \r
86 \r
87 int WavesDataPort::disconnect (WavesDataPort *port)\r
88 {\r
89     if (port == NULL) {\r
90         std::cerr << "WavesDataPort::disconnect (): invalid (null) port to disconnect from!" << std::endl;\r
91         return -1;\r
92     }\r
93 \r
94     if (!is_connected (port)) {\r
95         std::cerr << "WavesDataPort::disconnect (): the ports are not connected!" << std::endl;\r
96         return -1;\r
97     }\r
98         \r
99     _disconnect (port, true);\r
100 \r
101     return 0;\r
102 }\r
103 \r
104 \r
105 void WavesDataPort::_disconnect (WavesDataPort *port, bool api_call)\r
106 {\r
107     std::vector<WavesDataPort*>::iterator it = std::find (_connections.begin (), _connections.end (), port);\r
108     \r
109     if (it != _connections.end ()) { // actually, it's supposed to be always true.\r
110         _connections.erase (it);\r
111     }\r
112 \r
113     if (api_call) {\r
114         port->_disconnect (this, false);\r
115     }\r
116 \r
117         if (is_input() && _connections.empty())\r
118         {\r
119                 _wipe_buffer();\r
120         }\r
121 }\r
122 \r
123 \r
124 void WavesDataPort::disconnect_all ()\r
125 {\r
126     while (!_connections.empty ()) {\r
127         _connections.back ()->_disconnect (this, false);\r
128         _connections.pop_back ();\r
129     }\r
130 }\r
131 \r
132 \r
133 bool WavesDataPort::is_physically_connected () const\r
134 {\r
135     for (std::vector<WavesDataPort*>::const_iterator it = _connections.begin (); it != _connections.end (); ++it) {\r
136         if ((*it)->is_physical ()) {\r
137             return true;\r
138         }\r
139     }\r
140 \r
141     return false;\r
142 }\r