Tidy.
[ardour.git] / libs / ardour / ardour / port.h
index c1e502727f44cc53dc03b25d6fb6d96d95e385f0..c63faa162d8bd78568d6945ccda82dc027ddaa5a 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 <sigc++/signal.h>
-#include <pbd/failed_constructor.h>
-#include <ardour/ardour.h>
-#include <ardour/data_type.h>
+#include <set>
+#include <string>
+#include <vector>
 #include <jack/jack.h>
+#include <sigc++/trackable.h>
+#include "ardour/data_type.h"
+#include "ardour/types.h"
 
 namespace ARDOUR {
 
 class AudioEngine;
-class Buffer;
+class Buffer;  
 
-/** Abstract base for ports
- */
-class Port : public virtual sigc::trackable {
-   public:
+class Port : public sigc::trackable
+{
+public:
        enum Flags {
                IsInput = JackPortIsInput,
                IsOutput = JackPortIsOutput,
-               IsPhysical = JackPortIsPhysical,
-               IsTerminal = JackPortIsTerminal,
-               CanMonitor = JackPortCanMonitor
        };
 
-       virtual ~Port() {}
+       virtual ~Port ();
 
-       std::string name() const { 
+       /** @return Port short name */
+       std::string name () const {
                return _name;
        }
 
+       int set_name (std::string const &);
 
-       Flags flags() const {
+       /** @return flags */
+       Flags 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 & JackPortIsOutput;
+               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--; }
-       }
-       
-       virtual DataType type() const = 0;
-       virtual void cycle_start(nframes_t nframes) {}
-       virtual void cycle_end() {}
-       virtual Buffer& get_buffer() = 0;
-       virtual std::string short_name() = 0;
-       virtual int set_name (std::string str) = 0;
-       virtual bool is_mine (jack_client_t *client) = 0;
-       virtual int reestablish () = 0;
-       virtual int connected () const = 0;
-       virtual bool connected_to (const std::string& portname) const = 0;
-       virtual const char ** get_connections () 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;
-
-  protected:
-       friend class AudioEngine;
+       /* connection by name */
+       bool connected_to (std::string const &) const;
+       int connect (std::string const &);
+       int disconnect (std::string const &);
+
+       /* connection by Port* */
+       bool connected_to (Port *) const;
+       virtual int connect (Port *);
+       int disconnect (Port *);
 
-       Port ();
+       void ensure_monitor_input (bool);
+       bool monitoring_input () const;
+       nframes_t total_latency () const;
+       int reestablish ();
+       int reconnect ();
+       void request_monitor_input (bool);
+       void set_latency (nframes_t);
 
-       virtual int disconnect () = 0;
-       virtual void recompute_total_latency() const = 0;
        virtual void reset ();
+
+       virtual DataType type () const = 0;
+       virtual void cycle_start (nframes_t, nframes_t) = 0;
+       virtual void cycle_end (nframes_t, nframes_t) = 0;
+       virtual Buffer& get_buffer (nframes_t, nframes_t) = 0;
+       virtual void flush_buffers (nframes_t, nframes_t) {}
+
+       static void set_engine (AudioEngine *);
+
+       sigc::signal<void, bool> MonitorInputChanged;
+
+protected:
        
-       /* engine isn't supposed to access below here */
+       Port (std::string const &, DataType, Flags);
+
+       jack_port_t* _jack_port; ///< JACK port
+
+       static AudioEngine* _engine; ///< the AudioEngine
+
+private:
+       friend class AudioEngine;
 
-       Flags _flags;
-       std::string    _type;
-       std::string    _name;
-       unsigned short _metering;
-       bool           _last_monitor;
+       void recompute_total_latency () const;
+       
+       /* XXX */
+       bool _last_monitor;
+
+       std::string _name; ///< port short name
+       Flags _flags; ///< flags
+
+       /** ports that we are connected to, kept so that we can
+           reconnect to JACK when required */
+       std::set<std::string> _connections;
 };
-} // namespace ARDOUR
 
-#endif /* __ardour_port_h__ */
+}
+
+#endif