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 (ArdourCanvas::Group* parent,
99 boost::shared_ptr<ARDOUR::Region> r,
101 Gdk::Color& basic_color,
102 TimeAxisViewItem::Visibility visibility)
103 : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(), visibility)
108 , current_visible_sync_position(0.0)
110 , _enable_display(false)
112 , in_destructor(false)
113 , wait_for_data(false)
118 RegionView::init (Gdk::Color& basic_color, bool wfd)
121 _enable_display = false;
122 in_destructor = false;
129 compute_colors (basic_color);
131 name_highlight->set_data ("regionview", this);
134 name_text->set_data ("regionview", this);
138 _enable_display = true;
140 set_y_position_and_height (0, trackview.height - 2);
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 ColorsChanged.connect (mem_fun (*this, &RegionView::color_handler));
150 // set_pango_fontsize();
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 ();
209 this should not be needed now that only playlist can change layering
212 if (what_changed & Region::LayerChanged) {
216 if (what_changed & Region::LockChanged) {
222 RegionView::region_locked ()
224 /* name will show locked status */
229 RegionView::region_resized (Change what_changed)
233 if (what_changed & ARDOUR::PositionChanged) {
234 set_position (_region->position(), 0);
237 if (what_changed & Change (StartChanged|LengthChanged)) {
239 set_duration (_region->length(), 0);
241 unit_length = _region->length() / samples_per_unit;
243 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
245 (*i)->set_duration (unit_length);
252 RegionView::reset_width_dependent_items (double pixel_width)
254 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
255 _pixel_width = pixel_width;
257 /*for (AutomationChildren::iterator i = _automation_children.begin();
258 i != _automation_children.end(); ++i) {
259 i->second->reset_width_dependent_items(pixel_width);
264 RegionView::region_layered ()
266 RouteTimeAxisView *rtv = dynamic_cast<RouteTimeAxisView*>(&get_time_axis_view());
268 rtv->view()->region_layered (this);
272 RegionView::region_muted ()
279 RegionView::region_opacity ()
285 RegionView::raise_to_top ()
287 _region->raise_to_top ();
291 RegionView::lower_to_bottom ()
293 _region->lower_to_bottom ();
297 RegionView::set_position (nframes_t pos, void* src, double* ignored)
302 if (!(ret = TimeAxisViewItem::set_position (pos, this, &delta))) {
311 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
312 (*i)->group->move (delta, 0.0);
315 for (AutomationChildren::iterator i = _automation_children.begin();
316 i != _automation_children.end(); ++i) {
317 i->second->get_canvas_group()->move(delta, 0.0);
325 RegionView::set_samples_per_unit (gdouble spu)
327 TimeAxisViewItem::set_samples_per_unit (spu);
329 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
330 (*i)->set_samples_per_unit (spu);
331 (*i)->set_duration (_region->length() / samples_per_unit);
334 region_sync_changed ();
338 RegionView::set_duration (nframes_t frames, void *src)
340 if (!TimeAxisViewItem::set_duration (frames, src)) {
344 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
345 (*i)->set_duration (_region->length() / samples_per_unit);
352 RegionView::compute_colors (Gdk::Color& basic_color)
354 TimeAxisViewItem::compute_colors (basic_color);
358 RegionView::set_colors ()
360 TimeAxisViewItem::set_colors ();
363 sync_mark->property_fill_color_rgba() = fill_color;
364 sync_line->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)
393 RegionView::hide_region_editor()
401 RegionView::make_name () const
405 // XXX nice to have some good icons for this
407 if (_region->locked()) {
409 str += _region->name();
411 } else if (_region->position_locked()) {
413 str += _region->name();
416 str = _region->name();
419 if (_region->muted()) {
420 str = string ("!") + str;
427 RegionView::region_renamed ()
429 Glib::ustring str = make_name ();
431 set_item_name (str, this);
433 reset_width_dependent_items (_pixel_width);
437 RegionView::region_sync_changed ()
440 nframes_t sync_offset;
442 sync_offset = _region->sync_offset (sync_dir);
444 if (sync_offset == 0) {
445 /* no need for a sync mark */
455 /* points set below */
457 sync_mark = new ArdourCanvas::Polygon (*group);
458 sync_mark->property_fill_color_rgba() = fill_color;
460 sync_line = new ArdourCanvas::Line (*group);
461 sync_line->property_fill_color_rgba() = fill_color;
462 sync_line->property_width_pixels() = 1;
465 /* this has to handle both a genuine change of position, a change of samples_per_unit,
466 and a change in the bounds of the _region->
469 if (sync_offset == 0) {
471 /* no sync mark - its the start of the region */
478 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > _region->length()))) {
480 /* no sync mark - its out of the bounds of the region */
491 //points = sync_mark->property_points().get_value();
493 double offset = sync_offset / samples_per_unit;
494 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
495 points.push_back (Gnome::Art::Point (offset + ((sync_mark_width-1)/2), 1));
496 points.push_back (Gnome::Art::Point (offset, sync_mark_width - 1));
497 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
498 sync_mark->property_points().set_value (points);
502 points.push_back (Gnome::Art::Point (offset, 0));
503 points.push_back (Gnome::Art::Point (offset, trackview.height - NAME_HIGHLIGHT_SIZE));
505 sync_line->property_points().set_value (points);
512 RegionView::move (double x_delta, double y_delta)
514 if (!_region->can_move() || (x_delta == 0 && y_delta == 0)) {
518 get_canvas_group()->move (x_delta, y_delta);
520 /* note: ghosts never leave their tracks so y_delta for them is always zero */
522 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
523 (*i)->group->move (x_delta, 0.0);
526 for (AutomationChildren::iterator i = _automation_children.begin();
527 i != _automation_children.end(); ++i) {
528 i->second->get_canvas_group()->move(x_delta, 0.0);
533 RegionView::remove_ghost_in (TimeAxisView& tv)
535 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
536 if (&(*i)->trackview == &tv) {
544 RegionView::remove_ghost (GhostRegion* ghost)
550 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
559 RegionView::get_fill_color ()
565 RegionView::set_height (double h)
570 nframes_t sync_offset;
571 sync_offset = _region->sync_offset (sync_dir);
572 double offset = sync_offset / samples_per_unit;
574 points.push_back (Gnome::Art::Point (offset, 0));
575 points.push_back (Gnome::Art::Point (offset, h - NAME_HIGHLIGHT_SIZE));
576 sync_line->property_points().set_value (points);