X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fardour%2Fport.h;h=084022541d3993d3c9639237215e87f0dbc501a8;hb=1d210a54f9b1c0da7a196413bd760ff53f198270;hp=ff9c25e1c4e0c4f0cd06da2f3c368da85439e332;hpb=cf0da62ff0e4ef7dfcf0730f1af057edd34dc15a;p=ardour.git diff --git a/libs/ardour/ardour/port.h b/libs/ardour/ardour/port.h index ff9c25e1c4..084022541d 100644 --- a/libs/ardour/ardour/port.h +++ b/libs/ardour/ardour/port.h @@ -15,199 +15,166 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #ifndef __ardour_port_h__ #define __ardour_port_h__ +#include +#include +#include +#include #include #include #include +#include #include namespace ARDOUR { class AudioEngine; +class Buffer; -class Port : public sigc::trackable { +/** Abstract base for ports + */ +class Port : public virtual sigc::trackable { public: - virtual ~Port() { - free (port); - } - - Sample *get_buffer (jack_nframes_t nframes) { - if (_flags & JackPortIsOutput) { - return _buffer; - } else { - return (Sample *) jack_port_get_buffer (port, nframes); - } - } + enum Flags { + IsInput = JackPortIsInput, + IsOutput = JackPortIsOutput, + IsPhysical = JackPortIsPhysical, + IsTerminal = JackPortIsTerminal, + CanMonitor = JackPortCanMonitor + }; - void reset_buffer () { - if (_flags & JackPortIsOutput) { - _buffer = (Sample *) jack_port_get_buffer (port, 0); - } else { - _buffer = 0; /* catch illegal attempts to use it */ - } - silent = false; - } + virtual ~Port(); - std::string name() { + std::string name() const { return _name; } - std::string short_name() { - return jack_port_short_name (port); - } - - int set_name (std::string str); - - JackPortFlags flags() const { + Flags flags() const { return _flags; } - bool is_mine (jack_client_t *client) { - return jack_port_is_mine (client, port); - } - - const char* type() const { - return _type.c_str(); - } - - int connected () const { - return jack_port_connected (port); - } - - bool connected_to (const std::string& portname) const { - return jack_port_connected_to (port, portname.c_str()); - } - - const char ** get_connections () const { - return jack_port_get_connections (port); + bool receives_input() const { + return _flags & IsInput; } - void reset_overs () { - _short_overs = 0; - _long_overs = 0; - overlen = 0; + bool sends_output () const { + return _flags & IsOutput; } - void reset_peak_meter () { - _peak = 0; - } - - void reset_meters () { - reset_peak_meter (); - reset_overs (); + bool can_monitor () const { + return _flags & CanMonitor; } void enable_metering() { - metering++; + _metering++; } void disable_metering () { - if (metering) { metering--; } + if (_metering) { _metering--; } } - float peak_db() const { return _peak_db; } - jack_default_audio_sample_t peak() const { return _peak; } + virtual void cycle_start (nframes_t nframes, nframes_t offset) {} + virtual void cycle_end (nframes_t nframes, nframes_t offset) {} + virtual DataType type() const = 0; + virtual Buffer& get_buffer() = 0; - uint32_t short_overs () const { return _short_overs; } - uint32_t long_overs () const { return _long_overs; } - - static void set_short_over_length (jack_nframes_t); - static void set_long_over_length (jack_nframes_t); - - bool receives_input() const { - return _flags & JackPortIsInput; - } + virtual bool connected () const; + virtual bool connected_to (const std::string& portname) const; + virtual int get_connections (std::vector&) const; - bool sends_output () const { - return _flags & JackPortIsOutput; - } + virtual int connect (Port& other); + virtual int disconnect (Port& other); + virtual int disconnect_all (); - bool monitoring_input () const { - return jack_port_monitoring_input (port); - } + virtual void reset (); + virtual int reestablish () {return 0; } + virtual int reconnect () { return 0; } - bool can_monitor () const { - return _flags & JackPortCanMonitor; - } - - void ensure_monitor_input (bool yn) { - jack_port_request_monitor (port, yn); - } - - void request_monitor_input (bool yn) { - jack_port_request_monitor (port, yn); + virtual int set_name (const std::string& str) { + _name = str; + return 0; } - jack_nframes_t latency () const { - return jack_port_get_latency (port); - } - - void set_latency (jack_nframes_t nframes) { - jack_port_set_latency (port, nframes); - } + virtual std::string short_name() const = 0; + virtual bool monitoring_input () const = 0; + virtual void ensure_monitor_input (bool yn) = 0; + virtual void request_monitor_input (bool yn) = 0; + virtual nframes_t latency () const = 0; + virtual nframes_t total_latency () const = 0; + virtual void set_latency (nframes_t nframes) = 0; sigc::signal MonitorInputChanged; sigc::signal ClockSyncChanged; - bool is_silent() const { return silent; } - - void silence (jack_nframes_t nframes, jack_nframes_t offset) { - /* assumes that the port is an output port */ - - if (!silent) { - memset (_buffer + offset, 0, sizeof (Sample) * nframes); - if (offset == 0) { - /* XXX this isn't really true, but i am not sure - how to set this correctly. we really just - want to set it true when the entire port - buffer has been overrwritten. - */ - silent = true; - } - } - } - - void mark_silence (bool yn) { - silent = yn; - } + static void set_engine (AudioEngine*); - private: + protected: friend class AudioEngine; - Port (jack_port_t *port); - void reset (); - - /* engine isn't supposed to below here */ - - Sample *_buffer; - - /* cache these 3 from JACK so that we can - access them for reconnecting. - */ - - JackPortFlags _flags; - std::string _type; - std::string _name; - - bool last_monitor : 1; - bool silent : 1; - jack_port_t *port; - jack_nframes_t overlen; - jack_default_audio_sample_t _peak; - float _peak_db; - uint32_t _short_overs; - uint32_t _long_overs; - unsigned short metering; + Port (const std::string& name, Flags flgs); + + virtual void recompute_total_latency() const {} - static jack_nframes_t long_over_length; - static jack_nframes_t short_over_length; + /* engine isn't supposed to access below here */ + + Flags _flags; + std::string _type; + std::string _name; + unsigned short _metering; + bool _last_monitor; + nframes_t _latency; + + std::set _connections; + + static AudioEngine* engine; +}; + +class PortConnectableByName { + public: + PortConnectableByName() {} + virtual ~PortConnectableByName() {} + + virtual int connect (const std::string& other_name) = 0; + virtual int disconnect (const std::string& other_name) = 0; }; -}; /* namespace ARDOUR */ +class PortFacade : public virtual Port, public PortConnectableByName { + public: + PortFacade (const std::string& name, Flags flgs) : Port (name, flgs), _ext_port (0) {} + ~PortFacade() {} + + void reset (); + int reestablish (); + int reconnect (); + + int connect (Port& other); + int disconnect (Port& other); + int disconnect_all (); + + int connect (const std::string& other_name); + int disconnect (const std::string& other_name); + + bool connected () const; + bool connected_to (const std::string& portname) const; + int get_connections (std::vector&) const; + + std::string short_name() const; + int set_name (const std::string& str); + bool monitoring_input () const; + void ensure_monitor_input (bool yn); + void request_monitor_input (bool yn); + nframes_t latency () const; + nframes_t total_latency () const; + void set_latency (nframes_t nframes); + + protected: + Port* _ext_port; +}; + +} // namespace ARDOUR #endif /* __ardour_port_h__ */