use XML state to store processors in mixer (strips) and fixup crash caused by missing...
[ardour.git] / libs / ardour / ardour / region.h
index 8ab99fa1514268b6c32c329511ea101837e9ffe3..c3aac3dfa881959ad563911aaaa84c6525fc2594 100644 (file)
@@ -20,6 +20,7 @@
 #ifndef __ardour_region_h__
 #define __ardour_region_h__
 
+#include <vector>
 #include <boost/shared_ptr.hpp>
 #include <boost/enable_shared_from_this.hpp>
 
@@ -27,6 +28,7 @@
 #include <pbd/statefuldestructible.h> 
 
 #include <ardour/ardour.h>
+#include <ardour/data_type.h>
 
 class XMLNode;
 
@@ -43,6 +45,8 @@ enum RegionEditState {
 class Region : public PBD::StatefulDestructible, public boost::enable_shared_from_this<Region>
 {
   public:
+       typedef std::vector<boost::shared_ptr<Source> > SourceList;
+
        enum Flag {
                Muted = 0x1,
                Opaque = 0x2,
@@ -62,6 +66,7 @@ class Region : public PBD::StatefulDestructible, public boost::enable_shared_fro
                RightOfSplit = 0x8000,
                Hidden = 0x10000,
                DoNotSaveState = 0x20000,
+               PositionLocked = 0x40000,
                //
                range_guarantoor = USHRT_MAX
        };
@@ -85,10 +90,12 @@ class Region : public PBD::StatefulDestructible, public boost::enable_shared_fro
        string name() const { return _name; }
        void set_name (string str);
 
+       const DataType& data_type() const { return _type; }
+
        nframes_t position () const { return _position; }
        nframes_t start ()    const { return _start; }
        nframes_t length()    const { return _length; }
-       layer_t        layer ()    const { return _layer; }
+       layer_t   layer ()    const { return _layer; }
        
        nframes_t sync_offset(int& dir) const;
        nframes_t sync_position() const;
@@ -100,13 +107,16 @@ class Region : public PBD::StatefulDestructible, public boost::enable_shared_fro
        nframes_t first_frame() const { return _position; }
        nframes_t last_frame() const { return _position + _length - 1; }
 
+       Flag flags()      const { return _flags; }
        bool hidden()     const { return _flags & Hidden; }
        bool muted()      const { return _flags & Muted; }
        bool opaque ()    const { return _flags & Opaque; }
        bool locked()     const { return _flags & Locked; }
+       bool position_locked() const { return _flags & PositionLocked; }
        bool automatic()  const { return _flags & Automatic; }
        bool whole_file() const { return _flags & WholeFile ; }
-       Flag flags()      const { return _flags; }
+       bool captured()   const { return !(_flags & (Region::Flag (Region::Import|Region::External))); }
+       bool can_move()   const { return !(_flags & (Locked|PositionLocked)); }
 
        virtual bool should_save_state () const { return !(_flags & DoNotSaveState); };
 
@@ -125,10 +135,8 @@ class Region : public PBD::StatefulDestructible, public boost::enable_shared_fro
        bool size_equivalent (boost::shared_ptr<const Region>) const;
        bool overlap_equivalent (boost::shared_ptr<const Region>) const;
        bool region_list_equivalent (boost::shared_ptr<const Region>) const;
-       virtual bool source_equivalent (boost::shared_ptr<const Region>) const = 0;
+       bool source_equivalent (boost::shared_ptr<const Region>) const;
        
-       virtual bool speed_mismatch (float) const = 0;
-
        /* EDITING OPERATIONS */
 
        void set_length (nframes_t, void *src);
@@ -147,8 +155,6 @@ class Region : public PBD::StatefulDestructible, public boost::enable_shared_fro
        void trim_to (nframes_t position, nframes_t length, void *src);
        
        void set_layer (layer_t l); /* ONLY Playlist can call this */
-       void raise ();
-       void lower ();
        void raise_to_top ();
        void lower_to_bottom ();
 
@@ -158,12 +164,23 @@ class Region : public PBD::StatefulDestructible, public boost::enable_shared_fro
        void set_muted (bool yn);
        void set_opaque (bool yn);
        void set_locked (bool yn);
+       void set_position_locked (bool yn);
 
        virtual uint32_t read_data_count() const { return _read_data_count; }
 
        boost::shared_ptr<ARDOUR::Playlist> playlist() const { return _playlist.lock(); }
        virtual void set_playlist (boost::weak_ptr<ARDOUR::Playlist>);
 
+       void source_deleted (boost::shared_ptr<Source>);
+       
+       boost::shared_ptr<Source> source (uint32_t n=0) const { return _sources[ (n < _sources.size()) ? n : 0 ]; }
+       uint32_t                  n_channels()          const { return _sources.size(); }
+
+       std::vector<string> master_source_names();
+       
+       const SourceList& sources() const { return _sources; }
+       const SourceList& master_sources() const { return _master_sources; }
+
        /* serialization */
        
        XMLNode&         get_state ();
@@ -171,20 +188,30 @@ class Region : public PBD::StatefulDestructible, public boost::enable_shared_fro
        virtual int      set_state (const XMLNode&);
        virtual int      set_live_state (const XMLNode&, Change&, bool send);
 
-       virtual boost::shared_ptr<Region> get_parent() const = 0;
+       virtual boost::shared_ptr<Region> get_parent() const;
        
        uint64_t last_layer_op() const { return _last_layer_op; }
        void set_last_layer_op (uint64_t when);
 
+       virtual bool is_dependent() const { return false; }
+       virtual bool depends_on (boost::shared_ptr<Region> other) const { return false; }
+
   protected:
        friend class RegionFactory;
 
-       Region (nframes_t start, nframes_t length, 
-               const string& name, layer_t = 0, Flag flags = DefaultFlags);
+       Region (boost::shared_ptr<Source> src, nframes_t start, nframes_t length, 
+               const string& name, DataType type, layer_t = 0, Flag flags = DefaultFlags);
+       Region (SourceList& srcs, nframes_t start, nframes_t length, 
+               const string& name, DataType type, layer_t = 0, Flag flags = DefaultFlags);
+       
        Region (boost::shared_ptr<const Region>, nframes_t start, nframes_t length, const string& name, layer_t = 0, Flag flags = DefaultFlags);
        Region (boost::shared_ptr<const Region>);
-       Region (const XMLNode&);
+       Region (boost::shared_ptr<Source> src, const XMLNode&);
+       Region (SourceList& srcs, const XMLNode&);
+
+       /* this one is for derived types of derived types */
 
+       Region (nframes_t start, nframes_t length, const string& name, DataType, layer_t = 0, Flag flags = DefaultFlags);
 
   protected:
        XMLNode& get_short_state (); /* used only by Session */
@@ -197,28 +224,31 @@ class Region : public PBD::StatefulDestructible, public boost::enable_shared_fro
        void maybe_uncopy ();
        void first_edit ();
        
-       virtual bool verify_start (nframes_t) = 0;
-       virtual bool verify_start_and_length (nframes_t, nframes_t) = 0;
-       virtual bool verify_start_mutable (nframes_t&_start) = 0;
-       virtual bool verify_length (nframes_t) = 0;
+       virtual bool verify_start (nframes_t);
+       virtual bool verify_start_and_length (nframes_t, nframes_t);
+       virtual bool verify_start_mutable (nframes_t&_start);
+       virtual bool verify_length (nframes_t);
        virtual void recompute_at_start () = 0;
        virtual void recompute_at_end () = 0;
-       
-       
+
+       string                  _name;
+       DataType                _type;
+       Flag                    _flags;
        nframes_t          _start;
        nframes_t          _length;
        nframes_t          _position;
-       Flag                     _flags;
        nframes_t          _sync_position;
        layer_t                 _layer;
-       string                  _name;        
        mutable RegionEditState _first_edit;
        int                     _frozen;
-       Glib::Mutex             lock;
+       mutable uint32_t        _read_data_count;  ///< modified in read()
+       Change                  _pending_changed;
+       uint64_t                _last_layer_op;  ///< timestamp
+       Glib::Mutex             _lock;
        boost::weak_ptr<ARDOUR::Playlist> _playlist;
-       mutable uint32_t        _read_data_count; // modified in read()
-       Change                   pending_changed;
-       uint64_t                _last_layer_op; // timestamp
+       SourceList              _sources;
+       /** Used when timefx are applied, so we can always use the original source */
+       SourceList              _master_sources;
 };
 
 } /* namespace ARDOUR */