Add a couple of missing attach_buffers() calls after _ports has been changed. I...
[ardour2.git] / gtk2_ardour / region_view.cc
blob0302e8f345069872549d3eace017f66ead2a5c00
1 /*
2 Copyright (C) 2001-2006 Paul Davis
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.
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.
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.
20 #include <cmath>
21 #include <cassert>
22 #include <algorithm>
24 #include <gtkmm.h>
26 #include <gtkmm2ext/gtk_ui.h>
28 #include "ardour/playlist.h"
29 #include "ardour/audioregion.h"
30 #include "ardour/audiosource.h"
31 #include "ardour/audio_diskstream.h"
32 #include "ardour/session.h"
34 #include "ardour_ui.h"
35 #include "global_signals.h"
36 #include "canvas-noevent-text.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 "ui_config.h"
49 #include "utils.h"
50 #include "rgb_macros.h"
51 #include "gui_thread.h"
53 #include "i18n.h"
55 using namespace std;
56 using namespace ARDOUR;
57 using namespace PBD;
58 using namespace Editing;
59 using namespace Gtk;
60 using namespace ArdourCanvas;
62 static const int32_t sync_mark_width = 9;
64 PBD::Signal1<void,RegionView*> RegionView::RegionViewGoingAway;
66 RegionView::RegionView (ArdourCanvas::Group* parent,
67 TimeAxisView& tv,
68 boost::shared_ptr<ARDOUR::Region> r,
69 double spu,
70 Gdk::Color const & basic_color,
71 bool automation)
72 : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(), false, automation,
73 TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowNameText|
74 TimeAxisViewItem::ShowNameHighlight| TimeAxisViewItem::ShowFrame))
75 , _region (r)
76 , sync_mark(0)
77 , sync_line(0)
78 , editor(0)
79 , current_visible_sync_position(0.0)
80 , valid(false)
81 , _enable_display(false)
82 , _pixel_width(1.0)
83 , in_destructor(false)
84 , wait_for_data(false)
85 , _silence_text (0)
86 , _time_converter(r->session().tempo_map(), r->position())
88 GhostRegion::CatchDeletion.connect (*this, invalidator (*this), ui_bind (&RegionView::remove_ghost, this, _1), gui_context());
91 RegionView::RegionView (const RegionView& other)
92 : sigc::trackable(other)
93 , TimeAxisViewItem (other)
94 , _silence_text (0)
95 , _time_converter(other._time_converter)
97 /* derived concrete type will call init () */
99 _region = other._region;
100 current_visible_sync_position = other.current_visible_sync_position;
101 valid = false;
102 _pixel_width = other._pixel_width;
104 GhostRegion::CatchDeletion.connect (*this, invalidator (*this), ui_bind (&RegionView::remove_ghost, this, _1), gui_context());
107 RegionView::RegionView (const RegionView& other, boost::shared_ptr<Region> other_region)
108 : sigc::trackable(other)
109 , TimeAxisViewItem (other)
110 , _silence_text (0)
111 , _time_converter(other._time_converter)
113 /* this is a pseudo-copy constructor used when dragging regions
114 around on the canvas.
117 /* derived concrete type will call init () */
119 _region = other_region;
120 current_visible_sync_position = other.current_visible_sync_position;
121 valid = false;
122 _pixel_width = other._pixel_width;
124 GhostRegion::CatchDeletion.connect (*this, invalidator (*this), ui_bind (&RegionView::remove_ghost, this, _1), gui_context());
127 RegionView::RegionView (ArdourCanvas::Group* parent,
128 TimeAxisView& tv,
129 boost::shared_ptr<ARDOUR::Region> r,
130 double spu,
131 Gdk::Color const & basic_color,
132 bool recording,
133 TimeAxisViewItem::Visibility visibility)
134 : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(), recording, false, visibility)
135 , _region (r)
136 , sync_mark(0)
137 , sync_line(0)
138 , editor(0)
139 , current_visible_sync_position(0.0)
140 , valid(false)
141 , _enable_display(false)
142 , _pixel_width(1.0)
143 , in_destructor(false)
144 , wait_for_data(false)
145 , _silence_text (0)
146 , _time_converter(r->session().tempo_map(), r->position())
150 void
151 RegionView::init (Gdk::Color const & basic_color, bool wfd)
153 editor = 0;
154 valid = true;
155 in_destructor = false;
156 wait_for_data = wfd;
157 sync_mark = 0;
158 sync_line = 0;
159 sync_mark = 0;
160 sync_line = 0;
162 compute_colors (basic_color);
164 if (name_highlight) {
165 name_highlight->set_data ("regionview", this);
166 name_highlight->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event), name_highlight, this));
168 if (frame_handle_start) {
169 frame_handle_start->set_data ("regionview", this);
170 frame_handle_start->set_data ("isleft", (void*) 1);
171 frame_handle_start->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_frame_handle_event), frame_handle_start, this));
172 frame_handle_start->raise_to_top();
175 if (frame_handle_end) {
176 frame_handle_end->set_data ("regionview", this);
177 frame_handle_end->set_data ("isleft", (void*) 0);
178 frame_handle_end->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_frame_handle_event), frame_handle_end, this));
179 frame_handle_end->raise_to_top();
183 if (name_pixbuf) {
184 name_pixbuf->set_data ("regionview", this);
185 name_pixbuf->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_event), name_pixbuf, this));
188 if (wfd) {
189 _enable_display = true;
192 set_height (trackview.current_height());
194 _region->PropertyChanged.connect (*this, invalidator (*this), ui_bind (&RegionView::region_changed, this, _1), gui_context());
196 group->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_event), group, this));
198 set_colors ();
200 ColorsChanged.connect (sigc::mem_fun (*this, &RegionView::color_handler));
202 /* XXX sync mark drag? */
205 RegionView::~RegionView ()
207 in_destructor = true;
209 for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
210 delete *g;
213 for (list<ArdourCanvas::SimpleRect*>::iterator i = _coverage_frames.begin (); i != _coverage_frames.end (); ++i) {
214 delete *i;
217 drop_silent_frames ();
219 delete editor;
222 void
223 RegionView::set_silent_frames (const AudioIntervalResult& silences, double threshold)
225 framecnt_t shortest = max_framecnt;
227 /* remove old silent frames */
228 drop_silent_frames ();
230 if (silences.empty()) {
231 return;
234 uint32_t const color = ARDOUR_UI::config()->canvasvar_Silence.get();
236 for (AudioIntervalResult::const_iterator i = silences.begin(); i != silences.end(); ++i) {
238 ArdourCanvas::SimpleRect* cr = new ArdourCanvas::SimpleRect (*group);
239 _silent_frames.push_back (cr);
241 /* coordinates for the rect are relative to the regionview origin */
243 cr->property_x1() = trackview.editor().frame_to_pixel (i->first - _region->start());
244 cr->property_x2() = trackview.editor().frame_to_pixel (i->second - _region->start());
245 cr->property_y1() = 1;
246 cr->property_y2() = _height - 2;
247 cr->property_outline_pixels() = 0;
248 cr->property_fill_color_rgba () = color;
250 shortest = min (shortest, i->second - i->first);
253 /* Find shortest audible segment */
254 framecnt_t shortest_audible = max_framecnt;
256 framecnt_t s = _region->start();
257 for (AudioIntervalResult::const_iterator i = silences.begin(); i != silences.end(); ++i) {
258 framecnt_t const dur = i->first - s;
259 if (dur > 0) {
260 shortest_audible = min (shortest_audible, dur);
263 s = i->second;
266 framecnt_t const dur = _region->start() + _region->length() - 1 - s;
267 if (dur > 0) {
268 shortest_audible = min (shortest_audible, dur);
271 _silence_text = new ArdourCanvas::NoEventText (*group);
272 _silence_text->property_font_desc() = get_font_for_style (N_("SilenceText"));
273 _silence_text->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SilenceText.get();
274 _silence_text->property_anchor() = ANCHOR_NW;
276 /* both positions are relative to the region start offset in source */
278 _silence_text->property_x() = trackview.editor().frame_to_pixel (silences.front().first - _region->start()) + 10.0;
279 _silence_text->property_y() = 20.0;
281 double ms = (float) shortest/_region->session().frame_rate();
283 /* ms are now in seconds */
285 char const * sunits;
287 if (ms >= 60.0) {
288 sunits = _("minutes");
289 ms /= 60.0;
290 } else if (ms < 1.0) {
291 sunits = _("msecs");
292 ms *= 1000.0;
293 } else {
294 sunits = _("secs");
297 string text = string_compose (ngettext ("%1 silent segment", "%1 silent segments", silences.size()), silences.size())
298 + ", "
299 + string_compose (_("shortest = %1 %2"), ms, sunits);
301 if (shortest_audible != max_framepos) {
302 /* ms are now in seconds */
303 double ma = (float) shortest_audible / _region->session().frame_rate();
304 char const * aunits;
306 if (ma >= 60.0) {
307 aunits = _("minutes");
308 ma /= 60.0;
309 } else if (ma < 1.0) {
310 aunits = _("msecs");
311 ma *= 1000.0;
312 } else {
313 aunits = _("secs");
316 text += string_compose (_("\n (shortest audible segment = %1 %2)"), ma, aunits);
319 _silence_text->property_text() = text.c_str ();
322 void
323 RegionView::hide_silent_frames ()
325 for (list<ArdourCanvas::SimpleRect*>::iterator i = _silent_frames.begin (); i != _silent_frames.end (); ++i) {
326 (*i)->hide ();
328 _silence_text->hide();
331 void
332 RegionView::drop_silent_frames ()
334 for (list<ArdourCanvas::SimpleRect*>::iterator i = _silent_frames.begin (); i != _silent_frames.end (); ++i) {
335 delete *i;
337 _silent_frames.clear ();
339 delete _silence_text;
340 _silence_text = 0;
343 gint
344 RegionView::_lock_toggle (ArdourCanvas::Item*, GdkEvent* ev, void* arg)
346 switch (ev->type) {
347 case GDK_BUTTON_RELEASE:
348 static_cast<RegionView*>(arg)->lock_toggle ();
349 return TRUE;
350 break;
351 default:
352 break;
354 return FALSE;
357 void
358 RegionView::lock_toggle ()
360 _region->set_locked (!_region->locked());
363 void
364 RegionView::region_changed (const PropertyChange& what_changed)
366 ENSURE_GUI_THREAD (*this, &RegionView::region_changed, what_changed);
368 if (what_changed.contains (ARDOUR::bounds_change)) {
369 region_resized (what_changed);
370 region_sync_changed ();
372 if (what_changed.contains (ARDOUR::Properties::muted)) {
373 region_muted ();
375 if (what_changed.contains (ARDOUR::Properties::opaque)) {
376 region_opacity ();
378 if (what_changed.contains (ARDOUR::Properties::name)) {
379 region_renamed ();
381 if (what_changed.contains (ARDOUR::Properties::sync_position)) {
382 region_sync_changed ();
384 if (what_changed.contains (ARDOUR::Properties::locked)) {
385 region_locked ();
389 void
390 RegionView::region_locked ()
392 /* name will show locked status */
393 region_renamed ();
396 void
397 RegionView::region_resized (const PropertyChange& what_changed)
399 double unit_length;
401 if (what_changed.contains (ARDOUR::Properties::position)) {
402 set_position (_region->position(), 0);
403 _time_converter.set_origin_b (_region->position());
406 PropertyChange s_and_l;
407 s_and_l.add (ARDOUR::Properties::start);
408 s_and_l.add (ARDOUR::Properties::length);
410 if (what_changed.contains (s_and_l)) {
412 set_duration (_region->length(), 0);
414 unit_length = _region->length() / samples_per_unit;
416 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
418 (*i)->set_duration (unit_length);
424 void
425 RegionView::reset_width_dependent_items (double pixel_width)
427 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
428 _pixel_width = pixel_width;
431 void
432 RegionView::region_muted ()
434 set_frame_color ();
435 region_renamed ();
438 void
439 RegionView::region_opacity ()
441 set_frame_color ();
444 void
445 RegionView::raise_to_top ()
447 _region->raise_to_top ();
450 void
451 RegionView::lower_to_bottom ()
453 _region->lower_to_bottom ();
456 bool
457 RegionView::set_position (framepos_t pos, void* /*src*/, double* ignored)
459 double delta;
460 bool ret;
462 if (!(ret = TimeAxisViewItem::set_position (pos, this, &delta))) {
463 return false;
466 if (ignored) {
467 *ignored = delta;
470 if (delta) {
471 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
472 (*i)->group->move (delta, 0.0);
476 return ret;
479 void
480 RegionView::set_samples_per_unit (gdouble spu)
482 TimeAxisViewItem::set_samples_per_unit (spu);
484 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
485 (*i)->set_samples_per_unit (spu);
486 (*i)->set_duration (_region->length() / samples_per_unit);
489 region_sync_changed ();
492 bool
493 RegionView::set_duration (framecnt_t frames, void *src)
495 if (!TimeAxisViewItem::set_duration (frames, src)) {
496 return false;
499 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
500 (*i)->set_duration (_region->length() / samples_per_unit);
503 return true;
506 void
507 RegionView::set_colors ()
509 TimeAxisViewItem::set_colors ();
511 if (sync_mark) {
512 sync_mark->property_fill_color_rgba() = RGBA_TO_UINT(0,255,0,255); // fill_color; // FIXME make a themeable colour
513 sync_line->property_fill_color_rgba() = RGBA_TO_UINT(0,255,0,255); // fill_color; // FIXME make a themeable colour
517 void
518 RegionView::set_frame_color ()
520 if (_region->opaque()) {
521 fill_opacity = 130;
522 } else {
523 fill_opacity = 60;
526 TimeAxisViewItem::set_frame_color ();
529 void
530 RegionView::fake_set_opaque (bool yn)
532 if (yn) {
533 fill_opacity = 130;
534 } else {
535 fill_opacity = 60;
538 set_frame_color ();
541 void
542 RegionView::show_region_editor ()
544 if (editor == 0) {
545 editor = new RegionEditor (trackview.session(), region());
548 editor->present ();
549 editor->show_all();
552 void
553 RegionView::hide_region_editor()
555 if (editor) {
556 editor->hide_all ();
560 std::string
561 RegionView::make_name () const
563 std::string str;
565 // XXX nice to have some good icons for this
567 if (_region->locked()) {
568 str += '>';
569 str += _region->name();
570 str += '<';
571 } else if (_region->position_locked()) {
572 str += '{';
573 str += _region->name();
574 str += '}';
575 } else {
576 str = _region->name();
579 if (_region->muted()) {
580 str = string ("!") + str;
583 return str;
586 void
587 RegionView::region_renamed ()
589 std::string str = make_name ();
591 set_item_name (str, this);
592 set_name_text (str);
593 reset_width_dependent_items (_pixel_width);
596 void
597 RegionView::region_sync_changed ()
599 int sync_dir;
600 framecnt_t sync_offset;
602 sync_offset = _region->sync_offset (sync_dir);
604 if (sync_offset == 0) {
605 /* no need for a sync mark */
606 if (sync_mark) {
607 sync_mark->hide();
608 sync_line->hide ();
610 return;
613 if (!sync_mark) {
615 /* points set below */
617 sync_mark = new ArdourCanvas::Polygon (*group);
618 sync_mark->property_fill_color_rgba() = RGBA_TO_UINT(0,255,0,255); // fill_color; // FIXME make a themeable colour
620 sync_line = new ArdourCanvas::Line (*group);
621 sync_line->property_fill_color_rgba() = RGBA_TO_UINT(0,255,0,255); // fill_color; // FIXME make a themeable colour
622 sync_line->property_width_pixels() = 1;
625 /* this has to handle both a genuine change of position, a change of samples_per_unit,
626 and a change in the bounds of the _region->
629 if (sync_offset == 0) {
631 /* no sync mark - its the start of the region */
633 sync_mark->hide();
634 sync_line->hide ();
636 } else {
638 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > _region->length()))) {
640 /* no sync mark - its out of the bounds of the region */
642 sync_mark->hide();
643 sync_line->hide ();
645 } else {
647 /* lets do it */
649 Points points;
651 //points = sync_mark->property_points().get_value();
653 double offset = sync_offset / samples_per_unit;
654 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
655 points.push_back (Gnome::Art::Point (offset + ((sync_mark_width-1)/2), 1));
656 points.push_back (Gnome::Art::Point (offset, sync_mark_width - 1));
657 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
658 sync_mark->property_points().set_value (points);
659 sync_mark->show ();
661 points.clear ();
662 points.push_back (Gnome::Art::Point (offset, 0));
663 points.push_back (Gnome::Art::Point (offset, trackview.current_height() - NAME_HIGHLIGHT_SIZE));
665 sync_line->property_points().set_value (points);
666 sync_line->show ();
671 void
672 RegionView::move (double x_delta, double y_delta)
674 if (!_region->can_move() || (x_delta == 0 && y_delta == 0)) {
675 return;
678 get_canvas_group()->move (x_delta, y_delta);
680 /* note: ghosts never leave their tracks so y_delta for them is always zero */
682 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
683 (*i)->group->move (x_delta, 0.0);
687 void
688 RegionView::remove_ghost_in (TimeAxisView& tv)
690 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
691 if (&(*i)->trackview == &tv) {
692 delete *i;
693 break;
698 void
699 RegionView::remove_ghost (GhostRegion* ghost)
701 if (in_destructor) {
702 return;
705 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
706 if (*i == ghost) {
707 ghosts.erase (i);
708 break;
713 uint32_t
714 RegionView::get_fill_color ()
716 return fill_color;
719 void
720 RegionView::set_height (double h)
722 TimeAxisViewItem::set_height(h);
724 if (sync_line) {
725 Points points;
726 int sync_dir;
727 framecnt_t sync_offset;
728 sync_offset = _region->sync_offset (sync_dir);
729 double offset = sync_offset / samples_per_unit;
731 points.push_back (Gnome::Art::Point (offset, 0));
732 points.push_back (Gnome::Art::Point (offset, h - NAME_HIGHLIGHT_SIZE));
733 sync_line->property_points().set_value (points);
736 for (list<ArdourCanvas::SimpleRect*>::iterator i = _coverage_frames.begin(); i != _coverage_frames.end(); ++i) {
737 (*i)->property_y2() = h + 1;
740 for (list<ArdourCanvas::SimpleRect*>::iterator i = _silent_frames.begin(); i != _silent_frames.end(); ++i) {
741 (*i)->property_y2() = h + 1;
746 /** Remove old coverage frames and make new ones, if we're in a LayerDisplay mode
747 * which uses them. */
748 void
749 RegionView::update_coverage_frames (LayerDisplay d)
751 /* remove old coverage frames */
752 for (list<ArdourCanvas::SimpleRect*>::iterator i = _coverage_frames.begin (); i != _coverage_frames.end (); ++i) {
753 delete *i;
756 _coverage_frames.clear ();
758 if (d != Stacked) {
759 /* don't do coverage frames unless we're in stacked mode */
760 return;
763 boost::shared_ptr<Playlist> pl (_region->playlist ());
764 if (!pl) {
765 return;
768 framepos_t const position = _region->first_frame ();
769 framepos_t t = position;
770 framepos_t const end = _region->last_frame ();
772 ArdourCanvas::SimpleRect* cr = 0;
773 bool me = false;
775 uint32_t const color = frame->property_fill_color_rgba ();
776 uint32_t const base_alpha = UINT_RGBA_A (color);
778 while (t < end) {
780 t++;
782 /* is this region is on top at time t? */
783 bool const new_me = (pl->top_unmuted_region_at (t) == _region);
785 /* finish off any old rect, if required */
786 if (cr && me != new_me) {
787 cr->property_x2() = trackview.editor().frame_to_pixel (t - position);
790 /* start off any new rect, if required */
791 if (cr == 0 || me != new_me) {
792 cr = new ArdourCanvas::SimpleRect (*group);
793 _coverage_frames.push_back (cr);
794 cr->property_x1() = trackview.editor().frame_to_pixel (t - position);
795 cr->property_y1() = 1;
796 cr->property_y2() = _height + 1;
797 cr->property_outline_pixels() = 0;
798 /* areas that will be played get a lower alpha */
799 uint32_t alpha = base_alpha;
800 if (new_me) {
801 alpha /= 2;
803 cr->property_fill_color_rgba () = UINT_RGBA_CHANGE_A (color, alpha);
806 t = pl->find_next_region_boundary (t, 1);
807 me = new_me;
810 if (cr) {
811 /* finish off the last rectangle */
812 cr->property_x2() = trackview.editor().frame_to_pixel (end - position);
815 if (frame_handle_start) {
816 frame_handle_start->raise_to_top ();
819 if (frame_handle_end) {
820 frame_handle_end->raise_to_top ();
823 if (name_highlight) {
824 name_highlight->raise_to_top ();
827 if (name_pixbuf) {
828 name_pixbuf->raise_to_top ();
832 void
833 RegionView::trim_front (framepos_t new_bound, bool no_overlap)
835 if (_region->locked()) {
836 return;
839 RouteTimeAxisView& rtv = dynamic_cast<RouteTimeAxisView&> (trackview);
840 double const speed = rtv.track()->speed ();
842 framepos_t const pre_trim_first_frame = _region->first_frame();
844 _region->trim_front ((framepos_t) (new_bound * speed));
846 if (no_overlap) {
847 // Get the next region on the left of this region and shrink/expand it.
848 boost::shared_ptr<Playlist> playlist (_region->playlist());
849 boost::shared_ptr<Region> region_left = playlist->find_next_region (pre_trim_first_frame, End, 0);
851 bool regions_touching = false;
853 if (region_left != 0 && (pre_trim_first_frame == region_left->last_frame() + 1)) {
854 regions_touching = true;
857 // Only trim region on the left if the first frame has gone beyond the left region's last frame.
858 if (region_left != 0 && (region_left->last_frame() > _region->first_frame() || regions_touching)) {
859 region_left->trim_end (_region->first_frame() - 1);
863 region_changed (ARDOUR::bounds_change);
866 void
867 RegionView::trim_end (framepos_t new_bound, bool no_overlap)
869 if (_region->locked()) {
870 return;
873 RouteTimeAxisView& rtv = dynamic_cast<RouteTimeAxisView&> (trackview);
874 double const speed = rtv.track()->speed ();
876 framepos_t const pre_trim_last_frame = _region->last_frame();
878 _region->trim_end ((framepos_t) (new_bound * speed));
880 if (no_overlap) {
881 // Get the next region on the right of this region and shrink/expand it.
882 boost::shared_ptr<Playlist> playlist (_region->playlist());
883 boost::shared_ptr<Region> region_right = playlist->find_next_region (pre_trim_last_frame, Start, 1);
885 bool regions_touching = false;
887 if (region_right != 0 && (pre_trim_last_frame == region_right->first_frame() - 1)) {
888 regions_touching = true;
891 // Only trim region on the right if the last frame has gone beyond the right region's first frame.
892 if (region_right != 0 && (region_right->first_frame() < _region->last_frame() || regions_touching)) {
893 region_right->trim_front (_region->last_frame() + 1);
896 region_changed (ARDOUR::bounds_change);
898 } else {
899 region_changed (PropertyChange (ARDOUR::Properties::length));
904 void
905 RegionView::thaw_after_trim ()
907 if (_region->locked()) {
908 return;
911 _region->resume_property_changes ();
915 void
916 RegionView::trim_contents (framepos_t frame_delta, bool left_direction, bool swap_direction)
918 if (_region->locked()) {
919 return;
922 framepos_t new_bound;
924 RouteTimeAxisView& rtv = dynamic_cast<RouteTimeAxisView&> (trackview);
925 double const speed = rtv.track()->speed ();
927 if (left_direction) {
928 if (swap_direction) {
929 new_bound = (framepos_t) (_region->position() / speed) + frame_delta;
930 } else {
931 new_bound = (framepos_t) (_region->position() / speed) - frame_delta;
933 } else {
934 if (swap_direction) {
935 new_bound = (framepos_t) (_region->position() / speed) - frame_delta;
936 } else {
937 new_bound = (framepos_t) (_region->position() / speed) + frame_delta;
941 _region->trim_start ((framepos_t) (new_bound * speed));
942 region_changed (PropertyChange (ARDOUR::Properties::start));