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