Improve visual cues during plugin drag and drop. Fixes #3566.
[ardour.git] / gtk2_ardour / region_view.cc
1 /*
2     Copyright (C) 2001-2006 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <cmath>
21 #include <cassert>
22 #include <algorithm>
23
24 #include <gtkmm.h>
25
26 #include <gtkmm2ext/gtk_ui.h>
27 #include "pbd/stacktrace.h"
28
29 #include "ardour/playlist.h"
30 #include "ardour/audioregion.h"
31 #include "ardour/audiosource.h"
32 #include "ardour/audio_diskstream.h"
33 #include "ardour/session.h"
34
35 #include "ardour_ui.h"
36 #include "streamview.h"
37 #include "region_view.h"
38 #include "automation_region_view.h"
39 #include "route_time_axis.h"
40 #include "simplerect.h"
41 #include "simpleline.h"
42 #include "waveview.h"
43 #include "public_editor.h"
44 #include "region_editor.h"
45 #include "ghostregion.h"
46 #include "route_time_axis.h"
47 #include "utils.h"
48 #include "rgb_macros.h"
49 #include "gui_thread.h"
50
51 #include "i18n.h"
52
53 using namespace std;
54 using namespace ARDOUR;
55 using namespace PBD;
56 using namespace Editing;
57 using namespace ArdourCanvas;
58
59 static const int32_t sync_mark_width = 9;
60
61 PBD::Signal1<void,RegionView*> RegionView::RegionViewGoingAway;
62
63 RegionView::RegionView (ArdourCanvas::Group*              parent,
64                         TimeAxisView&                     tv,
65                         boost::shared_ptr<ARDOUR::Region> r,
66                         double                            spu,
67                         Gdk::Color const &                basic_color,
68                         bool                              automation)
69         : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(), false, automation,
70                             TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowNameText|
71                                                           TimeAxisViewItem::ShowNameHighlight| TimeAxisViewItem::ShowFrame))
72         , _region (r)
73         , sync_mark(0)
74         , sync_line(0)
75         , editor(0)
76         , current_visible_sync_position(0.0)
77         , valid(false)
78         , _enable_display(false)
79         , _pixel_width(1.0)
80         , in_destructor(false)
81         , wait_for_data(false)
82         , _time_converter(r->session().tempo_map(), r->position())
83 {
84         GhostRegion::CatchDeletion.connect (*this, invalidator (*this), ui_bind (&RegionView::remove_ghost, this, _1), gui_context());
85 }
86
87 RegionView::RegionView (const RegionView& other)
88         : sigc::trackable(other)
89         , TimeAxisViewItem (other)
90         , _time_converter(other._time_converter)
91 {
92         /* derived concrete type will call init () */
93
94         _region = other._region;
95         current_visible_sync_position = other.current_visible_sync_position;
96         valid = false;
97         _pixel_width = other._pixel_width;
98
99         GhostRegion::CatchDeletion.connect (*this, invalidator (*this), ui_bind (&RegionView::remove_ghost, this, _1), gui_context());
100 }
101
102 RegionView::RegionView (const RegionView& other, boost::shared_ptr<Region> other_region)
103         : sigc::trackable(other)
104         , TimeAxisViewItem (other)
105         , _time_converter(other._time_converter)
106 {
107         /* this is a pseudo-copy constructor used when dragging regions
108            around on the canvas.
109         */
110
111         /* derived concrete type will call init () */
112
113         _region = other_region;
114         current_visible_sync_position = other.current_visible_sync_position;
115         valid = false;
116         _pixel_width = other._pixel_width;
117
118         GhostRegion::CatchDeletion.connect (*this, invalidator (*this), ui_bind (&RegionView::remove_ghost, this, _1), gui_context());
119 }
120
121 RegionView::RegionView (ArdourCanvas::Group*         parent,
122                         TimeAxisView&                tv,
123                         boost::shared_ptr<ARDOUR::Region> r,
124                         double                       spu,
125                         Gdk::Color const &           basic_color,
126                         bool                         recording,
127                         TimeAxisViewItem::Visibility visibility)
128         : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(), recording, false, visibility)
129         , _region (r)
130         , sync_mark(0)
131         , sync_line(0)
132         , editor(0)
133         , current_visible_sync_position(0.0)
134         , valid(false)
135         , _enable_display(false)
136         , _pixel_width(1.0)
137         , in_destructor(false)
138         , wait_for_data(false)
139         , _time_converter(r->session().tempo_map(), r->position())
140 {
141 }
142
143 void
144 RegionView::init (Gdk::Color const & basic_color, bool wfd)
145 {
146         editor        = 0;
147         valid         = true;
148         in_destructor = false;
149         wait_for_data = wfd;
150         sync_mark     = 0;
151         sync_line     = 0;
152         sync_mark     = 0;
153         sync_line     = 0;
154
155         compute_colors (basic_color);
156
157         if (name_highlight) {
158                 name_highlight->set_data ("regionview", this);
159                 name_highlight->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event), name_highlight, this));
160
161                 if (frame_handle_start) {
162                         frame_handle_start->set_data ("regionview", this);
163                         frame_handle_start->set_data ("isleft", (void*) 1);
164                         frame_handle_start->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_frame_handle_event), frame_handle_start, this));
165                         frame_handle_start->raise_to_top();
166                 }
167
168                 if (frame_handle_end) {
169                         frame_handle_end->set_data ("regionview", this);
170                         frame_handle_end->set_data ("isleft", (void*) 0);
171                         frame_handle_end->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_frame_handle_event), frame_handle_end, this));
172                         frame_handle_end->raise_to_top();
173                 }
174         }
175
176         if (name_pixbuf) {
177                 name_pixbuf->set_data ("regionview", this);
178                 name_pixbuf->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_event), name_pixbuf, this));
179         }
180
181         if (wfd) {
182                 _enable_display = true;
183         }
184
185         set_height (trackview.current_height());
186
187         _region->PropertyChanged.connect (*this, invalidator (*this), ui_bind (&RegionView::region_changed, this, _1), gui_context());
188         
189         group->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_event), group, this));
190
191         set_colors ();
192
193         ColorsChanged.connect (sigc::mem_fun (*this, &RegionView::color_handler));
194
195         /* XXX sync mark drag? */
196 }
197
198 RegionView::~RegionView ()
199 {
200         in_destructor = true;
201
202         for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
203                 delete *g;
204         }
205
206         for (list<ArdourCanvas::SimpleRect*>::iterator i = _coverage_frames.begin (); i != _coverage_frames.end (); ++i) {
207                 delete *i;
208         }
209
210         delete editor;
211 }
212
213 gint
214 RegionView::_lock_toggle (ArdourCanvas::Item*, GdkEvent* ev, void* arg)
215 {
216         switch (ev->type) {
217         case GDK_BUTTON_RELEASE:
218                 static_cast<RegionView*>(arg)->lock_toggle ();
219                 return TRUE;
220                 break;
221         default:
222                 break;
223         }
224         return FALSE;
225 }
226
227 void
228 RegionView::lock_toggle ()
229 {
230         _region->set_locked (!_region->locked());
231 }
232
233 void
234 RegionView::region_changed (const PropertyChange& what_changed)
235 {
236         ENSURE_GUI_THREAD (*this, &RegionView::region_changed, what_changed);
237
238         if (what_changed.contains (ARDOUR::bounds_change)) {
239                 region_resized (what_changed);
240                 region_sync_changed ();
241         }
242         if (what_changed.contains (ARDOUR::Properties::muted)) {
243                 region_muted ();
244         }
245         if (what_changed.contains (ARDOUR::Properties::opaque)) {
246                 region_opacity ();
247         }
248         if (what_changed.contains (ARDOUR::Properties::name)) {
249                 region_renamed ();
250         }
251         if (what_changed.contains (ARDOUR::Properties::sync_position)) {
252                 region_sync_changed ();
253         }
254         if (what_changed.contains (ARDOUR::Properties::locked)) {
255                 region_locked ();
256         }
257 }
258
259 void
260 RegionView::region_locked ()
261 {
262         /* name will show locked status */
263         region_renamed ();
264 }
265
266 void
267 RegionView::region_resized (const PropertyChange& what_changed)
268 {
269         double unit_length;
270
271         if (what_changed.contains (ARDOUR::Properties::position)) {
272                 set_position (_region->position(), 0);
273                 _time_converter.set_origin_b (_region->position());
274         }
275
276         PropertyChange s_and_l;
277         s_and_l.add (ARDOUR::Properties::start);
278         s_and_l.add (ARDOUR::Properties::length);
279
280         if (what_changed.contains (s_and_l)) {
281
282                 set_duration (_region->length(), 0);
283
284                 unit_length = _region->length() / samples_per_unit;
285
286                 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
287
288                         (*i)->set_duration (unit_length);
289
290                 }
291         }
292 }
293
294 void
295 RegionView::reset_width_dependent_items (double pixel_width)
296 {
297         TimeAxisViewItem::reset_width_dependent_items (pixel_width);
298         _pixel_width = pixel_width;
299 }
300
301 void
302 RegionView::region_muted ()
303 {
304         set_frame_color ();
305         region_renamed ();
306 }
307
308 void
309 RegionView::region_opacity ()
310 {
311         set_frame_color ();
312 }
313
314 void
315 RegionView::raise_to_top ()
316 {
317         _region->raise_to_top ();
318 }
319
320 void
321 RegionView::lower_to_bottom ()
322 {
323         _region->lower_to_bottom ();
324 }
325
326 bool
327 RegionView::set_position (framepos_t pos, void* /*src*/, double* ignored)
328 {
329         double delta;
330         bool ret;
331
332         if (!(ret = TimeAxisViewItem::set_position (pos, this, &delta))) {
333                 return false;
334         }
335
336         if (ignored) {
337                 *ignored = delta;
338         }
339
340         if (delta) {
341                 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
342                         (*i)->group->move (delta, 0.0);
343                 }
344         }
345
346         return ret;
347 }
348
349 void
350 RegionView::set_samples_per_unit (gdouble spu)
351 {
352         TimeAxisViewItem::set_samples_per_unit (spu);
353
354         for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
355                 (*i)->set_samples_per_unit (spu);
356                 (*i)->set_duration (_region->length() / samples_per_unit);
357         }
358
359         region_sync_changed ();
360 }
361
362 bool
363 RegionView::set_duration (framecnt_t frames, void *src)
364 {
365         if (!TimeAxisViewItem::set_duration (frames, src)) {
366                 return false;
367         }
368
369         for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
370                 (*i)->set_duration (_region->length() / samples_per_unit);
371         }
372
373         return true;
374 }
375
376 void
377 RegionView::set_colors ()
378 {
379         TimeAxisViewItem::set_colors ();
380
381         if (sync_mark) {
382                 sync_mark->property_fill_color_rgba() = RGBA_TO_UINT(0,255,0,255);     // fill_color;                   // FIXME make a themeable colour
383                 sync_line->property_fill_color_rgba() = RGBA_TO_UINT(0,255,0,255);     // fill_color;                   // FIXME make a themeable colour
384         }
385 }
386
387 void
388 RegionView::set_frame_color ()
389 {
390         if (_region->opaque()) {
391                 fill_opacity = 130;
392         } else {
393                 fill_opacity = 60;
394         }
395
396         TimeAxisViewItem::set_frame_color ();
397 }
398
399 void
400 RegionView::fake_set_opaque (bool yn)
401 {
402        if (yn) {
403                fill_opacity = 130;
404        } else {
405                fill_opacity = 60;
406        }
407
408        set_frame_color ();
409 }
410
411 void
412 RegionView::show_region_editor ()
413 {
414         if (editor == 0) {
415                 editor = new RegionEditor (trackview.session(), region());
416         }
417
418         editor->present ();
419         editor->show_all();
420 }
421
422 void
423 RegionView::hide_region_editor()
424 {
425         if (editor) {
426                 editor->hide_all ();
427         }
428 }
429
430 std::string
431 RegionView::make_name () const
432 {
433         std::string str;
434
435         // XXX nice to have some good icons for this
436
437         if (_region->locked()) {
438                 str += '>';
439                 str += _region->name();
440                 str += '<';
441         } else if (_region->position_locked()) {
442                 str += '{';
443                 str += _region->name();
444                 str += '}';
445         } else {
446                 str = _region->name();
447         }
448
449         if (_region->muted()) {
450                 str = string ("!") + str;
451         }
452
453         return str;
454 }
455
456 void
457 RegionView::region_renamed ()
458 {
459         std::string str = make_name ();
460
461         set_item_name (str, this);
462         set_name_text (str);
463         reset_width_dependent_items (_pixel_width);
464 }
465
466 void
467 RegionView::region_sync_changed ()
468 {
469         int sync_dir;
470         nframes_t sync_offset;
471
472         sync_offset = _region->sync_offset (sync_dir);
473
474         if (sync_offset == 0) {
475                 /* no need for a sync mark */
476                 if (sync_mark) {
477                         sync_mark->hide();
478                         sync_line->hide ();
479                 }
480                 return;
481         }
482
483         if (!sync_mark) {
484
485                 /* points set below */
486
487                 sync_mark = new ArdourCanvas::Polygon (*group);
488                 sync_mark->property_fill_color_rgba() = RGBA_TO_UINT(0,255,0,255);     // fill_color;                   // FIXME make a themeable colour
489
490                 sync_line = new ArdourCanvas::Line (*group);
491                 sync_line->property_fill_color_rgba() = RGBA_TO_UINT(0,255,0,255);     // fill_color;                   // FIXME make a themeable colour        
492                 sync_line->property_width_pixels() = 1;
493         }
494
495         /* this has to handle both a genuine change of position, a change of samples_per_unit,
496            and a change in the bounds of the _region->
497          */
498
499         if (sync_offset == 0) {
500
501                 /* no sync mark - its the start of the region */
502
503                 sync_mark->hide();
504                 sync_line->hide ();
505
506         } else {
507
508                 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > _region->length()))) {
509
510                         /* no sync mark - its out of the bounds of the region */
511
512                         sync_mark->hide();
513                         sync_line->hide ();
514
515                 } else {
516
517                         /* lets do it */
518
519                         Points points;
520
521                         //points = sync_mark->property_points().get_value();
522
523                         double offset = sync_offset / samples_per_unit;
524                         points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
525                         points.push_back (Gnome::Art::Point (offset + ((sync_mark_width-1)/2), 1));
526                         points.push_back (Gnome::Art::Point (offset, sync_mark_width - 1));
527                         points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
528                         sync_mark->property_points().set_value (points);
529                         sync_mark->show ();
530
531                         points.clear ();
532                         points.push_back (Gnome::Art::Point (offset, 0));
533                         points.push_back (Gnome::Art::Point (offset, trackview.current_height() - NAME_HIGHLIGHT_SIZE));
534
535                         sync_line->property_points().set_value (points);
536                         sync_line->show ();
537                 }
538         }
539 }
540
541 void
542 RegionView::move (double x_delta, double y_delta)
543 {
544         if (!_region->can_move() || (x_delta == 0 && y_delta == 0)) {
545                 return;
546         }
547
548         get_canvas_group()->move (x_delta, y_delta);
549
550         /* note: ghosts never leave their tracks so y_delta for them is always zero */
551
552         for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
553                 (*i)->group->move (x_delta, 0.0);
554         }
555 }
556
557 void
558 RegionView::remove_ghost_in (TimeAxisView& tv)
559 {
560         for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
561                 if (&(*i)->trackview == &tv) {
562                         delete *i;
563                         break;
564                 }
565         }
566 }
567
568 void
569 RegionView::remove_ghost (GhostRegion* ghost)
570 {
571         if (in_destructor) {
572                 return;
573         }
574
575         for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
576                 if (*i == ghost) {
577                         ghosts.erase (i);
578                         break;
579                 }
580         }
581 }
582
583 uint32_t
584 RegionView::get_fill_color ()
585 {
586         return fill_color;
587 }
588
589 void
590 RegionView::set_height (double h)
591 {
592         TimeAxisViewItem::set_height(h);
593
594         if (sync_line) {
595                 Points points;
596                 int sync_dir;
597                 nframes_t sync_offset;
598                 sync_offset = _region->sync_offset (sync_dir);
599                 double offset = sync_offset / samples_per_unit;
600
601                 points.push_back (Gnome::Art::Point (offset, 0));
602                 points.push_back (Gnome::Art::Point (offset, h - NAME_HIGHLIGHT_SIZE));
603                 sync_line->property_points().set_value (points);
604         }
605
606         for (list<ArdourCanvas::SimpleRect*>::iterator i = _coverage_frames.begin(); i != _coverage_frames.end(); ++i) {
607                 (*i)->property_y2() = h + 1;
608         }
609 }
610
611 /** Remove old coverage frames and make new ones, if we're in a LayerDisplay mode
612  *  which uses them. */
613 void
614 RegionView::update_coverage_frames (LayerDisplay d)
615 {
616         /* remove old coverage frames */
617         for (list<ArdourCanvas::SimpleRect*>::iterator i = _coverage_frames.begin (); i != _coverage_frames.end (); ++i) {
618                 delete *i;
619         }
620
621         _coverage_frames.clear ();
622
623         if (d != Stacked) {
624                 /* don't do coverage frames unless we're in stacked mode */
625                 return;
626         }
627
628         boost::shared_ptr<Playlist> pl (_region->playlist ());
629         if (!pl) {
630                 return;
631         }
632
633         nframes_t const position = _region->first_frame ();
634         nframes_t t = position;
635         nframes_t const end = _region->last_frame ();
636
637         ArdourCanvas::SimpleRect* cr = 0;
638         bool me = false;
639
640         uint32_t const color = frame->property_fill_color_rgba ();
641         uint32_t const base_alpha = UINT_RGBA_A (color);
642
643         while (t < end) {
644
645                 t++;
646
647                 /* is this region is on top at time t? */
648                 bool const new_me = (pl->top_unmuted_region_at (t) == _region);
649
650                 /* finish off any old rect, if required */
651                 if (cr && me != new_me) {
652                         cr->property_x2() = trackview.editor().frame_to_pixel (t - position);
653                 }
654
655                 /* start off any new rect, if required */
656                 if (cr == 0 || me != new_me) {
657                         cr = new ArdourCanvas::SimpleRect (*group);
658                         _coverage_frames.push_back (cr);
659                         cr->property_x1() = trackview.editor().frame_to_pixel (t - position);
660                         cr->property_y1() = 1;
661                         cr->property_y2() = _height + 1;
662                         cr->property_outline_pixels() = 0;
663                         /* areas that will be played get a lower alpha */
664                         uint32_t alpha = base_alpha;
665                         if (new_me) {
666                                 alpha /= 2;
667                         }
668                         cr->property_fill_color_rgba () = UINT_RGBA_CHANGE_A (color, alpha);
669                 }
670
671                 t = pl->find_next_region_boundary (t, 1);
672                 me = new_me;
673         }
674
675         if (cr) {
676                 /* finish off the last rectangle */
677                 cr->property_x2() = trackview.editor().frame_to_pixel (end - position);
678         }
679
680         if (frame_handle_start) {
681                 frame_handle_start->raise_to_top ();
682         }
683
684         if (frame_handle_end) {
685                 frame_handle_end->raise_to_top ();
686         }
687
688         if (name_highlight) {
689                 name_highlight->raise_to_top ();
690         }
691
692         if (name_pixbuf) {
693                 name_pixbuf->raise_to_top ();
694         }
695 }
696
697 void
698 RegionView::trim_start (framepos_t new_bound, bool no_overlap)
699 {
700         if (_region->locked()) {
701                 return;
702         }
703
704         RouteTimeAxisView& rtv = dynamic_cast<RouteTimeAxisView&> (trackview);
705         double const speed = rtv.track()->speed ();
706
707         framepos_t const pre_trim_first_frame = _region->first_frame();
708
709         _region->trim_front ((framepos_t) (new_bound * speed), this);
710
711         if (no_overlap) {
712                 // Get the next region on the left of this region and shrink/expand it.
713                 boost::shared_ptr<Playlist> playlist (_region->playlist());
714                 boost::shared_ptr<Region> region_left = playlist->find_next_region (pre_trim_first_frame, End, 0);
715
716                 bool regions_touching = false;
717
718                 if (region_left != 0 && (pre_trim_first_frame == region_left->last_frame() + 1)) {
719                         regions_touching = true;
720                 }
721
722                 // Only trim region on the left if the first frame has gone beyond the left region's last frame.
723                 if (region_left != 0 && (region_left->last_frame() > _region->first_frame() || regions_touching)) {
724                         region_left->trim_end (_region->first_frame() - 1, this);
725                 }
726         }
727
728         region_changed (ARDOUR::bounds_change);
729 }
730
731 void
732 RegionView::trim_end (framepos_t new_bound, bool no_overlap)
733 {
734         if (_region->locked()) {
735                 return;
736         }
737
738         RouteTimeAxisView& rtv = dynamic_cast<RouteTimeAxisView&> (trackview);
739         double const speed = rtv.track()->speed ();
740
741         framepos_t const pre_trim_last_frame = _region->last_frame();
742
743         _region->trim_end ((framepos_t) (new_bound * speed), this);
744
745         if (no_overlap) {
746                 // Get the next region on the right of this region and shrink/expand it.
747                 boost::shared_ptr<Playlist> playlist (_region->playlist());
748                 boost::shared_ptr<Region> region_right = playlist->find_next_region (pre_trim_last_frame, Start, 1);
749
750                 bool regions_touching = false;
751
752                 if (region_right != 0 && (pre_trim_last_frame == region_right->first_frame() - 1)) {
753                         regions_touching = true;
754                 }
755
756                 // Only trim region on the right if the last frame has gone beyond the right region's first frame.
757                 if (region_right != 0 && (region_right->first_frame() < _region->last_frame() || regions_touching)) {
758                         region_right->trim_front (_region->last_frame() + 1, this);
759                 }
760
761                 region_changed (ARDOUR::bounds_change);
762                         
763         } else {
764                 region_changed (PropertyChange (ARDOUR::Properties::length));
765         }
766 }
767
768
769 void
770 RegionView::thaw_after_trim ()
771 {
772         if (_region->locked()) {
773                 return;
774         }
775
776         _region->resume_property_changes ();
777 }
778
779
780 void
781 RegionView::trim_contents (framepos_t frame_delta, bool left_direction, bool swap_direction)
782 {
783         if (_region->locked()) {
784                 return;
785         }
786
787         framepos_t new_bound;
788
789         RouteTimeAxisView& rtv = dynamic_cast<RouteTimeAxisView&> (trackview);
790         double const speed = rtv.track()->speed ();
791
792         if (left_direction) {
793                 if (swap_direction) {
794                         new_bound = (framepos_t) (_region->position() / speed) + frame_delta;
795                 } else {
796                         new_bound = (framepos_t) (_region->position() / speed) - frame_delta;
797                 }
798         } else {
799                 if (swap_direction) {
800                         new_bound = (framepos_t) (_region->position() / speed) - frame_delta;
801                 } else {
802                         new_bound = (framepos_t) (_region->position() / speed) + frame_delta;
803                 }
804         }
805
806         _region->trim_start ((framepos_t) (new_bound * speed), this);
807         region_changed (PropertyChange (ARDOUR::Properties::start));
808 }