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"
50 #include "streamview.h"
51 #include "audio_region_view.h"
52 #include "audio_time_axis.h"
53 #include "public_editor.h"
54 #include "audio_region_editor.h"
55 #include "audio_streamview.h"
56 #include "region_gain_line.h"
57 #include "control_point.h"
58 #include "ghostregion.h"
59 #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::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
79 Gdk::Color const & basic_color)
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)
95 Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&AudioRegionView::parameter_changed, this, _1), gui_context());
98 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
99 Gdk::Color const & basic_color, bool recording, TimeAxisViewItem::Visibility visibility)
100 : RegionView (parent, tv, r, spu, basic_color, recording, visibility)
104 , fade_in_trim_handle(0)
105 , fade_out_trim_handle(0)
106 , start_xfade_curve (0)
107 , start_xfade_rect (0)
108 , _start_xfade_visible (false)
109 , end_xfade_curve (0)
111 , _end_xfade_visible (false)
112 , _amplitude_above_axis(1.0)
115 Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&AudioRegionView::parameter_changed, this, _1), gui_context());
118 AudioRegionView::AudioRegionView (const AudioRegionView& other, boost::shared_ptr<AudioRegion> other_region)
119 : RegionView (other, boost::shared_ptr<Region> (other_region))
122 , fade_in_trim_handle(0)
123 , fade_out_trim_handle(0)
124 , start_xfade_curve (0)
125 , start_xfade_rect (0)
126 , _start_xfade_visible (false)
127 , end_xfade_curve (0)
129 , _end_xfade_visible (false)
130 , _amplitude_above_axis (other._amplitude_above_axis)
136 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
137 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
141 Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&AudioRegionView::parameter_changed, this, _1), gui_context());
145 AudioRegionView::init (Gdk::Color const & basic_color, bool wfd)
147 // FIXME: Some redundancy here with RegionView::init. Need to figure out
148 // where order is important and where it isn't...
150 RegionView::init (basic_color, wfd);
152 _amplitude_above_axis = 1.0;
154 compute_colors (basic_color);
159 fade_in_handle = new ArdourCanvas::Rectangle (group);
160 CANVAS_DEBUG_NAME (fade_in_handle, string_compose ("fade in handle for %1", region()->name()));
161 fade_in_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 255));
162 fade_in_handle->set_fill_color (ARDOUR_UI::config()->get_canvasvar_InactiveFadeHandle());
163 fade_in_handle->set_data ("regionview", this);
164 fade_in_handle->hide ();
166 fade_out_handle = new ArdourCanvas::Rectangle (group);
167 CANVAS_DEBUG_NAME (fade_out_handle, string_compose ("fade out handle for %1", region()->name()));
168 fade_out_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 255));
169 fade_out_handle->set_fill_color (ARDOUR_UI::config()->get_canvasvar_InactiveFadeHandle());
170 fade_out_handle->set_data ("regionview", this);
171 fade_out_handle->hide ();
173 fade_in_trim_handle = new ArdourCanvas::Rectangle (group);
174 CANVAS_DEBUG_NAME (fade_in_handle, string_compose ("fade in trim handle for %1", region()->name()));
175 fade_in_trim_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 255));
176 fade_in_trim_handle->set_fill_color (ARDOUR_UI::config()->get_canvasvar_InactiveFadeHandle());
177 fade_in_trim_handle->set_data ("regionview", this);
178 fade_in_trim_handle->hide ();
180 fade_out_trim_handle = new ArdourCanvas::Rectangle (group);
181 CANVAS_DEBUG_NAME (fade_out_handle, string_compose ("fade out trim handle for %1", region()->name()));
182 fade_out_trim_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 255));
183 fade_out_trim_handle->set_fill_color (ARDOUR_UI::config()->get_canvasvar_InactiveFadeHandle());
184 fade_out_trim_handle->set_data ("regionview", this);
185 fade_out_trim_handle->hide ();
188 setup_fade_handle_positions ();
190 if (!trackview.session()->config.get_show_region_fades()) {
191 set_fade_visibility (false);
194 const string line_name = _region->name() + ":gain";
196 if (!Profile->get_sae()) {
197 gain_line.reset (new AudioRegionGainLine (line_name, *this, *group, audio_region()->envelope()));
200 update_envelope_visibility ();
203 set_height (trackview.current_height());
206 region_sync_changed ();
208 region_resized (ARDOUR::bounds_change);
210 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
211 (*i)->set_duration (_region->length() / samples_per_pixel);
215 envelope_active_changed ();
216 fade_in_active_changed ();
217 fade_out_active_changed ();
219 reset_width_dependent_items (_pixel_width);
221 if (fade_in_handle) {
222 fade_in_handle->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this, false));
225 if (fade_out_handle) {
226 fade_out_handle->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this, false));
229 if (fade_in_trim_handle) {
230 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));
233 if (fade_out_trim_handle) {
234 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));
239 setup_waveform_visibility ();
241 if (frame_handle_start) {
242 frame_handle_start->raise_to_top ();
244 if (frame_handle_end) {
245 frame_handle_end->raise_to_top ();
248 /* XXX sync mark drag? */
251 AudioRegionView::~AudioRegionView ()
253 in_destructor = true;
255 RegionViewGoingAway (this); /* EMIT_SIGNAL */
257 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
261 for (list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator i = feature_lines.begin(); i != feature_lines.end(); ++i) {
262 delete ((*i).second);
265 /* all waveviews etc will be destroyed when the group is destroyed */
268 boost::shared_ptr<ARDOUR::AudioRegion>
269 AudioRegionView::audio_region() const
271 // "Guaranteed" to succeed...
272 return boost::dynamic_pointer_cast<AudioRegion>(_region);
276 AudioRegionView::region_changed (const PropertyChange& what_changed)
278 ENSURE_GUI_THREAD (*this, &AudioRegionView::region_changed, what_changed);
280 RegionView::region_changed (what_changed);
282 if (what_changed.contains (ARDOUR::Properties::scale_amplitude)) {
283 region_scale_amplitude_changed ();
285 if (what_changed.contains (ARDOUR::Properties::fade_in)) {
288 if (what_changed.contains (ARDOUR::Properties::fade_out)) {
291 if (what_changed.contains (ARDOUR::Properties::fade_in_active)) {
292 fade_in_active_changed ();
294 if (what_changed.contains (ARDOUR::Properties::fade_out_active)) {
295 fade_out_active_changed ();
297 if (what_changed.contains (ARDOUR::Properties::envelope_active)) {
298 envelope_active_changed ();
300 if (what_changed.contains (ARDOUR::Properties::valid_transients)) {
301 transients_changed ();
306 AudioRegionView::fade_in_changed ()
308 reset_fade_in_shape ();
312 AudioRegionView::fade_out_changed ()
314 reset_fade_out_shape ();
318 AudioRegionView::fade_in_active_changed ()
320 if (start_xfade_rect) {
321 if (audio_region()->fade_in_active()) {
322 start_xfade_rect->set_fill (false);
324 start_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_InactiveCrossfade());
325 start_xfade_rect->set_fill (true);
331 AudioRegionView::fade_out_active_changed ()
333 if (end_xfade_rect) {
334 if (audio_region()->fade_out_active()) {
335 end_xfade_rect->set_fill (false);
337 end_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_InactiveCrossfade());
338 end_xfade_rect->set_fill (true);
345 AudioRegionView::region_scale_amplitude_changed ()
347 for (uint32_t n = 0; n < waves.size(); ++n) {
348 waves[n]->gain_changed ();
353 AudioRegionView::region_renamed ()
355 std::string str = RegionView::make_name ();
357 if (audio_region()->speed_mismatch (trackview.session()->frame_rate())) {
358 str = string ("*") + str;
361 if (_region->muted()) {
362 str = string ("!") + str;
365 set_item_name (str, this);
370 AudioRegionView::region_resized (const PropertyChange& what_changed)
372 AudioGhostRegion* agr;
374 RegionView::region_resized(what_changed);
375 PropertyChange interesting_stuff;
377 interesting_stuff.add (ARDOUR::Properties::start);
378 interesting_stuff.add (ARDOUR::Properties::length);
380 if (what_changed.contains (interesting_stuff)) {
382 for (uint32_t n = 0; n < waves.size(); ++n) {
383 waves[n]->region_resized ();
386 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
387 if ((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
389 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
390 (*w)->region_resized ();
395 /* hide transient lines that extend beyond the region end */
397 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
399 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
400 if (l->first > _region->length() - 1) {
410 AudioRegionView::reset_width_dependent_items (double pixel_width)
412 RegionView::reset_width_dependent_items(pixel_width);
413 assert(_pixel_width == pixel_width);
415 if (pixel_width <= 6.0 || _height < 5.0 || !trackview.session()->config.get_show_region_fades()) {
416 if (fade_in_handle) { fade_in_handle->hide(); }
417 if (fade_out_handle) { fade_out_handle->hide(); }
418 if (fade_in_trim_handle) { fade_in_trim_handle->hide(); }
419 if (fade_out_trim_handle) { fade_out_trim_handle->hide(); }
422 AnalysisFeatureList analysis_features = _region->transients();
423 AnalysisFeatureList::const_iterator i;
425 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
427 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
429 float x_pos = trackview.editor().sample_to_pixel (*i);
431 (*l).second->set (ArdourCanvas::Duple (x_pos, 2.0),
432 ArdourCanvas::Duple (x_pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
436 (*l).second->set (ArdourCanvas::Duple (x_pos, 2.0),
437 ArdourCanvas::Duple (x_pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
440 reset_fade_shapes ();
444 AudioRegionView::region_muted ()
446 RegionView::region_muted();
447 set_waveform_colors ();
451 AudioRegionView::setup_fade_handle_positions()
453 /* position of fade handle offset from the top of the region view */
454 double const handle_pos = 0.0;
456 if (fade_in_handle) {
457 fade_in_handle->set_y0 (handle_pos);
458 fade_in_handle->set_y1 (handle_pos + handle_size);
461 if (fade_out_handle) {
462 fade_out_handle->set_y0 (handle_pos);
463 fade_out_handle->set_y1 (handle_pos + handle_size);
466 if (fade_in_trim_handle) {
467 fade_in_trim_handle->set_y0 (_height - handle_size);
468 fade_in_trim_handle->set_y1 (_height);
471 if (fade_out_trim_handle) {
472 fade_out_trim_handle->set_y0 (_height - handle_size );
473 fade_out_trim_handle->set_y1 (_height);
478 AudioRegionView::set_height (gdouble height)
480 RegionView::set_height (height);
482 uint32_t wcnt = waves.size();
484 for (uint32_t n = 0; n < wcnt; ++n) {
487 if (height < NAME_HIGHLIGHT_THRESH) {
488 ht = ((height - 2 * wcnt) / (double) wcnt);
490 ht = (((height - 2 * wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
493 gdouble yoff = n * (ht + 1);
495 waves[n]->set_height (ht);
496 waves[n]->set_y_position (yoff + 2);
501 if ((height/wcnt) < NAME_HIGHLIGHT_THRESH) {
504 update_envelope_visibility ();
507 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE) - 2);
510 reset_fade_shapes ();
512 /* Update hights for any active feature lines */
513 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
515 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
517 float pos_x = trackview.editor().sample_to_pixel((*l).first);
519 if (height >= NAME_HIGHLIGHT_THRESH) {
520 (*l).second->set (ArdourCanvas::Duple (pos_x, 2.0),
521 ArdourCanvas::Duple (pos_x, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
523 (*l).second->set (ArdourCanvas::Duple (pos_x, 2.0),
524 ArdourCanvas::Duple (pos_x, _height - 1));
529 name_text->raise_to_top();
534 AudioRegionView::reset_fade_shapes ()
536 if (!trim_fade_in_drag_active) { reset_fade_in_shape (); }
537 if (!trim_fade_out_drag_active) { reset_fade_out_shape (); }
541 AudioRegionView::reset_fade_in_shape ()
543 reset_fade_in_shape_width (audio_region(), (framecnt_t) audio_region()->fade_in()->back()->when);
547 AudioRegionView::reset_fade_in_shape_width (boost::shared_ptr<AudioRegion> ar, framecnt_t width, bool drag_active)
549 trim_fade_in_drag_active = drag_active;
550 if (fade_in_handle == 0) {
554 /* smallest size for a fade is 64 frames */
556 width = std::max ((framecnt_t) 64, width);
558 /* round here to prevent little visual glitches with sub-pixel placement */
559 double const pwidth = rint (width / samples_per_pixel);
560 double const handle_left = pwidth;
562 /* Put the fade in handle so that its left side is at the end-of-fade line */
563 fade_in_handle->set_x0 (handle_left);
564 fade_in_handle->set_x1 (handle_left + handle_size);
566 if (fade_in_trim_handle) {
567 fade_in_trim_handle->set_x0 (0);
568 fade_in_trim_handle->set_x1 (handle_size);
576 if (!trackview.session()->config.get_show_region_fades()) {
581 double effective_height;
583 if (_height >= NAME_HIGHLIGHT_THRESH) {
584 effective_height = _height - NAME_HIGHLIGHT_SIZE;
586 effective_height = _height;
589 /* points *MUST* be in anti-clockwise order */
592 Points::size_type npoints;
593 Points::size_type pi;
594 boost::shared_ptr<const Evoral::ControlList> list (audio_region()->fade_in());
595 Evoral::ControlList::const_iterator x;
596 double length = list->length();
597 npoints = list->size();
599 points.assign (list->size(), Duple());
601 for (x = list->begin(), pi = 0; x != list->end(); ++x, ++pi) {
602 points[pi].x = 1.0 + (pwidth * ((*x)->when/length));
603 points[pi].y = effective_height - ((*x)->value * effective_height);
608 redraw_start_xfade_to (ar, width, points, effective_height, handle_left);
610 /* ensure trim handle stays on top */
611 if (frame_handle_start) {
612 frame_handle_start->raise_to_top();
617 AudioRegionView::reset_fade_out_shape ()
619 reset_fade_out_shape_width (audio_region(), (framecnt_t) audio_region()->fade_out()->back()->when);
623 AudioRegionView::reset_fade_out_shape_width (boost::shared_ptr<AudioRegion> ar, framecnt_t width, bool drag_active)
625 trim_fade_out_drag_active = drag_active;
626 if (fade_out_handle == 0) {
630 /* smallest size for a fade is 64 frames */
632 width = std::max ((framecnt_t) 64, width);
634 double const pwidth = rint(trackview.editor().sample_to_pixel (width));
636 /* the right edge should be right on the region frame is the pixel
637 * width is zero. Hence the additional + 1.0 at the end.
640 double const handle_right = rint(trackview.editor().sample_to_pixel (_region->length()) + TimeAxisViewItem::RIGHT_EDGE_SHIFT - pwidth);
641 double const trim_handle_right = rint(trackview.editor().sample_to_pixel (_region->length()) + TimeAxisViewItem::RIGHT_EDGE_SHIFT);
643 /* Put the fade out handle so that its right side is at the end-of-fade line;
645 fade_out_handle->set_x0 (1 + handle_right - handle_size);
646 fade_out_handle->set_x1 (1 + handle_right);
647 if (fade_out_trim_handle) {
648 fade_out_trim_handle->set_x0 (1 + trim_handle_right - handle_size);
649 fade_out_trim_handle->set_x1 (1 + trim_handle_right);
652 /* don't show shape if its too small */
659 if (!trackview.session()->config.get_show_region_fades()) {
664 double effective_height;
666 if (_height >= NAME_HIGHLIGHT_THRESH) {
667 effective_height = _height - NAME_HIGHLIGHT_SIZE;
669 effective_height = _height;
672 /* points *MUST* be in anti-clockwise order */
675 Points::size_type npoints;
676 Points::size_type pi;
677 boost::shared_ptr<const Evoral::ControlList> list (audio_region()->fade_out());
678 Evoral::ControlList::const_iterator x;
679 double length = list->length();
680 npoints = list->size();
682 points.assign (list->size(), Duple());
684 for (x = list->begin(), pi = 0; x != list->end(); ++x, ++pi) {
685 points[pi].x = 1.0 + _pixel_width - pwidth + (pwidth * ((*x)->when/length));
686 points[pi].y = effective_height - ((*x)->value * effective_height);
691 redraw_end_xfade_to (ar, width, points, effective_height, handle_right, pwidth);
693 /* ensure trim handle stays on top */
694 if (frame_handle_end) {
695 frame_handle_end->raise_to_top();
700 AudioRegionView::get_fade_in_shape_width ()
702 return audio_region()->fade_in()->back()->when;
706 AudioRegionView::get_fade_out_shape_width ()
708 return audio_region()->fade_out()->back()->when;
713 AudioRegionView::redraw_start_xfade ()
715 boost::shared_ptr<AudioRegion> ar (audio_region());
717 if (!ar->fade_in() || ar->fade_in()->empty()) {
722 reset_fade_in_shape_width (ar, ar->fade_in()->back()->when);
726 AudioRegionView::redraw_start_xfade_to (boost::shared_ptr<AudioRegion> ar, framecnt_t /*width*/, Points& points, double effective_height,
729 if (points.size() < 2) {
733 if (!start_xfade_curve) {
734 start_xfade_curve = new ArdourCanvas::XFadeCurve (group, ArdourCanvas::XFadeCurve::Start);
735 CANVAS_DEBUG_NAME (start_xfade_curve, string_compose ("xfade start out line for %1", region()->name()));
736 start_xfade_curve->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
737 start_xfade_curve->set_outline_color (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine());
738 start_xfade_curve->set_ignore_events (true);
740 if (!start_xfade_rect) {
741 start_xfade_rect = new ArdourCanvas::Rectangle (group);
742 CANVAS_DEBUG_NAME (start_xfade_rect, string_compose ("xfade start rect for %1", region()->name()));
743 start_xfade_rect->set_outline_color (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine());
744 start_xfade_rect->set_fill (false);
745 start_xfade_rect->set_outline (true);
746 start_xfade_rect->set_outline_width (0.5);
747 start_xfade_rect->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_start_xfade_event), start_xfade_rect, this));
748 start_xfade_rect->set_data ("regionview", this);
751 start_xfade_rect->set (ArdourCanvas::Rect (0.0, 0.0, rect_width + TimeAxisViewItem::RIGHT_EDGE_SHIFT, effective_height));
755 boost::shared_ptr<AutomationList> inverse = ar->inverse_fade_in ();
757 Points::size_type npoints;
761 /* there is no explicit inverse fade in curve, so take the
762 * regular fade in curve given to use as "points" (already a
763 * set of coordinates), and convert to the inverse shape.
766 npoints = points.size();
767 ipoints.assign (npoints, Duple());
769 for (Points::size_type i = 0, pci = 0; i < npoints; ++i, ++pci) {
770 ArdourCanvas::Duple &p (ipoints[pci]);
771 /* leave x-axis alone but invert with respect to y-axis */
772 p.y = effective_height - points[pci].y;
777 /* there is an explicit inverse fade in curve. Grab the points
778 and convert them into coordinates for the inverse fade in
782 npoints = inverse->size();
783 ipoints.assign (npoints, Duple());
785 Evoral::ControlList::const_iterator x;
786 Points::size_type pi;
787 double length = inverse->length();
789 for (x = inverse->begin(), pi = 0; x != inverse->end(); ++x, ++pi) {
790 ArdourCanvas::Duple& p (ipoints[pi]);
791 p.x = 1.0 + (rect_width * ((*x)->when/length));
792 p.y = effective_height - ((*x)->value * effective_height);
796 start_xfade_curve->set_inout (points, ipoints);
802 AudioRegionView::redraw_end_xfade ()
804 boost::shared_ptr<AudioRegion> ar (audio_region());
806 if (!ar->fade_out() || ar->fade_out()->empty()) {
812 reset_fade_out_shape_width (ar, ar->fade_out()->back()->when);
816 AudioRegionView::redraw_end_xfade_to (boost::shared_ptr<AudioRegion> ar, framecnt_t width, Points& points, double effective_height,
817 double rect_edge, double rect_width)
819 if (points.size() < 2) {
823 if (!end_xfade_curve) {
824 end_xfade_curve = new ArdourCanvas::XFadeCurve (group, ArdourCanvas::XFadeCurve::End);
825 CANVAS_DEBUG_NAME (end_xfade_curve, string_compose ("xfade end out line for %1", region()->name()));
826 end_xfade_curve->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
827 end_xfade_curve->set_outline_color (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine());
828 end_xfade_curve->set_ignore_events (true);
831 if (!end_xfade_rect) {
832 end_xfade_rect = new ArdourCanvas::Rectangle (group);
833 CANVAS_DEBUG_NAME (end_xfade_rect, string_compose ("xfade end rect for %1", region()->name()));
834 end_xfade_rect->set_outline_color (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine());
835 end_xfade_rect->set_fill (false);
836 end_xfade_rect->set_outline (true);
837 end_xfade_rect->set_outline_width (0.5);
838 end_xfade_rect->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_end_xfade_event), end_xfade_rect, this));
839 end_xfade_rect->set_data ("regionview", this);
842 end_xfade_rect->set (ArdourCanvas::Rect (rect_edge, 0.0, rect_edge + rect_width + TimeAxisViewItem::RIGHT_EDGE_SHIFT, effective_height));
846 boost::shared_ptr<AutomationList> inverse = ar->inverse_fade_out ();
848 Points::size_type npoints;
852 /* there is no explicit inverse fade out curve, so take the
853 * regular fade out curve given to use as "points" (already a
854 * set of coordinates), and convert to the inverse shape.
857 npoints = points.size();
858 ipoints.assign (npoints, Duple());
860 Points::size_type pci;
862 for (pci = 0; pci < npoints; ++pci) {
863 ArdourCanvas::Duple &p (ipoints[pci]);
864 p.y = effective_height - points[pci].y;
869 /* there is an explicit inverse fade out curve. Grab the points
870 and convert them into coordinates for the inverse fade out
874 npoints = inverse->size();
875 ipoints.assign (npoints, Duple());
877 const double rend = trackview.editor().sample_to_pixel (_region->length() - width);
879 Evoral::ControlList::const_iterator x;
881 Points::size_type pi;
882 double length = inverse->length();
884 for (x = inverse->begin(), i = 0, pi = 0; x != inverse->end(); ++x, ++pi, ++i) {
885 ArdourCanvas::Duple& p (ipoints[pi]);
886 p.x = 1.0 + (rect_width * ((*x)->when/length)) + rend;
887 p.y = effective_height - ((*x)->value * effective_height);
891 end_xfade_curve->set_inout (ipoints, points);
897 AudioRegionView::hide_xfades ()
904 AudioRegionView::hide_start_xfade ()
906 if (start_xfade_curve) {
907 start_xfade_curve->hide();
909 if (start_xfade_rect) {
910 start_xfade_rect->hide ();
913 _start_xfade_visible = false;
917 AudioRegionView::hide_end_xfade ()
919 if (end_xfade_curve) {
920 end_xfade_curve->hide();
922 if (end_xfade_rect) {
923 end_xfade_rect->hide ();
926 _end_xfade_visible = false;
930 AudioRegionView::show_start_xfade ()
932 if (start_xfade_curve) {
933 start_xfade_curve->show();
935 if (start_xfade_rect) {
936 start_xfade_rect->show ();
939 _start_xfade_visible = true;
943 AudioRegionView::show_end_xfade ()
945 if (end_xfade_curve) {
946 end_xfade_curve->show();
948 if (end_xfade_rect) {
949 end_xfade_rect->show ();
952 _end_xfade_visible = true;
956 AudioRegionView::set_samples_per_pixel (gdouble fpp)
958 RegionView::set_samples_per_pixel (fpp);
960 if (Config->get_show_waveforms ()) {
961 for (uint32_t n = 0; n < waves.size(); ++n) {
962 waves[n]->set_samples_per_pixel (fpp);
970 reset_fade_shapes ();
974 AudioRegionView::set_amplitude_above_axis (gdouble a)
976 for (uint32_t n=0; n < waves.size(); ++n) {
977 waves[n]->set_amplitude_above_axis (a);
982 AudioRegionView::compute_colors (Gdk::Color const & basic_color)
984 RegionView::compute_colors (basic_color);
986 /* gain color computed in envelope_active_changed() */
988 fade_color = UINT_RGBA_CHANGE_A (fill_color, 120);
992 AudioRegionView::set_colors ()
994 RegionView::set_colors();
997 gain_line->set_line_color (audio_region()->envelope_active() ?
998 ARDOUR_UI::config()->get_canvasvar_GainLine() :
999 ARDOUR_UI::config()->get_canvasvar_GainLineInactive());
1002 set_waveform_colors ();
1004 if (start_xfade_curve) {
1005 start_xfade_curve->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
1006 start_xfade_curve->set_outline_color (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine());
1008 if (end_xfade_curve) {
1009 end_xfade_curve->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
1010 end_xfade_curve->set_outline_color (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine());
1013 if (start_xfade_rect) {
1014 start_xfade_rect->set_outline_color (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine());
1016 if (end_xfade_rect) {
1017 end_xfade_rect->set_outline_color (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine());
1022 AudioRegionView::setup_waveform_visibility ()
1024 if (Config->get_show_waveforms ()) {
1025 for (uint32_t n = 0; n < waves.size(); ++n) {
1026 /* make sure the zoom level is correct, since we don't update
1027 this when waveforms are hidden.
1030 // waves[n]->set_samples_per_pixel (_samples_per_pixel);
1034 for (uint32_t n = 0; n < waves.size(); ++n) {
1041 AudioRegionView::temporarily_hide_envelope ()
1049 AudioRegionView::unhide_envelope ()
1051 update_envelope_visibility ();
1055 AudioRegionView::update_envelope_visibility ()
1061 if (Config->get_show_region_gain() || trackview.editor().current_mouse_mode() == Editing::MouseGain) {
1062 gain_line->add_visibility (AutomationLine::Line);
1069 AudioRegionView::create_waves ()
1071 // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
1072 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
1078 ChanCount nchans = atv.track()->n_channels();
1080 // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data
1081 // << " and channels = " << nchans.n_audio() << endl;
1083 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
1084 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
1085 tmp_waves.push_back (0);
1088 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
1092 _data_ready_connections.clear ();
1094 for (uint32_t i = 0; i < nchans.n_audio(); ++i) {
1095 _data_ready_connections.push_back (0);
1098 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
1100 if (n >= audio_region()->n_channels()) {
1104 // cerr << "\tchannel " << n << endl;
1106 if (wait_for_data) {
1107 if (audio_region()->audio_source(n)->peaks_ready (boost::bind (&AudioRegionView::peaks_ready_handler, this, n), &_data_ready_connections[n], gui_context())) {
1108 // cerr << "\tData is ready\n";
1109 create_one_wave (n, true);
1111 // cerr << "\tdata is not ready\n";
1112 // we'll get a PeaksReady signal from the source in the future
1113 // and will call create_one_wave(n) then.
1117 // cerr << "\tdon't delay, display today!\n";
1118 create_one_wave (n, true);
1125 AudioRegionView::create_one_wave (uint32_t which, bool /*direct*/)
1127 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
1128 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
1129 uint32_t nchans = atv.track()->n_channels().n_audio();
1131 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
1134 if (trackview.current_height() < NAME_HIGHLIGHT_THRESH) {
1135 ht = ((trackview.current_height()) / (double) nchans);
1137 ht = ((trackview.current_height() - NAME_HIGHLIGHT_SIZE) / (double) nchans);
1140 gdouble yoff = which * ht;
1142 WaveView *wave = new WaveView (group, audio_region ());
1143 CANVAS_DEBUG_NAME (wave, string_compose ("wave view for chn %1 of %2", which, get_item_name()));
1145 wave->set_channel (which);
1146 wave->set_y_position (yoff);
1147 wave->set_height (ht);
1148 wave->set_samples_per_pixel (samples_per_pixel);
1149 wave->set_show_zero_line (true);
1151 switch (Config->get_waveform_shape()) {
1153 wave->set_shape (WaveView::Rectified);
1156 wave->set_shape (WaveView::Normal);
1159 wave->set_logscaled (Config->get_waveform_scale() == Logarithmic);
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) {
1313 if (fade_in_handle) {
1314 fade_in_handle->show ();
1315 fade_in_handle->raise_to_top ();
1317 if (fade_out_handle) {
1318 fade_out_handle->show ();
1319 fade_out_handle->raise_to_top ();
1321 if (fade_in_trim_handle) {
1322 fade_in_trim_handle->show ();
1323 fade_in_trim_handle->raise_to_top ();
1325 if (fade_out_trim_handle) {
1326 fade_out_trim_handle->show ();
1327 fade_out_trim_handle->raise_to_top ();
1333 AudioRegionView::exited ()
1335 trackview.editor().set_current_trimmable (boost::shared_ptr<Trimmable>());
1336 trackview.editor().set_current_movable (boost::shared_ptr<Movable>());
1339 gain_line->remove_visibility (AutomationLine::ControlPoints);
1342 if (fade_in_handle) { fade_in_handle->hide(); }
1343 if (fade_out_handle) { fade_out_handle->hide(); }
1344 if (fade_in_trim_handle) { fade_in_trim_handle->hide(); }
1345 if (fade_out_trim_handle) { fade_out_trim_handle->hide(); }
1349 AudioRegionView::envelope_active_changed ()
1352 gain_line->set_line_color (audio_region()->envelope_active() ?
1353 ARDOUR_UI::config()->get_canvasvar_GainLine() :
1354 ARDOUR_UI::config()->get_canvasvar_GainLineInactive());
1355 update_envelope_visibility ();
1360 AudioRegionView::color_handler ()
1362 //case cMutedWaveForm:
1364 //case cWaveFormClip:
1368 //case cGainLineInactive:
1370 envelope_active_changed();
1375 AudioRegionView::set_waveform_colors ()
1377 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1378 set_one_waveform_color (*w);
1383 AudioRegionView::set_one_waveform_color (ArdourCanvas::WaveView* wave)
1385 ArdourCanvas::Color fill;
1386 ArdourCanvas::Color outline;
1389 if (_region->muted()) {
1390 /* hide outline with zero alpha */
1391 outline = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_SelectedWaveForm(), 0);
1392 fill = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_SelectedWaveFormFill(), MUTED_ALPHA);
1394 outline = ARDOUR_UI::config()->get_canvasvar_SelectedWaveForm();
1395 fill = ARDOUR_UI::config()->get_canvasvar_SelectedWaveFormFill();
1399 outline = ARDOUR_UI::config()->get_canvasvar_RecWaveForm();
1400 fill = ARDOUR_UI::config()->get_canvasvar_RecWaveFormFill();
1402 if (_region->muted()) {
1403 /* hide outline with zero alpha */
1404 outline = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_WaveForm(), 0);
1405 fill = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_WaveFormFill(), MUTED_ALPHA);
1407 outline = ARDOUR_UI::config()->get_canvasvar_WaveForm();
1408 fill = ARDOUR_UI::config()->get_canvasvar_WaveFormFill();
1413 if (ARDOUR_UI::config()->get_color_regions_using_track_color()) {
1415 /* just use a slightly transparent version of the selected
1416 * color so that some of the track color bleeds through
1420 ArdourCanvas::color_to_rgba (fill, r, g, b, a);
1421 fill = ArdourCanvas::rgba_to_color (r, g, b, 0.85); /* magic number, not user controllable */
1422 outline = ARDOUR_UI::config()->get_canvasvar_WaveForm();
1424 if (!Config->get_show_name_highlight()) {
1425 /* recolor name text because it needs to contrast with
1426 the waveform background, not the name highlight.
1431 wave->set_fill_color (fill);
1432 wave->set_outline_color (outline);
1433 wave->set_clip_color (ARDOUR_UI::config()->get_canvasvar_WaveFormClip());
1434 wave->set_zero_color (ARDOUR_UI::config()->get_canvasvar_ZeroLine());
1438 AudioRegionView::set_frame_color ()
1444 if (_region->opaque()) {
1450 TimeAxisViewItem::set_frame_color ();
1452 set_waveform_colors ();
1456 AudioRegionView::set_fade_visibility (bool yn)
1459 if (fade_in_handle) { fade_in_handle->show(); }
1460 if (fade_out_handle) { fade_out_handle->show(); }
1461 if (fade_in_trim_handle) { fade_in_trim_handle->show(); }
1462 if (fade_out_trim_handle) { fade_out_trim_handle->show(); }
1464 if (fade_in_handle) { fade_in_handle->hide(); }
1465 if (fade_out_handle) { fade_out_handle->hide(); }
1466 if (fade_in_trim_handle) { fade_in_trim_handle->hide(); }
1467 if (fade_out_trim_handle) { fade_out_trim_handle->hide(); }
1472 AudioRegionView::update_coverage_frames (LayerDisplay d)
1474 RegionView::update_coverage_frames (d);
1476 if (fade_in_handle) { fade_in_handle->raise_to_top (); }
1477 if (fade_out_handle) { fade_out_handle->raise_to_top (); }
1478 if (fade_in_trim_handle) { fade_in_trim_handle->raise_to_top (); }
1479 if (fade_out_trim_handle) { fade_out_trim_handle->raise_to_top (); }
1483 AudioRegionView::show_region_editor ()
1486 editor = new AudioRegionEditor (trackview.session(), audio_region());
1494 AudioRegionView::transients_changed ()
1496 AnalysisFeatureList analysis_features = _region->transients();
1498 while (feature_lines.size() < analysis_features.size()) {
1500 ArdourCanvas::Line* canvas_item = new ArdourCanvas::Line(group);
1501 CANVAS_DEBUG_NAME (canvas_item, string_compose ("transient group for %1", region()->name()));
1503 canvas_item->set (ArdourCanvas::Duple (-1.0, 2.0),
1504 ArdourCanvas::Duple (1.0, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
1506 canvas_item->raise_to_top ();
1507 canvas_item->show ();
1509 canvas_item->set_data ("regionview", this);
1510 canvas_item->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_feature_line_event), canvas_item, this));
1512 feature_lines.push_back (make_pair(0, canvas_item));
1515 while (feature_lines.size() > analysis_features.size()) {
1516 ArdourCanvas::Line* line = feature_lines.back().second;
1517 feature_lines.pop_back ();
1521 AnalysisFeatureList::const_iterator i;
1522 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1524 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
1526 float *pos = new float;
1527 *pos = trackview.editor().sample_to_pixel (*i);
1530 ArdourCanvas::Duple (*pos, 2.0),
1531 ArdourCanvas::Duple (*pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1)
1534 (*l).second->set_data ("position", pos);
1540 AudioRegionView::update_transient(float /*old_pos*/, float new_pos)
1542 /* Find frame at old pos, calulate new frame then update region transients*/
1543 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1545 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1547 /* Line has been updated in drag so we compare to new_pos */
1549 float* pos = (float*) (*l).second->get_data ("position");
1551 if (rint(new_pos) == rint(*pos)) {
1553 framepos_t old_frame = (*l).first;
1554 framepos_t new_frame = trackview.editor().pixel_to_sample (new_pos);
1556 _region->update_transient (old_frame, new_frame);
1564 AudioRegionView::remove_transient(float pos)
1566 /* Find frame at old pos, calulate new frame then update region transients*/
1567 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1569 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1571 /* Line has been updated in drag so we compare to new_pos */
1572 float *line_pos = (float*) (*l).second->get_data ("position");
1574 if (rint(pos) == rint(*line_pos)) {
1575 _region->remove_transient ((*l).first);
1582 AudioRegionView::thaw_after_trim ()
1584 RegionView::thaw_after_trim ();
1591 AudioRegionView::show_xfades ()
1593 show_start_xfade ();
1598 AudioRegionView::drag_start ()
1600 TimeAxisViewItem::drag_start ();
1602 //we used to hide xfades here. I don't see the point with the new model, but we can re-implement if needed
1606 AudioRegionView::drag_end ()
1608 TimeAxisViewItem::drag_end ();
1610 //see comment for drag_start
1614 AudioRegionView::parameter_changed (string const & p)
1616 if (p == "show-waveforms") {
1617 setup_waveform_visibility ();