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 (ArdourCanvas::Group* parent,
98 boost::shared_ptr<ARDOUR::Region> r,
100 Gdk::Color& basic_color,
101 TimeAxisViewItem::Visibility visibility)
102 : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(), visibility)
107 , current_visible_sync_position(0.0)
111 , in_destructor(false)
112 , wait_for_data(false)
117 RegionView::init (Gdk::Color& basic_color, bool wfd)
120 in_destructor = false;
126 compute_colors (basic_color);
128 name_highlight->set_data ("regionview", this);
131 name_text->set_data ("regionview", this);
134 reset_width_dependent_items ((double) _region->length() / samples_per_unit);
136 set_height (trackview.height);
138 _region->StateChanged.connect (mem_fun(*this, &RegionView::region_changed));
140 group->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_event), group, this));
141 name_highlight->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event), name_highlight, this));
145 ColorsChanged.connect (mem_fun (*this, &RegionView::color_handler));
146 // set_pango_fontsize();
147 /* XXX sync mark drag? */
150 RegionView::~RegionView ()
152 in_destructor = true;
154 for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
164 RegionView::_lock_toggle (ArdourCanvas::Item* item, GdkEvent* ev, void* arg)
167 case GDK_BUTTON_RELEASE:
168 static_cast<RegionView*>(arg)->lock_toggle ();
178 RegionView::lock_toggle ()
180 _region->set_locked (!_region->locked());
184 RegionView::region_changed (Change what_changed)
186 ENSURE_GUI_THREAD (bind (mem_fun(*this, &RegionView::region_changed), what_changed));
188 if (what_changed & BoundsChanged) {
189 region_resized (what_changed);
190 region_sync_changed ();
192 if (what_changed & Region::MuteChanged) {
195 if (what_changed & Region::OpacityChanged) {
198 if (what_changed & ARDOUR::NameChanged) {
201 if (what_changed & Region::SyncOffsetChanged) {
202 region_sync_changed ();
204 if (what_changed & Region::LayerChanged) {
207 if (what_changed & Region::LockChanged) {
213 RegionView::region_locked ()
215 /* name will show locked status */
220 RegionView::region_resized (Change what_changed)
224 if (what_changed & ARDOUR::PositionChanged) {
225 set_position (_region->position(), 0);
228 if (what_changed & Change (StartChanged|LengthChanged)) {
230 set_duration (_region->length(), 0);
232 unit_length = _region->length() / samples_per_unit;
234 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
236 (*i)->set_duration (unit_length);
243 RegionView::reset_width_dependent_items (double pixel_width)
245 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
246 _pixel_width = pixel_width;
250 RegionView::region_layered ()
252 RouteTimeAxisView *rtv = dynamic_cast<RouteTimeAxisView*>(&get_time_axis_view());
254 rtv->view()->region_layered (this);
258 RegionView::region_muted ()
265 RegionView::region_opacity ()
277 RegionView::raise_to_top ()
279 _region->raise_to_top ();
289 RegionView::lower_to_bottom ()
291 _region->lower_to_bottom ();
295 RegionView::set_position (nframes_t pos, void* src, double* ignored)
300 if (!(ret = TimeAxisViewItem::set_position (pos, this, &delta))) {
309 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
310 (*i)->group->move (delta, 0.0);
318 RegionView::set_samples_per_unit (gdouble spu)
320 TimeAxisViewItem::set_samples_per_unit (spu);
322 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
323 (*i)->set_samples_per_unit (spu);
324 (*i)->set_duration (_region->length() / samples_per_unit);
327 region_sync_changed ();
331 RegionView::set_duration (nframes_t frames, void *src)
333 if (!TimeAxisViewItem::set_duration (frames, src)) {
337 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
338 (*i)->set_duration (_region->length() / samples_per_unit);
345 RegionView::compute_colors (Gdk::Color& basic_color)
347 TimeAxisViewItem::compute_colors (basic_color);
351 RegionView::set_colors ()
353 TimeAxisViewItem::set_colors ();
356 sync_mark->property_fill_color_rgba() = fill_color;
357 sync_line->property_fill_color_rgba() = fill_color;
362 RegionView::set_frame_color ()
364 if (_region->opaque()) {
370 TimeAxisViewItem::set_frame_color ();
374 RegionView::fake_set_opaque (bool yn)
386 RegionView::hide_region_editor()
394 RegionView::region_renamed ()
398 if (_region->locked()) {
400 str += _region->name();
403 str = _region->name();
406 if (_region->speed_mismatch (trackview.session().frame_rate())) {
407 str = string ("*") + str;
410 if (_region->muted()) {
411 str = string ("!") + str;
414 set_item_name (str, this);
416 reset_width_dependent_items (_pixel_width);
420 RegionView::region_sync_changed ()
423 nframes_t sync_offset;
425 sync_offset = _region->sync_offset (sync_dir);
427 if (sync_offset == 0) {
428 /* no need for a sync mark */
438 /* points set below */
440 sync_mark = new ArdourCanvas::Polygon (*group);
441 sync_mark->property_fill_color_rgba() = fill_color;
443 sync_line = new ArdourCanvas::Line (*group);
444 sync_line->property_fill_color_rgba() = fill_color;
445 sync_line->property_width_pixels() = 1;
448 /* this has to handle both a genuine change of position, a change of samples_per_unit,
449 and a change in the bounds of the _region->
452 if (sync_offset == 0) {
454 /* no sync mark - its the start of the region */
461 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > _region->length()))) {
463 /* no sync mark - its out of the bounds of the region */
474 //points = sync_mark->property_points().get_value();
476 double offset = sync_offset / samples_per_unit;
477 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
478 points.push_back (Gnome::Art::Point (offset + ((sync_mark_width-1)/2), 1));
479 points.push_back (Gnome::Art::Point (offset, sync_mark_width - 1));
480 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
481 sync_mark->property_points().set_value (points);
485 points.push_back (Gnome::Art::Point (offset, 0));
486 points.push_back (Gnome::Art::Point (offset, _height - NAME_HIGHLIGHT_SIZE));
488 sync_line->property_points().set_value (points);
495 RegionView::move (double x_delta, double y_delta)
497 if (_region->locked() || (x_delta == 0 && y_delta == 0)) {
501 get_canvas_group()->move (x_delta, y_delta);
503 /* note: ghosts never leave their tracks so y_delta for them is always zero */
505 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
506 (*i)->group->move (x_delta, 0.0);
511 RegionView::remove_ghost (GhostRegion* ghost)
517 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
526 RegionView::get_fill_color ()
532 RegionView::set_height (double h)
537 nframes_t sync_offset;
538 sync_offset = _region->sync_offset (sync_dir);
539 double offset = sync_offset / samples_per_unit;
541 points.push_back (Gnome::Art::Point (offset, 0));
542 points.push_back (Gnome::Art::Point (offset, h - NAME_HIGHLIGHT_SIZE));
543 sync_line->property_points().set_value (points);