+ if (frame_handle_start) {
+ frame_handle_start->raise_to_top ();
+ }
+
+ if (frame_handle_end) {
+ frame_handle_end->raise_to_top ();
+ }
+
+ if (name_highlight) {
+ name_highlight->raise_to_top ();
+ }
+
+ if (name_pixbuf) {
+ name_pixbuf->raise_to_top ();
+ }
+}
+
+void
+RegionView::trim_front (framepos_t new_bound, bool no_overlap)
+{
+ if (_region->locked()) {
+ return;
+ }
+
+ RouteTimeAxisView& rtv = dynamic_cast<RouteTimeAxisView&> (trackview);
+ double const speed = rtv.track()->speed ();
+
+ framepos_t const pre_trim_first_frame = _region->first_frame();
+
+ _region->trim_front ((framepos_t) (new_bound * speed));
+
+ if (no_overlap) {
+ // Get the next region on the left of this region and shrink/expand it.
+ boost::shared_ptr<Playlist> playlist (_region->playlist());
+ boost::shared_ptr<Region> region_left = playlist->find_next_region (pre_trim_first_frame, End, 0);
+
+ bool regions_touching = false;
+
+ if (region_left != 0 && (pre_trim_first_frame == region_left->last_frame() + 1)) {
+ regions_touching = true;
+ }
+
+ // Only trim region on the left if the first frame has gone beyond the left region's last frame.
+ if (region_left != 0 && (region_left->last_frame() > _region->first_frame() || regions_touching)) {
+ region_left->trim_end (_region->first_frame() - 1);
+ }
+ }
+
+ region_changed (ARDOUR::bounds_change);
+}
+
+void
+RegionView::trim_end (framepos_t new_bound, bool no_overlap)
+{
+ if (_region->locked()) {
+ return;
+ }
+
+ RouteTimeAxisView& rtv = dynamic_cast<RouteTimeAxisView&> (trackview);
+ double const speed = rtv.track()->speed ();
+
+ framepos_t const pre_trim_last_frame = _region->last_frame();
+
+ _region->trim_end ((framepos_t) (new_bound * speed));
+
+ if (no_overlap) {
+ // Get the next region on the right of this region and shrink/expand it.
+ boost::shared_ptr<Playlist> playlist (_region->playlist());
+ boost::shared_ptr<Region> region_right = playlist->find_next_region (pre_trim_last_frame, Start, 1);
+
+ bool regions_touching = false;
+
+ if (region_right != 0 && (pre_trim_last_frame == region_right->first_frame() - 1)) {
+ regions_touching = true;
+ }
+
+ // Only trim region on the right if the last frame has gone beyond the right region's first frame.
+ if (region_right != 0 && (region_right->first_frame() < _region->last_frame() || regions_touching)) {
+ region_right->trim_front (_region->last_frame() + 1);
+ }
+
+ region_changed (ARDOUR::bounds_change);
+
+ } else {
+ region_changed (PropertyChange (ARDOUR::Properties::length));
+ }
+}
+
+
+void
+RegionView::thaw_after_trim ()
+{
+ if (_region->locked()) {
+ return;
+ }
+
+ _region->resume_property_changes ();
+}
+
+
+void
+RegionView::trim_contents (framepos_t frame_delta, bool left_direction, bool swap_direction)
+{
+ if (_region->locked()) {
+ return;
+ }
+
+ framepos_t new_bound;
+
+ RouteTimeAxisView& rtv = dynamic_cast<RouteTimeAxisView&> (trackview);
+ double const speed = rtv.track()->speed ();
+
+ if (left_direction) {
+ if (swap_direction) {
+ new_bound = (framepos_t) (_region->position() / speed) + frame_delta;
+ } else {
+ new_bound = (framepos_t) (_region->position() / speed) - frame_delta;
+ }
+ } else {
+ if (swap_direction) {
+ new_bound = (framepos_t) (_region->position() / speed) - frame_delta;
+ } else {
+ new_bound = (framepos_t) (_region->position() / speed) + frame_delta;
+ }
+ }
+
+ _region->trim_start ((framepos_t) (new_bound * speed));
+ region_changed (PropertyChange (ARDOUR::Properties::start));
+}
+
+/** Snap a frame offset within our region using the current snap settings.
+ * @param x Frame offset from this region's position.
+ * @return Snapped frame offset from this region's position.
+ */
+frameoffset_t
+RegionView::snap_frame_to_frame (frameoffset_t x) const
+{
+ PublicEditor& editor = trackview.editor();
+
+ /* x is region relative, convert it to global absolute frames */
+ framepos_t const session_frame = x + _region->position();
+
+ /* try a snap in either direction */
+ framepos_t frame = session_frame;
+ editor.snap_to (frame, 0);
+
+ /* if we went off the beginning of the region, snap forwards */
+ if (frame < _region->position ()) {
+ frame = session_frame;
+ editor.snap_to (frame, 1);
+ }
+
+ /* back to region relative */
+ return frame - _region->position();