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/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 = 15; /* 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)
86 , start_xfade_rect (0)
87 , _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)
105 , start_xfade_out (0)
106 , start_xfade_rect (0)
107 , _start_xfade_visible (false)
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))
123 , start_xfade_out (0)
124 , start_xfade_rect (0)
125 , _start_xfade_visible (false)
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 ();
174 setup_fade_handle_positions ();
176 if (!trackview.session()->config.get_show_region_fades()) {
177 set_fade_visibility (false);
180 const string line_name = _region->name() + ":gain";
182 if (!Profile->get_sae()) {
183 gain_line.reset (new AudioRegionGainLine (line_name, *this, *group, audio_region()->envelope()));
186 update_envelope_visibility ();
189 set_height (trackview.current_height());
192 region_sync_changed ();
194 region_resized (ARDOUR::bounds_change);
196 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
197 (*i)->set_duration (_region->length() / samples_per_pixel);
201 envelope_active_changed ();
202 fade_in_active_changed ();
203 fade_out_active_changed ();
205 reset_width_dependent_items (_pixel_width);
207 if (fade_in_handle) {
208 fade_in_handle->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
211 if (fade_out_handle) {
212 fade_out_handle->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
217 setup_waveform_visibility ();
218 setup_waveform_shape ();
220 if (frame_handle_start) {
221 frame_handle_start->raise_to_top ();
223 if (frame_handle_end) {
224 frame_handle_end->raise_to_top ();
227 /* XXX sync mark drag? */
230 AudioRegionView::~AudioRegionView ()
232 in_destructor = true;
234 RegionViewGoingAway (this); /* EMIT_SIGNAL */
236 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
240 for (list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator i = feature_lines.begin(); i != feature_lines.end(); ++i) {
241 delete ((*i).second);
244 /* all waveviews etc will be destroyed when the group is destroyed */
247 boost::shared_ptr<ARDOUR::AudioRegion>
248 AudioRegionView::audio_region() const
250 // "Guaranteed" to succeed...
251 return boost::dynamic_pointer_cast<AudioRegion>(_region);
255 AudioRegionView::region_changed (const PropertyChange& what_changed)
257 ENSURE_GUI_THREAD (*this, &AudioRegionView::region_changed, what_changed);
259 RegionView::region_changed (what_changed);
261 if (what_changed.contains (ARDOUR::Properties::scale_amplitude)) {
262 region_scale_amplitude_changed ();
264 if (what_changed.contains (ARDOUR::Properties::fade_in)) {
267 if (what_changed.contains (ARDOUR::Properties::fade_out)) {
270 if (what_changed.contains (ARDOUR::Properties::fade_in_active)) {
271 fade_in_active_changed ();
273 if (what_changed.contains (ARDOUR::Properties::fade_out_active)) {
274 fade_out_active_changed ();
276 if (what_changed.contains (ARDOUR::Properties::envelope_active)) {
277 envelope_active_changed ();
279 if (what_changed.contains (ARDOUR::Properties::valid_transients)) {
280 transients_changed ();
285 AudioRegionView::fade_in_changed ()
287 reset_fade_in_shape ();
291 AudioRegionView::fade_out_changed ()
293 reset_fade_out_shape ();
297 AudioRegionView::fade_in_active_changed ()
299 if (start_xfade_rect) {
300 if (audio_region()->fade_in_active()) {
301 start_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
303 start_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_InactiveCrossfade());
309 AudioRegionView::fade_out_active_changed ()
311 if (end_xfade_rect) {
312 if (audio_region()->fade_out_active()) {
313 end_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
315 end_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_InactiveCrossfade());
322 AudioRegionView::region_scale_amplitude_changed ()
324 for (uint32_t n = 0; n < waves.size(); ++n) {
325 waves[n]->gain_changed ();
330 AudioRegionView::region_renamed ()
332 std::string str = RegionView::make_name ();
334 if (audio_region()->speed_mismatch (trackview.session()->frame_rate())) {
335 str = string ("*") + str;
338 if (_region->muted()) {
339 str = string ("!") + str;
342 set_item_name (str, this);
347 AudioRegionView::region_resized (const PropertyChange& what_changed)
349 AudioGhostRegion* agr;
351 RegionView::region_resized(what_changed);
352 PropertyChange interesting_stuff;
354 interesting_stuff.add (ARDOUR::Properties::start);
355 interesting_stuff.add (ARDOUR::Properties::length);
357 if (what_changed.contains (interesting_stuff)) {
359 for (uint32_t n = 0; n < waves.size(); ++n) {
360 waves[n]->region_resized ();
363 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
364 if ((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
366 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
367 (*w)->region_resized ();
372 /* hide transient lines that extend beyond the region end */
374 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
376 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
377 if (l->first > _region->length() - 1) {
387 AudioRegionView::reset_width_dependent_items (double pixel_width)
389 RegionView::reset_width_dependent_items(pixel_width);
390 assert(_pixel_width == pixel_width);
392 if (fade_in_handle) {
393 if (pixel_width <= 6.0 || _height < 5.0 || !trackview.session()->config.get_show_region_fades()) {
394 fade_in_handle->hide();
395 fade_out_handle->hide();
397 //fade_in_handle->show();
398 //fade_out_handle->show();
402 AnalysisFeatureList analysis_features = _region->transients();
403 AnalysisFeatureList::const_iterator i;
405 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
407 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
409 float x_pos = trackview.editor().sample_to_pixel (*i);
411 (*l).second->set (ArdourCanvas::Duple (x_pos, 2.0),
412 ArdourCanvas::Duple (x_pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
416 (*l).second->set (ArdourCanvas::Duple (x_pos, 2.0),
417 ArdourCanvas::Duple (x_pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
420 reset_fade_shapes ();
424 AudioRegionView::region_muted ()
426 RegionView::region_muted();
427 set_waveform_colors ();
431 AudioRegionView::setup_fade_handle_positions()
433 /* position of fade handle offset from the top of the region view */
434 double const handle_pos = 0.0;
436 if (fade_in_handle) {
437 fade_in_handle->set_y0 (handle_pos);
438 fade_in_handle->set_y1 (handle_pos + handle_size);
441 if (fade_out_handle) {
442 fade_out_handle->set_y0 (handle_pos);
443 fade_out_handle->set_y1 (handle_pos + handle_size);
448 AudioRegionView::set_height (gdouble height)
450 RegionView::set_height (height);
452 uint32_t wcnt = waves.size();
454 for (uint32_t n = 0; n < wcnt; ++n) {
457 if (height < NAME_HIGHLIGHT_THRESH) {
458 ht = ((height - 2 * wcnt) / (double) wcnt);
460 ht = (((height - 2 * wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
463 gdouble yoff = n * (ht + 1);
465 waves[n]->set_height (ht);
466 waves[n]->set_y_position (yoff + 2);
471 if ((height/wcnt) < NAME_HIGHLIGHT_THRESH) {
474 update_envelope_visibility ();
477 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE) - 2);
480 reset_fade_shapes ();
482 /* Update hights for any active feature lines */
483 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
485 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
487 float pos_x = trackview.editor().sample_to_pixel((*l).first);
489 if (height >= NAME_HIGHLIGHT_THRESH) {
490 (*l).second->set (ArdourCanvas::Duple (pos_x, 2.0),
491 ArdourCanvas::Duple (pos_x, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
493 (*l).second->set (ArdourCanvas::Duple (pos_x, 2.0),
494 ArdourCanvas::Duple (pos_x, _height - 1));
499 name_text->raise_to_top();
504 AudioRegionView::reset_fade_shapes ()
506 reset_fade_in_shape ();
507 reset_fade_out_shape ();
511 AudioRegionView::reset_fade_in_shape ()
513 reset_fade_in_shape_width (audio_region(), (framecnt_t) audio_region()->fade_in()->back()->when);
517 AudioRegionView::reset_fade_in_shape_width (boost::shared_ptr<AudioRegion> ar, framecnt_t width)
519 if (fade_in_handle == 0) {
523 /* smallest size for a fade is 64 frames */
525 width = std::max ((framecnt_t) 64, width);
527 /* round here to prevent little visual glitches with sub-pixel placement */
528 double const pwidth = rint (width / samples_per_pixel);
529 double const handle_left = pwidth;
531 /* Put the fade in handle so that its left side is at the end-of-fade line */
532 fade_in_handle->set_x0 (handle_left);
533 fade_in_handle->set_x1 (handle_left + handle_size);
540 if (!trackview.session()->config.get_show_region_fades()) {
545 double effective_height;
547 if (_height >= NAME_HIGHLIGHT_THRESH) {
548 effective_height = _height - NAME_HIGHLIGHT_SIZE;
550 effective_height = _height;
553 /* points *MUST* be in anti-clockwise order */
556 Points::size_type npoints;
557 Points::size_type pi;
558 boost::shared_ptr<const Evoral::ControlList> list (audio_region()->fade_in());
559 Evoral::ControlList::const_iterator x;
560 double length = list->length();
561 npoints = list->size();
563 points.assign (list->size(), Duple());
565 for (x = list->begin(), pi = 0; x != list->end(); ++x, ++pi) {
566 points[pi].x = 1.0 + (pwidth * ((*x)->when/length));
567 points[pi].y = effective_height - ((*x)->value * effective_height);
572 redraw_start_xfade_to (ar, width, points, effective_height, handle_left);
574 /* ensure trim handle stays on top */
575 if (frame_handle_start) {
576 frame_handle_start->raise_to_top();
581 AudioRegionView::reset_fade_out_shape ()
583 reset_fade_out_shape_width (audio_region(), (framecnt_t) audio_region()->fade_out()->back()->when);
587 AudioRegionView::reset_fade_out_shape_width (boost::shared_ptr<AudioRegion> ar, framecnt_t width)
589 if (fade_out_handle == 0) {
593 /* smallest size for a fade is 64 frames */
595 width = std::max ((framecnt_t) 64, width);
597 double const pwidth = trackview.editor().sample_to_pixel (width);
599 /* the right edge should be right on the region frame is the pixel
600 * width is zero. Hence the additional + 1.0 at the end.
603 double const handle_right = trackview.editor().sample_to_pixel (_region->length()) + TimeAxisViewItem::RIGHT_EDGE_SHIFT - pwidth;
605 /* Put the fade out handle so that its right side is at the end-of-fade line;
607 fade_out_handle->set_x0 (handle_right - handle_size);
608 fade_out_handle->set_x1 (handle_right);
610 /* don't show shape if its too small */
617 if (!trackview.session()->config.get_show_region_fades()) {
622 double effective_height;
624 if (_height >= NAME_HIGHLIGHT_THRESH) {
625 effective_height = _height - NAME_HIGHLIGHT_SIZE;
627 effective_height = _height;
630 /* points *MUST* be in anti-clockwise order */
633 Points::size_type npoints;
634 Points::size_type pi;
635 boost::shared_ptr<const Evoral::ControlList> list (audio_region()->fade_out());
636 Evoral::ControlList::const_iterator x;
637 double length = list->length();
638 npoints = list->size();
640 points.assign (list->size(), Duple());
642 for (x = list->begin(), pi = 0; x != list->end(); ++x, ++pi) {
643 points[pi].x = 1.0 + _pixel_width - pwidth + (pwidth * ((*x)->when/length));
644 points[pi].y = effective_height - ((*x)->value * effective_height);
649 redraw_end_xfade_to (ar, width, points, effective_height, handle_right, pwidth);
651 /* ensure trim handle stays on top */
652 if (frame_handle_end) {
653 frame_handle_end->raise_to_top();
658 AudioRegionView::get_fade_in_shape_width ()
660 return audio_region()->fade_in()->back()->when;
664 AudioRegionView::get_fade_out_shape_width ()
666 return audio_region()->fade_out()->back()->when;
671 AudioRegionView::redraw_start_xfade ()
673 boost::shared_ptr<AudioRegion> ar (audio_region());
675 if (!ar->fade_in() || ar->fade_in()->empty()) {
680 reset_fade_in_shape_width (ar, ar->fade_in()->back()->when);
684 AudioRegionView::redraw_start_xfade_to (boost::shared_ptr<AudioRegion> ar, framecnt_t /*width*/, Points& points, double effective_height,
687 if (points.size() < 2) {
691 if (!start_xfade_in) {
692 start_xfade_in = new ArdourCanvas::Curve (group);
693 CANVAS_DEBUG_NAME (start_xfade_in, string_compose ("xfade start in line for %1", region()->name()));
694 start_xfade_in->set_outline_color (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine());
695 start_xfade_in->set_outline_width (1.5);
696 start_xfade_in->set_ignore_events (true);
699 if (!start_xfade_out) {
700 start_xfade_out = new ArdourCanvas::Curve (group);
701 CANVAS_DEBUG_NAME (start_xfade_out, string_compose ("xfade start out line for %1", region()->name()));
702 uint32_t col = UINT_RGBA_CHANGE_A (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine(), 128);
703 start_xfade_out->set_outline_color (col);
704 start_xfade_out->set_outline_width (2.0);
705 start_xfade_out->set_ignore_events (true);
708 if (!start_xfade_rect) {
709 start_xfade_rect = new ArdourCanvas::Rectangle (group);
710 CANVAS_DEBUG_NAME (start_xfade_rect, string_compose ("xfade start rect for %1", region()->name()));
711 start_xfade_rect->set_fill (true);
712 start_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
713 start_xfade_rect->set_outline (false);
714 start_xfade_rect->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_start_xfade_event), start_xfade_rect, this));
715 start_xfade_rect->set_data ("regionview", this);
718 start_xfade_rect->set (ArdourCanvas::Rect (1.0, 0.0, rect_width, effective_height));
720 start_xfade_in->set (points);
724 boost::shared_ptr<AutomationList> inverse = ar->inverse_fade_in ();
726 Points::size_type npoints;
730 /* there is no explicit inverse fade in curve, so take the
731 * regular fade in curve given to use as "points" (already a
732 * set of coordinates), and convert to the inverse shape.
735 npoints = points.size();
736 ipoints.assign (npoints, Duple());
738 for (Points::size_type i = 0, pci = 0; i < npoints; ++i, ++pci) {
739 ArdourCanvas::Duple &p (ipoints[pci]);
740 /* leave x-axis alone but invert with respect to y-axis */
741 p.y = effective_height - points[pci].y;
746 /* there is an explicit inverse fade in curve. Grab the points
747 and convert them into coordinates for the inverse fade in
751 npoints = inverse->size();
752 ipoints.assign (npoints, Duple());
754 Evoral::ControlList::const_iterator x;
755 Points::size_type pi;
756 double length = inverse->length();
758 for (x = inverse->begin(), pi = 0; x != inverse->end(); ++x, ++pi) {
759 ArdourCanvas::Duple& p (ipoints[pi]);
760 p.x = 1.0 + (rect_width * ((*x)->when/length));
761 p.y = effective_height - ((*x)->value * effective_height);
765 start_xfade_out->set (ipoints);
771 AudioRegionView::redraw_end_xfade ()
773 boost::shared_ptr<AudioRegion> ar (audio_region());
775 if (!ar->fade_out() || ar->fade_out()->empty()) {
781 reset_fade_out_shape_width (ar, ar->fade_out()->back()->when);
785 AudioRegionView::redraw_end_xfade_to (boost::shared_ptr<AudioRegion> ar, framecnt_t width, Points& points, double effective_height,
786 double rect_edge, double rect_width)
788 if (points.size() < 2) {
793 end_xfade_in = new ArdourCanvas::Curve (group);
794 CANVAS_DEBUG_NAME (end_xfade_in, string_compose ("xfade end in line for %1", region()->name()));
795 uint32_t col UINT_RGBA_CHANGE_A (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine(), 128);
796 end_xfade_in->set_outline_color (col);
797 end_xfade_in->set_outline_width (1.5);
798 end_xfade_in->set_ignore_events (true);
801 if (!end_xfade_out) {
802 end_xfade_out = new ArdourCanvas::Curve (group);
803 CANVAS_DEBUG_NAME (end_xfade_out, string_compose ("xfade end out line for %1", region()->name()));
804 end_xfade_out->set_outline_color (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine());
805 end_xfade_out->set_outline_width (2.0);
806 end_xfade_out->set_ignore_events (true);
809 if (!end_xfade_rect) {
810 end_xfade_rect = new ArdourCanvas::Rectangle (group);
811 CANVAS_DEBUG_NAME (end_xfade_rect, string_compose ("xfade end rect for %1", region()->name()));
812 end_xfade_rect->set_fill (true);
813 end_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
814 end_xfade_rect->set_outline (0);
815 end_xfade_rect->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_end_xfade_event), end_xfade_rect, this));
816 end_xfade_rect->set_data ("regionview", this);
819 end_xfade_rect->set (ArdourCanvas::Rect (rect_edge, 0.0, rect_edge + rect_width + TimeAxisViewItem::RIGHT_EDGE_SHIFT, effective_height));
821 end_xfade_in->set (points);
825 boost::shared_ptr<AutomationList> inverse = ar->inverse_fade_out ();
827 Points::size_type npoints;
831 /* there is no explicit inverse fade out curve, so take the
832 * regular fade out curve given to use as "points" (already a
833 * set of coordinates), and convert to the inverse shape.
836 npoints = points.size();
837 ipoints.assign (npoints, Duple());
839 Points::size_type pci;
841 for (pci = 0; pci < npoints; ++pci) {
842 ArdourCanvas::Duple &p (ipoints[pci]);
843 p.y = effective_height - points[pci].y;
848 /* there is an explicit inverse fade out curve. Grab the points
849 and convert them into coordinates for the inverse fade out
853 npoints = inverse->size();
854 ipoints.assign (npoints, Duple());
856 const double rend = trackview.editor().sample_to_pixel (_region->length() - width);
858 Evoral::ControlList::const_iterator x;
860 Points::size_type pi;
861 double length = inverse->length();
863 for (x = inverse->begin(), i = 0, pi = 0; x != inverse->end(); ++x, ++pi, ++i) {
864 ArdourCanvas::Duple& p (ipoints[pi]);
865 p.x = 1.0 + (rect_width * ((*x)->when/length)) + rend;
866 p.y = effective_height - ((*x)->value * effective_height);
870 end_xfade_out->set (ipoints);
876 AudioRegionView::hide_xfades ()
883 AudioRegionView::hide_start_xfade ()
885 if (start_xfade_in) {
886 start_xfade_in->hide();
888 if (start_xfade_out) {
889 start_xfade_out->hide();
891 if (start_xfade_rect) {
892 start_xfade_rect->hide ();
895 _start_xfade_visible = false;
899 AudioRegionView::hide_end_xfade ()
902 end_xfade_in->hide();
905 end_xfade_out->hide();
907 if (end_xfade_rect) {
908 end_xfade_rect->hide ();
911 _end_xfade_visible = false;
915 AudioRegionView::show_start_xfade ()
917 if (start_xfade_in) {
918 start_xfade_in->show();
920 if (start_xfade_out) {
921 start_xfade_out->show();
923 if (start_xfade_rect) {
924 start_xfade_rect->show ();
927 _start_xfade_visible = true;
931 AudioRegionView::show_end_xfade ()
934 end_xfade_in->show();
937 end_xfade_out->show();
939 if (end_xfade_rect) {
940 end_xfade_rect->show ();
943 _end_xfade_visible = true;
947 AudioRegionView::set_samples_per_pixel (gdouble fpp)
949 RegionView::set_samples_per_pixel (fpp);
951 if (Config->get_show_waveforms ()) {
952 for (uint32_t n = 0; n < waves.size(); ++n) {
953 waves[n]->set_samples_per_pixel (fpp);
961 reset_fade_shapes ();
965 AudioRegionView::set_amplitude_above_axis (gdouble a)
967 for (uint32_t n=0; n < waves.size(); ++n) {
968 waves[n]->set_amplitude_above_axis (a);
973 AudioRegionView::compute_colors (Gdk::Color const & basic_color)
975 RegionView::compute_colors (basic_color);
977 /* gain color computed in envelope_active_changed() */
979 fade_color = UINT_RGBA_CHANGE_A (fill_color, 120);
983 AudioRegionView::set_colors ()
985 RegionView::set_colors();
988 gain_line->set_line_color (audio_region()->envelope_active() ?
989 ARDOUR_UI::config()->get_canvasvar_GainLine() :
990 ARDOUR_UI::config()->get_canvasvar_GainLineInactive());
993 set_waveform_colors ();
995 if (start_xfade_in) {
996 start_xfade_in->set_outline_color (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine());
998 if (start_xfade_out) {
999 uint32_t col UINT_RGBA_CHANGE_A (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine(), 128);
1000 start_xfade_out->set_outline_color (col);
1003 end_xfade_in->set_outline_color (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine());
1005 if (end_xfade_out) {
1006 uint32_t col UINT_RGBA_CHANGE_A (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine(), 128);
1007 end_xfade_out->set_outline_color (col);
1010 if (start_xfade_rect) {
1011 start_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
1013 if (end_xfade_rect) {
1014 end_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
1019 AudioRegionView::setup_waveform_visibility ()
1021 if (Config->get_show_waveforms ()) {
1022 for (uint32_t n = 0; n < waves.size(); ++n) {
1023 /* make sure the zoom level is correct, since we don't update
1024 this when waveforms are hidden.
1027 // waves[n]->set_samples_per_pixel (_samples_per_pixel);
1031 for (uint32_t n = 0; n < waves.size(); ++n) {
1038 AudioRegionView::temporarily_hide_envelope ()
1046 AudioRegionView::unhide_envelope ()
1048 update_envelope_visibility ();
1052 AudioRegionView::update_envelope_visibility ()
1058 if (Config->get_show_region_gain() || trackview.editor().current_mouse_mode() == Editing::MouseGain) {
1059 gain_line->add_visibility (AutomationLine::Line);
1066 AudioRegionView::create_waves ()
1068 // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
1069 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
1075 ChanCount nchans = atv.track()->n_channels();
1077 // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data
1078 // << " and channels = " << nchans.n_audio() << endl;
1080 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
1081 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
1082 tmp_waves.push_back (0);
1085 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
1089 _data_ready_connections.clear ();
1091 for (uint32_t i = 0; i < nchans.n_audio(); ++i) {
1092 _data_ready_connections.push_back (0);
1095 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
1097 if (n >= audio_region()->n_channels()) {
1101 // cerr << "\tchannel " << n << endl;
1103 if (wait_for_data) {
1104 if (audio_region()->audio_source(n)->peaks_ready (boost::bind (&AudioRegionView::peaks_ready_handler, this, n), &_data_ready_connections[n], gui_context())) {
1105 // cerr << "\tData is ready\n";
1106 create_one_wave (n, true);
1108 // cerr << "\tdata is not ready\n";
1109 // we'll get a PeaksReady signal from the source in the future
1110 // and will call create_one_wave(n) then.
1114 // cerr << "\tdon't delay, display today!\n";
1115 create_one_wave (n, true);
1122 AudioRegionView::create_one_wave (uint32_t which, bool /*direct*/)
1124 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
1125 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
1126 uint32_t nchans = atv.track()->n_channels().n_audio();
1128 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
1131 if (trackview.current_height() < NAME_HIGHLIGHT_THRESH) {
1132 ht = ((trackview.current_height()) / (double) nchans);
1134 ht = ((trackview.current_height() - NAME_HIGHLIGHT_SIZE) / (double) nchans);
1137 gdouble yoff = which * ht;
1139 WaveView *wave = new WaveView (group, audio_region ());
1140 CANVAS_DEBUG_NAME (wave, string_compose ("wave view for chn %1 of %2", which, get_item_name()));
1142 wave->set_channel (which);
1143 wave->set_y_position (yoff);
1144 wave->set_height (ht);
1145 wave->set_samples_per_pixel (samples_per_pixel);
1146 wave->set_show_zero_line (true);
1148 switch (Config->get_waveform_shape()) {
1150 wave->set_shape (WaveView::Rectified);
1153 wave->set_shape (WaveView::Normal);
1156 wave->set_logscaled (Config->get_waveform_scale() == Logarithmic);
1158 if (!Config->get_show_waveforms ()) {
1162 /* note: calling this function is serialized by the lock
1163 held in the peak building thread that signals that
1164 peaks are ready for use *or* by the fact that it is
1165 called one by one from the GUI thread.
1168 if (which < nchans) {
1169 tmp_waves[which] = wave;
1171 /* n-channel track, >n-channel source */
1174 /* see if we're all ready */
1176 for (n = 0; n < nchans; ++n) {
1177 if (tmp_waves[n] == 0) {
1182 if (n == nwaves && waves.empty()) {
1183 /* all waves are ready */
1184 tmp_waves.resize(nwaves);
1189 /* all waves created, don't hook into peaks ready anymore */
1190 delete _data_ready_connections[which];
1191 _data_ready_connections[which] = 0;
1196 AudioRegionView::peaks_ready_handler (uint32_t which)
1198 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AudioRegionView::create_one_wave, this, which, false));
1199 // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
1203 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev, bool with_guard_points)
1211 /* don't create points that can't be seen */
1213 update_envelope_visibility ();
1218 item->canvas_to_item (x, y);
1220 framepos_t fx = trackview.editor().pixel_to_sample (x);
1222 if (fx > _region->length()) {
1226 /* compute vertical fractional position */
1228 y = 1.0 - (y / (_height - NAME_HIGHLIGHT_SIZE));
1230 /* map using gain line */
1232 gain_line->view_to_model_coord (x, y);
1234 /* XXX STATEFUL: can't convert to stateful diff until we
1235 can represent automation data with it.
1238 trackview.session()->begin_reversible_command (_("add gain control point"));
1239 XMLNode &before = audio_region()->envelope()->get_state();
1241 if (!audio_region()->envelope_active()) {
1242 XMLNode ®ion_before = audio_region()->get_state();
1243 audio_region()->set_envelope_active(true);
1244 XMLNode ®ion_after = audio_region()->get_state();
1245 trackview.session()->add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
1248 audio_region()->envelope()->add (fx, y, with_guard_points);
1250 XMLNode &after = audio_region()->envelope()->get_state();
1251 trackview.session()->add_command (new MementoCommand<AutomationList>(*audio_region()->envelope().get(), &before, &after));
1252 trackview.session()->commit_reversible_command ();
1256 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent* /*ev*/)
1258 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1259 audio_region()->envelope()->erase (cp->model());
1263 AudioRegionView::setup_waveform_shape ()
1265 WaveView::Shape shape;
1267 switch (Config->get_waveform_shape()) {
1269 shape = WaveView::Rectified;
1272 shape = WaveView::Normal;
1274 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1275 (*wave)->set_shape (shape);
1280 AudioRegionView::setup_waveform_scale ()
1282 WaveView::set_global_logscaled (Config->get_waveform_scale() == Logarithmic);
1286 AudioRegionView::setup_waveform_clipping ()
1288 WaveView::set_global_show_waveform_clipping (ARDOUR_UI::config()->get_show_waveform_clipping());
1292 AudioRegionView::add_ghost (TimeAxisView& tv)
1294 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1297 double unit_position = _region->position () / samples_per_pixel;
1298 AudioGhostRegion* ghost = new AudioGhostRegion (tv, trackview, unit_position);
1301 nchans = rtv->track()->n_channels().n_audio();
1303 for (uint32_t n = 0; n < nchans; ++n) {
1305 if (n >= audio_region()->n_channels()) {
1309 WaveView *wave = new WaveView (ghost->group, audio_region());
1310 CANVAS_DEBUG_NAME (wave, string_compose ("ghost wave for %1", get_item_name()));
1312 wave->set_channel (n);
1313 wave->set_samples_per_pixel (samples_per_pixel);
1314 wave->set_amplitude_above_axis (_amplitude_above_axis);
1316 ghost->waves.push_back(wave);
1319 ghost->set_height ();
1320 ghost->set_duration (_region->length() / samples_per_pixel);
1321 ghost->set_colors();
1322 ghosts.push_back (ghost);
1328 AudioRegionView::entered (bool internal_editing)
1330 trackview.editor().set_current_trimmable (_region);
1331 trackview.editor().set_current_movable (_region);
1334 /* these may or may not be visible depending on mouse mode */
1335 gain_line->add_visibility (AutomationLine::ControlPoints);
1338 if (fade_in_handle && !internal_editing) {
1339 fade_in_handle->show ();
1340 fade_out_handle->show ();
1341 fade_out_handle->raise_to_top ();
1342 fade_in_handle->raise_to_top ();
1347 AudioRegionView::exited ()
1349 trackview.editor().set_current_trimmable (boost::shared_ptr<Trimmable>());
1350 trackview.editor().set_current_movable (boost::shared_ptr<Movable>());
1353 gain_line->remove_visibility (AutomationLine::ControlPoints);
1356 if (fade_in_handle) {
1357 fade_in_handle->hide ();
1358 fade_out_handle->hide ();
1363 AudioRegionView::envelope_active_changed ()
1366 gain_line->set_line_color (audio_region()->envelope_active() ?
1367 ARDOUR_UI::config()->get_canvasvar_GainLine() :
1368 ARDOUR_UI::config()->get_canvasvar_GainLineInactive());
1369 update_envelope_visibility ();
1374 AudioRegionView::color_handler ()
1376 //case cMutedWaveForm:
1378 //case cWaveFormClip:
1382 //case cGainLineInactive:
1384 envelope_active_changed();
1389 AudioRegionView::set_waveform_colors ()
1391 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1392 set_one_waveform_color (*w);
1397 AudioRegionView::set_one_waveform_color (ArdourCanvas::WaveView* wave)
1399 ArdourCanvas::Color fill;
1400 ArdourCanvas::Color outline;
1403 if (_region->muted()) {
1404 /* hide outline with zero alpha */
1405 outline = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_SelectedWaveForm(), 0);
1406 fill = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_SelectedWaveFormFill(), MUTED_ALPHA);
1408 outline = ARDOUR_UI::config()->get_canvasvar_SelectedWaveForm();
1409 fill = ARDOUR_UI::config()->get_canvasvar_SelectedWaveFormFill();
1413 outline = ARDOUR_UI::config()->get_canvasvar_RecWaveForm();
1414 fill = ARDOUR_UI::config()->get_canvasvar_RecWaveFormFill();
1416 if (_region->muted()) {
1417 /* hide outline with zero alpha */
1418 outline = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_WaveForm(), 0);
1419 fill = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_WaveFormFill(), MUTED_ALPHA);
1421 outline = ARDOUR_UI::config()->get_canvasvar_WaveForm();
1422 fill = ARDOUR_UI::config()->get_canvasvar_WaveFormFill();
1427 if (ARDOUR_UI::config()->get_color_regions_using_track_color()) {
1429 /* just use a slightly transparent version of the selected
1430 * color so that some of the track color bleeds through
1434 ArdourCanvas::color_to_rgba (fill, r, g, b, a);
1435 fill = ArdourCanvas::rgba_to_color (r, g, b, 0.85); /* magic number, not user controllable */
1436 outline = ARDOUR_UI::config()->get_canvasvar_WaveForm();
1438 if (!Config->get_show_name_highlight()) {
1439 /* recolor name text because it needs to contrast with
1440 the waveform background, not the name highlight.
1445 wave->set_fill_color (fill);
1446 wave->set_outline_color (outline);
1447 wave->set_clip_color (ARDOUR_UI::config()->get_canvasvar_WaveFormClip());
1448 wave->set_zero_color (ARDOUR_UI::config()->get_canvasvar_ZeroLine());
1452 AudioRegionView::set_frame_color ()
1458 if (_region->opaque()) {
1464 TimeAxisViewItem::set_frame_color ();
1466 set_waveform_colors ();
1470 AudioRegionView::set_fade_visibility (bool yn)
1473 if (fade_in_handle) {
1474 fade_in_handle->show ();
1476 if (fade_out_handle) {
1477 fade_out_handle->show ();
1480 if (fade_in_handle) {
1481 fade_in_handle->hide ();
1483 if (fade_out_handle) {
1484 fade_out_handle->hide ();
1490 AudioRegionView::update_coverage_frames (LayerDisplay d)
1492 RegionView::update_coverage_frames (d);
1494 if (fade_in_handle) {
1495 fade_in_handle->raise_to_top ();
1496 fade_out_handle->raise_to_top ();
1501 AudioRegionView::show_region_editor ()
1504 editor = new AudioRegionEditor (trackview.session(), audio_region());
1512 AudioRegionView::transients_changed ()
1514 AnalysisFeatureList analysis_features = _region->transients();
1516 while (feature_lines.size() < analysis_features.size()) {
1518 ArdourCanvas::Line* canvas_item = new ArdourCanvas::Line(group);
1519 CANVAS_DEBUG_NAME (canvas_item, string_compose ("transient group for %1", region()->name()));
1521 canvas_item->set (ArdourCanvas::Duple (-1.0, 2.0),
1522 ArdourCanvas::Duple (1.0, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
1524 canvas_item->raise_to_top ();
1525 canvas_item->show ();
1527 canvas_item->set_data ("regionview", this);
1528 canvas_item->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_feature_line_event), canvas_item, this));
1530 feature_lines.push_back (make_pair(0, canvas_item));
1533 while (feature_lines.size() > analysis_features.size()) {
1534 ArdourCanvas::Line* line = feature_lines.back().second;
1535 feature_lines.pop_back ();
1539 AnalysisFeatureList::const_iterator i;
1540 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1542 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
1544 float *pos = new float;
1545 *pos = trackview.editor().sample_to_pixel (*i);
1548 ArdourCanvas::Duple (*pos, 2.0),
1549 ArdourCanvas::Duple (*pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1)
1552 (*l).second->set_data ("position", pos);
1558 AudioRegionView::update_transient(float /*old_pos*/, float new_pos)
1560 /* Find frame at old pos, calulate new frame then update region transients*/
1561 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1563 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1565 /* Line has been updated in drag so we compare to new_pos */
1567 float* pos = (float*) (*l).second->get_data ("position");
1569 if (rint(new_pos) == rint(*pos)) {
1571 framepos_t old_frame = (*l).first;
1572 framepos_t new_frame = trackview.editor().pixel_to_sample (new_pos);
1574 _region->update_transient (old_frame, new_frame);
1582 AudioRegionView::remove_transient(float pos)
1584 /* Find frame at old pos, calulate new frame then update region transients*/
1585 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1587 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1589 /* Line has been updated in drag so we compare to new_pos */
1590 float *line_pos = (float*) (*l).second->get_data ("position");
1592 if (rint(pos) == rint(*line_pos)) {
1593 _region->remove_transient ((*l).first);
1600 AudioRegionView::thaw_after_trim ()
1602 RegionView::thaw_after_trim ();
1609 AudioRegionView::show_xfades ()
1611 show_start_xfade ();
1616 AudioRegionView::drag_start ()
1618 TimeAxisViewItem::drag_start ();
1620 //we used to hide xfades here. I don't see the point with the new model, but we can re-implement if needed
1624 AudioRegionView::drag_end ()
1626 TimeAxisViewItem::drag_end ();
1628 //see comment for drag_start
1632 AudioRegionView::parameter_changed (string const & p)
1634 if (p == "show-waveforms") {
1635 setup_waveform_visibility ();
1636 } else if (p == "waveform-scale") {
1637 setup_waveform_scale ();
1638 } else if (p == "waveform-shape") {
1639 setup_waveform_shape ();
1640 } else if (p == "show-waveform-clipping") {
1641 setup_waveform_clipping ();