Merge branch 'master' into windows
[ardour.git] / libs / ardour / playlist.cc
index 390f9fdaaddc0a879dd3fbe4b4eae9f57143994f..47462a3575be3b19274698290d9dbf861f68a3d8 100644 (file)
@@ -47,9 +47,9 @@ using namespace ARDOUR;
 using namespace PBD;
 
 namespace ARDOUR {
-namespace Properties {
-PBD::PropertyDescriptor<bool> regions;
-}
+       namespace Properties {
+               PBD::PropertyDescriptor<bool> regions;
+       }
 }
 
 struct ShowMeTheList {
@@ -250,7 +250,7 @@ Playlist::Playlist (boost::shared_ptr<const Playlist> other, framepos_t start, f
                plist.add (Properties::layer, region->layer());
                plist.add (Properties::layering_index, region->layering_index());
 
-               new_region = RegionFactory::RegionFactory::create (region, plist);
+               new_region = RegionFactory::create (region, plist);
 
                add_region_internal (new_region, position);
        }
@@ -284,7 +284,7 @@ Playlist::copy_regions (RegionList& newlist) const
        RegionReadLock rlock (const_cast<Playlist *> (this));
 
        for (RegionList::const_iterator i = regions.begin(); i != regions.end(); ++i) {
-               newlist.push_back (RegionFactory::RegionFactory::create (*i, true));
+               newlist.push_back (RegionFactory::create (*i, true));
        }
 }
 
@@ -311,6 +311,7 @@ Playlist::init (bool hide)
        in_partition = false;
        subcnt = 0;
        _frozen = false;
+       _capture_insertion_underway = false;
        _combine_ops = 0;
 
        _session.history().BeginUndoRedo.connect_same_thread (*this, boost::bind (&Playlist::begin_undo, this));
@@ -750,10 +751,6 @@ Playlist::flush_notifications (bool from_undo)
 
         notify_region_added (region);
 
-        if (!holding_state ()) {
-                check_crossfades (region->range ());
-        }
-
         region->PropertyChanged.connect_same_thread (region_state_changed_connections, boost::bind (&Playlist::region_changed_proxy, this, _1, boost::weak_ptr<Region> (region)));
 
         return true;
@@ -847,6 +844,17 @@ Playlist::flush_notifications (bool from_undo)
         }
  }
 
+ void
+ Playlist::get_source_equivalent_regions (boost::shared_ptr<Region> other, vector<boost::shared_ptr<Region> >& results)
+ {
+        for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) {
+
+                if ((*i) && (*i)->any_source_equivalent (other)) {
+                        results.push_back (*i);
+                }
+        }
+ }
+
  void
  Playlist::partition (framepos_t start, framepos_t end, bool cut)
  {
@@ -1094,8 +1102,6 @@ Playlist::flush_notifications (bool from_undo)
 
                 in_partition = false;
         }
-
-        check_crossfades (Evoral::Range<framepos_t> (start, end));
  }
 
  boost::shared_ptr<Playlist>
@@ -1552,10 +1558,6 @@ Playlist::flush_notifications (bool from_undo)
                 save = !(_splicing || _nudging);
         }
 
-        if (what_changed.contains (our_interests) && !what_changed.contains (pos_and_length)) {
-                check_crossfades (region->range ());
-        }
-
         if (what_changed.contains (Properties::position) && !what_changed.contains (Properties::length)) {
                 notify_region_moved (region);
         } else if (!what_changed.contains (Properties::position) && what_changed.contains (Properties::length)) {
@@ -1995,11 +1997,11 @@ Playlist::find_next_region (framepos_t frame, RegionPoint point, int dir)
 
         freeze ();
         /* add the added regions */
-        for (RegionListProperty::ChangeContainer::iterator i = change.added.begin(); i != change.added.end(); ++i) {
+        for (RegionListProperty::ChangeContainer::const_iterator i = change.added.begin(); i != change.added.end(); ++i) {
                 add_region_internal ((*i), (*i)->position());
         }
         /* remove the removed regions */
-        for (RegionListProperty::ChangeContainer::iterator i = change.removed.begin(); i != change.removed.end(); ++i) {
+        for (RegionListProperty::ChangeContainer::const_iterator i = change.removed.begin(); i != change.removed.end(); ++i) {
                 remove_region (*i);
         }
 
@@ -2099,15 +2101,6 @@ Playlist::find_next_region (framepos_t frame, RegionPoint point, int dir)
 
        if (seen_region_nodes && regions.empty()) {
                ret = -1;
-       } else {
-
-               /* update dependents, which was not done during add_region_internal
-                  due to in_set_state being true
-               */
-               
-               for (RegionList::iterator r = regions.begin(); r != regions.end(); ++r) {
-                       check_crossfades ((*r)->range ());
-               }
        }
                
        thaw ();
@@ -2179,6 +2172,16 @@ Playlist::n_regions() const
        return regions.size();
 }
 
+/** @return true if the all_regions list is empty, ie this playlist
+ *  has never had a region added to it.
+ */
+bool
+Playlist::all_regions_empty() const
+{
+       RegionReadLock rl (const_cast<Playlist *> (this));
+       return all_regions.empty();
+}
+
 pair<framepos_t, framepos_t>
 Playlist::get_extent () const
 {
@@ -2410,7 +2413,6 @@ Playlist::raise_region (boost::shared_ptr<Region> region)
 {
        set_layer (region, region->layer() + 1.5);
        relayer ();
-       check_crossfades (region->range ());
 }
 
 void
@@ -2418,7 +2420,6 @@ Playlist::lower_region (boost::shared_ptr<Region> region)
 {
        set_layer (region, region->layer() - 1.5);
        relayer ();
-       check_crossfades (region->range ());
 }
 
 void
@@ -2426,7 +2427,6 @@ Playlist::raise_region_to_top (boost::shared_ptr<Region> region)
 {
        set_layer (region, DBL_MAX);
        relayer ();
-       check_crossfades (region->range ());
 }
 
 void
@@ -2434,7 +2434,6 @@ Playlist::lower_region_to_bottom (boost::shared_ptr<Region> region)
 {
        set_layer (region, -0.5);
        relayer ();
-       check_crossfades (region->range ());
 }
 
 void
@@ -2489,7 +2488,7 @@ Playlist::uses_source (boost::shared_ptr<const Source> src) const
 {
        RegionReadLock rlock (const_cast<Playlist*> (this));
 
-       for (set<boost::shared_ptr<Region> >::iterator r = all_regions.begin(); r != all_regions.end(); ++r) {
+       for (set<boost::shared_ptr<Region> >::const_iterator r = all_regions.begin(); r != all_regions.end(); ++r) {
                if ((*r)->uses_source (src)) {
                        return true;
                }
@@ -2534,7 +2533,7 @@ Playlist::region_by_id (const ID& id) const
 {
        /* searches all regions ever added to this playlist */
 
-       for (set<boost::shared_ptr<Region> >::iterator i = all_regions.begin(); i != all_regions.end(); ++i) {
+       for (set<boost::shared_ptr<Region> >::const_iterator i = all_regions.begin(); i != all_regions.end(); ++i) {
                if ((*i)->id() == id) {
                        return *i;
                }
@@ -2826,6 +2825,7 @@ Playlist::combine (const RegionList& r)
                /* make position relative to zero */
 
                pl->add_region (copied_region, original_region->position() - earliest_position);
+               copied_region->set_layer (original_region->layer ());
 
                /* use the maximum number of channels for any region */
 
@@ -3103,8 +3103,10 @@ restart:
                        }
                }
        }
+}
 
-       for (list<Evoral::Range<framepos_t> >::iterator i = ranges.begin(); i != ranges.end(); ++i) {
-               check_crossfades (*i);
-       }
+void
+Playlist::set_capture_insertion_in_progress (bool yn)
+{
+       _capture_insertion_underway = yn;
 }