fix SConstruct so that it can build from a git checkout rather than an svn checkout
[ardour.git] / libs / ardour / ardour / port.h
index cf36f95b873db1d80bc8aeb59cca10de5c80796d..084022541d3993d3c9639237215e87f0dbc501a8 100644 (file)
     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 <set>
+#include <vector>
+#include <string>
+#include <cstring>
 #include <sigc++/signal.h>
 #include <pbd/failed_constructor.h>
 #include <ardour/ardour.h>
@@ -32,69 +35,38 @@ namespace ARDOUR {
 class AudioEngine;
 class Buffer;
 
-/** Abstract base for all outside ports (eg Jack ports)
+/** Abstract base for ports
  */
-class Port : public sigc::trackable {
+class Port : public virtual sigc::trackable {
    public:
-       virtual ~Port() { 
-               free (_port);
-       }
-
-       virtual DataType type() const = 0;
-
-       virtual void cycle_start(jack_nframes_t nframes) {}
-       virtual void cycle_end() {}
-
-       virtual Buffer& get_buffer() = 0;
-       
-       /** Silence/Empty the port, output ports only */
-       virtual void silence (jack_nframes_t nframes, jack_nframes_t offset) = 0;
+       enum Flags {
+               IsInput = JackPortIsInput,
+               IsOutput = JackPortIsOutput,
+               IsPhysical = JackPortIsPhysical,
+               IsTerminal = JackPortIsTerminal,
+               CanMonitor = JackPortCanMonitor
+       };
 
+       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);
-       }
-
-       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 & JackPortIsInput;
+               return _flags & IsInput;
        }
 
        bool sends_output () const {
-               return _flags & JackPortIsOutput;
-       }
-       
-       bool monitoring_input () const {
-               return jack_port_monitoring_input (_port);
+               return _flags & IsOutput;
        }
 
        bool can_monitor () const {
-               return _flags & JackPortCanMonitor;
+               return _flags & CanMonitor;
        }
 
        void enable_metering() {
@@ -104,54 +76,105 @@ class Port : public sigc::trackable {
        void disable_metering () {
                if (_metering) { _metering--; }
        }
-       
-       void ensure_monitor_input (bool yn) {
-               jack_port_request_monitor (_port, yn);
-       }
-       
-       void request_monitor_input (bool yn) {
-               jack_port_request_monitor (_port, yn);
-       }
 
-       jack_nframes_t latency () const {
-               return jack_port_get_latency (_port);
-       }
+       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;
 
-       void set_latency (jack_nframes_t nframes) {
-               jack_port_set_latency (_port, nframes);
-       }
+       virtual bool connected () const;
+       virtual bool connected_to (const std::string& portname) const;
+       virtual int get_connections (std::vector<std::string>&) const;
 
-       bool is_silent() const { return _silent; }
+       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; }
 
-       void mark_silence (bool yn) {
-               _silent = yn;
+       virtual int set_name (const std::string& str) {
+               _name = str;
+               return 0;
        }
-       
+
+       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<void,bool> MonitorInputChanged;
        sigc::signal<void,bool> ClockSyncChanged;
 
+       static void set_engine (AudioEngine*);
+
   protected:
        friend class AudioEngine;
 
-       Port (jack_port_t *port);
-       
-       virtual void reset ();
+       Port (const std::string& name, Flags flgs);
+
+       virtual void recompute_total_latency() const {}
        
        /* engine isn't supposed to access below here */
 
-       /* cache these 3 from JACK so we can access them for reconnecting */
-       JackPortFlags _flags;
-       std::string   _type;
-       std::string   _name;
+       Flags          _flags;
+       std::string    _type;
+       std::string    _name;
+       unsigned short _metering;
+       bool           _last_monitor;
+       nframes_t      _latency;
 
-       jack_port_t*  _port;
+       std::set<Port*> _connections;
 
-       unsigned short _metering;
+       static AudioEngine* engine;
+};
 
-       bool          _last_monitor : 1;
-       bool          _silent : 1;
+class PortConnectableByName {
+  public:
+       PortConnectableByName() {}
+       virtual ~PortConnectableByName() {}
+
+       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() {}
+
+       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<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;
+};
+
 } // namespace ARDOUR
 
 #endif /* __ardour_port_h__ */