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>
28 #include <ardour/playlist.h>
29 #include <ardour/audioregion.h>
30 #include <ardour/audiosource.h>
31 #include <ardour/audio_diskstream.h>
33 #include "streamview.h"
34 #include "region_view.h"
35 #include "route_time_axis.h"
36 #include "simplerect.h"
37 #include "simpleline.h"
39 #include "public_editor.h"
40 #include "region_editor.h"
41 #include "ghostregion.h"
42 #include "route_time_axis.h"
44 #include "rgb_macros.h"
45 #include "gui_thread.h"
50 using namespace ARDOUR;
52 using namespace Editing;
53 using namespace ArdourCanvas;
55 static const int32_t sync_mark_width = 9;
57 sigc::signal<void,RegionView*> RegionView::RegionViewGoingAway;
59 RegionView::RegionView (ArdourCanvas::Group* parent,
61 boost::shared_ptr<ARDOUR::Region> r,
63 Gdk::Color& basic_color)
64 : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(),
65 TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowNameText|
66 TimeAxisViewItem::ShowNameHighlight|
67 TimeAxisViewItem::ShowFrame))
71 , 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;
90 _height = other._height;
93 RegionView::RegionView (ArdourCanvas::Group* parent,
95 boost::shared_ptr<ARDOUR::Region> r,
97 Gdk::Color& basic_color,
98 TimeAxisViewItem::Visibility visibility)
99 : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(), visibility)
103 , current_visible_sync_position(0.0)
107 , in_destructor(false)
108 , wait_for_data(false)
113 RegionView::init (Gdk::Color& basic_color, bool wfd)
116 in_destructor = false;
120 compute_colors (basic_color);
122 name_highlight->set_data ("regionview", this);
125 name_text->set_data ("regionview", this);
128 /* an equilateral triangle */
130 ArdourCanvas::Points shape;
131 shape.push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
132 shape.push_back (Gnome::Art::Point ((sync_mark_width - 1)/2, 1));
133 shape.push_back (Gnome::Art::Point (0, sync_mark_width - 1));
134 shape.push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
136 sync_mark = new ArdourCanvas::Polygon (*group);
137 sync_mark->property_points() = shape;
138 sync_mark->property_fill_color_rgba() = fill_color;
141 reset_width_dependent_items ((double) _region->length() / samples_per_unit);
143 set_height (trackview.height);
145 _region->StateChanged.connect (mem_fun(*this, &RegionView::region_changed));
147 group->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_event), group, this));
148 name_highlight->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event), name_highlight, this));
152 ColorChanged.connect (mem_fun (*this, &RegionView::color_handler));
154 /* XXX sync mark drag? */
157 RegionView::~RegionView ()
159 in_destructor = true;
161 for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
171 RegionView::_lock_toggle (ArdourCanvas::Item* item, GdkEvent* ev, void* arg)
174 case GDK_BUTTON_RELEASE:
175 static_cast<RegionView*>(arg)->lock_toggle ();
185 RegionView::lock_toggle ()
187 _region->set_locked (!_region->locked());
191 RegionView::region_changed (Change what_changed)
193 ENSURE_GUI_THREAD (bind (mem_fun(*this, &RegionView::region_changed), what_changed));
195 if (what_changed & BoundsChanged) {
196 region_resized (what_changed);
197 region_sync_changed ();
199 if (what_changed & Region::MuteChanged) {
202 if (what_changed & Region::OpacityChanged) {
205 if (what_changed & ARDOUR::NameChanged) {
208 if (what_changed & Region::SyncOffsetChanged) {
209 region_sync_changed ();
211 if (what_changed & Region::LayerChanged) {
214 if (what_changed & Region::LockChanged) {
220 RegionView::region_locked ()
222 /* name will show locked status */
227 RegionView::region_resized (Change what_changed)
231 if (what_changed & ARDOUR::PositionChanged) {
232 set_position (_region->position(), 0);
235 if (what_changed & Change (StartChanged|LengthChanged)) {
237 set_duration (_region->length(), 0);
239 unit_length = _region->length() / samples_per_unit;
241 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
243 (*i)->set_duration (unit_length);
250 RegionView::reset_width_dependent_items (double pixel_width)
252 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
253 _pixel_width = pixel_width;
257 RegionView::region_layered ()
259 RouteTimeAxisView *rtv = dynamic_cast<RouteTimeAxisView*>(&get_time_axis_view());
261 rtv->view()->region_layered (this);
265 RegionView::region_muted ()
272 RegionView::region_opacity ()
284 RegionView::raise_to_top ()
286 _region->raise_to_top ();
296 RegionView::lower_to_bottom ()
298 _region->lower_to_bottom ();
302 RegionView::set_position (nframes_t pos, void* src, double* ignored)
307 if (!(ret = TimeAxisViewItem::set_position (pos, this, &delta))) {
316 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
317 (*i)->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;
368 RegionView::set_frame_color ()
370 if (_region->opaque()) {
376 TimeAxisViewItem::set_frame_color ();
380 RegionView::fake_set_opaque (bool yn)
388 TimeAxisViewItem::set_frame_color ();
392 RegionView::hide_region_editor()
400 RegionView::region_renamed ()
404 if (_region->locked()) {
406 str += _region->name();
409 str = _region->name();
412 if (_region->speed_mismatch (trackview.session().frame_rate())) {
413 str = string ("*") + str;
416 if (_region->muted()) {
417 str = string ("!") + str;
420 set_item_name (str, this);
422 reset_width_dependent_items (_pixel_width);
426 RegionView::region_sync_changed ()
428 if (sync_mark == 0) {
433 nframes_t sync_offset;
435 sync_offset = _region->sync_offset (sync_dir);
437 /* this has to handle both a genuine change of position, a change of samples_per_unit,
438 and a change in the bounds of the _region->
441 if (sync_offset == 0) {
443 /* no sync mark - its the start of the region */
449 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > _region->length()))) {
451 /* no sync mark - its out of the bounds of the region */
461 //points = sync_mark->property_points().get_value();
463 double offset = sync_offset / samples_per_unit;
464 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
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));
467 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
468 sync_mark->property_points().set_value (points);
476 RegionView::move (double x_delta, double y_delta)
478 if (_region->locked() || (x_delta == 0 && y_delta == 0)) {
482 get_canvas_group()->move (x_delta, y_delta);
484 /* note: ghosts never leave their tracks so y_delta for them is always zero */
486 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
487 (*i)->group->move (x_delta, 0.0);
492 RegionView::remove_ghost (GhostRegion* ghost)
498 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
507 RegionView::get_fill_color ()