Tweak transmission of MMC on locate. Should fix #3121.
[ardour.git] / libs / ardour / playlist.cc
index 0526d48b11b9aa434044d42f1e3f1c40154e0dac..cc9dc62ec79c027fcc3f8417c11ab7821bb5d190 100644 (file)
@@ -134,7 +134,7 @@ RegionListProperty::copy_for_history () const
 }
 
 void 
-RegionListProperty::diff (PropertyList& undo, PropertyList& redo) const
+RegionListProperty::diff (PropertyList& undo, PropertyList& redo, Command* cmd) const
 {
         if (changed()) {
                /* list of the removed/added regions since clear_history() was last called */
@@ -144,6 +144,18 @@ RegionListProperty::diff (PropertyList& undo, PropertyList& redo) const
                 RegionListProperty* b = copy_for_history ();
                 b->invert_changes ();
 
+                if (cmd) {
+                        /* whenever one of the regions emits DropReferences, make sure
+                           that the Destructible we've been told to notify hears about
+                           it. the Destructible is likely to be the Command being built
+                           with this diff().
+                        */
+                        
+                        for (set<boost::shared_ptr<Region> >::iterator i = a->change().added.begin(); i != a->change().added.end(); ++i) {
+                                (*i)->DropReferences.connect_same_thread (*cmd, boost::bind (&Destructible::drop_references, cmd));
+                        }
+                }
+
                 undo.add (b);
                 redo.add (a);
         }
@@ -540,6 +552,7 @@ Playlist::notify_region_added (boost::shared_ptr<Region> r)
                pending_contents_change = true;
                pending_length = true;
        } else {
+                r->clear_history ();
                pending_length = false;
                LengthChanged (); /* EMIT SIGNAL */
                pending_contents_change = false;
@@ -608,7 +621,10 @@ Playlist::flush_notifications ()
 
        for (s = pending_adds.begin(); s != pending_adds.end(); ++s) {
                // cerr << _name << " sends RegionAdded\n";
-               RegionAdded (boost::weak_ptr<Region> (*s)); /* EMIT SIGNAL */
+                /* don't emit RegionAdded signal until relayering is done,
+                   so that the region is fully setup by the time
+                   anyone hear's that its been added
+                */
                dependent_checks_needed.insert (*s);
        }
 
@@ -635,6 +651,11 @@ Playlist::flush_notifications ()
                // cerr << _name << "done contents change @ " << get_microseconds() << endl;
        }
 
+       for (s = pending_adds.begin(); s != pending_adds.end(); ++s) {
+                (*s)->clear_history ();
+               RegionAdded (boost::weak_ptr<Region> (*s)); /* EMIT SIGNAL */
+        }
+
        for (s = dependent_checks_needed.begin(); s != dependent_checks_needed.end(); ++s) {
                check_dependents (*s, false);
        }
@@ -1314,7 +1335,7 @@ Playlist::shift (framepos_t at, frameoffset_t distance, bool move_intersected, b
                   has to be done separately.
                */
 
-               if (!ignore_music_glue && (*r)->positional_lock_style() != Region::AudioTime) {
+               if (!ignore_music_glue && (*r)->position_lock_style() != AudioTime) {
                        fixup.push_back (*r);
                        continue;
                }