Ardour  8.12
port_engine.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013-2018 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2015-2018 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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  ProtoPort() {}
81  virtual ~ProtoPort () {}
82 };
83 
85 {
86 public:
87  PortEngine (PortManager& pm) : manager (pm) {}
88  virtual ~PortEngine() {}
89 
93  virtual void* private_handle() const = 0;
94 
108  typedef std::shared_ptr<ProtoPort> PortPtr;
109 
110  /* We use this to declare arguments to methods/functions, in order to
111  * avoid copying shared_ptr<ProtoPort> every time (a practice we use in
112  * other contexts where we pass shared_ptr<T>).
113  */
114  typedef PortPtr const & PortHandle;
115 
119  virtual const std::string& my_name() const = 0;
120 
122  virtual uint32_t port_name_size() const = 0;
123 
130  virtual int set_port_name (PortHandle port, const std::string& name) = 0;
131 
138  virtual std::string get_port_name (PortHandle port) const = 0;
139 
146  virtual PortFlags get_port_flags (PortHandle port) const = 0;
147 
165  virtual int get_port_property (PortHandle, const std::string& key, std::string& value, std::string& type) const { return -1; }
166 
176  virtual int set_port_property (PortHandle, const std::string& key, const std::string& value, const std::string& type) { return -1; }
177 
183  virtual PortPtr get_port_by_name (const std::string& name) const = 0;
184 
194  virtual int get_ports (const std::string& port_name_pattern, DataType type, PortFlags flags, std::vector<std::string>& ports) const = 0;
195 
202  virtual DataType port_data_type (PortHandle port) const = 0;
203 
213  virtual PortPtr register_port (const std::string& shortname, ARDOUR::DataType type, ARDOUR::PortFlags flags) = 0;
214 
215  /* Destroy the port referred to by \p port, including all resources
216  * associated with it. This will also disconnect \p port from any ports it
217  * is connected to.
218  *
219  * @param port \ref PortHandle of the port to destroy
220  */
221  virtual void unregister_port (PortHandle port) = 0;
222 
223  /* Connection management */
224 
232  virtual int connect (const std::string& src, const std::string& dst) = 0;
233 
241  virtual int disconnect (const std::string& src, const std::string& dst) = 0;
242 
250  virtual int connect (PortHandle src, const std::string& dst) = 0;
251 
259  virtual int disconnect (PortHandle src, const std::string& dst) = 0;
260 
267  virtual int disconnect_all (PortHandle port) = 0;
268 
275  virtual bool connected (PortHandle port, bool process_callback_safe = true) = 0;
276 
284  virtual bool connected_to (PortHandle port, const std::string& name, bool process_callback_safe = true) = 0;
285 
293  virtual bool physically_connected (PortHandle port, bool process_callback_safe = true) = 0;
294 
302  virtual bool externally_connected (PortHandle port, bool process_callback_safe = true) {
303  /* only with JACK, provides client ports that are not physical */
304  return physically_connected (port, process_callback_safe);
305  }
306 
315  virtual int get_connections (PortHandle port, std::vector<std::string>& names, bool process_callback_safe = true) = 0;
316 
317  /* MIDI */
318 
335  virtual int midi_event_get (pframes_t& timestamp, size_t& size, uint8_t const** buf, void* port_buffer, uint32_t event_index) = 0;
336 
351  virtual int midi_event_put (void* port_buffer, pframes_t timestamp, const uint8_t* buffer, size_t size) = 0;
352 
358  virtual uint32_t get_midi_event_count (void* port_buffer) = 0;
359 
368  virtual void midi_clear (void* port_buffer) = 0;
369 
370  /* Monitoring */
371 
380  virtual bool can_monitor_input() const = 0;
381 
396  virtual int request_input_monitoring (PortHandle port, bool yn) = 0;
397 
398  /* Force input monitoring of the hardware channel represented by the port
399  * referred to by \p port to be on or off, depending on the true/false
400  * status of \p yn. The request count is ignored when using this
401  * method, so if this is called with \p yn set to false, input monitoring will
402  * be disabled regardless of the number of requests to enable it.
403  *
404  * @param port \ref PortHandle
405  * @param yn true to enable hardware monitoring, false to disable
406  * @return 0 on success, -1 otherwise
407  */
408  virtual int ensure_input_monitoring (PortHandle port, bool yn) = 0;
409 
417  virtual bool monitoring_input (PortHandle port) = 0;
418 
419  /* Latency management */
420 
432  virtual void set_latency_range (PortHandle port, bool for_playback, LatencyRange r) = 0;
433 
442  virtual LatencyRange get_latency_range (PortHandle port, bool for_playback) = 0;
443 
444  /* Discovering physical ports */
445 
451  virtual bool port_is_physical (PortHandle port) const = 0;
452 
461  virtual void get_physical_outputs (DataType type, std::vector<std::string>& names) = 0;
462 
468  virtual void get_physical_inputs (DataType type, std::vector<std::string>& names) = 0;
469 
473  virtual ChanCount n_physical_outputs () const = 0;
474 
478  virtual ChanCount n_physical_inputs () const = 0;
479 
491  virtual void* get_buffer (PortHandle port, pframes_t off) = 0;
492 
493  /* MIDI ports (the ones in libmidi++) need this to be able to correctly
494  * schedule MIDI events within their buffers. It is a bit odd that we
495  * expose this here, because it is also exposed by AudioBackend, but they
496  * only have access to a PortEngine object, not an AudioBackend.
497  *
498  * Return the time according to the sample clock in use when the current
499  * buffer process cycle began.
500  *
501  * XXX to be removed after some more design cleanup.
502  */
504 
505 protected:
507 };
508 
509 } // namespace
510 
511 #endif /* __libardour_port_engine_h__ */
virtual int disconnect_all(PortHandle port)=0
virtual void set_latency_range(PortHandle port, bool for_playback, LatencyRange r)=0
virtual void get_physical_outputs(DataType type, std::vector< std::string > &names)=0
virtual samplepos_t sample_time_at_cycle_start()=0
virtual bool externally_connected(PortHandle port, bool process_callback_safe=true)
Definition: port_engine.h:302
virtual bool port_is_physical(PortHandle port) const =0
virtual uint32_t port_name_size() const =0
virtual int get_connections(PortHandle port, std::vector< std::string > &names, bool process_callback_safe=true)=0
virtual DataType port_data_type(PortHandle port) const =0
PortPtr const & PortHandle
Definition: port_engine.h:114
virtual PortFlags get_port_flags(PortHandle port) const =0
PortManager & manager
Definition: port_engine.h:506
virtual int get_port_property(PortHandle, const std::string &key, std::string &value, std::string &type) const
Definition: port_engine.h:165
virtual int request_input_monitoring(PortHandle port, bool yn)=0
PortEngine(PortManager &pm)
Definition: port_engine.h:87
virtual int disconnect(const std::string &src, const std::string &dst)=0
virtual uint32_t get_midi_event_count(void *port_buffer)=0
virtual void * get_buffer(PortHandle port, pframes_t off)=0
virtual LatencyRange get_latency_range(PortHandle port, bool for_playback)=0
virtual void * private_handle() const =0
virtual int connect(const std::string &src, const std::string &dst)=0
virtual bool monitoring_input(PortHandle port)=0
virtual bool physically_connected(PortHandle port, bool process_callback_safe=true)=0
virtual int connect(PortHandle src, const std::string &dst)=0
virtual std::string get_port_name(PortHandle port) const =0
std::shared_ptr< ProtoPort > PortPtr
Definition: port_engine.h:108
virtual bool connected(PortHandle port, bool process_callback_safe=true)=0
virtual void get_physical_inputs(DataType type, std::vector< std::string > &names)=0
virtual int get_ports(const std::string &port_name_pattern, DataType type, PortFlags flags, std::vector< std::string > &ports) const =0
virtual PortPtr get_port_by_name(const std::string &name) const =0
virtual int midi_event_get(pframes_t &timestamp, size_t &size, uint8_t const **buf, void *port_buffer, uint32_t event_index)=0
virtual bool can_monitor_input() const =0
virtual int midi_event_put(void *port_buffer, pframes_t timestamp, const uint8_t *buffer, size_t size)=0
virtual int set_port_name(PortHandle port, const std::string &name)=0
virtual void unregister_port(PortHandle port)=0
virtual bool connected_to(PortHandle port, const std::string &name, bool process_callback_safe=true)=0
virtual int set_port_property(PortHandle, const std::string &key, const std::string &value, const std::string &type)
Definition: port_engine.h:176
virtual ~PortEngine()
Definition: port_engine.h:88
virtual int disconnect(PortHandle src, const std::string &dst)=0
virtual void midi_clear(void *port_buffer)=0
virtual int ensure_input_monitoring(PortHandle port, bool yn)=0
virtual ChanCount n_physical_inputs() const =0
virtual const std::string & my_name() const =0
virtual ChanCount n_physical_outputs() const =0
virtual PortPtr register_port(const std::string &shortname, ARDOUR::DataType type, ARDOUR::PortFlags flags)=0
virtual ~ProtoPort()
Definition: port_engine.h:81
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBARDOUR_API
uint32_t pframes_t
Temporal::samplepos_t samplepos_t