copy plugin state to all instances when instantiating.
[ardour.git] / libs / ardour / playlist.cc
index 959b4884a347cd9812f8acd8f47ba151fabf5a05..239622a38c3252e3242dcd9e2ddbd37ff81f5edb 100644 (file)
@@ -1256,13 +1256,12 @@ Playlist::flush_notifications (bool from_undo)
 
         RegionWriteLock rl (this);
         int itimes = (int) floor (times);
-        framepos_t pos = position + 1;
 
         while (itimes--) {
                 boost::shared_ptr<Region> copy = RegionFactory::create (region, true);
-                add_region_internal (copy, pos);
+                add_region_internal (copy, position);
                 set_layer (copy, DBL_MAX);
-                pos += gap;
+                position += gap;
         }
 
         if (floor (times) != times) {
@@ -1278,12 +1277,78 @@ Playlist::flush_notifications (bool from_undo)
                         plist.add (Properties::name, name);
 
                         boost::shared_ptr<Region> sub = RegionFactory::create (region, plist);
-                        add_region_internal (sub, pos);
+                        add_region_internal (sub, position);
                         set_layer (sub, DBL_MAX);
                 }
         }
  }
 
+/** @param gap from the beginning of the region to the next beginning */
+/** @param end the first frame that does _not_ contain a duplicated frame */
+void
+Playlist::duplicate_until (boost::shared_ptr<Region> region, framepos_t position, framecnt_t gap, framepos_t end)
+{
+        RegionWriteLock rl (this);
+
+        while (position + region->length() - 1 < end) {
+                boost::shared_ptr<Region> copy = RegionFactory::create (region, true);
+                add_region_internal (copy, position);
+                set_layer (copy, DBL_MAX);
+                position += gap;
+        }
+
+        if (position < end) {
+                framecnt_t length = min (region->length(), end - position);
+                string name;
+                RegionFactory::region_name (name, region->name(), false);
+
+                {
+                        PropertyList plist;
+
+                        plist.add (Properties::start, region->start());
+                        plist.add (Properties::length, length);
+                        plist.add (Properties::name, name);
+
+                        boost::shared_ptr<Region> sub = RegionFactory::create (region, plist);
+                        add_region_internal (sub, position);
+                        set_layer (sub, DBL_MAX);
+                }
+        }
+}
+
+void
+Playlist::duplicate_range (AudioRange& range, float times)
+{
+       boost::shared_ptr<Playlist> pl = copy (range.start, range.length(), true);
+       framecnt_t offset = range.end - range.start;
+       paste (pl, range.start + offset, times);
+}
+
+void
+Playlist::duplicate_ranges (std::list<AudioRange>& ranges, float /* times */)
+{
+       if (ranges.empty()) {
+               return;
+       }
+
+       framepos_t min_pos = max_framepos;
+       framepos_t max_pos = 0;
+
+       for (std::list<AudioRange>::const_iterator i = ranges.begin();
+            i != ranges.end();
+            ++i) {
+               min_pos = min (min_pos, (*i).start);
+               max_pos = max (max_pos, (*i).end);
+       }
+
+       framecnt_t offset = max_pos - min_pos;
+
+       for (list<AudioRange>::iterator i = ranges.begin(); i != ranges.end(); ++i) {
+               boost::shared_ptr<Playlist> pl = copy ((*i).start, (*i).length(), true);
+               paste (pl, (*i).start + offset, 1.0f); // times ??
+       }
+}
+
  void
  Playlist::shift (framepos_t at, frameoffset_t distance, bool move_intersected, bool ignore_music_glue)
  {
@@ -1376,7 +1441,6 @@ Playlist::flush_notifications (bool from_undo)
         {
                 PropertyList plist;
 
-                plist.add (Properties::position, region->position ());
                 plist.add (Properties::length, before);
                 plist.add (Properties::name, before_name);
                 plist.add (Properties::left_of_split, true);
@@ -1395,7 +1459,6 @@ Playlist::flush_notifications (bool from_undo)
         {
                 PropertyList plist;
 
-                plist.add (Properties::position, region->position() + before);
                 plist.add (Properties::length, after);
                 plist.add (Properties::name, after_name);
                 plist.add (Properties::right_of_split, true);
@@ -1706,7 +1769,7 @@ Playlist::region_bounds_changed (const PropertyChange& what_changed, boost::shar
 
  }
 
- /***********************************************************************
+ /* *********************************************************************
   FINDING THINGS
   **********************************************************************/
 
@@ -2841,7 +2904,7 @@ Playlist::update_after_tempo_map_change ()
 void
 Playlist::foreach_region (boost::function<void(boost::shared_ptr<Region>)> s)
 {
-       RegionWriteLock rl (this, false);
+       RegionReadLock rl (this);
        for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) {
                s (*i);
        }
@@ -3110,7 +3173,7 @@ Playlist::uncombine (boost::shared_ptr<Region> target)
                }
 
                /* check to see how the original region (in the
-                * playlist before compounding occured) overlaps
+                * playlist before compounding occurred) overlaps
                 * with the new state of the compound region.
                 */