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"
34 #include "ardour_ui.h"
35 #include "streamview.h"
36 #include "region_view.h"
37 #include "automation_region_view.h"
38 #include "route_time_axis.h"
39 #include "simplerect.h"
40 #include "simpleline.h"
42 #include "public_editor.h"
43 #include "region_editor.h"
44 #include "ghostregion.h"
45 #include "route_time_axis.h"
47 #include "rgb_macros.h"
48 #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 sigc::signal<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(), r->position())
85 RegionView::RegionView (const RegionView& other)
86 : sigc::trackable(other)
87 , TimeAxisViewItem (other)
88 , _time_converter(other._time_converter)
90 /* derived concrete type will call init () */
92 _region = other._region;
93 current_visible_sync_position = other.current_visible_sync_position;
95 _pixel_width = other._pixel_width;
96 _height = other._height;
99 RegionView::RegionView (const RegionView& other, boost::shared_ptr<Region> other_region)
100 : sigc::trackable(other)
101 , TimeAxisViewItem (other)
102 , _time_converter(other._time_converter)
104 /* this is a pseudo-copy constructor used when dragging regions
105 around on the canvas.
108 /* derived concrete type will call init () */
110 _region = other_region;
111 current_visible_sync_position = other.current_visible_sync_position;
113 _pixel_width = other._pixel_width;
114 _height = other._height;
117 RegionView::RegionView (ArdourCanvas::Group* parent,
119 boost::shared_ptr<ARDOUR::Region> r,
121 Gdk::Color const & basic_color,
123 TimeAxisViewItem::Visibility visibility)
124 : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(), recording, visibility)
129 , current_visible_sync_position(0.0)
131 , _enable_display(false)
133 , in_destructor(false)
134 , wait_for_data(false)
135 , _time_converter(r->session(), r->position())
140 RegionView::init (Gdk::Color const & basic_color, bool wfd)
144 in_destructor = false;
152 compute_colors (basic_color);
154 if (name_highlight) {
155 name_highlight->set_data ("regionview", this);
156 name_highlight->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event), name_highlight, this));
160 name_pixbuf->set_data ("regionview", this);
164 _enable_display = true;
166 set_height (trackview.current_height());
168 _region->StateChanged.connect (mem_fun(*this, &RegionView::region_changed));
170 group->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_event), group, this));
174 ColorsChanged.connect (mem_fun (*this, &RegionView::color_handler));
176 /* XXX sync mark drag? */
179 RegionView::~RegionView ()
181 in_destructor = true;
183 for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
187 for (std::list<ArdourCanvas::SimpleRect*>::iterator i = _coverage_frames.begin (); i != _coverage_frames.end (); ++i) {
195 RegionView::_lock_toggle (ArdourCanvas::Item* item, GdkEvent* ev, void* arg)
198 case GDK_BUTTON_RELEASE:
199 static_cast<RegionView*>(arg)->lock_toggle ();
209 RegionView::lock_toggle ()
211 _region->set_locked (!_region->locked());
215 RegionView::region_changed (Change what_changed)
217 ENSURE_GUI_THREAD (bind (mem_fun(*this, &RegionView::region_changed), what_changed));
219 if (what_changed & BoundsChanged) {
220 region_resized (what_changed);
221 region_sync_changed ();
223 if (what_changed & Region::MuteChanged) {
226 if (what_changed & Region::OpacityChanged) {
229 if (what_changed & ARDOUR::NameChanged) {
232 if (what_changed & Region::SyncOffsetChanged) {
233 region_sync_changed ();
235 if (what_changed & Region::LockChanged) {
241 RegionView::region_locked ()
243 /* name will show locked status */
248 RegionView::region_resized (Change what_changed)
252 if (what_changed & ARDOUR::PositionChanged) {
253 set_position (_region->position(), 0);
254 _time_converter.set_origin(_region->position());
257 if (what_changed & Change (StartChanged|LengthChanged)) {
259 set_duration (_region->length(), 0);
261 unit_length = _region->length() / samples_per_unit;
263 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
265 (*i)->set_duration (unit_length);
272 RegionView::reset_width_dependent_items (double pixel_width)
274 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
275 _pixel_width = pixel_width;
279 RegionView::region_muted ()
286 RegionView::region_opacity ()
292 RegionView::raise_to_top ()
294 _region->raise_to_top ();
298 RegionView::lower_to_bottom ()
300 _region->lower_to_bottom ();
304 RegionView::set_position (nframes_t pos, void* src, double* ignored)
309 if (!(ret = TimeAxisViewItem::set_position (pos, this, &delta))) {
318 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
319 (*i)->group->move (delta, 0.0);
327 RegionView::set_samples_per_unit (gdouble spu)
329 TimeAxisViewItem::set_samples_per_unit (spu);
331 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
332 (*i)->set_samples_per_unit (spu);
333 (*i)->set_duration (_region->length() / samples_per_unit);
336 region_sync_changed ();
340 RegionView::set_duration (nframes_t frames, void *src)
342 if (!TimeAxisViewItem::set_duration (frames, src)) {
346 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
347 (*i)->set_duration (_region->length() / samples_per_unit);
354 RegionView::set_colors ()
356 TimeAxisViewItem::set_colors ();
359 sync_mark->property_fill_color_rgba() = fill_color;
360 sync_line->property_fill_color_rgba() = fill_color;
365 RegionView::set_frame_color ()
367 if (_region->opaque()) {
373 TimeAxisViewItem::set_frame_color ();
377 RegionView::fake_set_opaque (bool yn)
389 RegionView::hide_region_editor()
397 RegionView::make_name () const
401 // XXX nice to have some good icons for this
403 if (_region->locked()) {
405 str += _region->name();
407 } else if (_region->position_locked()) {
409 str += _region->name();
412 str = _region->name();
415 if (_region->muted()) {
416 str = string ("!") + str;
423 RegionView::region_renamed ()
425 Glib::ustring str = make_name ();
427 set_item_name (str, this);
429 reset_width_dependent_items (_pixel_width);
433 RegionView::region_sync_changed ()
436 nframes_t sync_offset;
438 sync_offset = _region->sync_offset (sync_dir);
440 if (sync_offset == 0) {
441 /* no need for a sync mark */
451 /* points set below */
453 sync_mark = new ArdourCanvas::Polygon (*group);
454 sync_mark->property_fill_color_rgba() = fill_color;
456 sync_line = new ArdourCanvas::Line (*group);
457 sync_line->property_fill_color_rgba() = fill_color;
458 sync_line->property_width_pixels() = 1;
461 /* this has to handle both a genuine change of position, a change of samples_per_unit,
462 and a change in the bounds of the _region->
465 if (sync_offset == 0) {
467 /* no sync mark - its the start of the region */
474 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > _region->length()))) {
476 /* no sync mark - its out of the bounds of the region */
487 //points = sync_mark->property_points().get_value();
489 double offset = sync_offset / samples_per_unit;
490 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
491 points.push_back (Gnome::Art::Point (offset + ((sync_mark_width-1)/2), 1));
492 points.push_back (Gnome::Art::Point (offset, sync_mark_width - 1));
493 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
494 sync_mark->property_points().set_value (points);
498 points.push_back (Gnome::Art::Point (offset, 0));
499 points.push_back (Gnome::Art::Point (offset, trackview.current_height() - NAME_HIGHLIGHT_SIZE));
501 sync_line->property_points().set_value (points);
508 RegionView::move (double x_delta, double y_delta)
510 if (!_region->can_move() || (x_delta == 0 && y_delta == 0)) {
514 get_canvas_group()->move (x_delta, y_delta);
516 /* note: ghosts never leave their tracks so y_delta for them is always zero */
518 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
519 (*i)->group->move (x_delta, 0.0);
524 RegionView::remove_ghost_in (TimeAxisView& tv)
526 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
527 if (&(*i)->trackview == &tv) {
535 RegionView::remove_ghost (GhostRegion* ghost)
541 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
550 RegionView::get_fill_color ()
556 RegionView::set_height (double h)
558 TimeAxisViewItem::set_height(h);
563 nframes_t sync_offset;
564 sync_offset = _region->sync_offset (sync_dir);
565 double offset = sync_offset / samples_per_unit;
567 points.push_back (Gnome::Art::Point (offset, 0));
568 points.push_back (Gnome::Art::Point (offset, h - NAME_HIGHLIGHT_SIZE));
569 sync_line->property_points().set_value (points);
573 /** Remove old coverage frames and make new ones, if we're in a LayerDisplay mode
574 * which uses them. */
576 RegionView::update_coverage_frames (LayerDisplay d)
578 /* remove old coverage frames */
579 for (std::list<ArdourCanvas::SimpleRect*>::iterator i = _coverage_frames.begin (); i != _coverage_frames.end (); ++i) {
583 _coverage_frames.clear ();
586 /* don't do coverage frames unless we're in stacked mode */
590 boost::shared_ptr<Playlist> pl (_region->playlist ());
595 nframes_t const position = _region->first_frame ();
596 nframes_t t = position;
597 nframes_t const end = _region->last_frame ();
599 ArdourCanvas::SimpleRect* cr = 0;
602 uint32_t const color = frame->property_fill_color_rgba ();
603 uint32_t const base_alpha = UINT_RGBA_A (color);
609 /* is this region is on top at time t? */
610 bool const new_me = (pl->top_region_at (t) == _region);
612 /* finish off any old rect, if required */
613 if (cr && me != new_me) {
614 cr->property_x2() = trackview.editor().frame_to_pixel (t - position);
617 /* start off any new rect, if required */
618 if (cr == 0 || me != new_me) {
619 cr = new ArdourCanvas::SimpleRect (*group);
620 _coverage_frames.push_back (cr);
621 cr->property_x1() = trackview.editor().frame_to_pixel (t - position);
622 cr->property_y1() = 1;
623 cr->property_y2() = _height + 1;
624 cr->property_outline_pixels() = 0;
625 /* areas that will be played get a lower alpha */
626 uint32_t alpha = base_alpha;
630 cr->property_fill_color_rgba () = UINT_RGBA_CHANGE_A (color, alpha);
633 t = pl->find_next_region_boundary (t, 1);
638 /* finish off the last rectangle */
639 cr->property_x2() = trackview.editor().frame_to_pixel (end - position);