Use a MementoCommandBinder for Crossfades so that the undo record can contain details...
authorCarl Hetherington <carl@carlh.net>
Wed, 21 Sep 2011 15:54:19 +0000 (15:54 +0000)
committerCarl Hetherington <carl@carlh.net>
Wed, 21 Sep 2011 15:54:19 +0000 (15:54 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@10104 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/crossfade_edit.cc
libs/ardour/ardour/midi_automation_list_binder.h
libs/ardour/midi_automation_list_binder.cc
libs/ardour/session_command.cc
libs/ardour/wscript
libs/pbd/pbd/memento_command.h

index 7ec19e97ad27a1bdf40e8cfe8a87a1abc542ea89..da833b8ea452f6eb40d87705c91f4a03f7b8fb3e 100644 (file)
@@ -37,6 +37,7 @@
 #include "ardour/audiosource.h"
 #include "ardour/region_factory.h"
 #include "ardour/profile.h"
+#include "ardour/crossfade_binder.h"
 
 #include <gtkmm2ext/gtk_ui.h>
 
@@ -791,7 +792,13 @@ CrossfadeEditor::apply ()
 
        _apply_to (xfade);
 
-       _session->add_command (new MementoCommand<Crossfade> (*xfade.get(), &before, &xfade->get_state ()));
+       _session->add_command (
+               new MementoCommand<Crossfade> (
+                       new ARDOUR::CrossfadeBinder (_session->playlists, xfade->id ()),
+                       &before, &xfade->get_state ()
+                       )
+               );
+
        _session->commit_reversible_command ();
 }
 
index 95576b47deec6262809bc390c113381939a276e0..89c6cdb90bb6d43af2892ee2575c032fa7ef08a0 100644 (file)
@@ -33,7 +33,7 @@ public:
        MidiAutomationListBinder (boost::shared_ptr<ARDOUR::MidiSource>, Evoral::Parameter);
        MidiAutomationListBinder (XMLNode *, ARDOUR::Session::SourceMap const &);
 
-       ARDOUR::AutomationList* get ();
+       ARDOUR::AutomationList* get () const;
        void add_state (XMLNode *);
 
 private:
index 0f8e4884ca0931dbfa0d6d2a7848884954f85efb..fbb87c5cfa2a2265191ae3051529ea30bcf99d92 100644 (file)
@@ -49,7 +49,7 @@ MidiAutomationListBinder::MidiAutomationListBinder (XMLNode* node, Session::Sour
 }
 
 AutomationList*
-MidiAutomationListBinder::get ()
+MidiAutomationListBinder::get () const
 {
        boost::shared_ptr<MidiModel> model = _source->model ();
        assert (model);
index c240a4aa9447b5b32f606ef0bb443ce18d6c4814..e5ddd0a0973ac9c816933584f7e852a74b76efcd 100644 (file)
@@ -34,6 +34,7 @@
 #include "ardour/session_playlists.h"
 #include "ardour/region_factory.h"
 #include "ardour/midi_automation_list_binder.h"
+#include "ardour/crossfade_binder.h"
 #include "ardour/crossfade.h"
 #include "pbd/error.h"
 #include "pbd/id.h"
@@ -143,11 +144,16 @@ Session::memento_command_factory(XMLNode *n)
            cerr << "Alist " << id << " not found\n";
 
     } else if (obj_T == "ARDOUR::Crossfade") {
-           boost::shared_ptr<Crossfade> c = playlists->find_crossfade (id);
-           if (c) {
-                   return new MementoCommand<Crossfade> (*c.get(), before, after);
+           if (have_id) {
+                   boost::shared_ptr<Crossfade> c = playlists->find_crossfade (id);
+                   if (c) {
+                           return new MementoCommand<Crossfade> (*c.get(), before, after);
+                   }
            } else {
-                   error << string_compose (X_("Crossfade %1 not found in session"), id) << endmsg;
+                   return new MementoCommand<Crossfade> (
+                           new CrossfadeBinder (n, playlists),
+                           before, after
+                           );
            }
 
     } else if (registry.count(id)) { // For Editor and AutomationLine which are off-limits herea
index b347e73e7ec49750d06b86c8e2d7ce365cccfc80..1b71f58298744c2782fe926966d6aae97d140935 100644 (file)
@@ -71,6 +71,7 @@ libardour_sources = [
         'control_protocol_manager.cc',
         'control_protocol_search_path.cc',
         'crossfade.cc',
+        'crossfade_binder.cc',
         'cycle_timer.cc',
         'data_type.cc',
         'default_click.cc',
index 8b412937effd59074b192f75d2623fa76f7c0716..45cb100a36e6d967e28771b6f935b565ad1d465e 100644 (file)
 /** A class that can return a Stateful object which is the subject of a MementoCommand.
  *
  *  The existence of this class means that the undo record can refer to objects which
- *  don't exist in the session file.  Currently this is just used for MIDI automation;
- *  when MIDI automation is edited, undo records are written for the AutomationList being
- *  changed.  However this AutomationList is a temporary structure, built by a MidiModel,
- *  which doesn't get written to the session file.  Hence we need to be able to go from
- *  a MidiSource and Parameter to an AutomationList.  This Binder mechanism allows this
- *  through MidiAutomationListBinder; the undo record stores the source and parameter,
+ *  don't exist in the session file.  Currently this is used for
+ *
+ *  1.  MIDI automation; when MIDI automation is edited, undo records are
+ *  written for the AutomationList being changed.  However this AutomationList
+ *  is a temporary structure, built by a MidiModel, which doesn't get written
+ *  to the session file.  Hence we need to be able to go from a MidiSource and
+ *  Parameter to an AutomationList.  This Binder mechanism allows this through
+ *  MidiAutomationListBinder; the undo record stores the source and parameter,
  *  and these are bound to an AutomationList by the Binder.
+ *
+ *  2.  Crossfades; unlike regions, these are completely removed from a session
+ *  when they are deleted.  This means that the undo record can contain
+ *  references to non-existant crossfades.  To get around this, CrossfadeBinder
+ *  can do `just-in-time' binding from the crossfade ID.
  */
 template <class obj_T>
 class MementoCommandBinder : public PBD::Destructible
 {
 public:
        /** @return Stateful object to operate on */
-       virtual obj_T* get () = 0;
+       virtual obj_T* get () const = 0;
+
+       /** @return Name of our type */
+       virtual std::string type_name () const {
+               return PBD::demangled_name (*get ());
+       }
 
        /** Add our own state to an XMLNode */
        virtual void add_state (XMLNode *) = 0;
@@ -64,7 +76,7 @@ public:
                _object.Destroyed.connect_same_thread (_object_death_connection, boost::bind (&SimpleMementoCommandBinder::object_died, this));
        }
 
-       obj_T* get () {
+       obj_T* get () const {
                return &_object;
        }
 
@@ -140,7 +152,7 @@ public:
                XMLNode* node = new XMLNode(name);
                _binder->add_state (node);
                
-               node->add_property("type_name", demangled_name (*_binder->get()));
+               node->add_property ("type_name", _binder->type_name ());
 
                if (before) {
                        node->add_child_copy(*before);