Exact beat - provide audio->music mapping for region split.
[ardour.git] / libs / ardour / ardour / port.h
index 93c34da16d9c28d3e0dd915354b268856c7022b6..619b8ba0f2dfb729fb2e8242467c4d0454fbca63 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2002 Paul Davis 
+    Copyright (C) 2009 Paul Davis
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 #ifndef __ardour_port_h__
 #define __ardour_port_h__
 
+#include "libardour-config.h"
+
 #include <set>
-#include <vector>
 #include <string>
+#include <vector>
+#include <boost/utility.hpp>
+#include "pbd/signals.h"
 
-#include <sigc++/signal.h>
-#include <pbd/failed_constructor.h>
-#include <ardour/ardour.h>
-#include <ardour/data_type.h>
-#include <jack/jack.h>
+#include "ardour/data_type.h"
+#include "ardour/port_engine.h"
+#include "ardour/libardour_visibility.h"
+#include "ardour/types.h"
 
 namespace ARDOUR {
 
 class AudioEngine;
 class Buffer;
 
-/** Abstract base for ports
- */
-class Port : public virtual sigc::trackable {
-   public:
-       enum Flags {
-               IsInput = JackPortIsInput,
-               IsOutput = JackPortIsOutput,
-               IsPhysical = JackPortIsPhysical,
-               IsTerminal = JackPortIsTerminal,
-               CanMonitor = JackPortCanMonitor
-       };
-
-       virtual ~Port();
-
-       std::string name() const { 
+class LIBARDOUR_API Port : public boost::noncopyable
+{
+public:
+       virtual ~Port ();
+
+       static void set_connecting_blocked( bool yn ) {
+               _connecting_blocked = yn;
+       }
+       static bool connecting_blocked() {
+               return _connecting_blocked;
+       }
+
+       /** @return Port short name */
+       std::string name () const {
                return _name;
        }
 
-       Flags flags() const {
+       /** @return Port human readable name */
+       std::string pretty_name (bool fallback_to_name = false) const;
+       bool set_pretty_name (const std::string&);
+
+       int set_name (std::string const &);
+
+       /** @return flags */
+       PortFlags flags () const {
                return _flags;
        }
 
-       bool receives_input() const {
+       /** @return true if this Port receives input, otherwise false */
+       bool receives_input () const {
                return _flags & IsInput;
        }
 
+       /** @return true if this Port sends output, otherwise false */
        bool sends_output () const {
                return _flags & IsOutput;
        }
 
-       bool can_monitor () const {
-               return _flags & CanMonitor;
-       }
+       bool connected () const;
+       int disconnect_all ();
+       int get_connections (std::vector<std::string> &) const;
 
-       void enable_metering() {
-               _metering++;
-       }
-       
-       void disable_metering () {
-               if (_metering) { _metering--; }
-       }
+       /* connection by name */
+       bool connected_to (std::string const &) const;
+       int connect (std::string const &);
+       int disconnect (std::string const &);
 
-       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;
+       /* connection by Port* */
+       bool connected_to (Port *) const;
+       virtual int connect (Port *);
+       int disconnect (Port *);
 
-       virtual bool connected () const;
-       virtual bool connected_to (const std::string& portname) const;
-       virtual int get_connections (std::vector<std::string>&) const;
+       void request_input_monitoring (bool);
+       void ensure_input_monitoring (bool);
+       bool monitoring_input () const;
+       int reestablish ();
+       int reconnect ();
+
+       bool last_monitor() const { return _last_monitor; }
+       void set_last_monitor (bool yn) { _last_monitor = yn; }
+
+       PortEngine::PortHandle port_handle() { return _port_handle; }
+
+       void get_connected_latency_range (LatencyRange& range, bool playback) const;
+
+       void set_private_latency_range (LatencyRange& range, bool playback);
+       const LatencyRange&  private_latency_range (bool playback) const;
+
+       void set_public_latency_range (LatencyRange& range, bool playback) const;
+       LatencyRange public_latency_range (bool playback) const;
 
-       virtual int connect (Port& other);
-       virtual int disconnect (Port& other);
-       virtual int disconnect_all ();
-       
        virtual void reset ();
-       virtual int reestablish () {return 0; }
-       virtual int reconnect () { return 0; }
 
-       virtual int set_name (const std::string& str) {
-               _name = str;
-               return 0;
-       }
+       virtual DataType type () const = 0;
+       virtual void cycle_start (pframes_t);
+       virtual void cycle_end (pframes_t) = 0;
+       virtual void cycle_split () = 0;
+       virtual Buffer& get_buffer (pframes_t nframes) = 0;
+       virtual void flush_buffers (pframes_t /*nframes*/) {}
+       virtual void transport_stopped () {}
+       virtual void realtime_locate () {}
 
-       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;
+       bool physically_connected () const;
 
-       sigc::signal<void,bool> MonitorInputChanged;
-       sigc::signal<void,bool> ClockSyncChanged;
+       PBD::Signal1<void,bool> MonitorInputChanged;
+       static PBD::Signal2<void,boost::shared_ptr<Port>,boost::shared_ptr<Port> > PostDisconnect;
+       static PBD::Signal0<void> PortDrop;
+       static PBD::Signal0<void> PortSignalDrop;
 
-       static void set_engine (AudioEngine*);
+       static void set_cycle_framecnt (pframes_t n) {
+               _cycle_nframes = n;
+       }
+       static framecnt_t port_offset() { return _global_port_buffer_offset; }
+       static void set_global_port_buffer_offset (pframes_t off) {
+               _global_port_buffer_offset = off;
+       }
+       static void increment_global_port_buffer_offset (pframes_t n) {
+               _global_port_buffer_offset += n;
+       }
 
-  protected:
-       friend class AudioEngine;
+       virtual void increment_port_buffer_offset (pframes_t n);
 
-       Port (const std::string& name, Flags flgs);
+       virtual XMLNode& get_state (void) const;
+       virtual int set_state (const XMLNode&, int version);
 
-       virtual void recompute_total_latency() const {}
-       
-       /* engine isn't supposed to access below here */
+        static std::string state_node_name;
 
-       Flags          _flags;
-       std::string    _type;
-       std::string    _name;
-       unsigned short _metering;
-       bool           _last_monitor;
-       nframes_t      _latency;
+protected:
 
-       std::set<Port*> _connections;
+       Port (std::string const &, DataType, PortFlags);
 
-       static AudioEngine* engine;
-};
+        PortEngine::PortHandle _port_handle;
 
-class PortConnectableByName {
-  public:
-       PortConnectableByName() {}
-       virtual ~PortConnectableByName() {}
+       static bool       _connecting_blocked;
+       static pframes_t  _global_port_buffer_offset;   /* access only from process() tree */
+       static pframes_t  _cycle_nframes; /* access only from process() tree */
 
-       virtual int connect (const std::string& other_name) = 0;
-       virtual int disconnect (const std::string& other_name) = 0;
-};
-class PortFacade : public virtual Port, public PortConnectableByName { 
-  public:
-       PortFacade (const std::string& name, Flags flgs) : Port (name, flgs), _ext_port (0) {}
-       ~PortFacade() {}
+       framecnt_t _port_buffer_offset; /* access only from process() tree */
 
-       void reset ();
-       int reestablish ();
-       int reconnect ();
+       LatencyRange _private_playback_latency;
+       LatencyRange _private_capture_latency;
 
-       int connect (Port& other);
-       int disconnect (Port& other);
-       int disconnect_all ();
+private:
+       std::string _name;  ///< port short name
+       PortFlags       _flags; ///< flags
+       bool        _last_monitor;
 
-       int connect (const std::string& other_name);
-       int disconnect (const std::string& other_name);
+       /** ports that we are connected to, kept so that we can
+           reconnect to the backend when required
+       */
+       std::set<std::string> _connections;
 
-       bool connected () const;
-       bool connected_to (const std::string& portname) const;
-       int get_connections (std::vector<std::string>&) 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;
+       void port_connected_or_disconnected (boost::weak_ptr<Port>, boost::weak_ptr<Port>, bool);
+       void signal_drop ();
+       void drop ();
+       PBD::ScopedConnection drop_connection;
+       PBD::ScopedConnection engine_connection;
 };
 
-} // namespace ARDOUR
+}
 
 #endif /* __ardour_port_h__ */