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.
23 #include <boost/scoped_array.hpp>
27 #include <gtkmm2ext/gtk_ui.h>
29 #include "ardour/playlist.h"
30 #include "ardour/audioregion.h"
31 #include "ardour/audiosource.h"
32 #include "ardour/profile.h"
33 #include "ardour/session.h"
35 #include "pbd/memento_command.h"
36 #include "pbd/stacktrace.h"
38 #include "evoral/Curve.hpp"
40 #include "canvas/rectangle.h"
41 #include "canvas/polygon.h"
42 #include "canvas/poly_line.h"
43 #include "canvas/line.h"
44 #include "canvas/text.h"
45 #include "canvas/debug.h"
46 #include "canvas/utils.h"
48 #include "streamview.h"
49 #include "audio_region_view.h"
50 #include "audio_time_axis.h"
51 #include "public_editor.h"
52 #include "audio_region_editor.h"
53 #include "audio_streamview.h"
54 #include "region_gain_line.h"
55 #include "control_point.h"
56 #include "ghostregion.h"
57 #include "audio_time_axis.h"
59 #include "rgb_macros.h"
60 #include "gui_thread.h"
61 #include "ardour_ui.h"
65 #define MUTED_ALPHA 10
68 using namespace ARDOUR;
70 using namespace Editing;
71 using namespace ArdourCanvas;
73 static const int32_t sync_mark_width = 9;
74 static double const handle_size = 15; /* height of fade handles */
76 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
77 Gdk::Color const & basic_color)
78 : 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)
107 , start_xfade_out (0)
108 , start_xfade_rect (0)
109 , _start_xfade_visible (false)
113 , _end_xfade_visible (false)
114 , _amplitude_above_axis(1.0)
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))
127 , start_xfade_out (0)
128 , start_xfade_rect (0)
129 , _start_xfade_visible (false)
133 , _end_xfade_visible (false)
134 , _amplitude_above_axis (other._amplitude_above_axis)
140 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
141 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
145 Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&AudioRegionView::parameter_changed, this, _1), gui_context());
149 AudioRegionView::init (Gdk::Color const & basic_color, bool wfd)
151 // FIXME: Some redundancy here with RegionView::init. Need to figure out
152 // where order is important and where it isn't...
154 RegionView::init (basic_color, wfd);
156 _amplitude_above_axis = 1.0;
158 compute_colors (basic_color);
162 fade_in_shape = new ArdourCanvas::PolyLine (group);
163 CANVAS_DEBUG_NAME (fade_in_shape, string_compose ("fade in shape for %1", region()->name()));
164 fade_in_shape->set_outline_color (fade_color);
165 fade_in_shape->set_data ("regionview", this);
167 fade_out_shape = new ArdourCanvas::PolyLine (group);
168 CANVAS_DEBUG_NAME (fade_out_shape, string_compose ("fade out shape for %1", region()->name()));
169 fade_out_shape->set_outline_color (fade_color);
170 fade_out_shape->set_data ("regionview", this);
173 fade_in_handle = new ArdourCanvas::Rectangle (group);
174 CANVAS_DEBUG_NAME (fade_in_handle, string_compose ("fade in handle for %1", region()->name()));
175 fade_in_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 255));
176 fade_in_handle->set_fill_color (ARDOUR_UI::config()->get_canvasvar_InactiveFadeHandle());
177 fade_in_handle->set_data ("regionview", this);
178 fade_in_handle->hide ();
180 fade_out_handle = new ArdourCanvas::Rectangle (group);
181 CANVAS_DEBUG_NAME (fade_out_handle, string_compose ("fade out handle for %1", region()->name()));
182 fade_out_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 255));
183 fade_out_handle->set_fill_color (ARDOUR_UI::config()->get_canvasvar_InactiveFadeHandle());
184 fade_out_handle->set_data ("regionview", this);
185 fade_out_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 fade_in_shape->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
222 if (fade_in_handle) {
223 fade_in_handle->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
226 fade_out_shape->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
228 if (fade_out_handle) {
229 fade_out_handle->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
234 setup_waveform_visibility ();
235 setup_waveform_shape ();
237 if (frame_handle_start) {
238 frame_handle_start->raise_to_top ();
240 if (frame_handle_end) {
241 frame_handle_end->raise_to_top ();
244 /* XXX sync mark drag? */
247 AudioRegionView::~AudioRegionView ()
249 in_destructor = true;
251 RegionViewGoingAway (this); /* EMIT_SIGNAL */
253 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
257 for (list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator i = feature_lines.begin(); i != feature_lines.end(); ++i) {
258 delete ((*i).second);
261 /* all waveviews etc will be destroyed when the group is destroyed */
264 boost::shared_ptr<ARDOUR::AudioRegion>
265 AudioRegionView::audio_region() const
267 // "Guaranteed" to succeed...
268 return boost::dynamic_pointer_cast<AudioRegion>(_region);
272 AudioRegionView::region_changed (const PropertyChange& what_changed)
274 ENSURE_GUI_THREAD (*this, &AudioRegionView::region_changed, what_changed);
276 RegionView::region_changed (what_changed);
278 if (what_changed.contains (ARDOUR::Properties::scale_amplitude)) {
279 region_scale_amplitude_changed ();
281 if (what_changed.contains (ARDOUR::Properties::fade_in)) {
284 if (what_changed.contains (ARDOUR::Properties::fade_out)) {
287 if (what_changed.contains (ARDOUR::Properties::fade_in_active)) {
288 fade_in_active_changed ();
290 if (what_changed.contains (ARDOUR::Properties::fade_out_active)) {
291 fade_out_active_changed ();
293 if (what_changed.contains (ARDOUR::Properties::envelope_active)) {
294 envelope_active_changed ();
296 if (what_changed.contains (ARDOUR::Properties::valid_transients)) {
297 transients_changed ();
302 AudioRegionView::fade_in_changed ()
304 reset_fade_in_shape ();
308 AudioRegionView::fade_out_changed ()
310 reset_fade_out_shape ();
314 AudioRegionView::fade_in_active_changed ()
316 if (audio_region()->fade_in_active()) {
317 /* XXX: make a themable colour */
318 fade_in_shape->set_outline_color (RGBA_TO_UINT (45, 45, 45, 90));
320 /* XXX: make a themable colour */
321 fade_in_shape->set_outline_color (RGBA_TO_UINT (45, 45, 45, 20));
326 AudioRegionView::fade_out_active_changed ()
328 if (audio_region()->fade_out_active()) {
329 /* XXX: make a themable colour */
330 fade_out_shape->set_outline_color (RGBA_TO_UINT (45, 45, 45, 90));
332 /* XXX: make a themable colour */
333 fade_out_shape->set_outline_color (RGBA_TO_UINT (45, 45, 45, 20));
339 AudioRegionView::region_scale_amplitude_changed ()
341 for (uint32_t n = 0; n < waves.size(); ++n) {
342 waves[n]->gain_changed ();
347 AudioRegionView::region_renamed ()
349 std::string str = RegionView::make_name ();
351 if (audio_region()->speed_mismatch (trackview.session()->frame_rate())) {
352 str = string ("*") + str;
355 if (_region->muted()) {
356 str = string ("!") + str;
359 set_item_name (str, this);
364 AudioRegionView::region_resized (const PropertyChange& what_changed)
366 AudioGhostRegion* agr;
368 RegionView::region_resized(what_changed);
369 PropertyChange interesting_stuff;
371 interesting_stuff.add (ARDOUR::Properties::start);
372 interesting_stuff.add (ARDOUR::Properties::length);
374 if (what_changed.contains (interesting_stuff)) {
376 for (uint32_t n = 0; n < waves.size(); ++n) {
377 waves[n]->region_resized ();
380 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
381 if ((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
383 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
384 (*w)->region_resized ();
389 /* hide transient lines that extend beyond the region end */
391 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
393 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
394 if (l->first > _region->length() - 1) {
404 AudioRegionView::reset_width_dependent_items (double pixel_width)
406 RegionView::reset_width_dependent_items(pixel_width);
407 assert(_pixel_width == pixel_width);
409 if (fade_in_handle) {
410 if (pixel_width <= 6.0 || _height < 5.0 || !trackview.session()->config.get_show_region_fades()) {
411 fade_in_handle->hide();
412 fade_out_handle->hide();
414 //fade_in_handle->show();
415 //fade_out_handle->show();
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 = 2;
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);
465 AudioRegionView::set_height (gdouble height)
467 RegionView::set_height (height);
469 uint32_t wcnt = waves.size();
471 for (uint32_t n = 0; n < wcnt; ++n) {
474 if (height < NAME_HIGHLIGHT_THRESH) {
475 ht = ((height - 2 * wcnt) / (double) wcnt);
477 ht = (((height - 2 * wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
480 gdouble yoff = n * (ht + 1);
482 waves[n]->set_height (ht);
483 waves[n]->set_y_position (yoff + 2);
488 if ((height/wcnt) < NAME_HIGHLIGHT_THRESH) {
491 update_envelope_visibility ();
494 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE) - 2);
497 reset_fade_shapes ();
499 /* Update hights for any active feature lines */
500 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
502 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
504 float pos_x = trackview.editor().sample_to_pixel((*l).first);
506 (*l).second->set (ArdourCanvas::Duple (pos_x, 2.0),
507 ArdourCanvas::Duple (pos_x, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
511 name_text->raise_to_top();
516 AudioRegionView::reset_fade_shapes ()
518 reset_fade_in_shape ();
519 reset_fade_out_shape ();
523 AudioRegionView::reset_fade_in_shape ()
525 reset_fade_in_shape_width (audio_region(), (framecnt_t) audio_region()->fade_in()->back()->when);
529 AudioRegionView::reset_fade_in_shape_width (boost::shared_ptr<AudioRegion> ar, framecnt_t width)
531 if (fade_in_handle == 0) {
535 /* smallest size for a fade is 64 frames */
537 width = std::max ((framecnt_t) 64, width);
539 /* round here to prevent little visual glitches with sub-pixel placement */
540 double const pwidth = rint (width / samples_per_pixel);
541 double const handle_left = pwidth;
543 /* Put the fade in handle so that its left side is at the end-of-fade line */
544 fade_in_handle->set_x0 (handle_left);
545 fade_in_handle->set_x1 (handle_left + handle_size);
549 fade_in_shape->hide();
553 if (trackview.session()->config.get_show_region_fades()) {
554 fade_in_shape->show();
557 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
558 double effective_height;
559 float curve[npoints];
561 audio_region()->fade_in()->curve().get_vector (0, audio_region()->fade_in()->back()->when, curve, npoints);
563 if (_height >= NAME_HIGHLIGHT_THRESH) {
564 effective_height = _height - NAME_HIGHLIGHT_SIZE - 2;
566 effective_height = _height - 2;
571 points.assign (npoints, Duple());
573 /* points *MUST* be in anti-clockwise order */
576 double xdelta = pwidth/npoints;
578 for (pi = 0, pc = 0; pc < npoints; ++pc) {
579 points[pi].x = 1 + (pc * xdelta);
580 points[pi++].y = 2 + (effective_height - (curve[pc] * effective_height));
585 redraw_start_xfade_to (ar, width, points, effective_height);
587 fade_in_shape->set (points);
589 /* ensure trim handle stays on top */
590 if (frame_handle_start) {
591 frame_handle_start->raise_to_top();
597 AudioRegionView::reset_fade_out_shape ()
599 reset_fade_out_shape_width (audio_region(), (framecnt_t) audio_region()->fade_out()->back()->when);
603 AudioRegionView::reset_fade_out_shape_width (boost::shared_ptr<AudioRegion> ar, framecnt_t width)
605 if (fade_out_handle == 0) {
609 /* smallest size for a fade is 64 frames */
611 width = std::max ((framecnt_t) 64, width);
613 /* round here to prevent little visual glitches with sub-pixel placement */
614 double const pwidth = rint (width / samples_per_pixel);
616 double const handle_right = (_region->length() / samples_per_pixel) - pwidth;
618 /* Put the fade out handle so that its right side is at the end-of-fade line;
620 fade_out_handle->set_x0 (handle_right - handle_size);
621 fade_out_handle->set_x1 (handle_right);
623 /* don't show shape if its too small */
627 fade_out_shape->hide();
631 if (trackview.session()->config.get_show_region_fades()) {
632 fade_out_shape->show();
635 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
636 double effective_height;
637 float curve[npoints];
639 audio_region()->fade_out()->curve().get_vector (0, audio_region()->fade_out()->back()->when, curve, npoints);
641 if (_height >= NAME_HIGHLIGHT_THRESH) {
642 effective_height = _height - NAME_HIGHLIGHT_SIZE - 2;
644 effective_height = _height - 2;
647 /* points *MUST* be in anti-clockwise order */
652 double xdelta = pwidth/npoints;
654 points.assign (npoints, Duple ());
656 for (pi = 0, pc = 0; pc < npoints; ++pc, ++pi) {
657 points[pi].x = _pixel_width - pwidth + (pc * xdelta);
658 points[pi].y = 2 + (effective_height - (curve[pc] * effective_height));
663 redraw_end_xfade_to (ar, width, points, effective_height);
665 fade_out_shape->set (points);
667 /* ensure trim handle stays on top */
668 if (frame_handle_end) {
669 frame_handle_end->raise_to_top();
675 AudioRegionView::get_fade_in_shape_width ()
677 return audio_region()->fade_in()->back()->when;
681 AudioRegionView::get_fade_out_shape_width ()
683 return audio_region()->fade_out()->back()->when;
688 AudioRegionView::redraw_start_xfade ()
690 boost::shared_ptr<AudioRegion> ar (audio_region());
692 if (!ar->fade_in() || ar->fade_in()->empty()) {
697 reset_fade_in_shape_width (ar, ar->fade_in()->back()->when);
701 AudioRegionView::redraw_start_xfade_to (boost::shared_ptr<AudioRegion> ar, framecnt_t /*width*/, Points& points, double effective_height)
703 if (points.size() < 3) {
707 if (!start_xfade_in) {
708 start_xfade_in = new ArdourCanvas::PolyLine (group);
709 CANVAS_DEBUG_NAME (start_xfade_in, string_compose ("xfade start in line for %1", region()->name()));
710 start_xfade_in->set_outline_color (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine());
711 start_xfade_in->set_outline_width (1.5);
714 if (!start_xfade_out) {
715 start_xfade_out = new ArdourCanvas::PolyLine (group);
716 CANVAS_DEBUG_NAME (start_xfade_out, string_compose ("xfade start out line for %1", region()->name()));
717 uint32_t col = UINT_RGBA_CHANGE_A (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine(), 128);
718 start_xfade_out->set_outline_color (col);
719 start_xfade_out->set_outline_width (2.0);
722 if (!start_xfade_rect) {
723 start_xfade_rect = new ArdourCanvas::Rectangle (group);
724 CANVAS_DEBUG_NAME (start_xfade_rect, string_compose ("xfade start rect for %1", region()->name()));
725 start_xfade_rect->set_fill (true);
726 start_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
727 start_xfade_rect->set_outline (false);
728 start_xfade_rect->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_start_xfade_event), start_xfade_rect, this));
729 start_xfade_rect->set_data ("regionview", this);
732 start_xfade_rect->set (ArdourCanvas::Rect (points.front().x, 1.0, points.back().x, effective_height));
733 start_xfade_rect->show ();
735 start_xfade_in->set (points);
736 start_xfade_in->show ();
740 boost::shared_ptr<AutomationList> inverse = ar->inverse_fade_in();
742 Points::size_type npoints = points.size();
744 ipoints.assign (npoints, Duple());
748 for (Points::size_type i = 0, pci = 0; i < npoints; ++i, ++pci) {
749 ArdourCanvas::Duple &p (ipoints[pci]);
751 p.y = effective_height - points[pci].y;
757 inverse->curve().get_vector (0, inverse->back()->when, vec, npoints);
759 for (Points::size_type i = 0, pci = 0; i < npoints; ++i, ++pci) {
760 ArdourCanvas::Duple &p (ipoints[pci]);
762 p.y = 1.0 + effective_height - (effective_height * vec[i]);
766 start_xfade_out->set (ipoints);
767 start_xfade_out->show ();
773 AudioRegionView::redraw_end_xfade ()
775 boost::shared_ptr<AudioRegion> ar (audio_region());
777 if (!ar->fade_out() || ar->fade_out()->empty()) {
783 reset_fade_out_shape_width (ar, ar->fade_out()->back()->when);
787 AudioRegionView::redraw_end_xfade_to (boost::shared_ptr<AudioRegion> ar, framecnt_t width, Points& points, double effective_height)
789 if (points.size() < 3) {
794 end_xfade_in = new ArdourCanvas::PolyLine (group);
795 CANVAS_DEBUG_NAME (end_xfade_in, string_compose ("xfade end in line for %1", region()->name()));
796 uint32_t col UINT_RGBA_CHANGE_A (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine(), 128);
797 end_xfade_in->set_outline_color (col);
798 end_xfade_in->set_outline_width (1.5);
801 if (!end_xfade_out) {
802 end_xfade_out = new ArdourCanvas::PolyLine (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);
808 if (!end_xfade_rect) {
809 end_xfade_rect = new ArdourCanvas::Rectangle (group);
810 CANVAS_DEBUG_NAME (end_xfade_rect, string_compose ("xfade end rect for %1", region()->name()));
811 end_xfade_rect->set_fill (true);
812 end_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
813 end_xfade_rect->set_outline (0);
814 end_xfade_rect->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_end_xfade_event), end_xfade_rect, this));
815 end_xfade_rect->set_data ("regionview", this);
818 end_xfade_rect->set (ArdourCanvas::Rect (points.front().x, 1.0, points.back().x, effective_height));
819 end_xfade_rect->show ();
821 end_xfade_in->set (points);
822 end_xfade_in->show ();
823 end_xfade_in->raise_to_top ();
827 boost::shared_ptr<AutomationList> inverse = ar->inverse_fade_out ();
829 Points::size_type npoints = points.size();
831 ipoints.assign (npoints, Duple());
835 const double rend = trackview.editor().sample_to_pixel (_region->length() - points.back().y);
837 for (Points::size_type i = 0, pci = 0; i < npoints; ++i, ++pci) {
838 ArdourCanvas::Duple &p (ipoints[pci]);
840 p.y = effective_height - points[pci].y;
845 boost::scoped_array<float> vec (new float[npoints]);
846 inverse->curve().get_vector (inverse->front()->when, inverse->back()->when, vec.get(), npoints);
848 const double rend = trackview.editor().sample_to_pixel (_region->length() - width);
850 float* vp = vec.get();
852 for (Points::size_type i = 0, pci = 0; i < npoints; ++i) {
853 ArdourCanvas::Duple& p (ipoints[pci++]);
855 p.y = 1.0 + effective_height - (effective_height * vp[i]);
859 end_xfade_out->set (ipoints);
860 end_xfade_out->show ();
861 end_xfade_out->raise_to_top ();
863 end_xfade_rect->raise_to_top (); //this needs to be topmost so the lines don't steal mouse focus
869 AudioRegionView::hide_xfades ()
876 AudioRegionView::hide_start_xfade ()
878 if (start_xfade_in) {
879 start_xfade_in->hide();
881 if (start_xfade_out) {
882 start_xfade_out->hide();
884 if (start_xfade_rect) {
885 start_xfade_rect->hide ();
888 _start_xfade_visible = false;
892 AudioRegionView::hide_end_xfade ()
895 end_xfade_in->hide();
898 end_xfade_out->hide();
900 if (end_xfade_rect) {
901 end_xfade_rect->hide ();
904 _end_xfade_visible = false;
908 AudioRegionView::show_start_xfade ()
910 if (start_xfade_in) {
911 start_xfade_in->show();
913 if (start_xfade_out) {
914 start_xfade_out->show();
916 if (start_xfade_rect) {
917 start_xfade_rect->show ();
920 _start_xfade_visible = true;
924 AudioRegionView::show_end_xfade ()
927 end_xfade_in->show();
930 end_xfade_out->show();
932 if (end_xfade_rect) {
933 end_xfade_rect->show ();
936 _end_xfade_visible = true;
940 AudioRegionView::set_samples_per_pixel (gdouble fpp)
942 RegionView::set_samples_per_pixel (fpp);
944 if (Config->get_show_waveforms ()) {
945 for (uint32_t n = 0; n < waves.size(); ++n) {
946 waves[n]->set_samples_per_pixel (fpp);
954 reset_fade_shapes ();
958 AudioRegionView::set_amplitude_above_axis (gdouble a)
960 for (uint32_t n=0; n < waves.size(); ++n) {
961 waves[n]->set_amplitude_above_axis (a);
966 AudioRegionView::compute_colors (Gdk::Color const & basic_color)
968 RegionView::compute_colors (basic_color);
970 /* gain color computed in envelope_active_changed() */
972 fade_color = UINT_RGBA_CHANGE_A (fill_color, 120);
976 AudioRegionView::set_colors ()
978 RegionView::set_colors();
981 gain_line->set_line_color (audio_region()->envelope_active() ?
982 ARDOUR_UI::config()->get_canvasvar_GainLine() :
983 ARDOUR_UI::config()->get_canvasvar_GainLineInactive());
986 set_waveform_colors ();
988 if (start_xfade_in) {
989 start_xfade_in->set_outline_color (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine());
991 if (start_xfade_out) {
992 uint32_t col UINT_RGBA_CHANGE_A (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine(), 128);
993 start_xfade_out->set_outline_color (col);
996 end_xfade_in->set_outline_color (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine());
999 uint32_t col UINT_RGBA_CHANGE_A (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine(), 128);
1000 end_xfade_out->set_outline_color (col);
1003 if (start_xfade_rect) {
1004 start_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
1006 if (end_xfade_rect) {
1007 end_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
1012 AudioRegionView::setup_waveform_visibility ()
1014 if (Config->get_show_waveforms ()) {
1015 for (uint32_t n = 0; n < waves.size(); ++n) {
1016 /* make sure the zoom level is correct, since we don't update
1017 this when waveforms are hidden.
1020 // waves[n]->set_samples_per_pixel (_samples_per_pixel);
1024 for (uint32_t n = 0; n < waves.size(); ++n) {
1031 AudioRegionView::temporarily_hide_envelope ()
1039 AudioRegionView::unhide_envelope ()
1041 update_envelope_visibility ();
1045 AudioRegionView::update_envelope_visibility ()
1051 if (Config->get_show_region_gain() || trackview.editor().current_mouse_mode() == Editing::MouseGain) {
1052 gain_line->add_visibility (AutomationLine::Line);
1059 AudioRegionView::create_waves ()
1061 // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
1062 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
1068 ChanCount nchans = atv.track()->n_channels();
1070 // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data
1071 // << " and channels = " << nchans.n_audio() << endl;
1073 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
1074 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
1075 tmp_waves.push_back (0);
1078 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
1082 _data_ready_connections.clear ();
1084 for (uint32_t i = 0; i < nchans.n_audio(); ++i) {
1085 _data_ready_connections.push_back (0);
1088 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
1090 if (n >= audio_region()->n_channels()) {
1094 // cerr << "\tchannel " << n << endl;
1096 if (wait_for_data) {
1097 if (audio_region()->audio_source(n)->peaks_ready (boost::bind (&AudioRegionView::peaks_ready_handler, this, n), &_data_ready_connections[n], gui_context())) {
1098 // cerr << "\tData is ready\n";
1099 create_one_wave (n, true);
1101 // cerr << "\tdata is not ready\n";
1102 // we'll get a PeaksReady signal from the source in the future
1103 // and will call create_one_wave(n) then.
1107 // cerr << "\tdon't delay, display today!\n";
1108 create_one_wave (n, true);
1115 AudioRegionView::create_one_wave (uint32_t which, bool /*direct*/)
1117 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
1118 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
1119 uint32_t nchans = atv.track()->n_channels().n_audio();
1121 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
1124 if (trackview.current_height() < NAME_HIGHLIGHT_THRESH) {
1125 ht = ((trackview.current_height()) / (double) nchans);
1127 ht = ((trackview.current_height() - NAME_HIGHLIGHT_SIZE) / (double) nchans);
1130 gdouble yoff = which * ht;
1132 WaveView *wave = new WaveView (group, audio_region ());
1133 CANVAS_DEBUG_NAME (wave, string_compose ("wave view for chn %1 of %2", which, get_item_name()));
1135 wave->set_channel (which);
1136 wave->set_y_position (yoff);
1137 wave->set_height (ht);
1138 wave->set_samples_per_pixel (samples_per_pixel);
1139 wave->set_show_zero_line (true);
1141 switch (Config->get_waveform_shape()) {
1143 wave->set_shape (WaveView::Rectified);
1146 wave->set_shape (WaveView::Normal);
1149 wave->set_logscaled (Config->get_waveform_scale() == Logarithmic);
1151 if (!Config->get_show_waveforms ()) {
1155 /* note: calling this function is serialized by the lock
1156 held in the peak building thread that signals that
1157 peaks are ready for use *or* by the fact that it is
1158 called one by one from the GUI thread.
1161 if (which < nchans) {
1162 tmp_waves[which] = wave;
1164 /* n-channel track, >n-channel source */
1167 /* see if we're all ready */
1169 for (n = 0; n < nchans; ++n) {
1170 if (tmp_waves[n] == 0) {
1175 if (n == nwaves && waves.empty()) {
1176 /* all waves are ready */
1177 tmp_waves.resize(nwaves);
1182 /* all waves created, don't hook into peaks ready anymore */
1183 delete _data_ready_connections[which];
1184 _data_ready_connections[which] = 0;
1189 AudioRegionView::peaks_ready_handler (uint32_t which)
1191 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AudioRegionView::create_one_wave, this, which, false));
1192 // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
1196 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1204 /* don't create points that can't be seen */
1206 update_envelope_visibility ();
1211 item->canvas_to_item (x, y);
1213 framepos_t fx = trackview.editor().pixel_to_sample (x);
1215 if (fx > _region->length()) {
1219 /* compute vertical fractional position */
1221 y = 1.0 - (y / (_height - NAME_HIGHLIGHT_SIZE));
1223 /* map using gain line */
1225 gain_line->view_to_model_coord (x, y);
1227 /* XXX STATEFUL: can't convert to stateful diff until we
1228 can represent automation data with it.
1231 trackview.session()->begin_reversible_command (_("add gain control point"));
1232 XMLNode &before = audio_region()->envelope()->get_state();
1234 if (!audio_region()->envelope_active()) {
1235 XMLNode ®ion_before = audio_region()->get_state();
1236 audio_region()->set_envelope_active(true);
1237 XMLNode ®ion_after = audio_region()->get_state();
1238 trackview.session()->add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
1241 audio_region()->envelope()->add (fx, y);
1243 XMLNode &after = audio_region()->envelope()->get_state();
1244 trackview.session()->add_command (new MementoCommand<AutomationList>(*audio_region()->envelope().get(), &before, &after));
1245 trackview.session()->commit_reversible_command ();
1249 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent */*ev*/)
1251 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1252 audio_region()->envelope()->erase (cp->model());
1256 AudioRegionView::setup_waveform_shape ()
1258 WaveView::Shape shape;
1260 switch (Config->get_waveform_shape()) {
1262 shape = WaveView::Rectified;
1265 shape = WaveView::Normal;
1267 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1268 (*wave)->set_shape (shape);
1273 AudioRegionView::setup_waveform_scale ()
1275 WaveView::set_global_logscaled (Config->get_waveform_scale() == Logarithmic);
1279 AudioRegionView::setup_waveform_clipping ()
1281 WaveView::set_global_show_waveform_clipping (ARDOUR_UI::config()->get_show_waveform_clipping());
1285 AudioRegionView::add_ghost (TimeAxisView& tv)
1287 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1290 double unit_position = _region->position () / samples_per_pixel;
1291 AudioGhostRegion* ghost = new AudioGhostRegion (tv, trackview, unit_position);
1294 nchans = rtv->track()->n_channels().n_audio();
1296 for (uint32_t n = 0; n < nchans; ++n) {
1298 if (n >= audio_region()->n_channels()) {
1302 WaveView *wave = new WaveView (ghost->group, audio_region());
1303 CANVAS_DEBUG_NAME (wave, string_compose ("ghost wave for %1", get_item_name()));
1305 wave->set_channel (n);
1306 wave->set_samples_per_pixel (samples_per_pixel);
1307 wave->set_amplitude_above_axis (_amplitude_above_axis);
1309 ghost->waves.push_back(wave);
1312 ghost->set_height ();
1313 ghost->set_duration (_region->length() / samples_per_pixel);
1314 ghost->set_colors();
1315 ghosts.push_back (ghost);
1321 AudioRegionView::entered (bool internal_editing)
1323 trackview.editor().set_current_trimmable (_region);
1324 trackview.editor().set_current_movable (_region);
1326 if (gain_line && trackview.editor().current_mouse_mode() == Editing::MouseGain) {
1327 gain_line->add_visibility (AutomationLine::ControlPoints);
1330 if (fade_in_handle && !internal_editing) {
1331 fade_in_handle->show ();
1332 fade_out_handle->show ();
1333 fade_out_handle->raise_to_top ();
1334 fade_in_handle->raise_to_top ();
1339 AudioRegionView::exited ()
1341 trackview.editor().set_current_trimmable (boost::shared_ptr<Trimmable>());
1342 trackview.editor().set_current_movable (boost::shared_ptr<Movable>());
1344 if (gain_line && trackview.editor().current_mouse_mode() == Editing::MouseGain) {
1345 gain_line->remove_visibility (AutomationLine::ControlPoints);
1348 if (fade_in_handle) {
1349 fade_in_handle->hide ();
1350 fade_out_handle->hide ();
1355 AudioRegionView::envelope_active_changed ()
1358 gain_line->set_line_color (audio_region()->envelope_active() ?
1359 ARDOUR_UI::config()->get_canvasvar_GainLine() :
1360 ARDOUR_UI::config()->get_canvasvar_GainLineInactive());
1365 AudioRegionView::color_handler ()
1367 //case cMutedWaveForm:
1369 //case cWaveFormClip:
1373 //case cGainLineInactive:
1375 envelope_active_changed();
1380 AudioRegionView::set_waveform_colors ()
1382 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1383 set_one_waveform_color (*w);
1388 AudioRegionView::set_one_waveform_color (ArdourCanvas::WaveView* wave)
1390 ArdourCanvas::Color fill;
1391 ArdourCanvas::Color outline;
1394 if (_region->muted()) {
1395 outline = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_SelectedWaveForm(), MUTED_ALPHA);
1397 outline = ARDOUR_UI::config()->get_canvasvar_SelectedWaveForm();
1399 fill = ARDOUR_UI::config()->get_canvasvar_SelectedWaveFormFill();
1402 outline = ARDOUR_UI::config()->get_canvasvar_RecWaveForm();
1403 fill = ARDOUR_UI::config()->get_canvasvar_RecWaveFormFill();
1405 if (_region->muted()) {
1406 outline = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_WaveForm(), MUTED_ALPHA);
1408 outline = ARDOUR_UI::config()->get_canvasvar_WaveForm();
1410 fill = ARDOUR_UI::config()->get_canvasvar_WaveFormFill();
1414 if (ARDOUR_UI::config()->get_color_regions_using_track_color()) {
1416 /* just use a slightly transparent version of the selected
1417 * color so that some of the track color bleeds through
1421 ArdourCanvas::color_to_rgba (fill, r, g, b, a);
1422 fill = ArdourCanvas::rgba_to_color (r, g, b, 0.85); /* magic number, not user controllable */
1426 wave->set_fill_color (fill);
1427 wave->set_outline_color (outline);
1428 wave->set_clip_color (ARDOUR_UI::config()->get_canvasvar_WaveFormClip());
1429 wave->set_zero_color (ARDOUR_UI::config()->get_canvasvar_ZeroLine());
1433 AudioRegionView::set_frame_color ()
1439 if (_region->opaque()) {
1445 TimeAxisViewItem::set_frame_color ();
1447 set_waveform_colors ();
1451 AudioRegionView::set_fade_visibility (bool yn)
1454 if (fade_in_shape) {
1455 fade_in_shape->show();
1457 if (fade_out_shape) {
1458 fade_out_shape->show ();
1460 if (fade_in_handle) {
1461 fade_in_handle->show ();
1463 if (fade_out_handle) {
1464 fade_out_handle->show ();
1467 if (fade_in_shape) {
1468 fade_in_shape->hide();
1470 if (fade_out_shape) {
1471 fade_out_shape->hide ();
1473 if (fade_in_handle) {
1474 fade_in_handle->hide ();
1476 if (fade_out_handle) {
1477 fade_out_handle->hide ();
1483 AudioRegionView::update_coverage_frames (LayerDisplay d)
1485 RegionView::update_coverage_frames (d);
1487 if (fade_in_handle) {
1488 fade_in_handle->raise_to_top ();
1489 fade_out_handle->raise_to_top ();
1494 AudioRegionView::show_region_editor ()
1497 editor = new AudioRegionEditor (trackview.session(), audio_region());
1505 AudioRegionView::transients_changed ()
1507 AnalysisFeatureList analysis_features = _region->transients();
1509 while (feature_lines.size() < analysis_features.size()) {
1511 ArdourCanvas::Line* canvas_item = new ArdourCanvas::Line(group);
1512 CANVAS_DEBUG_NAME (canvas_item, string_compose ("transient group for %1", region()->name()));
1514 canvas_item->set (ArdourCanvas::Duple (-1.0, 2.0),
1515 ArdourCanvas::Duple (1.0, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
1517 canvas_item->raise_to_top ();
1518 canvas_item->show ();
1520 canvas_item->set_data ("regionview", this);
1521 canvas_item->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_feature_line_event), canvas_item, this));
1523 feature_lines.push_back (make_pair(0, canvas_item));
1526 while (feature_lines.size() > analysis_features.size()) {
1527 ArdourCanvas::Line* line = feature_lines.back().second;
1528 feature_lines.pop_back ();
1532 AnalysisFeatureList::const_iterator i;
1533 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1535 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
1537 float *pos = new float;
1538 *pos = trackview.editor().sample_to_pixel (*i);
1541 ArdourCanvas::Duple (*pos, 2.0),
1542 ArdourCanvas::Duple (*pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1)
1545 (*l).second->set_data ("position", pos);
1551 AudioRegionView::update_transient(float /*old_pos*/, float new_pos)
1553 /* Find frame at old pos, calulate new frame then update region transients*/
1554 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1556 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1558 /* Line has been updated in drag so we compare to new_pos */
1560 float* pos = (float*) (*l).second->get_data ("position");
1562 if (rint(new_pos) == rint(*pos)) {
1564 framepos_t old_frame = (*l).first;
1565 framepos_t new_frame = trackview.editor().pixel_to_sample (new_pos);
1567 _region->update_transient (old_frame, new_frame);
1575 AudioRegionView::remove_transient(float pos)
1577 /* Find frame at old pos, calulate new frame then update region transients*/
1578 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1580 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1582 /* Line has been updated in drag so we compare to new_pos */
1583 float *line_pos = (float*) (*l).second->get_data ("position");
1585 if (rint(pos) == rint(*line_pos)) {
1586 _region->remove_transient ((*l).first);
1593 AudioRegionView::thaw_after_trim ()
1595 RegionView::thaw_after_trim ();
1602 AudioRegionView::show_xfades ()
1604 show_start_xfade ();
1609 AudioRegionView::drag_start ()
1611 TimeAxisViewItem::drag_start ();
1613 //we used to hide xfades here. I don't see the point with the new model, but we can re-implement if needed
1617 AudioRegionView::drag_end ()
1619 TimeAxisViewItem::drag_end ();
1621 //see comment for drag_start
1625 AudioRegionView::parameter_changed (string const & p)
1627 if (p == "show-waveforms") {
1628 setup_waveform_visibility ();
1629 } else if (p == "waveform-scale") {
1630 setup_waveform_scale ();
1631 } else if (p == "waveform-shape") {
1632 setup_waveform_shape ();
1633 } else if (p == "show-waveform-clipping") {
1634 setup_waveform_clipping ();