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))
72 , current_visible_sync_position(0.0)
76 , in_destructor(false)
77 , wait_for_data(false)
81 RegionView::RegionView (ArdourCanvas::Group* parent,
83 boost::shared_ptr<ARDOUR::Region> r,
85 Gdk::Color& basic_color,
86 TimeAxisViewItem::Visibility visibility)
87 : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(), visibility)
92 , current_visible_sync_position(0.0)
96 , in_destructor(false)
97 , wait_for_data(false)
102 RegionView::init (Gdk::Color& basic_color, bool wfd)
106 in_destructor = false;
110 compute_colors (basic_color);
112 name_highlight->set_data ("regionview", this);
115 name_text->set_data ("regionview", this);
118 /* an equilateral triangle */
120 ArdourCanvas::Points shape;
121 shape.push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
122 shape.push_back (Gnome::Art::Point ((sync_mark_width - 1)/2, 1));
123 shape.push_back (Gnome::Art::Point (0, sync_mark_width - 1));
124 shape.push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
126 sync_mark = new ArdourCanvas::Polygon (*group);
127 sync_mark->property_points() = shape;
128 sync_mark->property_fill_color_rgba() = fill_color;
131 reset_width_dependent_items ((double) _region->length() / samples_per_unit);
133 set_height (trackview.height);
135 _region->StateChanged.connect (mem_fun(*this, &RegionView::region_changed));
137 group->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_event), group, this));
138 name_highlight->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event), name_highlight, this));
142 ColorChanged.connect (mem_fun (*this, &RegionView::color_handler));
144 /* XXX sync mark drag? */
147 RegionView::~RegionView ()
149 in_destructor = true;
151 for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
161 RegionView::_lock_toggle (ArdourCanvas::Item* item, GdkEvent* ev, void* arg)
164 case GDK_BUTTON_RELEASE:
165 static_cast<RegionView*>(arg)->lock_toggle ();
175 RegionView::lock_toggle ()
177 _region->set_locked (!_region->locked());
181 RegionView::region_changed (Change what_changed)
183 ENSURE_GUI_THREAD (bind (mem_fun(*this, &RegionView::region_changed), what_changed));
185 if (what_changed & BoundsChanged) {
186 region_resized (what_changed);
187 region_sync_changed ();
189 if (what_changed & Region::MuteChanged) {
192 if (what_changed & Region::OpacityChanged) {
195 if (what_changed & ARDOUR::NameChanged) {
198 if (what_changed & Region::SyncOffsetChanged) {
199 region_sync_changed ();
201 if (what_changed & Region::LayerChanged) {
204 if (what_changed & Region::LockChanged) {
210 RegionView::region_locked ()
212 /* name will show locked status */
217 RegionView::region_resized (Change what_changed)
221 if (what_changed & ARDOUR::PositionChanged) {
222 set_position (_region->position(), 0);
225 if (what_changed & Change (StartChanged|LengthChanged)) {
227 set_duration (_region->length(), 0);
229 unit_length = _region->length() / samples_per_unit;
231 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
233 (*i)->set_duration (unit_length);
240 RegionView::reset_width_dependent_items (double pixel_width)
242 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
243 _pixel_width = pixel_width;
247 RegionView::region_layered ()
249 RouteTimeAxisView *rtv = dynamic_cast<RouteTimeAxisView*>(&get_time_axis_view());
251 rtv->view()->region_layered (this);
255 RegionView::region_muted ()
262 RegionView::region_opacity ()
274 RegionView::raise_to_top ()
276 _region->raise_to_top ();
286 RegionView::lower_to_bottom ()
288 _region->lower_to_bottom ();
292 RegionView::set_position (nframes_t pos, void* src, double* ignored)
297 if (!(ret = TimeAxisViewItem::set_position (pos, this, &delta))) {
306 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
307 (*i)->group->move (delta, 0.0);
315 RegionView::set_samples_per_unit (gdouble spu)
317 TimeAxisViewItem::set_samples_per_unit (spu);
319 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
320 (*i)->set_samples_per_unit (spu);
321 (*i)->set_duration (_region->length() / samples_per_unit);
324 region_sync_changed ();
328 RegionView::set_duration (nframes_t frames, void *src)
330 if (!TimeAxisViewItem::set_duration (frames, src)) {
334 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
335 (*i)->set_duration (_region->length() / samples_per_unit);
342 RegionView::compute_colors (Gdk::Color& basic_color)
344 TimeAxisViewItem::compute_colors (basic_color);
348 RegionView::set_colors ()
350 TimeAxisViewItem::set_colors ();
353 sync_mark->property_fill_color_rgba() = fill_color;
358 RegionView::set_frame_color ()
360 if (_region->opaque()) {
366 TimeAxisViewItem::set_frame_color ();
370 RegionView::hide_region_editor()
378 RegionView::region_renamed ()
382 if (_region->locked()) {
384 str += _region->name();
387 str = _region->name();
390 if (_region->speed_mismatch (trackview.session().frame_rate())) {
391 str = string ("*") + str;
394 if (_region->muted()) {
395 str = string ("!") + str;
398 set_item_name (str, this);
400 reset_width_dependent_items (_pixel_width);
404 RegionView::region_sync_changed ()
406 if (sync_mark == 0) {
411 nframes_t sync_offset;
413 sync_offset = _region->sync_offset (sync_dir);
415 /* this has to handle both a genuine change of position, a change of samples_per_unit,
416 and a change in the bounds of the _region->
419 if (sync_offset == 0) {
421 /* no sync mark - its the start of the region */
427 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > _region->length()))) {
429 /* no sync mark - its out of the bounds of the region */
439 //points = sync_mark->property_points().get_value();
441 double offset = sync_offset / samples_per_unit;
442 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
443 points.push_back (Gnome::Art::Point (offset + ((sync_mark_width-1)/2), 1));
444 points.push_back (Gnome::Art::Point (offset, sync_mark_width - 1));
445 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
446 sync_mark->property_points().set_value (points);
454 RegionView::move (double x_delta, double y_delta)
456 if (_region->locked() || (x_delta == 0 && y_delta == 0)) {
460 get_canvas_group()->move (x_delta, y_delta);
462 /* note: ghosts never leave their tracks so y_delta for them is always zero */
464 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
465 (*i)->group->move (x_delta, 0.0);
470 RegionView::remove_ghost (GhostRegion* ghost)
476 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
485 RegionView::get_fill_color ()