diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2010-06-23 20:14:07 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2010-06-23 20:14:07 +0000 |
commit | f4401c59284258c6aa56707da64e3da32756329f (patch) | |
tree | 73679199ae43516347d607adad212c10612f7eb9 /libs/pbd | |
parent | cac03dbeb6ebdcd406385dd14a746cb8c51dd5f8 (diff) |
midway snapshot of work done on managing Region & Source lifetimes correctly. may fix missing MIDI file bug ; save empty playlists because they may be referred to by the history file ; undo commands auto-delete when objects they refer to die (currently not commands built from XML deserialization); Sources now know how many regions are using them for something, meaning that we know if we can delete the files holding any data for the source
git-svn-id: svn://localhost/ardour2/branches/3.0@7291 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/pbd')
-rw-r--r-- | libs/pbd/pbd/command.h | 8 | ||||
-rw-r--r-- | libs/pbd/pbd/properties.h | 4 | ||||
-rw-r--r-- | libs/pbd/pbd/property_basics.h | 6 | ||||
-rw-r--r-- | libs/pbd/pbd/stateful.h | 2 | ||||
-rw-r--r-- | libs/pbd/pbd/stateful_diff_command.h | 8 | ||||
-rw-r--r-- | libs/pbd/pbd/undo.h | 3 | ||||
-rw-r--r-- | libs/pbd/stateful.cc | 4 | ||||
-rw-r--r-- | libs/pbd/stateful_diff_command.cc | 22 | ||||
-rw-r--r-- | libs/pbd/undo.cc | 28 |
9 files changed, 40 insertions, 45 deletions
diff --git a/libs/pbd/pbd/command.h b/libs/pbd/pbd/command.h index 5a7290bc89..c6c3c8d3fd 100644 --- a/libs/pbd/pbd/command.h +++ b/libs/pbd/pbd/command.h @@ -22,10 +22,12 @@ #ifndef __lib_pbd_command_h__ #define __lib_pbd_command_h__ +#include <string> + +#include "pbd/signals.h" #include "pbd/statefuldestructible.h" -#include <boost/utility.hpp> -class Command : public PBD::StatefulDestructible, public boost::noncopyable +class Command : public PBD::StatefulDestructible, public PBD::ScopedConnectionList { public: virtual ~Command() { /* NOTE: derived classes must call drop_references() */ } @@ -34,7 +36,7 @@ public: void set_name (const std::string& str) { _name = str; } const std::string& name() const { return _name; } - + virtual void undo() = 0; virtual void redo() { (*this)(); } diff --git a/libs/pbd/pbd/properties.h b/libs/pbd/pbd/properties.h index 784282ee9c..1914344db9 100644 --- a/libs/pbd/pbd/properties.h +++ b/libs/pbd/pbd/properties.h @@ -165,7 +165,7 @@ public: : PropertyTemplate<T> (q, v) {} - void diff (PropertyList& undo, PropertyList& redo) const { + void diff (PropertyList& undo, PropertyList& redo, Command* /*ignored*/) const { if (this->_have_old) { undo.add (new Property<T> (this->property_id(), this->_old)); redo.add (new Property<T> (this->property_id(), this->_current)); @@ -227,7 +227,7 @@ public: : PropertyTemplate<std::string> (q, v) {} - void diff (PropertyList& before, PropertyList& after) const { + void diff (PropertyList& before, PropertyList& after, Command* /*ignored*/) const { if (this->_have_old) { before.add (new Property<std::string> (PropertyDescriptor<std::string> (this->property_id()), this->_old)); after.add (new Property<std::string> (PropertyDescriptor<std::string> (this->property_id()), this->_current)); diff --git a/libs/pbd/pbd/property_basics.h b/libs/pbd/pbd/property_basics.h index 5e94abdfc3..2dea20e251 100644 --- a/libs/pbd/pbd/property_basics.h +++ b/libs/pbd/pbd/property_basics.h @@ -25,6 +25,8 @@ #include "pbd/xml++.h" +class Command; + namespace PBD { class PropertyList; @@ -83,7 +85,7 @@ public: {} virtual ~PropertyBase () {} - + /** Forget about any old value for this state */ virtual void clear_history () = 0; @@ -97,7 +99,7 @@ public: * the last call to clear_history, and one that allows redo * of those changes. */ - virtual void diff (PropertyList& undo, PropertyList& redo) const = 0; + virtual void diff (PropertyList& undo, PropertyList& redo, Command*) const = 0; virtual PropertyBase* maybe_clone_self_if_found_in_history_node (const XMLNode&) const { return 0; } diff --git a/libs/pbd/pbd/stateful.h b/libs/pbd/pbd/stateful.h index 4352e88201..1272a735f9 100644 --- a/libs/pbd/pbd/stateful.h +++ b/libs/pbd/pbd/stateful.h @@ -67,7 +67,7 @@ class Stateful { /* history management */ void clear_history (); - void diff (PropertyList&, PropertyList&) const; + void diff (PropertyList&, PropertyList&, Command*) const; bool changed() const; /* create a property list from an XMLNode diff --git a/libs/pbd/pbd/stateful_diff_command.h b/libs/pbd/pbd/stateful_diff_command.h index 21245f029a..25cdfbba12 100644 --- a/libs/pbd/pbd/stateful_diff_command.h +++ b/libs/pbd/pbd/stateful_diff_command.h @@ -27,7 +27,7 @@ namespace PBD { -class Stateful; +class StatefulDestructible; class PropertyList; /** A Command which stores its action as the differences between the before and after @@ -36,13 +36,13 @@ class PropertyList; class StatefulDiffCommand : public Command { public: - StatefulDiffCommand (boost::shared_ptr<Stateful>); - StatefulDiffCommand (boost::shared_ptr<Stateful>, XMLNode const &); + StatefulDiffCommand (boost::shared_ptr<StatefulDestructible>); + StatefulDiffCommand (boost::shared_ptr<StatefulDestructible>, XMLNode const &); ~StatefulDiffCommand (); void operator() (); void undo (); - + XMLNode& get_state (); private: diff --git a/libs/pbd/pbd/undo.h b/libs/pbd/pbd/undo.h index 6eb9e00056..fb5152c293 100644 --- a/libs/pbd/pbd/undo.h +++ b/libs/pbd/pbd/undo.h @@ -27,12 +27,11 @@ #include <sigc++/bind.h> #include <sys/time.h> -#include "pbd/signals.h" #include "pbd/command.h" typedef sigc::slot<void> UndoAction; -class UndoTransaction : public Command, public PBD::ScopedConnectionList +class UndoTransaction : public Command { public: UndoTransaction (); diff --git a/libs/pbd/stateful.cc b/libs/pbd/stateful.cc index b486319c4c..1c3d08b3a9 100644 --- a/libs/pbd/stateful.cc +++ b/libs/pbd/stateful.cc @@ -167,10 +167,10 @@ Stateful::clear_history () } void -Stateful::diff (PropertyList& before, PropertyList& after) const +Stateful::diff (PropertyList& before, PropertyList& after, Command* cmd) const { for (OwnedPropertyList::const_iterator i = _properties->begin(); i != _properties->end(); ++i) { - i->second->diff (before, after); + i->second->diff (before, after, cmd); } } diff --git a/libs/pbd/stateful_diff_command.cc b/libs/pbd/stateful_diff_command.cc index 635fe4829a..2c58acee14 100644 --- a/libs/pbd/stateful_diff_command.cc +++ b/libs/pbd/stateful_diff_command.cc @@ -32,15 +32,21 @@ using namespace PBD; * @param s Stateful object. */ -StatefulDiffCommand::StatefulDiffCommand (boost::shared_ptr<Stateful> s) - : _object (s) +StatefulDiffCommand::StatefulDiffCommand (boost::shared_ptr<StatefulDestructible> s) + : _object (s) , _undo (new PropertyList) , _redo (new PropertyList) { - s->diff (*_undo, *_redo); + s->diff (*_undo, *_redo, this); + + /* if the stateful object that this command refers to goes away, + be sure to notify owners of this command. + */ + + s->DropReferences.connect_same_thread (*this, boost::bind (&Destructible::drop_references, this)); } -StatefulDiffCommand::StatefulDiffCommand (boost::shared_ptr<Stateful> s, XMLNode const & n) +StatefulDiffCommand::StatefulDiffCommand (boost::shared_ptr<StatefulDestructible> s, XMLNode const & n) : _object (s) , _undo (0) , _redo (0) @@ -57,10 +63,18 @@ StatefulDiffCommand::StatefulDiffCommand (boost::shared_ptr<Stateful> s, XMLNode assert (_undo != 0); assert (_redo != 0); + + /* if the stateful object that this command refers to goes away, + be sure to notify owners of this command. + */ + + s->DropReferences.connect_same_thread (*this, boost::bind (&Destructible::drop_references, this)); } StatefulDiffCommand::~StatefulDiffCommand () { + drop_references (); + delete _undo; delete _redo; } diff --git a/libs/pbd/undo.cc b/libs/pbd/undo.cc index a06127926f..120f62c351 100644 --- a/libs/pbd/undo.cc +++ b/libs/pbd/undo.cc @@ -39,7 +39,6 @@ UndoTransaction::UndoTransaction () UndoTransaction::UndoTransaction (const UndoTransaction& rhs) : Command(rhs._name) - , PBD::ScopedConnectionList () , _clearing(false) { clear (); @@ -77,15 +76,15 @@ UndoTransaction::operator= (const UndoTransaction& rhs) } void -UndoTransaction::add_command (Command *const action) +UndoTransaction::add_command (Command *const cmd) { /* catch death of command (e.g. caused by death of object to which it refers. command_death() is a normal static function so there is no need to manage this connection. */ - action->DropReferences.connect_same_thread (*this, boost::bind (&command_death, this, action)); - actions.push_back (action); + cmd->DropReferences.connect_same_thread (*this, boost::bind (&command_death, this, cmd)); + actions.push_back (cmd); } void @@ -250,9 +249,6 @@ UndoHistory::undo (unsigned int n) return; } - struct timeval start, end, diff; - gettimeofday (&start, 0); - { UndoRedoSignaller exception_safe_signaller (*this); @@ -265,16 +261,8 @@ UndoHistory::undo (unsigned int n) ut->undo (); RedoList.push_back (ut); } - gettimeofday (&end, 0); - timersub (&end, &start, &diff); - cerr << "Undo-pre-signals took " << diff.tv_sec << '.' << diff.tv_usec << endl; - } - gettimeofday (&end, 0); - timersub (&end, &start, &diff); - cerr << "Undo took " << diff.tv_sec << '.' << diff.tv_usec << endl; - Changed (); /* EMIT SIGNAL */ } @@ -285,9 +273,6 @@ UndoHistory::redo (unsigned int n) return; } - struct timeval start, end, diff; - gettimeofday (&start, 0); - { UndoRedoSignaller exception_safe_signaller (*this); @@ -300,15 +285,8 @@ UndoHistory::redo (unsigned int n) ut->redo (); UndoList.push_back (ut); } - gettimeofday (&end, 0); - timersub (&end, &start, &diff); - cerr << "Redo-pre-signals took " << diff.tv_sec << '.' << diff.tv_usec << endl; } - gettimeofday (&end, 0); - timersub (&end, &start, &diff); - cerr << "Redo took " << diff.tv_sec << '.' << diff.tv_usec << endl; - Changed (); /* EMIT SIGNAL */ } |