faderport: switch long-press mechanism to a timeout
[ardour.git] / libs / ardour / playlist.cc
index 8862c633ab62fbe6578b5d5b3ed36605a174101a..842ff8f394ce43a322711403805d26d479a5cea2 100644 (file)
@@ -557,7 +557,7 @@ Playlist::notify_region_added (boost::shared_ptr<Region> r)
                pending_contents_change = false;
                RegionAdded (boost::weak_ptr<Region> (r)); /* EMIT SIGNAL */
                ContentsChanged (); /* EMIT SIGNAL */
-               
+
        }
 }
 
@@ -603,7 +603,7 @@ Playlist::flush_notifications (bool from_undo)
                remove_dependents (*s);
                RegionRemoved (boost::weak_ptr<Region> (*s)); /* EMIT SIGNAL */
        }
-       
+
        for (s = pending_adds.begin(); s != pending_adds.end(); ++s) {
                crossfade_ranges.push_back ((*s)->range ());
                /* don't emit RegionAdded signal until relayering is done,
@@ -620,25 +620,25 @@ Playlist::flush_notifications (bool from_undo)
                pending_layering = true;
                ContentsChanged (); /* EMIT SIGNAL */
        }
-       
+
        for (s = pending_adds.begin(); s != pending_adds.end(); ++s) {
                (*s)->clear_changes ();
                RegionAdded (boost::weak_ptr<Region> (*s)); /* EMIT SIGNAL */
        }
-       
+
        if ((regions_changed && !in_set_state) || pending_layering) {
                relayer ();
        }
-       
+
        coalesce_and_check_crossfades (crossfade_ranges);
-       
+
        if (!pending_range_moves.empty ()) {
                /* We don't need to check crossfades for these as pending_bounds has
                   already covered it.
                */
                RangesMoved (pending_range_moves, from_undo);
        }
-       
+
        if (!pending_region_extensions.empty ()) {
                RegionsExtended (pending_region_extensions);
        }
@@ -1225,11 +1225,11 @@ Playlist::flush_notifications (bool from_undo)
                         while (itimes--) {
                                 for (RegionList::iterator i = other->regions.begin(); i != other->regions.end(); ++i) {
                                         boost::shared_ptr<Region> copy_of_region = RegionFactory::create (*i, true);
-                                        
+
                                         /* 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);
                                         set_layer (copy_of_region, copy_of_region->layer() + top);
                                 }
@@ -1244,18 +1244,24 @@ Playlist::flush_notifications (bool from_undo)
 
  void
  Playlist::duplicate (boost::shared_ptr<Region> region, framepos_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, framepos_t position, framecnt_t gap, float times)
  {
         times = fabs (times);
 
         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 += region->length();
+                position += gap;
         }
 
         if (floor (times) != times) {
@@ -1271,7 +1277,7 @@ 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);
                 }
         }
@@ -1416,7 +1422,7 @@ Playlist::flush_notifications (bool from_undo)
 
         if (_edit_mode == Splice) {
                 splice_locked (at, distance, exclude);
-        } 
+        }
  }
 
  void
@@ -1515,8 +1521,8 @@ Playlist::core_ripple (framepos_t at, framecnt_t distance, RegionList *exclude)
                                new_pos = 0;
                        } else if (new_pos >= limit ) {
                                new_pos = limit;
-                       } 
-                               
+                       }
+
                        (*i)->set_position (new_pos);
                }
        }
@@ -1643,7 +1649,7 @@ Playlist::region_bounds_changed (const PropertyChange& what_changed, boost::shar
         }
 
         mark_session_dirty ();
-     
+
         return save;
  }
 
@@ -1776,15 +1782,15 @@ boost::shared_ptr<RegionList>
 Playlist::find_regions_at (framepos_t frame)
 {
        /* Caller must hold lock */
-       
+
        boost::shared_ptr<RegionList> rlist (new RegionList);
-       
+
        for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) {
                if ((*i)->covers (frame)) {
                        rlist->push_back (*i);
                }
        }
-       
+
        return rlist;
 }
 
@@ -1833,13 +1839,13 @@ boost::shared_ptr<RegionList>
 Playlist::regions_touched_locked (framepos_t start, framepos_t end)
 {
        boost::shared_ptr<RegionList> rlist (new RegionList);
-       
+
        for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) {
                if ((*i)->coverage (start, end) != Evoral::OverlapNone) {
                        rlist->push_back (*i);
                }
        }
-       
+
        return rlist;
 }
 
@@ -1849,7 +1855,7 @@ Playlist::find_next_transient (framepos_t from, int dir)
        RegionReadLock rlock (this);
        AnalysisFeatureList points;
        AnalysisFeatureList these_points;
-       
+
        for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) {
                if (dir > 0) {
                        if ((*i)->last_frame() < from) {
@@ -1860,30 +1866,30 @@ Playlist::find_next_transient (framepos_t from, int dir)
                                continue;
                        }
                }
-               
+
                (*i)->get_transients (these_points);
-               
+
                /* add first frame, just, err, because */
-               
+
                these_points.push_back ((*i)->first_frame());
-               
+
                points.insert (points.end(), these_points.begin(), these_points.end());
                these_points.clear ();
        }
-       
+
        if (points.empty()) {
                return -1;
        }
-       
+
        TransientDetector::cleanup_transients (points, _session.frame_rate(), 3.0);
        bool reached = false;
-       
+
        if (dir > 0) {
                for (AnalysisFeatureList::iterator x = points.begin(); x != points.end(); ++x) {
                        if ((*x) >= from) {
                                reached = true;
                        }
-                       
+
                        if (reached && (*x) > from) {
                                return *x;
                        }
@@ -1893,13 +1899,13 @@ Playlist::find_next_transient (framepos_t from, int dir)
                        if ((*x) <= from) {
                                reached = true;
                        }
-                       
+
                        if (reached && (*x) < from) {
                                return *x;
                        }
                }
        }
-       
+
        return -1;
 }
 
@@ -1909,17 +1915,17 @@ Playlist::find_next_region (framepos_t frame, RegionPoint point, int dir)
        RegionReadLock rlock (this);
        boost::shared_ptr<Region> ret;
        framepos_t closest = max_framepos;
-       
+
        bool end_iter = false;
-       
+
        for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) {
-               
+
                if(end_iter) break;
-               
+
                frameoffset_t distance;
                boost::shared_ptr<Region> r = (*i);
                framepos_t pos = 0;
-               
+
                switch (point) {
                case Start:
                        pos = r->first_frame ();
@@ -1931,10 +1937,10 @@ Playlist::find_next_region (framepos_t frame, RegionPoint point, int dir)
                        pos = r->sync_position ();
                        break;
                }
-               
+
                switch (dir) {
                case 1: /* forwards */
-                       
+
                        if (pos > frame) {
                                if ((distance = pos - frame) < closest) {
                                        closest = distance;
@@ -1942,11 +1948,11 @@ Playlist::find_next_region (framepos_t frame, RegionPoint point, int dir)
                                        end_iter = true;
                                }
                        }
-                       
+
                        break;
-                       
+
                default: /* backwards */
-                       
+
                        if (pos < frame) {
                                if ((distance = frame - pos) < closest) {
                                        closest = distance;
@@ -1955,11 +1961,11 @@ Playlist::find_next_region (framepos_t frame, RegionPoint point, int dir)
                        } else {
                                end_iter = true;
                        }
-                       
+
                        break;
                }
        }
-       
+
        return ret;
 }
 
@@ -2163,7 +2169,7 @@ Playlist::find_next_region (framepos_t frame, RegionPoint point, int dir)
                                 RegionWriteLock rlock (this);
                                 add_region_internal (region, region->position());
                         }
-                       
+
                        region->resume_property_changes ();
 
                }
@@ -2172,7 +2178,7 @@ Playlist::find_next_region (framepos_t frame, RegionPoint point, int dir)
        if (seen_region_nodes && regions.empty()) {
                ret = -1;
        }
-               
+
        thaw ();
        notify_contents_changed ();
 
@@ -2351,7 +2357,7 @@ Playlist::set_layer (boost::shared_ptr<Region> region, double new_layer)
                }
                ++i;
        }
-       
+
        copy.insert (i, region);
 
        setup_layering_indices (copy);
@@ -2834,7 +2840,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);
        }