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))
75 , current_visible_sync_position(0.0)
77 , _enable_display(false)
79 , in_destructor(false)
80 , wait_for_data(false)
84 RegionView::RegionView (const RegionView& other)
85 : TimeAxisViewItem (other)
87 /* derived concrete type will call init () */
89 _region = other._region;
91 current_visible_sync_position = other.current_visible_sync_position;
93 _enable_display = false;
94 _pixel_width = other._pixel_width;
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 editor = other.editor;
108 current_visible_sync_position = other.current_visible_sync_position;
110 _pixel_width = other._pixel_width;
111 _height = other._height;
114 RegionView::RegionView (ArdourCanvas::Group* parent,
116 boost::shared_ptr<ARDOUR::Region> r,
118 Gdk::Color& basic_color,
119 TimeAxisViewItem::Visibility visibility)
120 : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(), 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)
138 _enable_display = false;
139 in_destructor = false;
146 compute_colors (basic_color);
148 name_highlight->set_data ("regionview", this);
151 name_text->set_data ("regionview", this);
155 _enable_display = true;
157 set_y_position_and_height (0, trackview.height - 2);
159 _region->StateChanged.connect (mem_fun(*this, &RegionView::region_changed));
161 group->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_event), group, this));
162 name_highlight->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event), name_highlight, this));
166 ColorsChanged.connect (mem_fun (*this, &RegionView::color_handler));
167 // set_pango_fontsize();
168 /* XXX sync mark drag? */
171 RegionView::~RegionView ()
173 in_destructor = true;
175 for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
185 RegionView::_lock_toggle (ArdourCanvas::Item* item, GdkEvent* ev, void* arg)
188 case GDK_BUTTON_RELEASE:
189 static_cast<RegionView*>(arg)->lock_toggle ();
199 RegionView::lock_toggle ()
201 _region->set_locked (!_region->locked());
205 RegionView::region_changed (Change what_changed)
207 ENSURE_GUI_THREAD (bind (mem_fun(*this, &RegionView::region_changed), what_changed));
209 if (what_changed & BoundsChanged) {
210 region_resized (what_changed);
211 region_sync_changed ();
213 if (what_changed & Region::MuteChanged) {
216 if (what_changed & Region::OpacityChanged) {
219 if (what_changed & ARDOUR::NameChanged) {
222 if (what_changed & Region::SyncOffsetChanged) {
223 region_sync_changed ();
226 this should not be needed now that only playlist can change layering
229 if (what_changed & Region::LayerChanged) {
233 if (what_changed & Region::LockChanged) {
239 RegionView::region_locked ()
241 /* name will show locked status */
246 RegionView::region_resized (Change what_changed)
250 if (what_changed & ARDOUR::PositionChanged) {
251 set_position (_region->position(), 0);
254 if (what_changed & Change (StartChanged|LengthChanged)) {
256 set_duration (_region->length(), 0);
258 unit_length = _region->length() / samples_per_unit;
260 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
262 (*i)->set_duration (unit_length);
269 RegionView::reset_width_dependent_items (double pixel_width)
271 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
272 _pixel_width = pixel_width;
274 /*for (AutomationChildren::iterator i = _automation_children.begin();
275 i != _automation_children.end(); ++i) {
276 i->second->reset_width_dependent_items(pixel_width);
281 RegionView::region_layered ()
283 RouteTimeAxisView *rtv = dynamic_cast<RouteTimeAxisView*>(&get_time_axis_view());
285 rtv->view()->region_layered (this);
289 RegionView::region_muted ()
296 RegionView::region_opacity ()
302 RegionView::raise_to_top ()
304 _region->raise_to_top ();
308 RegionView::lower_to_bottom ()
310 _region->lower_to_bottom ();
314 RegionView::set_position (nframes_t pos, void* src, double* ignored)
319 if (!(ret = TimeAxisViewItem::set_position (pos, this, &delta))) {
328 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
329 (*i)->group->move (delta, 0.0);
332 for (AutomationChildren::iterator i = _automation_children.begin();
333 i != _automation_children.end(); ++i) {
334 i->second->get_canvas_group()->move(delta, 0.0);
342 RegionView::set_samples_per_unit (gdouble spu)
344 TimeAxisViewItem::set_samples_per_unit (spu);
346 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
347 (*i)->set_samples_per_unit (spu);
348 (*i)->set_duration (_region->length() / samples_per_unit);
351 region_sync_changed ();
355 RegionView::set_duration (nframes_t frames, void *src)
357 if (!TimeAxisViewItem::set_duration (frames, src)) {
361 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
362 (*i)->set_duration (_region->length() / samples_per_unit);
369 RegionView::compute_colors (Gdk::Color& basic_color)
371 TimeAxisViewItem::compute_colors (basic_color);
375 RegionView::set_colors ()
377 TimeAxisViewItem::set_colors ();
380 sync_mark->property_fill_color_rgba() = fill_color;
381 sync_line->property_fill_color_rgba() = fill_color;
386 RegionView::set_frame_color ()
388 if (_region->opaque()) {
394 TimeAxisViewItem::set_frame_color ();
398 RegionView::fake_set_opaque (bool yn)
410 RegionView::hide_region_editor()
418 RegionView::make_name () const
422 // XXX nice to have some good icons for this
424 if (_region->locked()) {
426 str += _region->name();
428 } else if (_region->position_locked()) {
430 str += _region->name();
433 str = _region->name();
436 if (_region->muted()) {
437 str = string ("!") + str;
444 RegionView::region_renamed ()
446 Glib::ustring str = make_name ();
448 set_item_name (str, this);
450 reset_width_dependent_items (_pixel_width);
454 RegionView::region_sync_changed ()
457 nframes_t sync_offset;
459 sync_offset = _region->sync_offset (sync_dir);
461 if (sync_offset == 0) {
462 /* no need for a sync mark */
472 /* points set below */
474 sync_mark = new ArdourCanvas::Polygon (*group);
475 sync_mark->property_fill_color_rgba() = fill_color;
477 sync_line = new ArdourCanvas::Line (*group);
478 sync_line->property_fill_color_rgba() = fill_color;
479 sync_line->property_width_pixels() = 1;
482 /* this has to handle both a genuine change of position, a change of samples_per_unit,
483 and a change in the bounds of the _region->
486 if (sync_offset == 0) {
488 /* no sync mark - its the start of the region */
495 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > _region->length()))) {
497 /* no sync mark - its out of the bounds of the region */
508 //points = sync_mark->property_points().get_value();
510 double offset = sync_offset / samples_per_unit;
511 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
512 points.push_back (Gnome::Art::Point (offset + ((sync_mark_width-1)/2), 1));
513 points.push_back (Gnome::Art::Point (offset, sync_mark_width - 1));
514 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
515 sync_mark->property_points().set_value (points);
519 points.push_back (Gnome::Art::Point (offset, 0));
520 points.push_back (Gnome::Art::Point (offset, trackview.height - NAME_HIGHLIGHT_SIZE));
522 sync_line->property_points().set_value (points);
529 RegionView::move (double x_delta, double y_delta)
531 if (!_region->can_move() || (x_delta == 0 && y_delta == 0)) {
535 get_canvas_group()->move (x_delta, y_delta);
537 /* note: ghosts never leave their tracks so y_delta for them is always zero */
539 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
540 (*i)->group->move (x_delta, 0.0);
543 for (AutomationChildren::iterator i = _automation_children.begin();
544 i != _automation_children.end(); ++i) {
545 i->second->get_canvas_group()->move(x_delta, 0.0);
550 RegionView::remove_ghost_in (TimeAxisView& tv)
552 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
553 if (&(*i)->trackview == &tv) {
561 RegionView::remove_ghost (GhostRegion* ghost)
567 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
576 RegionView::get_fill_color ()
582 RegionView::set_height (double h)
587 nframes_t sync_offset;
588 sync_offset = _region->sync_offset (sync_dir);
589 double offset = sync_offset / samples_per_unit;
591 points.push_back (Gnome::Art::Point (offset, 0));
592 points.push_back (Gnome::Art::Point (offset, h - NAME_HIGHLIGHT_SIZE));
593 sync_line->property_points().set_value (points);