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.
27 #include <gtkmm2ext/gtk_ui.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"
51 using namespace ARDOUR;
53 using namespace Editing;
54 using namespace ArdourCanvas;
56 static const int32_t sync_mark_width = 9;
58 sigc::signal<void,RegionView*> RegionView::RegionViewGoingAway;
60 RegionView::RegionView (ArdourCanvas::Group* parent,
62 boost::shared_ptr<ARDOUR::Region> r,
64 Gdk::Color& basic_color)
65 : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(),
66 TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowNameText|
67 TimeAxisViewItem::ShowNameHighlight|
68 TimeAxisViewItem::ShowFrame))
73 , current_visible_sync_position(0.0)
77 , in_destructor(false)
78 , wait_for_data(false)
82 RegionView::RegionView (ArdourCanvas::Group* parent,
84 boost::shared_ptr<ARDOUR::Region> r,
86 Gdk::Color& basic_color,
87 TimeAxisViewItem::Visibility visibility)
88 : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(), visibility)
93 , current_visible_sync_position(0.0)
97 , in_destructor(false)
98 , wait_for_data(false)
103 RegionView::init (Gdk::Color& basic_color, bool wfd)
107 in_destructor = false;
111 compute_colors (basic_color);
113 name_highlight->set_data ("regionview", this);
116 name_text->set_data ("regionview", this);
119 /* an equilateral triangle */
121 ArdourCanvas::Points shape;
122 shape.push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
123 shape.push_back (Gnome::Art::Point ((sync_mark_width - 1)/2, 1));
124 shape.push_back (Gnome::Art::Point (0, sync_mark_width - 1));
125 shape.push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
127 sync_mark = new ArdourCanvas::Polygon (*group);
128 sync_mark->property_points() = shape;
129 sync_mark->property_fill_color_rgba() = fill_color;
132 reset_width_dependent_items ((double) _region->length() / samples_per_unit);
134 set_height (trackview.height);
136 _region->StateChanged.connect (mem_fun(*this, &RegionView::region_changed));
138 group->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_event), group, this));
139 name_highlight->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event), name_highlight, this));
143 ColorChanged.connect (mem_fun (*this, &RegionView::color_handler));
145 /* XXX sync mark drag? */
148 RegionView::~RegionView ()
150 in_destructor = true;
152 for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
162 RegionView::_lock_toggle (ArdourCanvas::Item* item, GdkEvent* ev, void* arg)
165 case GDK_BUTTON_RELEASE:
166 static_cast<RegionView*>(arg)->lock_toggle ();
176 RegionView::lock_toggle ()
178 _region->set_locked (!_region->locked());
182 RegionView::region_changed (Change what_changed)
184 ENSURE_GUI_THREAD (bind (mem_fun(*this, &RegionView::region_changed), what_changed));
186 if (what_changed & BoundsChanged) {
187 region_resized (what_changed);
188 region_sync_changed ();
190 if (what_changed & Region::MuteChanged) {
193 if (what_changed & Region::OpacityChanged) {
196 if (what_changed & ARDOUR::NameChanged) {
199 if (what_changed & Region::SyncOffsetChanged) {
200 region_sync_changed ();
202 if (what_changed & Region::LayerChanged) {
205 if (what_changed & Region::LockChanged) {
211 RegionView::region_locked ()
213 /* name will show locked status */
218 RegionView::region_resized (Change what_changed)
222 if (what_changed & ARDOUR::PositionChanged) {
223 set_position (_region->position(), 0);
226 if (what_changed & Change (StartChanged|LengthChanged)) {
228 set_duration (_region->length(), 0);
230 unit_length = _region->length() / samples_per_unit;
232 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
234 (*i)->set_duration (unit_length);
241 RegionView::reset_width_dependent_items (double pixel_width)
243 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
244 _pixel_width = pixel_width;
248 RegionView::set_height (gdouble height)
250 TimeAxisViewItem::set_height (height - 2);
256 RegionView::region_layered ()
258 RouteTimeAxisView *rtv = dynamic_cast<RouteTimeAxisView*>(&get_time_axis_view());
260 rtv->view()->region_layered (this);
264 RegionView::region_muted ()
271 RegionView::region_opacity ()
283 RegionView::raise_to_top ()
285 _region->raise_to_top ();
295 RegionView::lower_to_bottom ()
297 _region->lower_to_bottom ();
301 RegionView::set_position (nframes_t pos, void* src, double* ignored)
306 if (!(ret = TimeAxisViewItem::set_position (pos, this, &delta))) {
315 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
316 (*i)->group->move (delta, 0.0);
324 RegionView::set_samples_per_unit (gdouble spu)
326 TimeAxisViewItem::set_samples_per_unit (spu);
328 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
329 (*i)->set_samples_per_unit (spu);
330 (*i)->set_duration (_region->length() / samples_per_unit);
333 region_sync_changed ();
337 RegionView::set_duration (nframes_t frames, void *src)
339 if (!TimeAxisViewItem::set_duration (frames, src)) {
343 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
344 (*i)->set_duration (_region->length() / samples_per_unit);
351 RegionView::compute_colors (Gdk::Color& basic_color)
353 TimeAxisViewItem::compute_colors (basic_color);
357 RegionView::set_colors ()
359 TimeAxisViewItem::set_colors ();
362 sync_mark->property_fill_color_rgba() = fill_color;
367 RegionView::set_frame_color ()
369 if (_region->opaque()) {
375 TimeAxisViewItem::set_frame_color ();
379 RegionView::hide_region_editor()
387 RegionView::region_renamed ()
391 if (_region->locked()) {
393 str += _region->name();
396 str = _region->name();
399 // speed mismatch handled in audio_region_view.cc
400 // FIXME: come up with more elegant solution for this
402 if (_region->muted()) {
403 str = string ("!") + str;
406 set_item_name (str, this);
408 reset_width_dependent_items (_pixel_width);
412 RegionView::region_sync_changed ()
414 if (sync_mark == 0) {
419 nframes_t sync_offset;
421 sync_offset = _region->sync_offset (sync_dir);
423 /* this has to handle both a genuine change of position, a change of samples_per_unit,
424 and a change in the bounds of the _region->
427 if (sync_offset == 0) {
429 /* no sync mark - its the start of the region */
435 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > _region->length()))) {
437 /* no sync mark - its out of the bounds of the region */
447 //points = sync_mark->property_points().get_value();
449 double offset = sync_offset / samples_per_unit;
450 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
451 points.push_back (Gnome::Art::Point (offset + ((sync_mark_width-1)/2), 1));
452 points.push_back (Gnome::Art::Point (offset, sync_mark_width - 1));
453 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
454 sync_mark->property_points().set_value (points);
462 RegionView::move (double x_delta, double y_delta)
464 if (_region->locked() || (x_delta == 0 && y_delta == 0)) {
468 get_canvas_group()->move (x_delta, y_delta);
470 /* note: ghosts never leave their tracks so y_delta for them is always zero */
472 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
473 (*i)->group->move (x_delta, 0.0);
478 RegionView::remove_ghost (GhostRegion* ghost)
484 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
493 RegionView::get_fill_color ()