use XML state to store processors in mixer (strips) and fixup crash caused by missing...
[ardour.git] / libs / ardour / ardour / playlist.h
index 4c2e75c6c9b271b9d1bf743e2737acfb10f8f899..55947a84a5779ac85494f50729c7812a26c83c5c 100644 (file)
@@ -15,7 +15,6 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id$
 */
 
 #ifndef __ardour_playlist_h__
@@ -26,6 +25,7 @@
 #include <map>
 #include <list>
 #include <boost/shared_ptr.hpp>
+#include <boost/enable_shared_from_this.hpp>
 
 #include <sys/stat.h>
 
 #include <pbd/statefuldestructible.h> 
 
 #include <ardour/ardour.h>
+#include <ardour/session_object.h>
 #include <ardour/crossfade_compare.h>
 #include <ardour/location.h>
-#include <ardour/state_manager.h>
+#include <ardour/data_type.h>
 
 namespace ARDOUR  {
 
 class Session;
 class Region;
 
-class Playlist : public StateManager, public PBD::StatefulDestructible {
+class Playlist : public SessionObject, public boost::enable_shared_from_this<Playlist> {
   public:
        typedef list<boost::shared_ptr<Region> >    RegionList;
 
-       Playlist (Session&, const XMLNode&, bool hidden = false);
-       Playlist (Session&, string name, bool hidden = false);
-       Playlist (const Playlist&, string name, bool hidden = false);
-       Playlist (const Playlist&, nframes_t start, nframes_t cnt, string name, bool hidden = false);
+       Playlist (Session&, const XMLNode&, DataType type, bool hidden = false);
+       Playlist (Session&, string name, DataType type, bool hidden = false);
+       Playlist (boost::shared_ptr<const Playlist>, string name, bool hidden = false);
+       Playlist (boost::shared_ptr<const Playlist>, nframes_t start, nframes_t cnt, string name, bool hidden = false);
 
-       virtual void clear (bool with_save = true);
+       virtual ~Playlist ();  
+
+       void set_region_ownership ();
+
+       virtual void clear (bool with_signals=true);
        virtual void dump () const;
-       virtual UndoAction get_memento() const = 0;
 
-       void ref();
-       void unref();
-       uint32_t refcnt() const { return _refcnt; }
+       void use();
+       void release();
+       bool used () const { return _refcnt != 0; }
 
-       const string& name() const { return _name; }
-       void set_name (const string& str);
+       bool set_name (const string& str);
+
+       const DataType& data_type() const { return _type; }
 
        bool frozen() const { return _frozen; }
        void set_frozen (bool yn);
 
        bool hidden() const { return _hidden; }
        bool empty() const;
+       uint32_t n_regions() const;
        nframes_t get_maximum_extent () const;
        layer_t top_layer() const;
 
@@ -80,7 +86,7 @@ class Playlist : public StateManager, public PBD::StatefulDestructible {
 
        /* Editing operations */
 
-       void add_region (boost::shared_ptr<Region>, nframes_t position, float times = 1, bool with_save = true);
+       void add_region (boost::shared_ptr<Region>, nframes_t position, float times = 1);
        void remove_region (boost::shared_ptr<Region>);
        void get_equivalent_regions (boost::shared_ptr<Region>, std::vector<boost::shared_ptr<Region> >&);
        void get_region_list_equivalent_regions (boost::shared_ptr<Region>, std::vector<boost::shared_ptr<Region> >&);
@@ -90,19 +96,15 @@ class Playlist : public StateManager, public PBD::StatefulDestructible {
        void duplicate (boost::shared_ptr<Region>, nframes_t position, float times);
        void nudge_after (nframes_t start, nframes_t distance, bool forwards);
 
-       boost::shared_ptr<Region> find_region (const PBD::ID&) const;
-
-       Playlist* cut  (list<AudioRange>&, bool result_is_hidden = true);
-       Playlist* copy (list<AudioRange>&, bool result_is_hidden = true);
-       int       paste (Playlist&, nframes_t position, float times);
+       boost::shared_ptr<Playlist> cut  (list<AudioRange>&, bool result_is_hidden = true);
+       boost::shared_ptr<Playlist> copy (list<AudioRange>&, bool result_is_hidden = true);
+       int                         paste (boost::shared_ptr<Playlist>, nframes_t position, float times);
 
-       uint32_t read_data_count() { return _read_data_count; }
-
-       RegionList* regions_at (nframes_t frame);
-       RegionList* regions_touched (nframes_t start, nframes_t end);
+       RegionList*                regions_at (nframes_t frame);
+       RegionList*                regions_touched (nframes_t start, nframes_t end);
+       boost::shared_ptr<Region>  find_region (const PBD::ID&) const;
        boost::shared_ptr<Region>  top_region_at (nframes_t frame);
-
-       boost::shared_ptr<Region>     find_next_region (nframes_t frame, RegionPoint point, int dir);
+       boost::shared_ptr<Region>  find_next_region (nframes_t frame, RegionPoint point, int dir);
 
        template<class T> void foreach_region (T *t, void (T::*func)(boost::shared_ptr<Region>, void *), void *arg);
        template<class T> void foreach_region (T *t, void (T::*func)(boost::shared_ptr<Region>));
@@ -111,16 +113,11 @@ class Playlist : public StateManager, public PBD::StatefulDestructible {
        int set_state (const XMLNode&);
        XMLNode& get_template ();
 
-       sigc::signal<void,boost::shared_ptr<Region> > RegionAdded;
-       sigc::signal<void,boost::shared_ptr<Region> > RegionRemoved;
-       sigc::signal<void,Playlist*,bool> InUse;
-       sigc::signal<void>                Modified;
-       sigc::signal<void>                NameChanged;
-       sigc::signal<void>                LengthChanged;
-       sigc::signal<void>                LayeringChanged;
-       sigc::signal<void>                StatePushed;
-
-       static sigc::signal<void,Playlist*> PlaylistCreated;
+       sigc::signal<void,bool> InUse;
+       sigc::signal<void>      Modified;
+       sigc::signal<void>      NameChanged;
+       sigc::signal<void>      LengthChanged;
+       sigc::signal<void>      LayeringChanged;
 
        static string bump_name (string old_name, Session&);
        static string bump_name_once (string old_name);
@@ -128,15 +125,11 @@ class Playlist : public StateManager, public PBD::StatefulDestructible {
        void freeze ();
        void thaw ();
 
-       void raise_region (boost::shared_ptr<Region>);
-       void lower_region (boost::shared_ptr<Region>);
        void raise_region_to_top (boost::shared_ptr<Region>);
        void lower_region_to_bottom (boost::shared_ptr<Region>);
 
        uint32_t read_data_count() const { return _read_data_count; }
 
-       Session& session() { return _session; }
-
        const PBD::ID& get_orig_diskstream_id () const { return _orig_diskstream_id; }
        void set_orig_diskstream_id (const PBD::ID& did) { _orig_diskstream_id = did; }  
 
@@ -144,9 +137,14 @@ class Playlist : public StateManager, public PBD::StatefulDestructible {
        
        virtual bool destroy_region (boost::shared_ptr<Region>) = 0;
 
+       /* special case function used by UI selection objects, which have playlists that actually own the regions
+          within them.
+       */
+
+       void drop_regions ();
+
   protected:
        friend class Session;
-       virtual ~Playlist ();  /* members of the public use unref() */
 
   protected:
        struct RegionLock {
@@ -169,19 +167,20 @@ class Playlist : public StateManager, public PBD::StatefulDestructible {
        friend class RegionLock;
 
        RegionList       regions;  /* the current list of regions in the playlist */
-       string          _name;
-       Session&        _session;
+       std::set<boost::shared_ptr<Region> > all_regions; /* all regions ever added to this playlist */
+       DataType        _type;
        mutable gint    block_notifications;
        mutable gint    ignore_state_changes;
        mutable Glib::Mutex region_lock;
-       RegionList       pending_removals;
-       RegionList       pending_adds;
+       std::set<boost::shared_ptr<Region> > pending_adds;
+       std::set<boost::shared_ptr<Region> > pending_removes;
        RegionList       pending_bounds;
        bool             pending_modified;
        bool             pending_length;
        bool             save_on_thaw;
        string           last_save_reason;
-       bool             in_set_state;
+       uint32_t         in_set_state;
+       bool             first_set_state;
        bool            _hidden;
        bool            _splicing;
        bool            _nudging;
@@ -244,31 +243,23 @@ class Playlist : public StateManager, public PBD::StatefulDestructible {
 
        virtual XMLNode& state (bool);
 
-       /* override state_manager::save_state so we can check in_set_state() */
-
-       void save_state (std::string why);
-       void maybe_save_state (std::string why);
-
-       void add_region_internal (boost::shared_ptr<Region>, nframes_t position, bool delay_sort = false);
+       boost::shared_ptr<Region> region_by_id (PBD::ID);
 
-       int remove_region_internal (boost::shared_ptr<Region>, bool delay_sort = false);
+       void add_region_internal (boost::shared_ptr<Region>, nframes_t position);
+       
+       int remove_region_internal (boost::shared_ptr<Region>);
        RegionList *find_regions_at (nframes_t frame);
        void copy_regions (RegionList&) const;
        void partition_internal (nframes_t start, nframes_t end, bool cutting, RegionList& thawlist);
 
        nframes_t _get_maximum_extent() const;
 
-       Playlist* cut_copy (Playlist* (Playlist::*pmf)(nframes_t, nframes_t, bool), 
-                           list<AudioRange>& ranges, bool result_is_hidden);
-       Playlist *cut (nframes_t start, nframes_t cnt, bool result_is_hidden);
-       Playlist *copy (nframes_t start, nframes_t cnt, bool result_is_hidden);
-
+       boost::shared_ptr<Playlist> cut_copy (boost::shared_ptr<Playlist> (Playlist::*pmf)(nframes_t, nframes_t, bool), 
+                                             list<AudioRange>& ranges, bool result_is_hidden);
+       boost::shared_ptr<Playlist> cut (nframes_t start, nframes_t cnt, bool result_is_hidden);
+       boost::shared_ptr<Playlist> copy (nframes_t start, nframes_t cnt, bool result_is_hidden);
 
-       int move_region_to_layer (layer_t, boost::shared_ptr<Region> r, int dir);
        void relayer ();
-
-       static Playlist* copyPlaylist (const Playlist&, nframes_t start, nframes_t length,
-                                      string name, bool result_is_hidden);
        
        void unset_freeze_parent (Playlist*);
        void unset_freeze_child (Playlist*);