diff options
author | Carl Hetherington <carl@carlh.net> | 2010-08-25 17:31:41 +0000 |
---|---|---|
committer | Carl Hetherington <carl@carlh.net> | 2010-08-25 17:31:41 +0000 |
commit | fde848282d43db6f7b337a959b5268236d377404 (patch) | |
tree | 0ee65ec91cccb654c99d40dc64fd3f8ce829d278 /libs | |
parent | 7b2975244165b4ffd1dcf4080c1be4c8dcbc6708 (diff) |
Move various code up the Property / Stateful hierarchies.
git-svn-id: svn://localhost/ardour2/branches/3.0@7682 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r-- | libs/ardour/ardour/playlist.h | 13 | ||||
-rw-r--r-- | libs/ardour/ardour/region.h | 2 | ||||
-rw-r--r-- | libs/ardour/playlist.cc | 50 | ||||
-rw-r--r-- | libs/ardour/region.cc | 16 | ||||
-rw-r--r-- | libs/pbd/pbd/property_basics.h | 10 | ||||
-rw-r--r-- | libs/pbd/pbd/sequence_property.h | 40 | ||||
-rw-r--r-- | libs/pbd/pbd/stateful.h | 4 | ||||
-rw-r--r-- | libs/pbd/stateful.cc | 33 |
8 files changed, 90 insertions, 78 deletions
diff --git a/libs/ardour/ardour/playlist.h b/libs/ardour/ardour/playlist.h index d87c6cb3a0..b60fa62879 100644 --- a/libs/ardour/ardour/playlist.h +++ b/libs/ardour/ardour/playlist.h @@ -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 (); diff --git a/libs/ardour/ardour/region.h b/libs/ardour/ardour/region.h index 089ca97eb2..1e2bbe3581 100644 --- a/libs/ardour/ardour/region.h +++ b/libs/ardour/ardour/region.h @@ -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 */ diff --git a/libs/ardour/playlist.cc b/libs/ardour/playlist.cc index 6ff51193d9..2062f343d9 100644 --- a/libs/ardour/playlist.cc +++ b/libs/ardour/playlist.cc @@ -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) { diff --git a/libs/ardour/region.cc b/libs/ardour/region.cc index da26c87f26..4ce1ae282b 100644 --- a/libs/ardour/region.cc +++ b/libs/ardour/region.cc @@ -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; -} diff --git a/libs/pbd/pbd/property_basics.h b/libs/pbd/pbd/property_basics.h index 39a7c043e9..433a25a59b 100644 --- a/libs/pbd/pbd/property_basics.h +++ b/libs/pbd/pbd/property_basics.h @@ -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. diff --git a/libs/pbd/pbd/sequence_property.h b/libs/pbd/pbd/sequence_property.h index 1486437f58..e92aa5c68e 100644 --- a/libs/pbd/pbd/sequence_property.h +++ b/libs/pbd/pbd/sequence_property.h @@ -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 */ diff --git a/libs/pbd/pbd/stateful.h b/libs/pbd/pbd/stateful.h index 619de5d06f..af26caab07 100644 --- a/libs/pbd/pbd/stateful.h +++ b/libs/pbd/pbd/stateful.h @@ -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 */ diff --git a/libs/pbd/stateful.cc b/libs/pbd/stateful.cc index f58c64603e..6ea8f19128 100644 --- a/libs/pbd/stateful.cc +++ b/libs/pbd/stateful.cc @@ -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 |