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.
26 #include <gtkmm2ext/gtk_ui.h>
27 #include "pbd/stacktrace.h"
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"
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"
43 #include "public_editor.h"
44 #include "region_editor.h"
45 #include "ghostregion.h"
46 #include "route_time_axis.h"
48 #include "rgb_macros.h"
49 #include "gui_thread.h"
54 using namespace ARDOUR;
56 using namespace Editing;
57 using namespace ArdourCanvas;
59 static const int32_t sync_mark_width = 9;
61 PBD::Signal1<void,RegionView*> RegionView::RegionViewGoingAway;
63 RegionView::RegionView (ArdourCanvas::Group* parent,
65 boost::shared_ptr<ARDOUR::Region> r,
67 Gdk::Color const & basic_color)
68 : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(), false,
69 TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowNameText|
70 TimeAxisViewItem::ShowNameHighlight| TimeAxisViewItem::ShowFrame))
75 , current_visible_sync_position(0.0)
77 , _enable_display(false)
79 , in_destructor(false)
80 , wait_for_data(false)
81 , _time_converter(r->session().tempo_map(), r->position())
83 GhostRegion::CatchDeletion.connect (*this, ui_bind (&RegionView::remove_ghost, this, _1), gui_context());
86 RegionView::RegionView (const RegionView& other)
87 : sigc::trackable(other)
88 , TimeAxisViewItem (other)
89 , _time_converter(other._time_converter)
91 /* derived concrete type will call init () */
93 _region = other._region;
94 current_visible_sync_position = other.current_visible_sync_position;
96 _pixel_width = other._pixel_width;
97 _height = other._height;
99 GhostRegion::CatchDeletion.connect (*this, ui_bind (&RegionView::remove_ghost, this, _1), gui_context());
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)
107 /* this is a pseudo-copy constructor used when dragging regions
108 around on the canvas.
111 /* derived concrete type will call init () */
113 _region = other_region;
114 current_visible_sync_position = other.current_visible_sync_position;
116 _pixel_width = other._pixel_width;
117 _height = other._height;
119 GhostRegion::CatchDeletion.connect (*this, ui_bind (&RegionView::remove_ghost, this, _1), gui_context());
122 RegionView::RegionView (ArdourCanvas::Group* parent,
124 boost::shared_ptr<ARDOUR::Region> r,
126 Gdk::Color const & basic_color,
128 TimeAxisViewItem::Visibility visibility)
129 : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(), recording, visibility)
134 , current_visible_sync_position(0.0)
136 , _enable_display(false)
138 , in_destructor(false)
139 , wait_for_data(false)
140 , _time_converter(r->session().tempo_map(), r->position())
145 RegionView::init (Gdk::Color const & basic_color, bool wfd)
149 in_destructor = false;
157 compute_colors (basic_color);
159 if (name_highlight) {
160 name_highlight->set_data ("regionview", this);
161 name_highlight->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event), name_highlight, this));
163 frame_handle_start->set_data ("regionview", this);
164 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_end->set_data ("regionview", this);
167 frame_handle_end->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_frame_handle_event), frame_handle_end, this));
169 frame_handle_start->raise_to_top();
170 frame_handle_end->raise_to_top();
174 name_pixbuf->set_data ("regionview", this);
175 name_pixbuf->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_event), name_pixbuf, this));
179 _enable_display = true;
182 set_height (trackview.current_height());
184 _region->StateChanged.connect (*this, ui_bind (&RegionView::region_changed, this, _1), gui_context());
186 group->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_event), group, this));
190 ColorsChanged.connect (sigc::mem_fun (*this, &RegionView::color_handler));
192 /* XXX sync mark drag? */
195 RegionView::~RegionView ()
197 in_destructor = true;
199 for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
203 for (list<ArdourCanvas::SimpleRect*>::iterator i = _coverage_frames.begin (); i != _coverage_frames.end (); ++i) {
211 RegionView::_lock_toggle (ArdourCanvas::Item*, GdkEvent* ev, void* arg)
214 case GDK_BUTTON_RELEASE:
215 static_cast<RegionView*>(arg)->lock_toggle ();
225 RegionView::lock_toggle ()
227 _region->set_locked (!_region->locked());
231 RegionView::region_changed (PropertyChange what_changed)
233 ENSURE_GUI_THREAD (*this, &RegionView::region_changed, what_changed)
235 if (what_changed & BoundsChanged) {
236 region_resized (what_changed);
237 region_sync_changed ();
239 if (what_changed & Region::MuteChanged) {
242 if (what_changed & Region::OpacityChanged) {
245 if (what_changed & ARDOUR::NameChanged) {
248 if (what_changed & Region::SyncOffsetChanged) {
249 region_sync_changed ();
251 if (what_changed & Region::LockChanged) {
257 RegionView::region_locked ()
259 /* name will show locked status */
264 RegionView::region_resized (PropertyChange what_changed)
268 if (what_changed & ARDOUR::PositionChanged) {
269 set_position (_region->position(), 0);
270 _time_converter.set_origin(_region->position());
273 if (what_changed & PropertyChange (StartChanged|LengthChanged)) {
275 set_duration (_region->length(), 0);
277 unit_length = _region->length() / samples_per_unit;
279 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
281 (*i)->set_duration (unit_length);
288 RegionView::reset_width_dependent_items (double pixel_width)
290 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
291 _pixel_width = pixel_width;
295 RegionView::region_muted ()
302 RegionView::region_opacity ()
308 RegionView::raise_to_top ()
310 _region->raise_to_top ();
314 RegionView::lower_to_bottom ()
316 _region->lower_to_bottom ();
320 RegionView::set_position (nframes64_t pos, void* /*src*/, double* ignored)
325 if (!(ret = TimeAxisViewItem::set_position (pos, this, &delta))) {
334 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
335 (*i)->group->move (delta, 0.0);
343 RegionView::set_samples_per_unit (gdouble spu)
345 TimeAxisViewItem::set_samples_per_unit (spu);
347 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
348 (*i)->set_samples_per_unit (spu);
349 (*i)->set_duration (_region->length() / samples_per_unit);
352 region_sync_changed ();
356 RegionView::set_duration (nframes64_t frames, void *src)
358 if (!TimeAxisViewItem::set_duration (frames, src)) {
362 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
363 (*i)->set_duration (_region->length() / samples_per_unit);
370 RegionView::set_colors ()
372 TimeAxisViewItem::set_colors ();
375 sync_mark->property_fill_color_rgba() = fill_color;
376 sync_line->property_fill_color_rgba() = fill_color;
381 RegionView::set_frame_color ()
383 if (_region->opaque()) {
389 TimeAxisViewItem::set_frame_color ();
393 RegionView::fake_set_opaque (bool yn)
405 RegionView::hide_region_editor()
413 RegionView::make_name () const
417 // XXX nice to have some good icons for this
419 if (_region->locked()) {
421 str += _region->name();
423 } else if (_region->position_locked()) {
425 str += _region->name();
428 str = _region->name();
431 if (_region->muted()) {
432 str = string ("!") + str;
439 RegionView::region_renamed ()
441 Glib::ustring str = make_name ();
443 set_item_name (str, this);
445 reset_width_dependent_items (_pixel_width);
449 RegionView::region_sync_changed ()
452 nframes_t sync_offset;
454 sync_offset = _region->sync_offset (sync_dir);
456 if (sync_offset == 0) {
457 /* no need for a sync mark */
467 /* points set below */
469 sync_mark = new ArdourCanvas::Polygon (*group);
470 sync_mark->property_fill_color_rgba() = fill_color;
472 sync_line = new ArdourCanvas::Line (*group);
473 sync_line->property_fill_color_rgba() = fill_color;
474 sync_line->property_width_pixels() = 1;
477 /* this has to handle both a genuine change of position, a change of samples_per_unit,
478 and a change in the bounds of the _region->
481 if (sync_offset == 0) {
483 /* no sync mark - its the start of the region */
490 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > _region->length()))) {
492 /* no sync mark - its out of the bounds of the region */
503 //points = sync_mark->property_points().get_value();
505 double offset = sync_offset / samples_per_unit;
506 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
507 points.push_back (Gnome::Art::Point (offset + ((sync_mark_width-1)/2), 1));
508 points.push_back (Gnome::Art::Point (offset, sync_mark_width - 1));
509 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
510 sync_mark->property_points().set_value (points);
514 points.push_back (Gnome::Art::Point (offset, 0));
515 points.push_back (Gnome::Art::Point (offset, trackview.current_height() - NAME_HIGHLIGHT_SIZE));
517 sync_line->property_points().set_value (points);
524 RegionView::move (double x_delta, double y_delta)
526 if (!_region->can_move() || (x_delta == 0 && y_delta == 0)) {
530 get_canvas_group()->move (x_delta, y_delta);
532 /* note: ghosts never leave their tracks so y_delta for them is always zero */
534 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
535 (*i)->group->move (x_delta, 0.0);
540 RegionView::remove_ghost_in (TimeAxisView& tv)
542 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
543 if (&(*i)->trackview == &tv) {
551 RegionView::remove_ghost (GhostRegion* ghost)
557 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
566 RegionView::get_fill_color ()
572 RegionView::set_height (double h)
574 TimeAxisViewItem::set_height(h);
579 nframes_t sync_offset;
580 sync_offset = _region->sync_offset (sync_dir);
581 double offset = sync_offset / samples_per_unit;
583 points.push_back (Gnome::Art::Point (offset, 0));
584 points.push_back (Gnome::Art::Point (offset, h - NAME_HIGHLIGHT_SIZE));
585 sync_line->property_points().set_value (points);
588 for (list<ArdourCanvas::SimpleRect*>::iterator i = _coverage_frames.begin(); i != _coverage_frames.end(); ++i) {
589 (*i)->property_y2() = h + 1;
593 /** Remove old coverage frames and make new ones, if we're in a LayerDisplay mode
594 * which uses them. */
596 RegionView::update_coverage_frames (LayerDisplay d)
598 /* remove old coverage frames */
599 for (list<ArdourCanvas::SimpleRect*>::iterator i = _coverage_frames.begin (); i != _coverage_frames.end (); ++i) {
603 _coverage_frames.clear ();
606 /* don't do coverage frames unless we're in stacked mode */
610 boost::shared_ptr<Playlist> pl (_region->playlist ());
615 nframes_t const position = _region->first_frame ();
616 nframes_t t = position;
617 nframes_t const end = _region->last_frame ();
619 ArdourCanvas::SimpleRect* cr = 0;
622 uint32_t const color = frame->property_fill_color_rgba ();
623 uint32_t const base_alpha = UINT_RGBA_A (color);
629 /* is this region is on top at time t? */
630 bool const new_me = (pl->top_unmuted_region_at (t) == _region);
632 /* finish off any old rect, if required */
633 if (cr && me != new_me) {
634 cr->property_x2() = trackview.editor().frame_to_pixel (t - position);
637 /* start off any new rect, if required */
638 if (cr == 0 || me != new_me) {
639 cr = new ArdourCanvas::SimpleRect (*group);
640 _coverage_frames.push_back (cr);
641 cr->property_x1() = trackview.editor().frame_to_pixel (t - position);
642 cr->property_y1() = 1;
643 cr->property_y2() = _height + 1;
644 cr->property_outline_pixels() = 0;
645 /* areas that will be played get a lower alpha */
646 uint32_t alpha = base_alpha;
650 cr->property_fill_color_rgba () = UINT_RGBA_CHANGE_A (color, alpha);
653 t = pl->find_next_region_boundary (t, 1);
658 /* finish off the last rectangle */
659 cr->property_x2() = trackview.editor().frame_to_pixel (end - position);
662 frame_handle_start->raise_to_top ();
663 frame_handle_end->raise_to_top ();