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"
53 using namespace ARDOUR;
55 using namespace Editing;
56 using namespace ArdourCanvas;
58 static const int32_t sync_mark_width = 9;
60 sigc::signal<void,RegionView*> RegionView::RegionViewGoingAway;
62 RegionView::RegionView (ArdourCanvas::Group* parent,
64 boost::shared_ptr<ARDOUR::Region> r,
66 Gdk::Color& basic_color)
67 : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(),
68 TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowNameText|
69 TimeAxisViewItem::ShowNameHighlight|
70 TimeAxisViewItem::ShowFrame))
74 , current_visible_sync_position(0.0)
76 , _enable_display(false)
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;
90 current_visible_sync_position = other.current_visible_sync_position;
92 _enable_display = false;
93 _pixel_width = other._pixel_width;
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)
106 , current_visible_sync_position(0.0)
108 , _enable_display(false)
110 , in_destructor(false)
111 , wait_for_data(false)
116 RegionView::init (Gdk::Color& basic_color, bool wfd)
119 _enable_display = false;
120 in_destructor = false;
123 compute_colors (basic_color);
125 name_highlight->set_data ("regionview", this);
128 name_text->set_data ("regionview", this);
131 /* an equilateral triangle */
133 ArdourCanvas::Points shape;
134 shape.push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
135 shape.push_back (Gnome::Art::Point ((sync_mark_width - 1)/2, 1));
136 shape.push_back (Gnome::Art::Point (0, sync_mark_width - 1));
137 shape.push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
139 sync_mark = new ArdourCanvas::Polygon (*group);
140 sync_mark->property_points() = shape;
141 sync_mark->property_fill_color_rgba() = fill_color;
144 //reset_width_dependent_items ((double) _region->length() / samples_per_unit);
147 _enable_display = true;
149 set_y_position_and_height (0, trackview.height - 2);
151 _region->StateChanged.connect (mem_fun(*this, &RegionView::region_changed));
153 group->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_event), group, this));
154 name_highlight->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event), name_highlight, this));
158 ColorsChanged.connect (mem_fun (*this, &RegionView::color_handler));
160 /* XXX sync mark drag? */
163 RegionView::~RegionView ()
165 in_destructor = true;
167 for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
177 RegionView::_lock_toggle (ArdourCanvas::Item* item, GdkEvent* ev, void* arg)
180 case GDK_BUTTON_RELEASE:
181 static_cast<RegionView*>(arg)->lock_toggle ();
191 RegionView::lock_toggle ()
193 _region->set_locked (!_region->locked());
197 RegionView::region_changed (Change what_changed)
199 ENSURE_GUI_THREAD (bind (mem_fun(*this, &RegionView::region_changed), what_changed));
201 if (what_changed & BoundsChanged) {
202 region_resized (what_changed);
203 region_sync_changed ();
205 if (what_changed & Region::MuteChanged) {
208 if (what_changed & Region::OpacityChanged) {
211 if (what_changed & ARDOUR::NameChanged) {
214 if (what_changed & Region::SyncOffsetChanged) {
215 region_sync_changed ();
218 this should not be needed now that only playlist can change layering
221 if (what_changed & Region::LayerChanged) {
225 if (what_changed & Region::LockChanged) {
231 RegionView::region_locked ()
233 /* name will show locked status */
238 RegionView::region_resized (Change what_changed)
242 if (what_changed & ARDOUR::PositionChanged) {
243 set_position (_region->position(), 0);
246 if (what_changed & Change (StartChanged|LengthChanged)) {
248 set_duration (_region->length(), 0);
250 unit_length = _region->length() / samples_per_unit;
252 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
254 (*i)->set_duration (unit_length);
261 RegionView::reset_width_dependent_items (double pixel_width)
263 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
264 _pixel_width = pixel_width;
266 /*for (AutomationChildren::iterator i = _automation_children.begin();
267 i != _automation_children.end(); ++i) {
268 i->second->reset_width_dependent_items(pixel_width);
273 RegionView::region_layered ()
275 RouteTimeAxisView *rtv = dynamic_cast<RouteTimeAxisView*>(&get_time_axis_view());
277 rtv->view()->region_layered (this);
281 RegionView::region_muted ()
288 RegionView::region_opacity ()
294 RegionView::raise_to_top ()
296 _region->raise_to_top ();
300 RegionView::lower_to_bottom ()
302 _region->lower_to_bottom ();
306 RegionView::set_position (nframes_t pos, void* src, double* ignored)
311 if (!(ret = TimeAxisViewItem::set_position (pos, this, &delta))) {
320 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
321 (*i)->group->move (delta, 0.0);
324 for (AutomationChildren::iterator i = _automation_children.begin();
325 i != _automation_children.end(); ++i) {
326 i->second->get_canvas_group()->move(delta, 0.0);
334 RegionView::set_samples_per_unit (gdouble spu)
336 TimeAxisViewItem::set_samples_per_unit (spu);
338 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
339 (*i)->set_samples_per_unit (spu);
340 (*i)->set_duration (_region->length() / samples_per_unit);
343 region_sync_changed ();
347 RegionView::set_duration (nframes_t frames, void *src)
349 if (!TimeAxisViewItem::set_duration (frames, src)) {
353 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
354 (*i)->set_duration (_region->length() / samples_per_unit);
361 RegionView::compute_colors (Gdk::Color& basic_color)
363 TimeAxisViewItem::compute_colors (basic_color);
367 RegionView::set_colors ()
369 TimeAxisViewItem::set_colors ();
372 sync_mark->property_fill_color_rgba() = fill_color;
377 RegionView::set_frame_color ()
379 if (_region->opaque()) {
385 TimeAxisViewItem::set_frame_color ();
389 RegionView::fake_set_opaque (bool yn)
397 TimeAxisViewItem::set_frame_color ();
401 RegionView::hide_region_editor()
409 RegionView::make_name () const
413 // XXX nice to have some good icons for this
415 if (_region->locked()) {
417 str += _region->name();
419 } else if (_region->position_locked()) {
421 str += _region->name();
424 str = _region->name();
427 if (_region->muted()) {
428 str = string ("!") + str;
435 RegionView::region_renamed ()
437 Glib::ustring str = make_name ();
439 set_item_name (str, this);
441 reset_width_dependent_items (_pixel_width);
445 RegionView::region_sync_changed ()
447 if (sync_mark == 0) {
452 nframes_t sync_offset;
454 sync_offset = _region->sync_offset (sync_dir);
456 /* this has to handle both a genuine change of position, a change of samples_per_unit,
457 and a change in the bounds of the _region->
460 if (sync_offset == 0) {
462 /* no sync mark - its the start of the region */
468 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > _region->length()))) {
470 /* no sync mark - its out of the bounds of the region */
480 //points = sync_mark->property_points().get_value();
482 double offset = sync_offset / samples_per_unit;
483 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
484 points.push_back (Gnome::Art::Point (offset + ((sync_mark_width-1)/2), 1));
485 points.push_back (Gnome::Art::Point (offset, sync_mark_width - 1));
486 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
487 sync_mark->property_points().set_value (points);
495 RegionView::move (double x_delta, double y_delta)
497 if (!_region->can_move() || (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);
509 for (AutomationChildren::iterator i = _automation_children.begin();
510 i != _automation_children.end(); ++i) {
511 i->second->get_canvas_group()->move(x_delta, 0.0);
516 RegionView::remove_ghost (GhostRegion* ghost)
522 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
531 RegionView::get_fill_color ()