Ardour  9.0-pre0-582-g084a23a80d
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 #pragma once
21 
22 #include <vector>
23 #include <string>
24 
25 #include <stdint.h>
26 
27 #include "ardour/data_type.h"
29 #include "ardour/types.h"
30 
31 namespace ARDOUR {
32 
33 class PortManager;
34 
78  public:
79  ProtoPort() {}
80  virtual ~ProtoPort () {}
81 };
82 
84 {
85 public:
86  PortEngine (PortManager& pm) : manager (pm) {}
87  virtual ~PortEngine() {}
88 
92  virtual void* private_handle() const = 0;
93 
107  typedef std::shared_ptr<ProtoPort> PortPtr;
108 
109  /* We use this to declare arguments to methods/functions, in order to
110  * avoid copying shared_ptr<ProtoPort> every time (a practice we use in
111  * other contexts where we pass shared_ptr<T>).
112  */
113  typedef PortPtr const & PortHandle;
114 
118  virtual const std::string& my_name() const = 0;
119 
121  virtual uint32_t port_name_size() const = 0;
122 
129  virtual int set_port_name (PortHandle port, const std::string& name) = 0;
130 
137  virtual std::string get_port_name (PortHandle port) const = 0;
138 
145  virtual PortFlags get_port_flags (PortHandle port) const = 0;
146 
164  virtual int get_port_property (PortHandle, const std::string& key, std::string& value, std::string& type) const { return -1; }
165 
175  virtual int set_port_property (PortHandle, const std::string& key, const std::string& value, const std::string& type) { return -1; }
176 
182  virtual PortPtr get_port_by_name (const std::string& name) const = 0;
183 
193  virtual int get_ports (const std::string& port_name_pattern, DataType type, PortFlags flags, std::vector<std::string>& ports) const = 0;
194 
201  virtual DataType port_data_type (PortHandle port) const = 0;
202 
212  virtual PortPtr register_port (const std::string& shortname, ARDOUR::DataType type, ARDOUR::PortFlags flags) = 0;
213 
214  /* Destroy the port referred to by \p port, including all resources
215  * associated with it. This will also disconnect \p port from any ports it
216  * is connected to.
217  *
218  * @param port \ref PortHandle of the port to destroy
219  */
220  virtual void unregister_port (PortHandle port) = 0;
221 
222  /* Connection management */
223 
231  virtual int connect (const std::string& src, const std::string& dst) = 0;
232 
240  virtual int disconnect (const std::string& src, const std::string& dst) = 0;
241 
249  virtual int connect (PortHandle src, const std::string& dst) = 0;
250 
258  virtual int disconnect (PortHandle src, const std::string& dst) = 0;
259 
266  virtual int disconnect_all (PortHandle port) = 0;
267 
274  virtual bool connected (PortHandle port, bool process_callback_safe = true) = 0;
275 
283  virtual bool connected_to (PortHandle port, const std::string& name, bool process_callback_safe = true) = 0;
284 
292  virtual bool physically_connected (PortHandle port, bool process_callback_safe = true) = 0;
293 
301  virtual bool externally_connected (PortHandle port, bool process_callback_safe = true) {
302  /* only with JACK, provides client ports that are not physical */
303  return physically_connected (port, process_callback_safe);
304  }
305 
314  virtual int get_connections (PortHandle port, std::vector<std::string>& names, bool process_callback_safe = true) = 0;
315 
316  /* MIDI */
317 
334  virtual int midi_event_get (pframes_t& timestamp, size_t& size, uint8_t const** buf, void* port_buffer, uint32_t event_index) = 0;
335 
350  virtual int midi_event_put (void* port_buffer, pframes_t timestamp, const uint8_t* buffer, size_t size) = 0;
351 
357  virtual uint32_t get_midi_event_count (void* port_buffer) = 0;
358 
367  virtual void midi_clear (void* port_buffer) = 0;
368 
369  /* Monitoring */
370 
379  virtual bool can_monitor_input() const = 0;
380 
395  virtual int request_input_monitoring (PortHandle port, bool yn) = 0;
396 
397  /* Force input monitoring of the hardware channel represented by the port
398  * referred to by \p port to be on or off, depending on the true/false
399  * status of \p yn. The request count is ignored when using this
400  * method, so if this is called with \p yn set to false, input monitoring will
401  * be disabled regardless of the number of requests to enable it.
402  *
403  * @param port \ref PortHandle
404  * @param yn true to enable hardware monitoring, false to disable
405  * @return 0 on success, -1 otherwise
406  */
407  virtual int ensure_input_monitoring (PortHandle port, bool yn) = 0;
408 
416  virtual bool monitoring_input (PortHandle port) = 0;
417 
418  /* Latency management */
419 
431  virtual void set_latency_range (PortHandle port, bool for_playback, LatencyRange r) = 0;
432 
441  virtual LatencyRange get_latency_range (PortHandle port, bool for_playback) = 0;
442 
443  /* Discovering physical ports */
444 
450  virtual bool port_is_physical (PortHandle port) const = 0;
451 
460  virtual void get_physical_outputs (DataType type, std::vector<std::string>& names) = 0;
461 
467  virtual void get_physical_inputs (DataType type, std::vector<std::string>& names) = 0;
468 
472  virtual ChanCount n_physical_outputs () const = 0;
473 
477  virtual ChanCount n_physical_inputs () const = 0;
478 
490  virtual void* get_buffer (PortHandle port, pframes_t off) = 0;
491 
492  /* MIDI ports (the ones in libmidi++) need this to be able to correctly
493  * schedule MIDI events within their buffers. It is a bit odd that we
494  * expose this here, because it is also exposed by AudioBackend, but they
495  * only have access to a PortEngine object, not an AudioBackend.
496  *
497  * Return the time according to the sample clock in use when the current
498  * buffer process cycle began.
499  *
500  * XXX to be removed after some more design cleanup.
501  */
503 
504 protected:
506 };
507 
508 } // namespace
509 
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:301
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:113
virtual PortFlags get_port_flags(PortHandle port) const =0
PortManager & manager
Definition: port_engine.h:505
virtual int get_port_property(PortHandle, const std::string &key, std::string &value, std::string &type) const
Definition: port_engine.h:164
virtual int request_input_monitoring(PortHandle port, bool yn)=0
PortEngine(PortManager &pm)
Definition: port_engine.h:86
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:107
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:175
virtual ~PortEngine()
Definition: port_engine.h:87
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:80
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBARDOUR_API
uint32_t pframes_t
Temporal::samplepos_t samplepos_t