Move various code up the Property / Stateful hierarchies.
authorCarl Hetherington <carl@carlh.net>
Wed, 25 Aug 2010 17:31:41 +0000 (17:31 +0000)
committerCarl Hetherington <carl@carlh.net>
Wed, 25 Aug 2010 17:31:41 +0000 (17:31 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@7682 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/playlist.h
libs/ardour/ardour/region.h
libs/ardour/playlist.cc
libs/ardour/region.cc
libs/pbd/pbd/property_basics.h
libs/pbd/pbd/sequence_property.h
libs/pbd/pbd/stateful.h
libs/pbd/stateful.cc

index d87c6cb3a056bb0c1c70066056f4868a51c7a688..b60fa62879da9d4c7a94537d47548dc0bd7b4505 100644 (file)
@@ -35,7 +35,6 @@
 
 #include "pbd/undo.h"
 #include "pbd/stateful.h"
-#include "pbd/stateful_owner.h"
 #include "pbd/statefuldestructible.h"
 #include "pbd/sequence_property.h"
 
@@ -74,11 +73,10 @@ class RegionListProperty : public PBD::SequenceProperty<std::list<boost::shared_
         Playlist& _playlist;
 };
 
-class Playlist : public SessionObject
-               , public PBD::StatefulOwner
-              , public boost::enable_shared_from_this<Playlist> {
-  public:
-       typedef std::list<boost::shared_ptr<Region> >    RegionList;
+class Playlist : public SessionObject , public boost::enable_shared_from_this<Playlist>
+{
+public:
+       typedef std::list<boost::shared_ptr<Region> > RegionList;
         static void make_property_quarks ();
 
        Playlist (Session&, const XMLNode&, DataType type, bool hidden = false);
@@ -88,13 +86,10 @@ class Playlist : public SessionObject
 
        virtual ~Playlist ();
 
-        bool set_property (const PBD::PropertyBase&);
         void update (const RegionListProperty::ChangeRecord&);
         void clear_owned_history ();
         void rdiff (std::vector<PBD::StatefulDiffCommand*>&) const;
 
-        PBD::PropertyList* property_factory (const XMLNode&) const;
-
        boost::shared_ptr<Region> region_by_id (const PBD::ID&);
 
        void set_region_ownership ();
index 089ca97eb27adc00b39716761f1b73219d2c661c..1e2bbe35811b4ec102f09b216adc783a2b4e4eb4 100644 (file)
@@ -88,8 +88,6 @@ class Region
        
        static PBD::Signal2<void,boost::shared_ptr<ARDOUR::Region>, const PBD::PropertyChange&> RegionPropertyChanged;
 
-        PBD::PropertyList* property_factory (const XMLNode&) const;
-
        virtual ~Region();
        
        /** Note: changing the name of a Region does not constitute an edit */
index 6ff51193d911cd8c2d02fd45ef53d9155babfaf5..2062f343d955a25d14422a18660eb41fec687525 100644 (file)
@@ -2079,38 +2079,18 @@ Playlist::mark_session_dirty ()
        }
 }
 
-bool
-Playlist::set_property (const PropertyBase& prop)
-{
-        if (prop == Properties::regions.property_id) {
-                const RegionListProperty::ChangeRecord& change (dynamic_cast<const RegionListProperty*>(&prop)->change());
-                regions.update (change);
-                return (!change.added.empty() && !change.removed.empty());
-        }
-        return false;
-}
-
 void
 Playlist::rdiff (vector<StatefulDiffCommand*>& cmds) const
 {
        RegionLock rlock (const_cast<Playlist *> (this));
-
-       for (RegionList::const_iterator i = regions.begin(); i != regions.end(); ++i) {
-               if ((*i)->changed ()) {
-                        StatefulDiffCommand* sdc = new StatefulDiffCommand (*i);
-                        cmds.push_back (sdc);
-                }
-       }
+       Stateful::rdiff (cmds);
 }
 
 void
 Playlist::clear_owned_history ()
 {
        RegionLock rlock (this);
-
-       for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) {
-                (*i)->clear_history ();
-        }
+       Stateful::clear_owned_history ();
 }
 
 void
@@ -2132,32 +2112,6 @@ Playlist::update (const RegionListProperty::ChangeRecord& change)
         thaw ();
 }
 
-PropertyList*
-Playlist::property_factory (const XMLNode& history_node) const
-{
-        const XMLNodeList& children (history_node.children());
-        PropertyList* prop_list = 0;
-
-        for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
-
-                if ((*i)->name() == capitalize (regions.property_name())) {
-                        
-                        RegionListProperty* rlp = new RegionListProperty (*const_cast<Playlist*> (this));
-
-                        if (rlp->set_change (**i)) {
-                                if (!prop_list) {
-                                        prop_list = new PropertyList();
-                                }
-                                prop_list->add (rlp);
-                        } else {
-                                delete rlp;
-                        }
-                }
-        }
-
-        return prop_list;
-}
-
 int
 Playlist::set_state (const XMLNode& node, int version)
 {
index da26c87f26c41a95aa3516f1d22c4cd5cdc93da3..4ce1ae282b0a3144d345ed4f070534426ec15ea4 100644 (file)
@@ -1582,19 +1582,3 @@ Region::use_sources (SourceList const & s)
                 }
        }
 }
-
-PropertyList*
-Region::property_factory (const XMLNode& history_node) const
-{
-        PropertyList* prop_list = new PropertyList;
-
-        for (OwnedPropertyList::const_iterator i = _properties->begin(); i != _properties->end(); ++i) {
-                PropertyBase* prop = i->second->maybe_clone_self_if_found_in_history_node (history_node);
-
-                if (prop) {
-                        prop_list->add (prop);
-                }
-        }
-
-        return prop_list;
-}
index 39a7c043e97c9afe9a3a25e1cd66f8beafedd8e2..433a25a59b7398573632505e4ff37ab4c048e361 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <glib.h>
 #include <set>
+#include <vector>
 
 #include "pbd/xml++.h"
 
@@ -30,6 +31,7 @@ class Command;
 namespace PBD {
 
 class PropertyList;
+class StatefulDiffCommand;     
 
 /** A unique identifier for a property of a Stateful object */
 typedef GQuark PropertyID;
@@ -89,6 +91,9 @@ public:
        /** Forget about any old value for this state */
        virtual void clear_history () = 0;
 
+       /** Tell any things we own to forget about their old values */
+       virtual void clear_owned_history () {}
+
         /** Get any change in this property as XML and add it to a node */
        virtual void get_change (XMLNode *) const = 0;
 
@@ -98,7 +103,10 @@ public:
         *  of those changes.
         */
        virtual void diff (PropertyList& undo, PropertyList& redo, Command*) const = 0;
-        
+
+       /** Collect StatefulDiffCommands for changes to anything that we own */
+       virtual void rdiff (std::vector<StatefulDiffCommand*> &) const {}
+       
         virtual PropertyBase* maybe_clone_self_if_found_in_history_node (const XMLNode&) const { return 0; }
 
        /** Set our value from an XML node.
index 1486437f58a6e2205334d146d2a7fc1052f778b5..e92aa5c68e89126bf895a7ac65be3c605981173d 100644 (file)
@@ -180,8 +180,46 @@ class SequenceProperty : public PropertyBase
                }
         }
 
+       SequenceProperty<Container>* maybe_clone_self_if_found_in_history_node (XMLNode const & node) const {
+
+               XMLNodeList const children = node.children ();
+               
+               for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
+
+                       if ((*i)->name() == capitalize (property_name())) {
+                               
+                               SequenceProperty<Container>* p = create ();
+                               
+                               if (p->set_change (**i)) {
+                                       return p;
+                               } else {
+                                       delete p;
+                               }
+                       }
+                }
+
+               return 0;
+        }
+
+       void clear_owned_history () {
+               for (typename Container::iterator i = begin(); i != end(); ++i) {
+                       (*i)->clear_history ();
+               }
+       }
+
+       void rdiff (std::vector<StatefulDiffCommand*>& cmds) const {
+               for (typename Container::const_iterator i = begin(); i != end(); ++i) {
+                       if ((*i)->changed ()) {
+                               StatefulDiffCommand* sdc = new StatefulDiffCommand (*i);
+                               cmds.push_back (sdc);
+                       }
+               }
+       }
+
+               
+
         Container rlist() { return _val; }
-       
+
        /* Wrap salient methods of Sequence
         */
 
index 619de5d06f9c56ff30c703c8335bbe9836922abd..af26caab07855a8eee72d50f1ac9820ebae56126 100644 (file)
@@ -68,12 +68,14 @@ class Stateful {
         /* history management */
 
        void clear_history ();
+       virtual void clear_owned_history ();
         void diff (PropertyList&, PropertyList&, Command*) const;
+       virtual void rdiff (std::vector<StatefulDiffCommand*> &) const;
         bool changed() const;
 
         /* create a property list from an XMLNode
          */
-        virtual PropertyList* property_factory(const XMLNode&) const { return 0; }
+        virtual PropertyList* property_factory (const XMLNode&) const;
 
        /* How stateful's notify of changes to their properties
         */
index f58c64603eb8c6a2ac3046c1496e47513f54aad2..6ea8f19128d789b9ca1c1121d14c18189af2a5e9 100644 (file)
@@ -314,4 +314,37 @@ Stateful::apply_change (const PropertyBase& prop)
        return true;
 }
 
+PropertyList*
+Stateful::property_factory (const XMLNode& history_node) const
+{
+        PropertyList* prop_list = new PropertyList;
+
+        for (OwnedPropertyList::const_iterator i = _properties->begin(); i != _properties->end(); ++i) {
+                PropertyBase* prop = i->second->maybe_clone_self_if_found_in_history_node (history_node);
+
+                if (prop) {
+                        prop_list->add (prop);
+                }
+        }
+
+        return prop_list;
+}
+
+void
+Stateful::rdiff (vector<StatefulDiffCommand*>& cmds) const
+{
+       for (OwnedPropertyList::const_iterator i = _properties->begin(); i != _properties->end(); ++i) {
+               i->second->rdiff (cmds);
+       }
+}
+
+void
+Stateful::clear_owned_history ()
+{
+       for (OwnedPropertyList::iterator i = _properties->begin(); i != _properties->end(); ++i) {
+               i->second->clear_owned_history ();
+       }
+}
+  
+
 } // namespace PBD