ardour
port_engine.h
Go to the documentation of this file.
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_port_engine_h__
21 #define __libardour_port_engine_h__
22 
23 #include <vector>
24 #include <string>
25 
26 #include <stdint.h>
27 
28 #include "ardour/data_type.h"
30 #include "ardour/types.h"
31 
32 namespace ARDOUR {
33 
34 class PortManager;
35 
79  public:
80  PortEngine (PortManager& pm) : manager (pm) {}
81  virtual ~PortEngine() {}
82 
86  virtual void* private_handle() const = 0;
87 
88  /* We use void* here so that the API can be defined for any implementation.
89  *
90  * We could theoretically use a template (PortEngine<T>) and define
91  * PortHandle as T, but this complicates the desired inheritance
92  * pattern in which FooPortEngine handles things for the Foo API,
93  * rather than being a derivative of PortEngine<Foo>.
94  */
95 
96  typedef void* PortHandle;
97 
101  virtual const std::string& my_name() const = 0;
102 
107  virtual bool available() const = 0;
108 
111  virtual uint32_t port_name_size() const = 0;
112 
116  virtual int set_port_name (PortHandle port, const std::string& name) = 0;
120  virtual std::string get_port_name (PortHandle) const = 0;
121 
139  virtual int get_port_property (PortHandle, const std::string& key, std::string& value, std::string& type) const { return -1; }
140 
144  virtual PortHandle get_port_by_name (const std::string&) const = 0;
145 
157  virtual int get_ports (const std::string& port_name_pattern, DataType type, PortFlags flags, std::vector<std::string>& ports) const = 0;
158 
162  virtual DataType port_data_type (PortHandle port) const = 0;
163 
169  virtual PortHandle register_port (const std::string& shortname, ARDOUR::DataType type, ARDOUR::PortFlags flags) = 0;
170 
171  /* Destroy the port referred to by @param port, including all resources
172  * associated with it. This will also disconnect @param port from any ports it
173  * is connected to.
174  */
175  virtual void unregister_port (PortHandle) = 0;
176 
177  /* Connection management */
178 
183  virtual int connect (const std::string& src, const std::string& dst) = 0;
184 
188  virtual int disconnect (const std::string& src, const std::string& dst) = 0;
189 
190 
195  virtual int connect (PortHandle src, const std::string& dst) = 0;
199  virtual int disconnect (PortHandle src, const std::string& dst) = 0;
200 
204  virtual int disconnect_all (PortHandle port) = 0;
205 
209  virtual bool connected (PortHandle port, bool process_callback_safe = true) = 0;
213  virtual bool connected_to (PortHandle, const std::string& name, bool process_callback_safe = true) = 0;
214 
218  virtual bool physically_connected (PortHandle port, bool process_callback_safe = true) = 0;
219 
223  virtual int get_connections (PortHandle port, std::vector<std::string>& names, bool process_callback_safe = true) = 0;
224 
225  /* MIDI */
226 
237  virtual int midi_event_get (pframes_t& timestamp, size_t& size, uint8_t** buf, void* port_buffer, uint32_t event_index) = 0;
238 
248  virtual int midi_event_put (void* port_buffer, pframes_t timestamp, const uint8_t* buffer, size_t size) = 0;
249 
252  virtual uint32_t get_midi_event_count (void* port_buffer) = 0;
253 
260  virtual void midi_clear (void* port_buffer) = 0;
261 
262  /* Monitoring */
263 
272  virtual bool can_monitor_input() const = 0;
283  virtual int request_input_monitoring (PortHandle port, bool yn) = 0;
284  /* Force input monitoring of the hardware channel represented by the port
285  * referred to by @param port to be on or off, depending on the true/false
286  * status of @param yn. The request count is ignored when using this
287  * method, so if this is called with yn set to false, input monitoring will
288  * be disabled regardless of the number of requests to enable it.
289  */
290  virtual int ensure_input_monitoring (PortHandle port, bool yn) = 0;
295  virtual bool monitoring_input (PortHandle port) = 0;
296 
297  /* Latency management
298  */
299 
304  virtual void set_latency_range (PortHandle port, bool for_playback, LatencyRange r) = 0;
309  virtual LatencyRange get_latency_range (PortHandle port, bool for_playback) = 0;
310 
311  /* Discovering physical ports */
312 
316  virtual bool port_is_physical (PortHandle port) const = 0;
317 
323  virtual void get_physical_outputs (DataType type, std::vector<std::string>& names) = 0;
329  virtual void get_physical_inputs (DataType type, std::vector<std::string>& names) = 0;
333  virtual ChanCount n_physical_outputs () const = 0;
337  virtual ChanCount n_physical_inputs () const = 0;
338 
346  virtual void* get_buffer (PortHandle, pframes_t) = 0;
347 
348  /* MIDI ports (the ones in libmidi++) need this to be able to correctly
349  * schedule MIDI events within their buffers. It is a bit odd that we
350  * expose this here, because it is also exposed by AudioBackend, but they
351  * only have access to a PortEngine object, not an AudioBackend.
352  *
353  * Return the time according to the sample clock in use when the current
354  * buffer process cycle began.
355  *
356  * XXX to be removed after some more design cleanup.
357  */
358  virtual framepos_t sample_time_at_cycle_start () = 0;
359 
360  protected:
362 };
363 
364 }
365 
366 #endif /* __libardour_port_engine_h__ */
virtual ~PortEngine()
Definition: port_engine.h:81
virtual int get_port_property(PortHandle, const std::string &key, std::string &value, std::string &type) const
Definition: port_engine.h:139
uint32_t pframes_t
Definition: types.h:61
Definition: amp.h:29
PortFlags
Definition: types.h:610
int64_t framepos_t
Definition: types.h:66
#define LIBARDOUR_API
const char * name
PortManager & manager
Definition: port_engine.h:361
PortEngine(PortManager &pm)
Definition: port_engine.h:80