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 "streamview.h"
35 #include "region_view.h"
36 #include "route_time_axis.h"
37 #include "simplerect.h"
38 #include "simpleline.h"
40 #include "public_editor.h"
41 #include "region_editor.h"
42 #include "ghostregion.h"
43 #include "route_time_axis.h"
45 #include "rgb_macros.h"
46 #include "gui_thread.h"
47 #include "ardour_ui.h"
52 using namespace ARDOUR;
54 using namespace Editing;
55 using namespace ArdourCanvas;
57 static const int32_t sync_mark_width = 9;
59 sigc::signal<void,RegionView*> RegionView::RegionViewGoingAway;
61 RegionView::RegionView (ArdourCanvas::Group* parent,
63 boost::shared_ptr<ARDOUR::Region> r,
65 Gdk::Color& basic_color)
66 : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(),
67 TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowNameText|
68 TimeAxisViewItem::ShowNameHighlight|
69 TimeAxisViewItem::ShowFrame))
74 , current_visible_sync_position(0.0)
78 , in_destructor(false)
79 , wait_for_data(false)
83 RegionView::RegionView (const RegionView& other)
84 : TimeAxisViewItem (other)
86 /* derived concrete type will call init () */
88 _region = other._region;
89 editor = other.editor;
90 current_visible_sync_position = other.current_visible_sync_position;
92 _pixel_width = other._pixel_width;
93 _height = other._height;
96 RegionView::RegionView (const RegionView& other, boost::shared_ptr<Region> other_region)
97 : TimeAxisViewItem (other)
99 /* this is a pseudo-copy constructor used when dragging regions
100 around on the canvas.
103 /* derived concrete type will call init () */
105 _region = other_region;
106 editor = other.editor;
107 current_visible_sync_position = other.current_visible_sync_position;
109 _pixel_width = other._pixel_width;
110 _height = other._height;
113 RegionView::RegionView (ArdourCanvas::Group* parent,
115 boost::shared_ptr<ARDOUR::Region> r,
117 Gdk::Color& basic_color,
118 TimeAxisViewItem::Visibility visibility)
119 : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(), visibility)
124 , current_visible_sync_position(0.0)
128 , in_destructor(false)
129 , wait_for_data(false)
134 RegionView::init (Gdk::Color& basic_color, bool wfd)
137 in_destructor = false;
143 compute_colors (basic_color);
145 name_highlight->set_data ("regionview", this);
148 name_text->set_data ("regionview", this);
151 reset_width_dependent_items ((double) _region->length() / samples_per_unit);
153 set_height (trackview.height);
155 _region->StateChanged.connect (mem_fun(*this, &RegionView::region_changed));
157 group->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_event), group, this));
158 name_highlight->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event), name_highlight, this));
162 ColorsChanged.connect (mem_fun (*this, &RegionView::color_handler));
163 // set_pango_fontsize();
164 /* XXX sync mark drag? */
167 RegionView::~RegionView ()
169 in_destructor = true;
171 for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
181 RegionView::_lock_toggle (ArdourCanvas::Item* item, GdkEvent* ev, void* arg)
184 case GDK_BUTTON_RELEASE:
185 static_cast<RegionView*>(arg)->lock_toggle ();
195 RegionView::lock_toggle ()
197 _region->set_locked (!_region->locked());
201 RegionView::region_changed (Change what_changed)
203 ENSURE_GUI_THREAD (bind (mem_fun(*this, &RegionView::region_changed), what_changed));
205 if (what_changed & BoundsChanged) {
206 region_resized (what_changed);
207 region_sync_changed ();
209 if (what_changed & Region::MuteChanged) {
212 if (what_changed & Region::OpacityChanged) {
215 if (what_changed & ARDOUR::NameChanged) {
218 if (what_changed & Region::SyncOffsetChanged) {
219 region_sync_changed ();
221 if (what_changed & Region::LayerChanged) {
224 if (what_changed & Region::LockChanged) {
230 RegionView::region_locked ()
232 /* name will show locked status */
237 RegionView::region_resized (Change what_changed)
241 if (what_changed & ARDOUR::PositionChanged) {
242 set_position (_region->position(), 0);
245 if (what_changed & Change (StartChanged|LengthChanged)) {
247 set_duration (_region->length(), 0);
249 unit_length = _region->length() / samples_per_unit;
251 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
253 (*i)->set_duration (unit_length);
260 RegionView::reset_width_dependent_items (double pixel_width)
262 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
263 _pixel_width = pixel_width;
267 RegionView::region_layered ()
269 RouteTimeAxisView *rtv = dynamic_cast<RouteTimeAxisView*>(&get_time_axis_view());
271 rtv->view()->region_layered (this);
275 RegionView::region_muted ()
282 RegionView::region_opacity ()
294 RegionView::raise_to_top ()
296 _region->raise_to_top ();
306 RegionView::lower_to_bottom ()
308 _region->lower_to_bottom ();
312 RegionView::set_position (nframes_t pos, void* src, double* ignored)
317 if (!(ret = TimeAxisViewItem::set_position (pos, this, &delta))) {
326 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
327 (*i)->group->move (delta, 0.0);
335 RegionView::set_samples_per_unit (gdouble spu)
337 TimeAxisViewItem::set_samples_per_unit (spu);
339 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
340 (*i)->set_samples_per_unit (spu);
341 (*i)->set_duration (_region->length() / samples_per_unit);
344 region_sync_changed ();
348 RegionView::set_duration (nframes_t frames, void *src)
350 if (!TimeAxisViewItem::set_duration (frames, src)) {
354 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
355 (*i)->set_duration (_region->length() / samples_per_unit);
362 RegionView::compute_colors (Gdk::Color& basic_color)
364 TimeAxisViewItem::compute_colors (basic_color);
368 RegionView::set_colors ()
370 TimeAxisViewItem::set_colors ();
373 sync_mark->property_fill_color_rgba() = fill_color;
374 sync_line->property_fill_color_rgba() = fill_color;
379 RegionView::set_frame_color ()
381 if (_region->opaque()) {
387 TimeAxisViewItem::set_frame_color ();
391 RegionView::fake_set_opaque (bool yn)
403 RegionView::hide_region_editor()
411 RegionView::region_renamed ()
415 if (_region->locked()) {
417 str += _region->name();
420 str = _region->name();
423 if (_region->speed_mismatch (trackview.session().frame_rate())) {
424 str = string ("*") + str;
427 if (_region->muted()) {
428 str = string ("!") + str;
431 set_item_name (str, this);
433 reset_width_dependent_items (_pixel_width);
437 RegionView::region_sync_changed ()
440 nframes_t sync_offset;
442 sync_offset = _region->sync_offset (sync_dir);
444 if (sync_offset == 0) {
445 /* no need for a sync mark */
455 /* points set below */
457 sync_mark = new ArdourCanvas::Polygon (*group);
458 sync_mark->property_fill_color_rgba() = fill_color;
460 sync_line = new ArdourCanvas::Line (*group);
461 sync_line->property_fill_color_rgba() = fill_color;
462 sync_line->property_width_pixels() = 1;
465 /* this has to handle both a genuine change of position, a change of samples_per_unit,
466 and a change in the bounds of the _region->
469 if (sync_offset == 0) {
471 /* no sync mark - its the start of the region */
478 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > _region->length()))) {
480 /* no sync mark - its out of the bounds of the region */
491 //points = sync_mark->property_points().get_value();
493 double offset = sync_offset / samples_per_unit;
494 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
495 points.push_back (Gnome::Art::Point (offset + ((sync_mark_width-1)/2), 1));
496 points.push_back (Gnome::Art::Point (offset, sync_mark_width - 1));
497 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
498 sync_mark->property_points().set_value (points);
502 points.push_back (Gnome::Art::Point (offset, 0));
503 points.push_back (Gnome::Art::Point (offset, _height - NAME_HIGHLIGHT_SIZE));
505 sync_line->property_points().set_value (points);
512 RegionView::move (double x_delta, double y_delta)
514 if (_region->locked() || (x_delta == 0 && y_delta == 0)) {
518 get_canvas_group()->move (x_delta, y_delta);
520 /* note: ghosts never leave their tracks so y_delta for them is always zero */
522 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
523 (*i)->group->move (x_delta, 0.0);
528 RegionView::remove_ghost (GhostRegion* ghost)
534 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
543 RegionView::get_fill_color ()
549 RegionView::set_height (double h)
554 nframes_t sync_offset;
555 sync_offset = _region->sync_offset (sync_dir);
556 double offset = sync_offset / samples_per_unit;
558 points.push_back (Gnome::Art::Point (offset, 0));
559 points.push_back (Gnome::Art::Point (offset, h - NAME_HIGHLIGHT_SIZE));
560 sync_line->property_points().set_value (points);