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"
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))
72 , current_visible_sync_position(0.0)
76 , in_destructor(false)
77 , wait_for_data(false)
81 RegionView::RegionView (const RegionView& other)
82 : TimeAxisViewItem (other)
84 /* derived concrete type will call init () */
86 _region = other._region;
87 editor = other.editor;
88 current_visible_sync_position = other.current_visible_sync_position;
90 _pixel_width = other._pixel_width;
91 _height = other._height;
94 RegionView::RegionView (ArdourCanvas::Group* parent,
96 boost::shared_ptr<ARDOUR::Region> r,
98 Gdk::Color& basic_color,
99 TimeAxisViewItem::Visibility visibility)
100 : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(), visibility)
104 , current_visible_sync_position(0.0)
108 , in_destructor(false)
109 , wait_for_data(false)
114 RegionView::init (Gdk::Color& basic_color, bool wfd)
117 in_destructor = false;
121 compute_colors (basic_color);
123 name_highlight->set_data ("regionview", this);
126 name_text->set_data ("regionview", this);
129 /* an equilateral triangle */
131 ArdourCanvas::Points shape;
132 shape.push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
133 shape.push_back (Gnome::Art::Point ((sync_mark_width - 1)/2, 1));
134 shape.push_back (Gnome::Art::Point (0, sync_mark_width - 1));
135 shape.push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
137 sync_mark = new ArdourCanvas::Polygon (*group);
138 sync_mark->property_points() = shape;
139 sync_mark->property_fill_color_rgba() = fill_color;
142 reset_width_dependent_items ((double) _region->length() / samples_per_unit);
144 set_height (trackview.height);
146 _region->StateChanged.connect (mem_fun(*this, &RegionView::region_changed));
148 group->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_event), group, this));
149 name_highlight->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event), name_highlight, this));
153 ColorChanged.connect (mem_fun (*this, &RegionView::color_handler));
155 /* XXX sync mark drag? */
158 RegionView::~RegionView ()
160 in_destructor = true;
162 for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
172 RegionView::_lock_toggle (ArdourCanvas::Item* item, GdkEvent* ev, void* arg)
175 case GDK_BUTTON_RELEASE:
176 static_cast<RegionView*>(arg)->lock_toggle ();
186 RegionView::lock_toggle ()
188 _region->set_locked (!_region->locked());
192 RegionView::region_changed (Change what_changed)
194 ENSURE_GUI_THREAD (bind (mem_fun(*this, &RegionView::region_changed), what_changed));
196 if (what_changed & BoundsChanged) {
197 region_resized (what_changed);
198 region_sync_changed ();
200 if (what_changed & Region::MuteChanged) {
203 if (what_changed & Region::OpacityChanged) {
206 if (what_changed & ARDOUR::NameChanged) {
209 if (what_changed & Region::SyncOffsetChanged) {
210 region_sync_changed ();
212 if (what_changed & Region::LayerChanged) {
215 if (what_changed & Region::LockChanged) {
221 RegionView::region_locked ()
223 /* name will show locked status */
228 RegionView::region_resized (Change what_changed)
232 if (what_changed & ARDOUR::PositionChanged) {
233 set_position (_region->position(), 0);
236 if (what_changed & Change (StartChanged|LengthChanged)) {
238 set_duration (_region->length(), 0);
240 unit_length = _region->length() / samples_per_unit;
242 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
244 (*i)->set_duration (unit_length);
251 RegionView::reset_width_dependent_items (double pixel_width)
253 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
254 _pixel_width = pixel_width;
258 RegionView::region_layered ()
260 RouteTimeAxisView *rtv = dynamic_cast<RouteTimeAxisView*>(&get_time_axis_view());
262 rtv->view()->region_layered (this);
266 RegionView::region_muted ()
273 RegionView::region_opacity ()
285 RegionView::raise_to_top ()
287 _region->raise_to_top ();
297 RegionView::lower_to_bottom ()
299 _region->lower_to_bottom ();
303 RegionView::set_position (nframes_t pos, void* src, double* ignored)
308 if (!(ret = TimeAxisViewItem::set_position (pos, this, &delta))) {
317 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
318 (*i)->group->move (delta, 0.0);
326 RegionView::set_samples_per_unit (gdouble spu)
328 TimeAxisViewItem::set_samples_per_unit (spu);
330 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
331 (*i)->set_samples_per_unit (spu);
332 (*i)->set_duration (_region->length() / samples_per_unit);
335 region_sync_changed ();
339 RegionView::set_duration (nframes_t frames, void *src)
341 if (!TimeAxisViewItem::set_duration (frames, src)) {
345 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
346 (*i)->set_duration (_region->length() / samples_per_unit);
353 RegionView::compute_colors (Gdk::Color& basic_color)
355 TimeAxisViewItem::compute_colors (basic_color);
359 RegionView::set_colors ()
361 TimeAxisViewItem::set_colors ();
364 sync_mark->property_fill_color_rgba() = fill_color;
369 RegionView::set_frame_color ()
371 if (_region->opaque()) {
377 TimeAxisViewItem::set_frame_color ();
381 RegionView::fake_set_opaque (bool yn)
389 TimeAxisViewItem::set_frame_color ();
393 RegionView::hide_region_editor()
401 RegionView::region_renamed ()
405 if (_region->locked()) {
407 str += _region->name();
410 str = _region->name();
413 if (_region->speed_mismatch (trackview.session().frame_rate())) {
414 str = string ("*") + str;
417 if (_region->muted()) {
418 str = string ("!") + str;
421 set_item_name (str, this);
423 reset_width_dependent_items (_pixel_width);
427 RegionView::region_sync_changed ()
429 if (sync_mark == 0) {
434 nframes_t sync_offset;
436 sync_offset = _region->sync_offset (sync_dir);
438 /* this has to handle both a genuine change of position, a change of samples_per_unit,
439 and a change in the bounds of the _region->
442 if (sync_offset == 0) {
444 /* no sync mark - its the start of the region */
450 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > _region->length()))) {
452 /* no sync mark - its out of the bounds of the region */
462 //points = sync_mark->property_points().get_value();
464 double offset = sync_offset / samples_per_unit;
465 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
466 points.push_back (Gnome::Art::Point (offset + ((sync_mark_width-1)/2), 1));
467 points.push_back (Gnome::Art::Point (offset, sync_mark_width - 1));
468 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
469 sync_mark->property_points().set_value (points);
477 RegionView::move (double x_delta, double y_delta)
479 if (_region->locked() || (x_delta == 0 && y_delta == 0)) {
483 get_canvas_group()->move (x_delta, y_delta);
485 /* note: ghosts never leave their tracks so y_delta for them is always zero */
487 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
488 (*i)->group->move (x_delta, 0.0);
493 RegionView::remove_ghost (GhostRegion* ghost)
499 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
508 RegionView::get_fill_color ()