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(), false,
69 TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowNameText|
70 TimeAxisViewItem::ShowNameHighlight|
71 TimeAxisViewItem::ShowFrame))
76 , current_visible_sync_position(0.0)
78 , _enable_display(false)
80 , in_destructor(false)
81 , wait_for_data(false)
85 RegionView::RegionView (const RegionView& other)
86 : TimeAxisViewItem (other)
88 /* derived concrete type will call init () */
90 _region = other._region;
91 current_visible_sync_position = other.current_visible_sync_position;
93 _pixel_width = other._pixel_width;
94 _height = other._height;
97 RegionView::RegionView (const RegionView& other, boost::shared_ptr<Region> other_region)
98 : TimeAxisViewItem (other)
100 /* this is a pseudo-copy constructor used when dragging regions
101 around on the canvas.
104 /* derived concrete type will call init () */
106 _region = other_region;
107 current_visible_sync_position = other.current_visible_sync_position;
109 _pixel_width = other._pixel_width;
110 _height = other._height;
113 RegionView::RegionView (ArdourCanvas::Group* parent,
115 boost::shared_ptr<ARDOUR::Region> r,
117 Gdk::Color& basic_color,
119 TimeAxisViewItem::Visibility visibility)
120 : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(), recording, visibility)
125 , current_visible_sync_position(0.0)
127 , _enable_display(false)
129 , in_destructor(false)
130 , wait_for_data(false)
135 RegionView::init (Gdk::Color& basic_color, bool wfd)
139 in_destructor = false;
147 compute_colors (basic_color);
149 if (name_highlight) {
150 name_highlight->set_data ("regionview", this);
151 name_highlight->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event), name_highlight, this));
155 name_text->set_data ("regionview", this);
159 _enable_display = true;
161 set_height (trackview.current_height());
163 _region->StateChanged.connect (mem_fun(*this, &RegionView::region_changed));
165 group->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_event), group, this));
169 ColorsChanged.connect (mem_fun (*this, &RegionView::color_handler));
171 /* XXX sync mark drag? */
174 RegionView::~RegionView ()
176 in_destructor = true;
178 for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
188 RegionView::_lock_toggle (ArdourCanvas::Item* item, GdkEvent* ev, void* arg)
191 case GDK_BUTTON_RELEASE:
192 static_cast<RegionView*>(arg)->lock_toggle ();
202 RegionView::lock_toggle ()
204 _region->set_locked (!_region->locked());
208 RegionView::region_changed (Change what_changed)
210 ENSURE_GUI_THREAD (bind (mem_fun(*this, &RegionView::region_changed), what_changed));
212 if (what_changed & BoundsChanged) {
213 region_resized (what_changed);
214 region_sync_changed ();
216 if (what_changed & Region::MuteChanged) {
219 if (what_changed & Region::OpacityChanged) {
222 if (what_changed & ARDOUR::NameChanged) {
225 if (what_changed & Region::SyncOffsetChanged) {
226 region_sync_changed ();
229 this should not be needed now that only playlist can change layering
232 if (what_changed & Region::LayerChanged) {
233 // this is handled by the playlist i believe
237 if (what_changed & Region::LockChanged) {
243 RegionView::region_locked ()
245 /* name will show locked status */
250 RegionView::region_resized (Change what_changed)
254 if (what_changed & ARDOUR::PositionChanged) {
255 set_position (_region->position(), 0);
258 if (what_changed & Change (StartChanged|LengthChanged)) {
260 set_duration (_region->length(), 0);
262 unit_length = _region->length() / samples_per_unit;
264 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
266 (*i)->set_duration (unit_length);
273 RegionView::reset_width_dependent_items (double pixel_width)
275 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
276 _pixel_width = pixel_width;
278 /*for (AutomationChildren::iterator i = _automation_children.begin();
279 i != _automation_children.end(); ++i) {
280 i->second->reset_width_dependent_items(pixel_width);
285 RegionView::region_layered ()
287 RouteTimeAxisView *rtv = dynamic_cast<RouteTimeAxisView*>(&get_time_axis_view());
289 //rtv->view()->region_layered (this);
293 RegionView::region_muted ()
300 RegionView::region_opacity ()
306 RegionView::raise_to_top ()
308 _region->raise_to_top ();
312 RegionView::lower_to_bottom ()
314 _region->lower_to_bottom ();
318 RegionView::set_position (nframes_t pos, void* src, double* ignored)
323 if (!(ret = TimeAxisViewItem::set_position (pos, this, &delta))) {
332 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
333 (*i)->group->move (delta, 0.0);
336 for (AutomationChildren::iterator i = _automation_children.begin();
337 i != _automation_children.end(); ++i) {
338 i->second->get_canvas_group()->move(delta, 0.0);
346 RegionView::set_samples_per_unit (gdouble spu)
348 TimeAxisViewItem::set_samples_per_unit (spu);
350 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
351 (*i)->set_samples_per_unit (spu);
352 (*i)->set_duration (_region->length() / samples_per_unit);
355 region_sync_changed ();
359 RegionView::set_duration (nframes_t frames, void *src)
361 if (!TimeAxisViewItem::set_duration (frames, src)) {
365 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
366 (*i)->set_duration (_region->length() / samples_per_unit);
373 RegionView::compute_colors (Gdk::Color& basic_color)
375 TimeAxisViewItem::compute_colors (basic_color);
379 RegionView::set_colors ()
381 TimeAxisViewItem::set_colors ();
384 sync_mark->property_fill_color_rgba() = fill_color;
385 sync_line->property_fill_color_rgba() = fill_color;
390 RegionView::set_frame_color ()
392 if (_region->opaque()) {
398 TimeAxisViewItem::set_frame_color ();
402 RegionView::fake_set_opaque (bool yn)
414 RegionView::hide_region_editor()
422 RegionView::make_name () const
426 // XXX nice to have some good icons for this
428 if (_region->locked()) {
430 str += _region->name();
432 } else if (_region->position_locked()) {
434 str += _region->name();
437 str = _region->name();
440 if (_region->muted()) {
441 str = string ("!") + str;
448 RegionView::region_renamed ()
450 Glib::ustring str = make_name ();
452 set_item_name (str, this);
454 reset_width_dependent_items (_pixel_width);
458 RegionView::region_sync_changed ()
461 nframes_t sync_offset;
463 sync_offset = _region->sync_offset (sync_dir);
465 if (sync_offset == 0) {
466 /* no need for a sync mark */
476 /* points set below */
478 sync_mark = new ArdourCanvas::Polygon (*group);
479 sync_mark->property_fill_color_rgba() = fill_color;
481 sync_line = new ArdourCanvas::Line (*group);
482 sync_line->property_fill_color_rgba() = fill_color;
483 sync_line->property_width_pixels() = 1;
486 /* this has to handle both a genuine change of position, a change of samples_per_unit,
487 and a change in the bounds of the _region->
490 if (sync_offset == 0) {
492 /* no sync mark - its the start of the region */
499 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > _region->length()))) {
501 /* no sync mark - its out of the bounds of the region */
512 //points = sync_mark->property_points().get_value();
514 double offset = sync_offset / samples_per_unit;
515 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
516 points.push_back (Gnome::Art::Point (offset + ((sync_mark_width-1)/2), 1));
517 points.push_back (Gnome::Art::Point (offset, sync_mark_width - 1));
518 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
519 sync_mark->property_points().set_value (points);
523 points.push_back (Gnome::Art::Point (offset, 0));
524 points.push_back (Gnome::Art::Point (offset, trackview.current_height() - NAME_HIGHLIGHT_SIZE));
526 sync_line->property_points().set_value (points);
533 RegionView::move (double x_delta, double y_delta)
535 if (!_region->can_move() || (x_delta == 0 && y_delta == 0)) {
539 get_canvas_group()->move (x_delta, y_delta);
541 /* note: ghosts never leave their tracks so y_delta for them is always zero */
543 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
544 (*i)->group->move (x_delta, 0.0);
547 for (AutomationChildren::iterator i = _automation_children.begin();
548 i != _automation_children.end(); ++i) {
549 i->second->get_canvas_group()->move(x_delta, 0.0);
554 RegionView::remove_ghost_in (TimeAxisView& tv)
556 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
557 if (&(*i)->trackview == &tv) {
565 RegionView::remove_ghost (GhostRegion* ghost)
571 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
580 RegionView::get_fill_color ()
586 RegionView::set_height (double h)
591 nframes_t sync_offset;
592 sync_offset = _region->sync_offset (sync_dir);
593 double offset = sync_offset / samples_per_unit;
595 points.push_back (Gnome::Art::Point (offset, 0));
596 points.push_back (Gnome::Art::Point (offset, h - NAME_HIGHLIGHT_SIZE));
597 sync_line->property_points().set_value (points);