Remove frame conversion for MidiRegionView::note_in_region_range(), speed up tempo...
[ardour.git] / libs / ardour / ardour / io.h
index 6793072cba8a710eb6c0da477e95cc210224c77d..db0f2c3cf8ca9907e5a0033f589da65b29245418 100644 (file)
@@ -23,9 +23,8 @@
 #include <string>
 #include <vector>
 #include <cmath>
-#include <jack/jack.h>
 
-#include <glibmm/thread.h>
+#include <glibmm/threads.h>
 
 #include "pbd/fastlog.h"
 #include "pbd/undo.h"
 #include "ardour/latent.h"
 #include "ardour/port_set.h"
 #include "ardour/session_object.h"
+#include "ardour/libardour_visibility.h"
 #include "ardour/types.h"
 #include "ardour/utils.h"
+#include "ardour/buffer_set.h"
 
 class XMLNode;
 
@@ -50,7 +51,6 @@ namespace ARDOUR {
 class Amp;
 class AudioEngine;
 class AudioPort;
-class BufferSet;
 class Bundle;
 class MidiPort;
 class PeakMeter;
@@ -64,7 +64,7 @@ class UserBundle;
  * An IO can contain ports of varying types, making routes/inserts/etc with
  * varied combinations of types (eg MIDI and audio) possible.
  */
-class IO : public SessionObject, public Latent
+class LIBARDOUR_API IO : public SessionObject, public Latent
 {
   public:
        static const std::string state_node_name;
@@ -74,8 +74,8 @@ class IO : public SessionObject, public Latent
                Output
        };
 
-       IO (Session&, const std::string& name, Direction, DataType default_type = DataType::AUDIO);
-       IO (Session&, const XMLNode&, DataType default_type = DataType::AUDIO);
+       IO (Session&, const std::string& name, Direction, DataType default_type = DataType::AUDIO, bool sendish = false);
+       IO (Session&, const XMLNode&, DataType default_type = DataType::AUDIO, bool sendish = false);
 
        virtual ~IO();
 
@@ -88,12 +88,15 @@ class IO : public SessionObject, public Latent
        void set_active(bool yn) { _active = yn; }
 
        bool set_name (const std::string& str);
+       void set_pretty_name (const std::string& str);
+       std::string pretty_name () const { return _pretty_name_prefix; }
 
-       virtual void silence  (nframes_t);
+       virtual void silence (framecnt_t);
+       void increment_port_buffer_offset (pframes_t offset);
 
        int ensure_io (ChanCount cnt, bool clear, void *src);
 
-       int connect_ports_to_bundle (boost::shared_ptr<Bundle>, void *);
+       int connect_ports_to_bundle (boost::shared_ptr<Bundle>, bool exclusive, void *);
        int disconnect_ports_from_bundle (boost::shared_ptr<Bundle>, void *);
 
        BundleList bundles_connected ();
@@ -101,51 +104,79 @@ class IO : public SessionObject, public Latent
        boost::shared_ptr<Bundle> bundle () { return _bundle; }
 
        int add_port (std::string connection, void *src, DataType type = DataType::NIL);
-       int remove_port (Port *, void *src);
-       int connect (Port *our_port, std::string other_port, void *src);
-       int disconnect (Port *our_port, std::string other_port, void *src);
+       int remove_port (boost::shared_ptr<Port>, void *src);
+       int connect (boost::shared_ptr<Port> our_port, std::string other_port, void *src);
+       int disconnect (boost::shared_ptr<Port> our_port, std::string other_port, void *src);
        int disconnect (void *src);
        bool connected_to (boost::shared_ptr<const IO>) const;
-        bool connected () const;
-        bool physically_connected () const;
-        
-       nframes_t signal_latency() const { return _own_latency; }
-       nframes_t latency() const;
-       void      set_port_latency (nframes_t);
+       bool connected_to (const std::string&) const;
+       bool connected () const;
+       bool physically_connected () const;
 
-       void update_port_total_latencies ();
+       framecnt_t signal_latency () const { return 0; }
+       framecnt_t latency () const;
 
        PortSet& ports() { return _ports; }
        const PortSet& ports() const { return _ports; }
 
-       Port *nth (uint32_t n) const {
+       bool has_port (boost::shared_ptr<Port>) const;
+
+       boost::shared_ptr<Port> nth (uint32_t n) const {
                if (n < _ports.num_ports()) {
                        return _ports.port(n);
                } else {
-                       return 0;
+                       return boost::shared_ptr<Port> ();
                }
        }
 
-       Port* port_by_name (const std::string& str) const;
+       boost::shared_ptr<Port> port_by_name (const std::string& str) const;
 
-       AudioPort* audio(uint32_t n) const;
-       MidiPort*  midi(uint32_t n) const;
+       boost::shared_ptr<AudioPort> audio(uint32_t n) const;
+       boost::shared_ptr<MidiPort>  midi(uint32_t n) const;
 
        const ChanCount& n_ports ()  const { return _ports.count(); }
 
-       PBD::Signal2<void,IOChange,void*> changed;
+       /* The process lock will be held on emission of this signal if
+        * IOChange contains ConfigurationChanged.  In other cases,
+        * the process lock status is undefined.
+        */
+       PBD::Signal2<void, IOChange, void *> changed;
 
        virtual XMLNode& state (bool full);
        XMLNode& get_state (void);
        int set_state (const XMLNode&, int version);
        int set_state_2X (const XMLNode&, int, bool);
+       static void prepare_for_reset (XMLNode&, const std::string&);
+
+       class BoolCombiner {
+       public:
+
+               typedef bool result_type;
+
+               template <typename Iter>
+               result_type operator() (Iter first, Iter last) const {
+                       bool r = false;
+                       while (first != last) {
+                               if (*first) {
+                                       r = true;
+                               }
+                               ++first;
+                       }
+
+                       return r;
+               }
+       };
+
+       /** Emitted when the port count is about to change.  Objects
+        *  can attach to this, and return `true' if they want to prevent
+        *  the change from happening.
+        */
+       PBD::Signal1<bool, ChanCount, BoolCombiner> PortCountChanging;
 
-       static int  disable_connecting (void);
-       static int  enable_connecting (void);
-       static int  disable_ports (void);
-       static int  enable_ports (void);
+       static int disable_connecting ();
+       static int enable_connecting ();
 
-       static PBD::Signal1<void,ChanCount> PortCountChanged; // emitted when the number of ports changes
+       static PBD::Signal1<void, ChanCount> PortCountChanged; // emitted when the number of ports changes
 
        static std::string name_from_state (const XMLNode&);
        static void set_name_in_state (XMLNode&, const std::string&);
@@ -162,22 +193,23 @@ class IO : public SessionObject, public Latent
 
        /* three utility functions - this just seems to be simplest place to put them */
 
-       void collect_input (BufferSet& bufs, nframes_t nframes, ChanCount offset);
-       void process_input (boost::shared_ptr<Processor>, framepos_t start_frame, framepos_t end_frame, nframes_t nframes);
-       void copy_to_outputs (BufferSet& bufs, DataType type, nframes_t nframes, nframes_t offset);
+       void collect_input (BufferSet& bufs, pframes_t nframes, ChanCount offset);
+       void process_input (boost::shared_ptr<Processor>, framepos_t start_frame, framepos_t end_frame, double speed, pframes_t nframes);
+       void copy_to_outputs (BufferSet& bufs, DataType type, pframes_t nframes, framecnt_t offset);
 
        /* AudioTrack::deprecated_use_diskstream_connections() needs these */
 
        int set_ports (const std::string& str);
 
   private:
-       mutable Glib::Mutex io_lock;
+       mutable Glib::Threads::Mutex io_lock;
 
   protected:
        PortSet   _ports;
        Direction _direction;
        DataType _default_type;
        bool     _active;
+       bool     _sendish;
 
   private:
        int connecting_became_legal ();
@@ -186,20 +218,19 @@ class IO : public SessionObject, public Latent
        boost::shared_ptr<Bundle> _bundle; ///< a bundle representing our ports
 
        struct UserBundleInfo {
-           UserBundleInfo (IO*, boost::shared_ptr<UserBundle> b);
-           boost::shared_ptr<UserBundle> bundle;
-           PBD::ScopedConnection changed;
+               UserBundleInfo (IO*, boost::shared_ptr<UserBundle> b);
+               boost::shared_ptr<UserBundle> bundle;
+               PBD::ScopedConnection changed;
        };
-       
+
        std::vector<UserBundleInfo*> _bundles_connected; ///< user bundles connected to our ports
 
        static int parse_io_string (const std::string&, std::vector<std::string>& chns);
        static int parse_gain_string (const std::string&, std::vector<std::string>& chns);
 
-       int ensure_ports (ChanCount, bool clear, bool lockit, void *src);
+       int ensure_ports (ChanCount, bool clear, void *src);
 
        void check_bundles_connected ();
-       void check_bundles (std::vector<UserBundleInfo*>&, const PortSet&);
 
        void bundle_changed (Bundle::Change);
 
@@ -211,13 +242,18 @@ class IO : public SessionObject, public Latent
 
        boost::shared_ptr<Bundle> find_possible_bundle (const std::string &desired_name);
 
-       bool ensure_ports_locked (ChanCount, bool clear, void *src);
+       int ensure_ports_locked (ChanCount, bool clear, bool& changed);
 
        std::string build_legal_port_name (DataType type);
        int32_t find_port_hole (const char* base);
 
        void setup_bundle ();
        std::string bundle_channel_name (uint32_t, uint32_t, DataType) const;
+
+       void apply_pretty_name ();
+       std::string _pretty_name_prefix;
+       BufferSet _buffers;
+       void disconnect_check (boost::shared_ptr<ARDOUR::Port>, boost::shared_ptr<ARDOUR::Port>);
 };
 
 } // namespace ARDOUR