2 Copyright (C) 2001-2006 Paul Davis
4 This program is free software; you can r>edistribute 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.
24 #include <boost/scoped_array.hpp>
28 #include <gtkmm2ext/gtk_ui.h>
30 #include "ardour/playlist.h"
31 #include "ardour/audioregion.h"
32 #include "ardour/audiosource.h"
33 #include "ardour/profile.h"
34 #include "ardour/session.h"
36 #include "pbd/memento_command.h"
37 #include "pbd/stacktrace.h"
39 #include "evoral/Curve.hpp"
41 #include "canvas/rectangle.h"
42 #include "canvas/polygon.h"
43 #include "canvas/poly_line.h"
44 #include "canvas/line.h"
45 #include "canvas/text.h"
46 #include "canvas/xfade_curve.h"
47 #include "canvas/debug.h"
48 #include "canvas/utils.h"
49 #include "canvas/colors.h"
51 #include "streamview.h"
52 #include "audio_region_view.h"
53 #include "audio_time_axis.h"
54 #include "public_editor.h"
55 #include "audio_region_editor.h"
56 #include "audio_streamview.h"
57 #include "region_gain_line.h"
58 #include "control_point.h"
59 #include "ghostregion.h"
60 #include "audio_time_axis.h"
61 #include "rgb_macros.h"
62 #include "gui_thread.h"
63 #include "ardour_ui.h"
67 #define MUTED_ALPHA 48
70 using namespace ARDOUR;
72 using namespace Editing;
73 using namespace ArdourCanvas;
75 static const int32_t sync_mark_width = 9;
76 static double const handle_size = 10; /* height of fade handles */
78 AudioRegionView::AudioRegionView (ArdourCanvas::Container *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
80 : RegionView (parent, tv, r, spu, basic_color)
84 , fade_in_trim_handle(0)
85 , fade_out_trim_handle(0)
86 , start_xfade_curve (0)
87 , start_xfade_rect (0)
88 , _start_xfade_visible (false)
91 , _end_xfade_visible (false)
92 , _amplitude_above_axis(1.0)
93 , trim_fade_in_drag_active(false)
94 , trim_fade_out_drag_active(false)
96 Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&AudioRegionView::parameter_changed, this, _1), gui_context());
99 AudioRegionView::AudioRegionView (ArdourCanvas::Container *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
100 uint32_t basic_color, bool recording, TimeAxisViewItem::Visibility visibility)
101 : RegionView (parent, tv, r, spu, basic_color, recording, visibility)
105 , fade_in_trim_handle(0)
106 , fade_out_trim_handle(0)
107 , start_xfade_curve (0)
108 , start_xfade_rect (0)
109 , _start_xfade_visible (false)
110 , end_xfade_curve (0)
112 , _end_xfade_visible (false)
113 , _amplitude_above_axis(1.0)
114 , trim_fade_in_drag_active(false)
115 , trim_fade_out_drag_active(false)
117 Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&AudioRegionView::parameter_changed, this, _1), gui_context());
120 AudioRegionView::AudioRegionView (const AudioRegionView& other, boost::shared_ptr<AudioRegion> other_region)
121 : RegionView (other, boost::shared_ptr<Region> (other_region))
124 , fade_in_trim_handle(0)
125 , fade_out_trim_handle(0)
126 , start_xfade_curve (0)
127 , start_xfade_rect (0)
128 , _start_xfade_visible (false)
129 , end_xfade_curve (0)
131 , _end_xfade_visible (false)
132 , _amplitude_above_axis (other._amplitude_above_axis)
133 , trim_fade_in_drag_active(false)
134 , trim_fade_out_drag_active(false)
138 Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&AudioRegionView::parameter_changed, this, _1), gui_context());
142 AudioRegionView::init (bool wfd)
144 // FIXME: Some redundancy here with RegionView::init. Need to figure out
145 // where order is important and where it isn't...
147 RegionView::init (wfd);
149 _amplitude_above_axis = 1.0;
154 fade_in_handle = new ArdourCanvas::Rectangle (group);
155 CANVAS_DEBUG_NAME (fade_in_handle, string_compose ("fade in handle for %1", region()->name()));
156 fade_in_handle->set_outline_color (ArdourCanvas::rgba_to_color (0, 0, 0, 1.0));
157 fade_in_handle->set_fill_color (ARDOUR_UI::config()->get_InactiveFadeHandle());
158 fade_in_handle->set_data ("regionview", this);
159 fade_in_handle->hide ();
161 fade_out_handle = new ArdourCanvas::Rectangle (group);
162 CANVAS_DEBUG_NAME (fade_out_handle, string_compose ("fade out handle for %1", region()->name()));
163 fade_out_handle->set_outline_color (ArdourCanvas::rgba_to_color (0, 0, 0, 1.0));
164 fade_out_handle->set_fill_color (ARDOUR_UI::config()->get_InactiveFadeHandle());
165 fade_out_handle->set_data ("regionview", this);
166 fade_out_handle->hide ();
168 fade_in_trim_handle = new ArdourCanvas::Rectangle (group);
169 CANVAS_DEBUG_NAME (fade_in_handle, string_compose ("fade in trim handle for %1", region()->name()));
170 fade_in_trim_handle->set_outline_color (ArdourCanvas::rgba_to_color (0, 0, 0, 1.0));
171 fade_in_trim_handle->set_fill_color (ARDOUR_UI::config()->get_InactiveFadeHandle());
172 fade_in_trim_handle->set_data ("regionview", this);
173 fade_in_trim_handle->hide ();
175 fade_out_trim_handle = new ArdourCanvas::Rectangle (group);
176 CANVAS_DEBUG_NAME (fade_out_handle, string_compose ("fade out trim handle for %1", region()->name()));
177 fade_out_trim_handle->set_outline_color (ArdourCanvas::rgba_to_color (0, 0, 0, 1.0));
178 fade_out_trim_handle->set_fill_color (ARDOUR_UI::config()->get_InactiveFadeHandle());
179 fade_out_trim_handle->set_data ("regionview", this);
180 fade_out_trim_handle->hide ();
183 setup_fade_handle_positions ();
185 if (!trackview.session()->config.get_show_region_fades()) {
186 set_fade_visibility (false);
189 const string line_name = _region->name() + ":gain";
191 if (!Profile->get_sae()) {
192 gain_line.reset (new AudioRegionGainLine (line_name, *this, *group, audio_region()->envelope()));
195 update_envelope_visibility ();
198 set_height (trackview.current_height());
201 region_sync_changed ();
203 region_resized (ARDOUR::bounds_change);
205 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
206 (*i)->set_duration (_region->length() / samples_per_pixel);
210 envelope_active_changed ();
211 fade_in_active_changed ();
212 fade_out_active_changed ();
214 reset_width_dependent_items (_pixel_width);
216 if (fade_in_handle) {
217 fade_in_handle->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this, false));
220 if (fade_out_handle) {
221 fade_out_handle->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this, false));
224 if (fade_in_trim_handle) {
225 fade_in_trim_handle->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_trim_handle, this, true));
228 if (fade_out_trim_handle) {
229 fade_out_trim_handle->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_trim_handle, this, true));
234 setup_waveform_visibility ();
236 if (frame_handle_start) {
237 frame_handle_start->raise_to_top ();
239 if (frame_handle_end) {
240 frame_handle_end->raise_to_top ();
243 /* XXX sync mark drag? */
246 AudioRegionView::~AudioRegionView ()
248 in_destructor = true;
250 RegionViewGoingAway (this); /* EMIT_SIGNAL */
252 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
256 for (list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator i = feature_lines.begin(); i != feature_lines.end(); ++i) {
257 delete ((*i).second);
260 /* all waveviews etc will be destroyed when the group is destroyed */
263 boost::shared_ptr<ARDOUR::AudioRegion>
264 AudioRegionView::audio_region() const
266 // "Guaranteed" to succeed...
267 return boost::dynamic_pointer_cast<AudioRegion>(_region);
271 AudioRegionView::region_changed (const PropertyChange& what_changed)
273 ENSURE_GUI_THREAD (*this, &AudioRegionView::region_changed, what_changed);
275 RegionView::region_changed (what_changed);
277 if (what_changed.contains (ARDOUR::Properties::scale_amplitude)) {
278 region_scale_amplitude_changed ();
280 if (what_changed.contains (ARDOUR::Properties::fade_in)) {
283 if (what_changed.contains (ARDOUR::Properties::fade_out)) {
286 if (what_changed.contains (ARDOUR::Properties::fade_in_active)) {
287 fade_in_active_changed ();
289 if (what_changed.contains (ARDOUR::Properties::fade_out_active)) {
290 fade_out_active_changed ();
292 if (what_changed.contains (ARDOUR::Properties::envelope_active)) {
293 envelope_active_changed ();
295 if (what_changed.contains (ARDOUR::Properties::valid_transients)) {
296 transients_changed ();
301 AudioRegionView::fade_in_changed ()
303 reset_fade_in_shape ();
307 AudioRegionView::fade_out_changed ()
309 reset_fade_out_shape ();
313 AudioRegionView::fade_in_active_changed ()
315 if (start_xfade_rect) {
316 if (audio_region()->fade_in_active()) {
317 start_xfade_rect->set_fill (false);
319 start_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_InactiveCrossfade());
320 start_xfade_rect->set_fill (true);
326 AudioRegionView::fade_out_active_changed ()
328 if (end_xfade_rect) {
329 if (audio_region()->fade_out_active()) {
330 end_xfade_rect->set_fill (false);
332 end_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_InactiveCrossfade());
333 end_xfade_rect->set_fill (true);
340 AudioRegionView::region_scale_amplitude_changed ()
342 for (uint32_t n = 0; n < waves.size(); ++n) {
343 waves[n]->gain_changed ();
348 AudioRegionView::region_renamed ()
350 std::string str = RegionView::make_name ();
352 if (audio_region()->speed_mismatch (trackview.session()->frame_rate())) {
353 str = string ("*") + str;
356 if (_region->muted()) {
357 str = string ("!") + str;
360 set_item_name (str, this);
365 AudioRegionView::region_resized (const PropertyChange& what_changed)
367 AudioGhostRegion* agr;
369 RegionView::region_resized(what_changed);
370 PropertyChange interesting_stuff;
372 interesting_stuff.add (ARDOUR::Properties::start);
373 interesting_stuff.add (ARDOUR::Properties::length);
375 if (what_changed.contains (interesting_stuff)) {
377 for (uint32_t n = 0; n < waves.size(); ++n) {
378 waves[n]->region_resized ();
381 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
382 if ((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
384 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
385 (*w)->region_resized ();
390 /* hide transient lines that extend beyond the region end */
392 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
394 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
395 if (l->first > _region->length() - 1) {
405 AudioRegionView::reset_width_dependent_items (double pixel_width)
407 RegionView::reset_width_dependent_items(pixel_width);
408 assert(_pixel_width == pixel_width);
410 if (pixel_width <= 20.0 || _height < 5.0 || !trackview.session()->config.get_show_region_fades()) {
411 if (fade_in_handle) { fade_in_handle->hide(); }
412 if (fade_out_handle) { fade_out_handle->hide(); }
413 if (fade_in_trim_handle) { fade_in_trim_handle->hide(); }
414 if (fade_out_trim_handle) { fade_out_trim_handle->hide(); }
415 if (start_xfade_rect) { start_xfade_rect->set_outline (false); }
416 if (end_xfade_rect) { end_xfade_rect->set_outline (false); }
419 AnalysisFeatureList analysis_features = _region->transients();
420 AnalysisFeatureList::const_iterator i;
422 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
424 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
426 float x_pos = trackview.editor().sample_to_pixel (*i);
428 (*l).second->set (ArdourCanvas::Duple (x_pos, 2.0),
429 ArdourCanvas::Duple (x_pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
433 (*l).second->set (ArdourCanvas::Duple (x_pos, 2.0),
434 ArdourCanvas::Duple (x_pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
437 reset_fade_shapes ();
441 AudioRegionView::region_muted ()
443 RegionView::region_muted();
444 set_waveform_colors ();
448 AudioRegionView::setup_fade_handle_positions()
450 /* position of fade handle offset from the top of the region view */
451 double const handle_pos = 0.0;
453 if (fade_in_handle) {
454 fade_in_handle->set_y0 (handle_pos);
455 fade_in_handle->set_y1 (handle_pos + handle_size);
458 if (fade_out_handle) {
459 fade_out_handle->set_y0 (handle_pos);
460 fade_out_handle->set_y1 (handle_pos + handle_size);
463 if (fade_in_trim_handle) {
464 fade_in_trim_handle->set_y0 (_height - handle_size);
465 fade_in_trim_handle->set_y1 (_height);
468 if (fade_out_trim_handle) {
469 fade_out_trim_handle->set_y0 (_height - handle_size );
470 fade_out_trim_handle->set_y1 (_height);
475 AudioRegionView::set_height (gdouble height)
477 RegionView::set_height (height);
479 uint32_t wcnt = waves.size();
481 for (uint32_t n = 0; n < wcnt; ++n) {
484 if (height < NAME_HIGHLIGHT_THRESH) {
485 ht = ((height - 2 * wcnt) / (double) wcnt);
487 ht = (((height - 2 * wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
490 gdouble yoff = n * (ht + 1);
492 waves[n]->set_height (ht);
493 waves[n]->set_y_position (yoff + 2);
498 if ((height/wcnt) < NAME_HIGHLIGHT_THRESH) {
501 update_envelope_visibility ();
504 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE) - 2);
507 reset_fade_shapes ();
509 /* Update hights for any active feature lines */
510 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
512 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
514 float pos_x = trackview.editor().sample_to_pixel((*l).first);
516 if (height >= NAME_HIGHLIGHT_THRESH) {
517 (*l).second->set (ArdourCanvas::Duple (pos_x, 2.0),
518 ArdourCanvas::Duple (pos_x, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
520 (*l).second->set (ArdourCanvas::Duple (pos_x, 2.0),
521 ArdourCanvas::Duple (pos_x, _height - 1));
526 name_text->raise_to_top();
529 setup_fade_handle_positions();
533 AudioRegionView::reset_fade_shapes ()
535 if (!trim_fade_in_drag_active) { reset_fade_in_shape (); }
536 if (!trim_fade_out_drag_active) { reset_fade_out_shape (); }
540 AudioRegionView::reset_fade_in_shape ()
542 reset_fade_in_shape_width (audio_region(), (framecnt_t) audio_region()->fade_in()->back()->when);
546 AudioRegionView::reset_fade_in_shape_width (boost::shared_ptr<AudioRegion> ar, framecnt_t width, bool drag_active)
548 trim_fade_in_drag_active = drag_active;
549 if (fade_in_handle == 0) {
553 /* smallest size for a fade is 64 frames */
555 width = std::max ((framecnt_t) 64, width);
557 /* round here to prevent little visual glitches with sub-pixel placement */
558 double const pwidth = rint (width / samples_per_pixel);
559 double const handle_left = pwidth;
561 /* Put the fade in handle so that its left side is at the end-of-fade line */
562 fade_in_handle->set_x0 (handle_left);
563 fade_in_handle->set_x1 (handle_left + handle_size);
565 if (fade_in_trim_handle) {
566 fade_in_trim_handle->set_x0 (0);
567 fade_in_trim_handle->set_x1 (handle_size);
570 if (fade_in_handle->visible()) {
571 //see comment for drag_start
580 if (!trackview.session()->config.get_show_region_fades()) {
585 double effective_height;
587 if (_height >= NAME_HIGHLIGHT_THRESH) {
588 effective_height = _height - NAME_HIGHLIGHT_SIZE;
590 effective_height = _height;
593 /* points *MUST* be in anti-clockwise order */
596 Points::size_type pi;
597 boost::shared_ptr<const Evoral::ControlList> list (audio_region()->fade_in());
598 Evoral::ControlList::const_iterator x;
599 double length = list->length();
601 points.assign (list->size(), Duple());
603 for (x = list->begin(), pi = 0; x != list->end(); ++x, ++pi) {
604 points[pi].x = 1.0 + (pwidth * ((*x)->when/length));
605 points[pi].y = effective_height - ((*x)->value * effective_height);
610 redraw_start_xfade_to (ar, width, points, effective_height, handle_left);
612 /* ensure trim handle stays on top */
613 if (frame_handle_start) {
614 frame_handle_start->raise_to_top();
619 AudioRegionView::reset_fade_out_shape ()
621 reset_fade_out_shape_width (audio_region(), (framecnt_t) audio_region()->fade_out()->back()->when);
625 AudioRegionView::reset_fade_out_shape_width (boost::shared_ptr<AudioRegion> ar, framecnt_t width, bool drag_active)
627 trim_fade_out_drag_active = drag_active;
628 if (fade_out_handle == 0) {
632 /* smallest size for a fade is 64 frames */
634 width = std::max ((framecnt_t) 64, width);
637 double const pwidth = rint(trackview.editor().sample_to_pixel (width));
639 /* the right edge should be right on the region frame is the pixel
640 * width is zero. Hence the additional + 1.0 at the end.
643 double const handle_right = rint(trackview.editor().sample_to_pixel (_region->length()) - pwidth);
644 double const trim_handle_right = rint(trackview.editor().sample_to_pixel (_region->length()));
646 /* Put the fade out handle so that its right side is at the end-of-fade line;
648 fade_out_handle->set_x0 (handle_right - handle_size);
649 fade_out_handle->set_x1 (handle_right);
650 if (fade_out_trim_handle) {
651 fade_out_trim_handle->set_x0 (1 + trim_handle_right - handle_size);
652 fade_out_trim_handle->set_x1 (1 + trim_handle_right);
655 if (fade_out_handle->visible()) {
656 //see comment for drag_start
659 /* don't show shape if its too small */
666 if (!trackview.session()->config.get_show_region_fades()) {
671 double effective_height;
673 effective_height = _height - 1.0;
675 if (Config->get_show_name_highlight() && effective_height >= NAME_HIGHLIGHT_THRESH) {
676 effective_height -= NAME_HIGHLIGHT_SIZE;
679 /* points *MUST* be in anti-clockwise order */
682 Points::size_type pi;
683 boost::shared_ptr<const Evoral::ControlList> list (audio_region()->fade_out());
684 Evoral::ControlList::const_iterator x;
685 double length = list->length();
687 points.assign (list->size(), Duple());
689 for (x = list->begin(), pi = 0; x != list->end(); ++x, ++pi) {
690 points[pi].x = _pixel_width - pwidth + (pwidth * ((*x)->when/length));
691 points[pi].y = 1.0 + effective_height - ((*x)->value * effective_height);
696 redraw_end_xfade_to (ar, width, points, effective_height, handle_right, pwidth);
698 /* ensure trim handle stays on top */
699 if (frame_handle_end) {
700 frame_handle_end->raise_to_top();
705 AudioRegionView::get_fade_in_shape_width ()
707 return audio_region()->fade_in()->back()->when;
711 AudioRegionView::get_fade_out_shape_width ()
713 return audio_region()->fade_out()->back()->when;
718 AudioRegionView::redraw_start_xfade ()
720 boost::shared_ptr<AudioRegion> ar (audio_region());
722 if (!ar->fade_in() || ar->fade_in()->empty()) {
727 reset_fade_in_shape_width (ar, ar->fade_in()->back()->when);
731 AudioRegionView::redraw_start_xfade_to (boost::shared_ptr<AudioRegion> ar, framecnt_t /*width*/, Points& points, double effective_height,
734 if (points.size() < 2) {
738 if (!start_xfade_curve) {
739 start_xfade_curve = new ArdourCanvas::XFadeCurve (group, ArdourCanvas::XFadeCurve::Start);
740 CANVAS_DEBUG_NAME (start_xfade_curve, string_compose ("xfade start out line for %1", region()->name()));
741 start_xfade_curve->set_fill_color (ARDOUR_UI::config()->get_ActiveCrossfade());
742 start_xfade_curve->set_outline_color (ARDOUR_UI::config()->get_CrossfadeLine());
743 start_xfade_curve->set_ignore_events (true);
745 if (!start_xfade_rect) {
746 start_xfade_rect = new ArdourCanvas::Rectangle (group);
747 CANVAS_DEBUG_NAME (start_xfade_rect, string_compose ("xfade start rect for %1", region()->name()));
748 start_xfade_rect->set_outline_color (ARDOUR_UI::config()->get_CrossfadeLine());
749 start_xfade_rect->set_fill (false);
750 start_xfade_rect->set_outline (false);
751 start_xfade_rect->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_start_xfade_event), start_xfade_rect, this));
752 start_xfade_rect->set_data ("regionview", this);
755 start_xfade_rect->set (ArdourCanvas::Rect (0.0, 0.0, rect_width, effective_height));
759 boost::shared_ptr<AutomationList> inverse = ar->inverse_fade_in ();
761 Points::size_type npoints;
765 /* there is no explicit inverse fade in curve, so take the
766 * regular fade in curve given to use as "points" (already a
767 * set of coordinates), and convert to the inverse shape.
770 npoints = points.size();
771 ipoints.assign (npoints, Duple());
773 for (Points::size_type i = 0, pci = 0; i < npoints; ++i, ++pci) {
774 ArdourCanvas::Duple &p (ipoints[pci]);
775 /* leave x-axis alone but invert with respect to y-axis */
776 p.y = 1.0 + effective_height - points[pci].y;
781 /* there is an explicit inverse fade in curve. Grab the points
782 and convert them into coordinates for the inverse fade in
786 npoints = inverse->size();
787 ipoints.assign (npoints, Duple());
789 Evoral::ControlList::const_iterator x;
790 Points::size_type pi;
791 double length = inverse->length();
793 for (x = inverse->begin(), pi = 0; x != inverse->end(); ++x, ++pi) {
794 ArdourCanvas::Duple& p (ipoints[pi]);
795 p.x = (rect_width * ((*x)->when/length));
796 p.y = 1.0 + effective_height - ((*x)->value * effective_height);
800 start_xfade_curve->set_inout (points, ipoints);
806 AudioRegionView::redraw_end_xfade ()
808 boost::shared_ptr<AudioRegion> ar (audio_region());
810 if (!ar->fade_out() || ar->fade_out()->empty()) {
816 reset_fade_out_shape_width (ar, ar->fade_out()->back()->when);
820 AudioRegionView::redraw_end_xfade_to (boost::shared_ptr<AudioRegion> ar, framecnt_t width, Points& points, double effective_height,
821 double rect_edge, double rect_width)
823 if (points.size() < 2) {
827 if (!end_xfade_curve) {
828 end_xfade_curve = new ArdourCanvas::XFadeCurve (group, ArdourCanvas::XFadeCurve::End);
829 CANVAS_DEBUG_NAME (end_xfade_curve, string_compose ("xfade end out line for %1", region()->name()));
830 end_xfade_curve->set_fill_color (ARDOUR_UI::config()->get_ActiveCrossfade());
831 end_xfade_curve->set_outline_color (ARDOUR_UI::config()->get_CrossfadeLine());
832 end_xfade_curve->set_ignore_events (true);
835 if (!end_xfade_rect) {
836 end_xfade_rect = new ArdourCanvas::Rectangle (group);
837 CANVAS_DEBUG_NAME (end_xfade_rect, string_compose ("xfade end rect for %1", region()->name()));
838 end_xfade_rect->set_outline_color (ARDOUR_UI::config()->get_CrossfadeLine());
839 end_xfade_rect->set_fill (false);
840 end_xfade_rect->set_outline (false);
841 end_xfade_rect->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_end_xfade_event), end_xfade_rect, this));
842 end_xfade_rect->set_data ("regionview", this);
845 end_xfade_rect->set (ArdourCanvas::Rect (rect_edge, 0.0, rect_edge + rect_width, effective_height));
849 boost::shared_ptr<AutomationList> inverse = ar->inverse_fade_out ();
851 Points::size_type npoints;
855 /* there is no explicit inverse fade out curve, so take the
856 * regular fade out curve given to use as "points" (already a
857 * set of coordinates), and convert to the inverse shape.
860 npoints = points.size();
861 ipoints.assign (npoints, Duple());
863 Points::size_type pci;
865 for (pci = 0; pci < npoints; ++pci) {
866 ArdourCanvas::Duple &p (ipoints[pci]);
867 p.y = effective_height - points[pci].y;
872 /* there is an explicit inverse fade out curve. Grab the points
873 and convert them into coordinates for the inverse fade out
877 npoints = inverse->size();
878 ipoints.assign (npoints, Duple());
880 const double rend = trackview.editor().sample_to_pixel (_region->length() - width);
882 Evoral::ControlList::const_iterator x;
884 Points::size_type pi;
885 double length = inverse->length();
887 for (x = inverse->begin(), i = 0, pi = 0; x != inverse->end(); ++x, ++pi, ++i) {
888 ArdourCanvas::Duple& p (ipoints[pi]);
889 p.x = (rect_width * ((*x)->when/length)) + rend;
890 p.y = 1.0 + effective_height - ((*x)->value * effective_height);
894 end_xfade_curve->set_inout (ipoints, points);
900 AudioRegionView::hide_xfades ()
907 AudioRegionView::hide_start_xfade ()
909 if (start_xfade_curve) {
910 start_xfade_curve->hide();
912 if (start_xfade_rect) {
913 start_xfade_rect->hide ();
916 _start_xfade_visible = false;
920 AudioRegionView::hide_end_xfade ()
922 if (end_xfade_curve) {
923 end_xfade_curve->hide();
925 if (end_xfade_rect) {
926 end_xfade_rect->hide ();
929 _end_xfade_visible = false;
933 AudioRegionView::show_start_xfade ()
935 if (start_xfade_curve) {
936 start_xfade_curve->show();
938 if (start_xfade_rect) {
939 start_xfade_rect->show ();
942 _start_xfade_visible = true;
946 AudioRegionView::show_end_xfade ()
948 if (end_xfade_curve) {
949 end_xfade_curve->show();
951 if (end_xfade_rect) {
952 end_xfade_rect->show ();
955 _end_xfade_visible = true;
959 AudioRegionView::set_samples_per_pixel (gdouble fpp)
961 RegionView::set_samples_per_pixel (fpp);
963 if (Config->get_show_waveforms ()) {
964 for (uint32_t n = 0; n < waves.size(); ++n) {
965 waves[n]->set_samples_per_pixel (fpp);
973 reset_fade_shapes ();
977 AudioRegionView::set_amplitude_above_axis (gdouble a)
979 for (uint32_t n=0; n < waves.size(); ++n) {
980 waves[n]->set_amplitude_above_axis (a);
985 AudioRegionView::set_colors ()
987 RegionView::set_colors();
990 gain_line->set_line_color (audio_region()->envelope_active() ?
991 ARDOUR_UI::config()->get_GainLine() :
992 ARDOUR_UI::config()->get_GainLineInactive());
995 set_waveform_colors ();
997 if (start_xfade_curve) {
998 start_xfade_curve->set_fill_color (ARDOUR_UI::config()->get_ActiveCrossfade());
999 start_xfade_curve->set_outline_color (ARDOUR_UI::config()->get_CrossfadeLine());
1001 if (end_xfade_curve) {
1002 end_xfade_curve->set_fill_color (ARDOUR_UI::config()->get_ActiveCrossfade());
1003 end_xfade_curve->set_outline_color (ARDOUR_UI::config()->get_CrossfadeLine());
1006 if (start_xfade_rect) {
1007 start_xfade_rect->set_outline_color (ARDOUR_UI::config()->get_CrossfadeLine());
1009 if (end_xfade_rect) {
1010 end_xfade_rect->set_outline_color (ARDOUR_UI::config()->get_CrossfadeLine());
1015 AudioRegionView::setup_waveform_visibility ()
1017 if (Config->get_show_waveforms ()) {
1018 for (uint32_t n = 0; n < waves.size(); ++n) {
1019 /* make sure the zoom level is correct, since we don't update
1020 this when waveforms are hidden.
1023 // waves[n]->set_samples_per_pixel (_samples_per_pixel);
1027 for (uint32_t n = 0; n < waves.size(); ++n) {
1034 AudioRegionView::temporarily_hide_envelope ()
1042 AudioRegionView::unhide_envelope ()
1044 update_envelope_visibility ();
1048 AudioRegionView::update_envelope_visibility ()
1054 if (Config->get_show_region_gain() || trackview.editor().current_mouse_mode() == Editing::MouseGain || trackview.editor().current_mouse_mode() == Editing::MouseRange ) {
1055 gain_line->add_visibility (AutomationLine::Line);
1062 AudioRegionView::create_waves ()
1064 // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
1065 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
1071 ChanCount nchans = atv.track()->n_channels();
1073 // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data
1074 // << " and channels = " << nchans.n_audio() << endl;
1076 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
1077 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
1078 tmp_waves.push_back (0);
1081 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
1085 _data_ready_connections.clear ();
1087 for (uint32_t i = 0; i < nchans.n_audio(); ++i) {
1088 _data_ready_connections.push_back (0);
1091 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
1093 if (n >= audio_region()->n_channels()) {
1097 // cerr << "\tchannel " << n << endl;
1099 if (wait_for_data) {
1100 if (audio_region()->audio_source(n)->peaks_ready (boost::bind (&AudioRegionView::peaks_ready_handler, this, n), &_data_ready_connections[n], gui_context())) {
1101 // cerr << "\tData is ready\n";
1102 create_one_wave (n, true);
1104 // cerr << "\tdata is not ready\n";
1105 // we'll get a PeaksReady signal from the source in the future
1106 // and will call create_one_wave(n) then.
1110 // cerr << "\tdon't delay, display today!\n";
1111 create_one_wave (n, true);
1118 AudioRegionView::create_one_wave (uint32_t which, bool /*direct*/)
1120 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
1121 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
1122 uint32_t nchans = atv.track()->n_channels().n_audio();
1124 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
1127 if (trackview.current_height() < NAME_HIGHLIGHT_THRESH) {
1128 ht = ((trackview.current_height()) / (double) nchans);
1130 ht = ((trackview.current_height() - NAME_HIGHLIGHT_SIZE) / (double) nchans);
1133 gdouble yoff = which * ht;
1135 WaveView *wave = new WaveView (group, audio_region ());
1136 CANVAS_DEBUG_NAME (wave, string_compose ("wave view for chn %1 of %2", which, get_item_name()));
1138 wave->set_channel (which);
1139 wave->set_y_position (yoff);
1140 wave->set_height (ht);
1141 wave->set_samples_per_pixel (samples_per_pixel);
1142 wave->set_show_zero_line (true);
1143 wave->set_clip_level (Config->get_waveform_clip_level ());
1145 wave->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_wave_view_event), wave, this));
1147 switch (Config->get_waveform_shape()) {
1149 wave->set_shape (WaveView::Rectified);
1152 wave->set_shape (WaveView::Normal);
1155 wave->set_logscaled (Config->get_waveform_scale() == Logarithmic);
1157 vector<ArdourCanvas::WaveView*> v;
1159 set_some_waveform_colors (v);
1161 if (!Config->get_show_waveforms ()) {
1165 /* note: calling this function is serialized by the lock
1166 held in the peak building thread that signals that
1167 peaks are ready for use *or* by the fact that it is
1168 called one by one from the GUI thread.
1171 if (which < nchans) {
1172 tmp_waves[which] = wave;
1174 /* n-channel track, >n-channel source */
1177 /* see if we're all ready */
1179 for (n = 0; n < nchans; ++n) {
1180 if (tmp_waves[n] == 0) {
1185 if (n == nwaves && waves.empty()) {
1186 /* all waves are ready */
1187 tmp_waves.resize(nwaves);
1192 /* all waves created, don't hook into peaks ready anymore */
1193 delete _data_ready_connections[which];
1194 _data_ready_connections[which] = 0;
1199 AudioRegionView::peaks_ready_handler (uint32_t which)
1201 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AudioRegionView::create_one_wave, this, which, false));
1202 // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
1206 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev, bool with_guard_points)
1214 /* don't create points that can't be seen */
1216 update_envelope_visibility ();
1221 item->canvas_to_item (x, y);
1223 framepos_t fx = trackview.editor().pixel_to_sample (x);
1225 if (fx > _region->length()) {
1229 /* compute vertical fractional position */
1231 y = 1.0 - (y / (_height - NAME_HIGHLIGHT_SIZE));
1233 /* map using gain line */
1235 gain_line->view_to_model_coord (x, y);
1237 /* XXX STATEFUL: can't convert to stateful diff until we
1238 can represent automation data with it.
1241 trackview.session()->begin_reversible_command (_("add gain control point"));
1242 XMLNode &before = audio_region()->envelope()->get_state();
1244 if (!audio_region()->envelope_active()) {
1245 XMLNode ®ion_before = audio_region()->get_state();
1246 audio_region()->set_envelope_active(true);
1247 XMLNode ®ion_after = audio_region()->get_state();
1248 trackview.session()->add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
1251 audio_region()->envelope()->add (fx, y, with_guard_points);
1253 XMLNode &after = audio_region()->envelope()->get_state();
1254 trackview.session()->add_command (new MementoCommand<AutomationList>(*audio_region()->envelope().get(), &before, &after));
1255 trackview.session()->commit_reversible_command ();
1259 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent* /*ev*/)
1261 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1262 audio_region()->envelope()->erase (cp->model());
1266 AudioRegionView::add_ghost (TimeAxisView& tv)
1268 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1271 double unit_position = _region->position () / samples_per_pixel;
1272 AudioGhostRegion* ghost = new AudioGhostRegion (tv, trackview, unit_position);
1275 nchans = rtv->track()->n_channels().n_audio();
1277 for (uint32_t n = 0; n < nchans; ++n) {
1279 if (n >= audio_region()->n_channels()) {
1283 WaveView *wave = new WaveView (ghost->group, audio_region());
1284 CANVAS_DEBUG_NAME (wave, string_compose ("ghost wave for %1", get_item_name()));
1286 wave->set_channel (n);
1287 wave->set_samples_per_pixel (samples_per_pixel);
1288 wave->set_amplitude_above_axis (_amplitude_above_axis);
1290 ghost->waves.push_back(wave);
1293 ghost->set_height ();
1294 ghost->set_duration (_region->length() / samples_per_pixel);
1295 ghost->set_colors();
1296 ghosts.push_back (ghost);
1302 AudioRegionView::entered (bool internal_editing)
1304 trackview.editor().set_current_trimmable (_region);
1305 trackview.editor().set_current_movable (_region);
1308 /* these may or may not be visible depending on mouse mode */
1309 gain_line->add_visibility (AutomationLine::ControlPoints);
1312 if (!internal_editing && ( trackview.editor().current_mouse_mode() == Editing::MouseObject ) ) {
1313 if (start_xfade_rect) {
1314 start_xfade_rect->set_outline (true);
1316 if (end_xfade_rect) {
1317 end_xfade_rect->set_outline (true);
1319 if (fade_in_handle) {
1320 fade_in_handle->show ();
1321 fade_in_handle->raise_to_top ();
1323 if (fade_out_handle) {
1324 fade_out_handle->show ();
1325 fade_out_handle->raise_to_top ();
1327 if (fade_in_trim_handle) {
1328 boost::shared_ptr<AudioRegion> ar (audio_region());
1329 if (!ar->locked() && (ar->fade_in()->back()->when > 64 || (ar->can_trim() & Trimmable::FrontTrimEarlier))) {
1330 fade_in_trim_handle->show ();
1331 fade_in_trim_handle->raise_to_top ();
1333 fade_in_trim_handle->hide ();
1336 if (fade_out_trim_handle) {
1337 boost::shared_ptr<AudioRegion> ar (audio_region());
1338 if (!ar->locked() && (ar->fade_out()->back()->when > 64 || (ar->can_trim() & Trimmable::EndTrimLater))) {
1339 fade_out_trim_handle->show ();
1340 fade_out_trim_handle->raise_to_top ();
1342 fade_out_trim_handle->hide ();
1349 AudioRegionView::exited ()
1351 trackview.editor().set_current_trimmable (boost::shared_ptr<Trimmable>());
1352 trackview.editor().set_current_movable (boost::shared_ptr<Movable>());
1355 gain_line->remove_visibility (AutomationLine::ControlPoints);
1358 if (fade_in_handle) { fade_in_handle->hide(); }
1359 if (fade_out_handle) { fade_out_handle->hide(); }
1360 if (fade_in_trim_handle) { fade_in_trim_handle->hide(); }
1361 if (fade_out_trim_handle) { fade_out_trim_handle->hide(); }
1362 if (start_xfade_rect) { start_xfade_rect->set_outline (false); }
1363 if (end_xfade_rect) { end_xfade_rect->set_outline (false); }
1367 AudioRegionView::envelope_active_changed ()
1370 gain_line->set_line_color (audio_region()->envelope_active() ?
1371 ARDOUR_UI::config()->get_GainLine() :
1372 ARDOUR_UI::config()->get_GainLineInactive());
1373 update_envelope_visibility ();
1378 AudioRegionView::color_handler ()
1380 //case cMutedWaveForm:
1382 //case cWaveFormClip:
1386 //case cGainLineInactive:
1388 envelope_active_changed();
1393 AudioRegionView::set_waveform_colors ()
1395 set_some_waveform_colors (waves);
1399 AudioRegionView::set_some_waveform_colors (vector<ArdourCanvas::WaveView*>& waves_to_color)
1401 ArdourCanvas::Color fill;
1402 ArdourCanvas::Color outline;
1403 ArdourCanvas::Color clip = ARDOUR_UI::config()->get_WaveFormClip();
1404 ArdourCanvas::Color zero = ARDOUR_UI::config()->get_ZeroLine();
1407 if (_region->muted()) {
1408 /* hide outline with zero alpha */
1409 outline = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_SelectedWaveForm(), 0);
1410 fill = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_SelectedWaveFormFill(), MUTED_ALPHA);
1412 outline = ARDOUR_UI::config()->get_SelectedWaveForm();
1413 fill = ARDOUR_UI::config()->get_SelectedWaveFormFill();
1417 outline = ARDOUR_UI::config()->get_RecWaveForm();
1418 fill = ARDOUR_UI::config()->get_RecWaveFormFill();
1420 if (_region->muted()) {
1421 /* hide outline with zero alpha */
1422 outline = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_WaveForm(), 0);
1423 fill = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_WaveFormFill(), MUTED_ALPHA);
1425 outline = ARDOUR_UI::config()->get_WaveForm();
1426 fill = ARDOUR_UI::config()->get_WaveFormFill();
1431 for (vector<ArdourCanvas::WaveView*>::iterator w = waves_to_color.begin(); w != waves_to_color.end(); ++w) {
1432 (*w)->set_fill_color (fill);
1433 (*w)->set_outline_color (outline);
1434 (*w)->set_clip_color (clip);
1435 (*w)->set_zero_color (zero);
1440 AudioRegionView::set_frame_color ()
1446 RegionView::set_frame_color ();
1448 set_waveform_colors ();
1452 AudioRegionView::set_fade_visibility (bool yn)
1455 if (start_xfade_curve) { start_xfade_curve->show (); }
1456 if (end_xfade_curve) { end_xfade_curve->show (); }
1457 if (start_xfade_rect) { start_xfade_rect->show (); }
1458 if (end_xfade_rect) { end_xfade_rect->show (); }
1460 if (start_xfade_curve) { start_xfade_curve->hide(); }
1461 if (end_xfade_curve) { end_xfade_curve->hide(); }
1462 if (fade_in_handle) { fade_in_handle->hide(); }
1463 if (fade_out_handle) { fade_out_handle->hide(); }
1464 if (fade_in_trim_handle) { fade_in_trim_handle->hide(); }
1465 if (fade_out_trim_handle) { fade_out_trim_handle->hide(); }
1466 if (start_xfade_rect) { start_xfade_rect->hide (); }
1467 if (end_xfade_rect) { end_xfade_rect->hide (); }
1468 if (start_xfade_rect) { start_xfade_rect->set_outline (false); }
1469 if (end_xfade_rect) { end_xfade_rect->set_outline (false); }
1474 AudioRegionView::update_coverage_frames (LayerDisplay d)
1476 RegionView::update_coverage_frames (d);
1478 if (fade_in_handle) { fade_in_handle->raise_to_top (); }
1479 if (fade_out_handle) { fade_out_handle->raise_to_top (); }
1480 if (fade_in_trim_handle) { fade_in_trim_handle->raise_to_top (); }
1481 if (fade_out_trim_handle) { fade_out_trim_handle->raise_to_top (); }
1485 AudioRegionView::show_region_editor ()
1488 editor = new AudioRegionEditor (trackview.session(), audio_region());
1496 AudioRegionView::transients_changed ()
1498 AnalysisFeatureList analysis_features = _region->transients();
1500 while (feature_lines.size() < analysis_features.size()) {
1502 ArdourCanvas::Line* canvas_item = new ArdourCanvas::Line(group);
1503 CANVAS_DEBUG_NAME (canvas_item, string_compose ("transient group for %1", region()->name()));
1505 canvas_item->set (ArdourCanvas::Duple (-1.0, 2.0),
1506 ArdourCanvas::Duple (1.0, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
1508 canvas_item->raise_to_top ();
1509 canvas_item->show ();
1511 canvas_item->set_data ("regionview", this);
1512 canvas_item->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_feature_line_event), canvas_item, this));
1514 feature_lines.push_back (make_pair(0, canvas_item));
1517 while (feature_lines.size() > analysis_features.size()) {
1518 ArdourCanvas::Line* line = feature_lines.back().second;
1519 feature_lines.pop_back ();
1523 AnalysisFeatureList::const_iterator i;
1524 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1526 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
1528 float *pos = new float;
1529 *pos = trackview.editor().sample_to_pixel (*i);
1532 ArdourCanvas::Duple (*pos, 2.0),
1533 ArdourCanvas::Duple (*pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1)
1536 (*l).second->set_data ("position", pos);
1542 AudioRegionView::update_transient(float /*old_pos*/, float new_pos)
1544 /* Find frame at old pos, calulate new frame then update region transients*/
1545 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1547 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1549 /* Line has been updated in drag so we compare to new_pos */
1551 float* pos = (float*) (*l).second->get_data ("position");
1553 if (rint(new_pos) == rint(*pos)) {
1555 framepos_t old_frame = (*l).first;
1556 framepos_t new_frame = trackview.editor().pixel_to_sample (new_pos);
1558 _region->update_transient (old_frame, new_frame);
1566 AudioRegionView::remove_transient(float pos)
1568 /* Find frame at old pos, calulate new frame then update region transients*/
1569 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1571 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1573 /* Line has been updated in drag so we compare to new_pos */
1574 float *line_pos = (float*) (*l).second->get_data ("position");
1576 if (rint(pos) == rint(*line_pos)) {
1577 _region->remove_transient ((*l).first);
1584 AudioRegionView::thaw_after_trim ()
1586 RegionView::thaw_after_trim ();
1593 AudioRegionView::show_xfades ()
1595 show_start_xfade ();
1600 AudioRegionView::drag_start ()
1602 TimeAxisViewItem::drag_start ();
1604 //we used to hide xfades here. I don't see the point with the new model, but we can re-implement if needed
1608 AudioRegionView::drag_end ()
1610 TimeAxisViewItem::drag_end ();
1611 //see comment for drag_start
1613 if (fade_in_handle && fade_in_handle->visible()) {
1614 // lenght of region or fade changed, re-check
1615 // if fade_in_trim_handle or fade_out_trim_handle should
1616 // be visible. -- If the fade_in_handle is visible
1617 // we have focus and are not in internal edit mode.
1623 AudioRegionView::parameter_changed (string const & p)
1625 if (p == "show-waveforms") {
1626 setup_waveform_visibility ();