+ /* put these new regions on top of all existing ones, but preserve
+ the ordering they had in the original playlist.
+ */
+
+ add_region_internal (copy_of_region, (*i)->position() + pos, sub_num);
+ set_layer (copy_of_region, copy_of_region->layer() + top);
+ }
+ pos += shift;
+ }
+ }
+ }
+
+ return 0;
+}
+
+
+void
+Playlist::duplicate (boost::shared_ptr<Region> region, samplepos_t position, float times)
+{
+ duplicate(region, position, region->length(), times);
+}
+
+/** @param gap from the beginning of the region to the next beginning */
+void
+Playlist::duplicate (boost::shared_ptr<Region> region, samplepos_t position, samplecnt_t gap, float times)
+{
+ times = fabs (times);
+
+ RegionWriteLock rl (this);
+ int itimes = (int) floor (times);
+
+ while (itimes--) {
+ boost::shared_ptr<Region> copy = RegionFactory::create (region, true);
+ add_region_internal (copy, position);
+ set_layer (copy, DBL_MAX);
+ position += gap;
+ }
+
+ if (floor (times) != times) {
+ samplecnt_t length = (samplecnt_t) floor (region->length() * (times - floor (times)));
+ 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);
+ }
+ }
+}