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)
75 , in_destructor(false)
76 , wait_for_data(false)
80 RegionView::RegionView (const RegionView& other)
81 : TimeAxisViewItem (other)
83 /* derived concrete type will call init () */
85 _region = other._region;
86 editor = other.editor;
87 current_visible_sync_position = other.current_visible_sync_position;
89 _pixel_width = other._pixel_width;
92 RegionView::RegionView (ArdourCanvas::Group* parent,
94 boost::shared_ptr<ARDOUR::Region> r,
96 Gdk::Color& basic_color,
97 TimeAxisViewItem::Visibility visibility)
98 : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(), visibility)
102 , current_visible_sync_position(0.0)
105 , in_destructor(false)
106 , wait_for_data(false)
111 RegionView::init (Gdk::Color& basic_color, bool wfd)
114 in_destructor = false;
117 compute_colors (basic_color);
119 name_highlight->set_data ("regionview", this);
122 name_text->set_data ("regionview", this);
125 /* an equilateral triangle */
127 ArdourCanvas::Points shape;
128 shape.push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
129 shape.push_back (Gnome::Art::Point ((sync_mark_width - 1)/2, 1));
130 shape.push_back (Gnome::Art::Point (0, sync_mark_width - 1));
131 shape.push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
133 sync_mark = new ArdourCanvas::Polygon (*group);
134 sync_mark->property_points() = shape;
135 sync_mark->property_fill_color_rgba() = fill_color;
138 reset_width_dependent_items ((double) _region->length() / samples_per_unit);
140 set_y_position_and_height (0, trackview.height);
142 _region->StateChanged.connect (mem_fun(*this, &RegionView::region_changed));
144 group->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_event), group, this));
145 name_highlight->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event), name_highlight, this));
149 ColorChanged.connect (mem_fun (*this, &RegionView::color_handler));
151 /* XXX sync mark drag? */
154 RegionView::~RegionView ()
156 in_destructor = true;
158 for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
168 RegionView::_lock_toggle (ArdourCanvas::Item* item, GdkEvent* ev, void* arg)
171 case GDK_BUTTON_RELEASE:
172 static_cast<RegionView*>(arg)->lock_toggle ();
182 RegionView::lock_toggle ()
184 _region->set_locked (!_region->locked());
188 RegionView::region_changed (Change what_changed)
190 ENSURE_GUI_THREAD (bind (mem_fun(*this, &RegionView::region_changed), what_changed));
192 if (what_changed & BoundsChanged) {
193 region_resized (what_changed);
194 region_sync_changed ();
196 if (what_changed & Region::MuteChanged) {
199 if (what_changed & Region::OpacityChanged) {
202 if (what_changed & ARDOUR::NameChanged) {
205 if (what_changed & Region::SyncOffsetChanged) {
206 region_sync_changed ();
208 if (what_changed & Region::LayerChanged) {
211 if (what_changed & Region::LockChanged) {
217 RegionView::region_locked ()
219 /* name will show locked status */
224 RegionView::region_resized (Change what_changed)
228 if (what_changed & ARDOUR::PositionChanged) {
229 set_position (_region->position(), 0);
232 if (what_changed & Change (StartChanged|LengthChanged)) {
234 set_duration (_region->length(), 0);
236 unit_length = _region->length() / samples_per_unit;
238 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
240 (*i)->set_duration (unit_length);
247 RegionView::reset_width_dependent_items (double pixel_width)
249 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
250 _pixel_width = pixel_width;
254 RegionView::region_layered ()
256 RouteTimeAxisView *rtv = dynamic_cast<RouteTimeAxisView*>(&get_time_axis_view());
258 rtv->view()->region_layered (this);
262 RegionView::region_muted ()
269 RegionView::region_opacity ()
275 RegionView::raise_to_top ()
277 _region->raise_to_top ();
281 RegionView::lower_to_bottom ()
283 _region->lower_to_bottom ();
287 RegionView::set_position (nframes_t pos, void* src, double* ignored)
292 if (!(ret = TimeAxisViewItem::set_position (pos, this, &delta))) {
301 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
302 (*i)->group->move (delta, 0.0);
310 RegionView::set_samples_per_unit (gdouble spu)
312 TimeAxisViewItem::set_samples_per_unit (spu);
314 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
315 (*i)->set_samples_per_unit (spu);
316 (*i)->set_duration (_region->length() / samples_per_unit);
319 region_sync_changed ();
323 RegionView::set_duration (nframes_t frames, void *src)
325 if (!TimeAxisViewItem::set_duration (frames, src)) {
329 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
330 (*i)->set_duration (_region->length() / samples_per_unit);
337 RegionView::compute_colors (Gdk::Color& basic_color)
339 TimeAxisViewItem::compute_colors (basic_color);
343 RegionView::set_colors ()
345 TimeAxisViewItem::set_colors ();
348 sync_mark->property_fill_color_rgba() = fill_color;
353 RegionView::set_frame_color ()
355 if (_region->opaque()) {
361 TimeAxisViewItem::set_frame_color ();
365 RegionView::fake_set_opaque (bool yn)
373 TimeAxisViewItem::set_frame_color ();
377 RegionView::hide_region_editor()
385 RegionView::make_name () const
389 // XXX nice to have some good icons for this
391 if (_region->locked()) {
393 str += _region->name();
395 } else if (_region->position_locked()) {
397 str += _region->name();
400 str = _region->name();
403 if (_region->muted()) {
404 str = string ("!") + str;
411 RegionView::region_renamed ()
413 Glib::ustring str = make_name ();
415 set_item_name (str, this);
417 reset_width_dependent_items (_pixel_width);
421 RegionView::region_sync_changed ()
423 if (sync_mark == 0) {
428 nframes_t sync_offset;
430 sync_offset = _region->sync_offset (sync_dir);
432 /* this has to handle both a genuine change of position, a change of samples_per_unit,
433 and a change in the bounds of the _region->
436 if (sync_offset == 0) {
438 /* no sync mark - its the start of the region */
444 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > _region->length()))) {
446 /* no sync mark - its out of the bounds of the region */
456 //points = sync_mark->property_points().get_value();
458 double offset = sync_offset / samples_per_unit;
459 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
460 points.push_back (Gnome::Art::Point (offset + ((sync_mark_width-1)/2), 1));
461 points.push_back (Gnome::Art::Point (offset, sync_mark_width - 1));
462 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
463 sync_mark->property_points().set_value (points);
471 RegionView::move (double x_delta, double y_delta)
473 if (!_region->can_move() || (x_delta == 0 && y_delta == 0)) {
477 get_canvas_group()->move (x_delta, y_delta);
479 /* note: ghosts never leave their tracks so y_delta for them is always zero */
481 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
482 (*i)->group->move (x_delta, 0.0);
487 RegionView::remove_ghost (GhostRegion* ghost)
493 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
502 RegionView::get_fill_color ()