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 "streamview.h"
35 #include "region_view.h"
36 #include "route_time_axis.h"
37 #include "simplerect.h"
38 #include "simpleline.h"
40 #include "public_editor.h"
41 #include "region_editor.h"
42 #include "ghostregion.h"
43 #include "route_time_axis.h"
45 #include "rgb_macros.h"
46 #include "gui_thread.h"
47 #include "ardour_ui.h"
52 using namespace ARDOUR
;
54 using namespace Editing
;
55 using namespace ArdourCanvas
;
57 static const int32_t sync_mark_width
= 9;
59 sigc::signal
<void,RegionView
*> RegionView::RegionViewGoingAway
;
61 RegionView::RegionView (ArdourCanvas::Group
* parent
,
63 boost::shared_ptr
<ARDOUR::Region
> r
,
65 Gdk::Color
& basic_color
67 : TimeAxisViewItem (r
->name(), *parent
, tv
, spu
, basic_color
, r
->position(), r
->length(), false,
68 TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowNameText
|
69 TimeAxisViewItem::ShowNameHighlight
|
70 TimeAxisViewItem::ShowFrame
))
75 , current_visible_sync_position(0.0)
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
;
90 current_visible_sync_position
= other
.current_visible_sync_position
;
92 _pixel_width
= other
._pixel_width
;
93 _height
= other
._height
;
96 RegionView::RegionView (const RegionView
& other
, boost::shared_ptr
<Region
> other_region
)
97 : TimeAxisViewItem (other
)
99 /* this is a pseudo-copy constructor used when dragging regions
100 around on the canvas.
103 /* derived concrete type will call init () */
105 _region
= other_region
;
106 current_visible_sync_position
= other
.current_visible_sync_position
;
108 _pixel_width
= other
._pixel_width
;
109 _height
= other
._height
;
112 RegionView::RegionView (ArdourCanvas::Group
* parent
,
114 boost::shared_ptr
<ARDOUR::Region
> r
,
116 Gdk::Color
& basic_color
,
118 TimeAxisViewItem::Visibility visibility
)
119 : TimeAxisViewItem (r
->name(), *parent
, tv
, spu
, basic_color
, r
->position(), r
->length(), recording
, visibility
)
124 , current_visible_sync_position(0.0)
128 , in_destructor(false)
129 , wait_for_data(false)
134 RegionView::init (Gdk::Color
& basic_color
, bool wfd
)
138 in_destructor
= false;
144 compute_colors (basic_color
);
146 if (name_highlight
) {
147 name_highlight
->set_data ("regionview", this);
148 name_highlight
->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event
), name_highlight
, this));
152 name_text
->set_data ("regionview", this);
155 reset_width_dependent_items ((double) _region
->length() / samples_per_unit
);
157 set_height (trackview
.current_height());
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));
165 ColorsChanged
.connect (mem_fun (*this, &RegionView::color_handler
));
166 /* XXX sync mark drag? */
169 RegionView::~RegionView ()
171 in_destructor
= true;
173 for (vector
<GhostRegion
*>::iterator g
= ghosts
.begin(); g
!= ghosts
.end(); ++g
) {
183 RegionView::_lock_toggle (ArdourCanvas::Item
* item
, GdkEvent
* ev
, void* arg
)
186 case GDK_BUTTON_RELEASE
:
187 static_cast<RegionView
*>(arg
)->lock_toggle ();
197 RegionView::lock_toggle ()
199 _region
->set_locked (!_region
->locked());
203 RegionView::region_changed (Change what_changed
)
205 ENSURE_GUI_THREAD (bind (mem_fun(*this, &RegionView::region_changed
), what_changed
));
207 if (what_changed
& BoundsChanged
) {
208 region_resized (what_changed
);
209 region_sync_changed ();
211 if (what_changed
& Region::MuteChanged
) {
214 if (what_changed
& Region::OpacityChanged
) {
217 if (what_changed
& ARDOUR::NameChanged
) {
220 if (what_changed
& Region::SyncOffsetChanged
) {
221 region_sync_changed ();
223 if (what_changed
& Region::LayerChanged
) {
224 // this is handled by the playlist i believe
227 if (what_changed
& Region::LockChanged
) {
233 RegionView::region_locked ()
235 /* name will show locked status */
240 RegionView::region_resized (Change what_changed
)
244 if (what_changed
& ARDOUR::PositionChanged
) {
245 set_position (_region
->position(), 0);
248 if (what_changed
& Change (StartChanged
|LengthChanged
)) {
250 set_duration (_region
->length(), 0);
252 unit_length
= _region
->length() / samples_per_unit
;
254 for (vector
<GhostRegion
*>::iterator i
= ghosts
.begin(); i
!= ghosts
.end(); ++i
) {
256 (*i
)->set_duration (unit_length
);
263 RegionView::reset_width_dependent_items (double pixel_width
)
265 TimeAxisViewItem::reset_width_dependent_items (pixel_width
);
266 _pixel_width
= pixel_width
;
270 RegionView::region_layered ()
272 RouteTimeAxisView
*rtv
= dynamic_cast<RouteTimeAxisView
*>(&get_time_axis_view());
274 //rtv->view()->region_layered (this);
278 RegionView::region_muted ()
285 RegionView::region_opacity ()
297 RegionView::raise_to_top ()
299 _region
->raise_to_top ();
309 RegionView::lower_to_bottom ()
311 _region
->lower_to_bottom ();
315 RegionView::set_position (nframes_t pos
, void* src
, double* ignored
)
320 if (!(ret
= TimeAxisViewItem::set_position (pos
, this, &delta
))) {
329 for (vector
<GhostRegion
*>::iterator i
= ghosts
.begin(); i
!= ghosts
.end(); ++i
) {
330 (*i
)->group
->move (delta
, 0.0);
338 RegionView::set_samples_per_unit (gdouble spu
)
340 TimeAxisViewItem::set_samples_per_unit (spu
);
342 for (vector
<GhostRegion
*>::iterator i
= ghosts
.begin(); i
!= ghosts
.end(); ++i
) {
343 (*i
)->set_samples_per_unit (spu
);
344 (*i
)->set_duration (_region
->length() / samples_per_unit
);
347 region_sync_changed ();
351 RegionView::set_duration (nframes_t frames
, void *src
)
353 if (!TimeAxisViewItem::set_duration (frames
, src
)) {
357 for (vector
<GhostRegion
*>::iterator i
= ghosts
.begin(); i
!= ghosts
.end(); ++i
) {
358 (*i
)->set_duration (_region
->length() / samples_per_unit
);
365 RegionView::compute_colors (Gdk::Color
& basic_color
)
367 TimeAxisViewItem::compute_colors (basic_color
);
371 RegionView::set_colors ()
373 TimeAxisViewItem::set_colors ();
376 sync_mark
->property_fill_color_rgba() = fill_color
;
377 sync_line
->property_fill_color_rgba() = fill_color
;
382 RegionView::set_frame_color ()
384 if (_region
->opaque()) {
390 TimeAxisViewItem::set_frame_color ();
394 RegionView::fake_set_opaque (bool yn
)
406 RegionView::hide_region_editor()
414 RegionView::region_renamed ()
418 if (_region
->locked()) {
420 str
+= _region
->name();
423 str
= _region
->name();
426 if (_region
->speed_mismatch (trackview
.session().frame_rate())) {
427 str
= string ("*") + str
;
430 if (_region
->muted()) {
431 str
= string ("!") + str
;
434 set_item_name (str
, this);
436 reset_width_dependent_items (_pixel_width
);
440 RegionView::region_sync_changed ()
443 nframes_t sync_offset
;
445 sync_offset
= _region
->sync_offset (sync_dir
);
447 if (sync_offset
== 0) {
448 /* no need for a sync mark */
458 /* points set below */
460 sync_mark
= new ArdourCanvas::Polygon (*group
);
461 sync_mark
->property_fill_color_rgba() = fill_color
;
463 sync_line
= new ArdourCanvas::Line (*group
);
464 sync_line
->property_fill_color_rgba() = fill_color
;
465 sync_line
->property_width_pixels() = 1;
468 /* this has to handle both a genuine change of position, a change of samples_per_unit,
469 and a change in the bounds of the _region->
472 if (sync_offset
== 0) {
474 /* no sync mark - its the start of the region */
481 if ((sync_dir
< 0) || ((sync_dir
> 0) && (sync_offset
> _region
->length()))) {
483 /* no sync mark - its out of the bounds of the region */
494 //points = sync_mark->property_points().get_value();
496 double offset
= sync_offset
/ samples_per_unit
;
497 points
.push_back (Gnome::Art::Point (offset
- ((sync_mark_width
-1)/2), 1));
498 points
.push_back (Gnome::Art::Point (offset
+ ((sync_mark_width
-1)/2), 1));
499 points
.push_back (Gnome::Art::Point (offset
, sync_mark_width
- 1));
500 points
.push_back (Gnome::Art::Point (offset
- ((sync_mark_width
-1)/2), 1));
501 sync_mark
->property_points().set_value (points
);
505 points
.push_back (Gnome::Art::Point (offset
, 0));
506 points
.push_back (Gnome::Art::Point (offset
, _height
- NAME_HIGHLIGHT_SIZE
));
508 sync_line
->property_points().set_value (points
);
515 RegionView::move (double x_delta
, double y_delta
)
517 if (_region
->locked() || (x_delta
== 0 && y_delta
== 0)) {
521 get_canvas_group()->move (x_delta
, y_delta
);
523 /* note: ghosts never leave their tracks so y_delta for them is always zero */
525 for (vector
<GhostRegion
*>::iterator i
= ghosts
.begin(); i
!= ghosts
.end(); ++i
) {
526 (*i
)->group
->move (x_delta
, 0.0);
531 RegionView::remove_ghost (GhostRegion
* ghost
)
537 for (vector
<GhostRegion
*>::iterator i
= ghosts
.begin(); i
!= ghosts
.end(); ++i
) {
546 RegionView::get_fill_color ()
552 RegionView::set_height (double h
)
557 nframes_t sync_offset
;
558 sync_offset
= _region
->sync_offset (sync_dir
);
559 double offset
= sync_offset
/ samples_per_unit
;
561 points
.push_back (Gnome::Art::Point (offset
, 0));
562 points
.push_back (Gnome::Art::Point (offset
, h
- NAME_HIGHLIGHT_SIZE
));
563 sync_line
->property_points().set_value (points
);