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"
46 #include "streamview.h"
47 #include "audio_region_view.h"
48 #include "audio_time_axis.h"
49 #include "public_editor.h"
50 #include "audio_region_editor.h"
51 #include "audio_streamview.h"
52 #include "region_gain_line.h"
53 #include "control_point.h"
54 #include "ghostregion.h"
55 #include "audio_time_axis.h"
57 #include "rgb_macros.h"
58 #include "gui_thread.h"
59 #include "ardour_ui.h"
63 #define MUTED_ALPHA 10
66 using namespace ARDOUR;
68 using namespace Editing;
69 using namespace ArdourCanvas;
71 static const int32_t sync_mark_width = 9;
72 static double const handle_size = 15; /* height of fade handles */
74 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
75 Gdk::Color const & basic_color)
76 : RegionView (parent, tv, r, spu, basic_color)
84 , start_xfade_rect (0)
85 , _start_xfade_visible (false)
89 , _end_xfade_visible (false)
90 , _amplitude_above_axis(1.0)
93 Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&AudioRegionView::parameter_changed, this, _1), gui_context());
96 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
97 Gdk::Color const & basic_color, bool recording, TimeAxisViewItem::Visibility visibility)
98 : 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))
125 , start_xfade_out (0)
126 , start_xfade_rect (0)
127 , _start_xfade_visible (false)
131 , _end_xfade_visible (false)
132 , _amplitude_above_axis (other._amplitude_above_axis)
138 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
139 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
143 Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&AudioRegionView::parameter_changed, this, _1), gui_context());
147 AudioRegionView::init (Gdk::Color const & basic_color, bool wfd)
149 // FIXME: Some redundancy here with RegionView::init. Need to figure out
150 // where order is important and where it isn't...
152 RegionView::init (basic_color, wfd);
154 _amplitude_above_axis = 1.0;
156 compute_colors (basic_color);
160 fade_in_shape = new ArdourCanvas::Polygon (group);
161 fade_in_shape->set_fill_color (fade_color);
162 fade_in_shape->set_data ("regionview", this);
164 fade_out_shape = new ArdourCanvas::Polygon (group);
165 fade_out_shape->set_fill_color (fade_color);
166 fade_out_shape->set_data ("regionview", this);
169 fade_in_handle = new ArdourCanvas::Rectangle (group);
170 fade_in_handle->set_fill_color (UINT_RGBA_CHANGE_A (fill_color, 0));
171 fade_in_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 0));
173 fade_in_handle->set_data ("regionview", this);
175 fade_out_handle = new ArdourCanvas::Rectangle (group);
176 fade_out_handle->set_fill_color (UINT_RGBA_CHANGE_A (fill_color, 0));
177 fade_out_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 0));
179 fade_out_handle->set_data ("regionview", this);
182 setup_fade_handle_positions ();
184 if (!trackview.session()->config.get_show_region_fades()) {
185 set_fade_visibility (false);
188 const string line_name = _region->name() + ":gain";
190 if (!Profile->get_sae()) {
191 gain_line.reset (new AudioRegionGainLine (line_name, *this, *group, audio_region()->envelope()));
194 update_envelope_visibility ();
197 set_height (trackview.current_height());
200 region_sync_changed ();
202 region_resized (ARDOUR::bounds_change);
204 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
205 (*i)->set_duration (_region->length() / samples_per_pixel);
209 envelope_active_changed ();
210 fade_in_active_changed ();
211 fade_out_active_changed ();
213 reset_width_dependent_items (_pixel_width);
215 fade_in_shape->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
216 if (fade_in_handle) {
217 fade_in_handle->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
220 fade_out_shape->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
222 if (fade_out_handle) {
223 fade_out_handle->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
228 setup_waveform_visibility ();
229 setup_waveform_shape ();
230 setup_waveform_scale ();
232 /* XXX sync mark drag? */
235 AudioRegionView::~AudioRegionView ()
237 in_destructor = true;
239 RegionViewGoingAway (this); /* EMIT_SIGNAL */
241 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
245 for (list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator i = feature_lines.begin(); i != feature_lines.end(); ++i) {
246 delete ((*i).second);
249 /* all waveviews etc will be destroyed when the group is destroyed */
252 boost::shared_ptr<ARDOUR::AudioRegion>
253 AudioRegionView::audio_region() const
255 // "Guaranteed" to succeed...
256 return boost::dynamic_pointer_cast<AudioRegion>(_region);
260 AudioRegionView::region_changed (const PropertyChange& what_changed)
262 ENSURE_GUI_THREAD (*this, &AudioRegionView::region_changed, what_changed);
264 RegionView::region_changed (what_changed);
266 if (what_changed.contains (ARDOUR::Properties::scale_amplitude)) {
267 region_scale_amplitude_changed ();
269 if (what_changed.contains (ARDOUR::Properties::fade_in)) {
272 if (what_changed.contains (ARDOUR::Properties::fade_out)) {
275 if (what_changed.contains (ARDOUR::Properties::fade_in_active)) {
276 fade_in_active_changed ();
278 if (what_changed.contains (ARDOUR::Properties::fade_out_active)) {
279 fade_out_active_changed ();
281 if (what_changed.contains (ARDOUR::Properties::envelope_active)) {
282 envelope_active_changed ();
284 if (what_changed.contains (ARDOUR::Properties::valid_transients)) {
285 transients_changed ();
290 AudioRegionView::fade_in_changed ()
292 reset_fade_in_shape ();
296 AudioRegionView::fade_out_changed ()
298 reset_fade_out_shape ();
302 AudioRegionView::fade_in_active_changed ()
304 if (audio_region()->fade_in_active()) {
305 /* XXX: make a themable colour */
306 fade_in_shape->set_fill_color (RGBA_TO_UINT (45, 45, 45, 90));
308 /* XXX: make a themable colour */
309 fade_in_shape->set_fill_color (RGBA_TO_UINT (45, 45, 45, 20));
314 AudioRegionView::fade_out_active_changed ()
316 if (audio_region()->fade_out_active()) {
317 /* XXX: make a themable colour */
318 fade_out_shape->set_fill_color (RGBA_TO_UINT (45, 45, 45, 90));
320 /* XXX: make a themable colour */
321 fade_out_shape->set_fill_color (RGBA_TO_UINT (45, 45, 45, 20));
327 AudioRegionView::region_scale_amplitude_changed ()
329 for (uint32_t n = 0; n < waves.size(); ++n) {
330 waves[n]->gain_changed ();
335 AudioRegionView::region_renamed ()
337 std::string str = RegionView::make_name ();
339 if (audio_region()->speed_mismatch (trackview.session()->frame_rate())) {
340 str = string ("*") + str;
343 if (_region->muted()) {
344 str = string ("!") + str;
347 set_item_name (str, this);
352 AudioRegionView::region_resized (const PropertyChange& what_changed)
354 AudioGhostRegion* agr;
356 RegionView::region_resized(what_changed);
357 PropertyChange interesting_stuff;
359 interesting_stuff.add (ARDOUR::Properties::start);
360 interesting_stuff.add (ARDOUR::Properties::length);
362 if (what_changed.contains (interesting_stuff)) {
364 for (uint32_t n = 0; n < waves.size(); ++n) {
365 waves[n]->region_resized ();
366 waves[n]->set_region_start (region()->start ());
369 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
370 if ((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
372 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
373 (*w)->region_resized ();
374 (*w)->set_region_start (region()->start ());
379 /* hide transient lines that extend beyond the region end */
381 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
383 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
384 if (l->first > _region->length() - 1) {
394 AudioRegionView::reset_width_dependent_items (double pixel_width)
396 RegionView::reset_width_dependent_items(pixel_width);
397 assert(_pixel_width == pixel_width);
399 if (fade_in_handle) {
400 if (pixel_width <= 6.0 || _height < 5.0 || !trackview.session()->config.get_show_region_fades()) {
401 fade_in_handle->hide();
402 fade_out_handle->hide();
405 fade_in_handle->show();
406 fade_out_handle->show();
410 AnalysisFeatureList analysis_features = _region->transients();
411 AnalysisFeatureList::const_iterator i;
413 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
415 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
417 float x_pos = trackview.editor().sample_to_pixel (*i);
419 (*l).second->set (ArdourCanvas::Duple (x_pos, 2.0),
420 ArdourCanvas::Duple (x_pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
424 (*l).second->set (ArdourCanvas::Duple (x_pos, 2.0),
425 ArdourCanvas::Duple (x_pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
428 reset_fade_shapes ();
432 AudioRegionView::region_muted ()
434 RegionView::region_muted();
436 for (uint32_t n=0; n < waves.size(); ++n) {
437 if (_region->muted()) {
438 waves[n]->set_outline_color (UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_WaveForm(), MUTED_ALPHA));
440 waves[n]->set_outline_color (ARDOUR_UI::config()->get_canvasvar_WaveForm());
446 AudioRegionView::setup_fade_handle_positions()
448 /* position of fade handle offset from the top of the region view */
449 double const handle_pos = 2;
451 if (fade_in_handle) {
452 fade_in_handle->set_y0 (handle_pos);
453 fade_in_handle->set_y1 (handle_pos + handle_size);
456 if (fade_out_handle) {
457 fade_out_handle->set_y0 (handle_pos);
458 fade_out_handle->set_y1 (handle_pos + handle_size);
463 AudioRegionView::set_height (gdouble height)
465 RegionView::set_height (height);
467 uint32_t wcnt = waves.size();
469 for (uint32_t n = 0; n < wcnt; ++n) {
472 if (height < NAME_HIGHLIGHT_THRESH) {
473 ht = ((height - 2 * wcnt) / (double) wcnt);
475 ht = (((height - 2 * wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
478 gdouble yoff = n * (ht + 1);
480 waves[n]->set_height (ht);
481 waves[n]->set_y_position (yoff + 2);
486 if ((height/wcnt) < NAME_HIGHLIGHT_THRESH) {
489 update_envelope_visibility ();
492 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE) - 2);
495 reset_fade_shapes ();
497 /* Update hights for any active feature lines */
498 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
500 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
502 float pos_x = trackview.editor().sample_to_pixel((*l).first);
504 (*l).second->set (ArdourCanvas::Duple (pos_x, 2.0),
505 ArdourCanvas::Duple (pos_x, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
509 name_text->raise_to_top();
514 AudioRegionView::reset_fade_shapes ()
516 reset_fade_in_shape ();
517 reset_fade_out_shape ();
521 AudioRegionView::reset_fade_in_shape ()
523 reset_fade_in_shape_width (audio_region(), (framecnt_t) audio_region()->fade_in()->back()->when);
527 AudioRegionView::reset_fade_in_shape_width (boost::shared_ptr<AudioRegion> ar, framecnt_t width)
529 if (fade_in_handle == 0) {
533 fade_in_handle->show ();
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 /* add 3 more points */
589 points.push_back (Duple());
590 points.push_back (Duple());
591 points.push_back (Duple());
595 points[pi].x = pwidth;
603 /* connect the dots ... */
605 points[pi] = points[0];
607 fade_in_shape->set (points);
609 /* ensure trim handle stays on top */
610 if (frame_handle_start) {
611 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)
625 if (fade_out_handle == 0) {
629 fade_out_handle->show ();
631 /* smallest size for a fade is 64 frames */
633 width = std::max ((framecnt_t) 64, width);
635 /* round here to prevent little visual glitches with sub-pixel placement */
636 double const pwidth = rint (width / samples_per_pixel);
638 double const handle_right = (_region->length() / samples_per_pixel) - pwidth;
640 /* Put the fade out handle so that its right side is at the end-of-fade line;
642 fade_out_handle->set_x0 (handle_right - handle_size);
643 fade_out_handle->set_x1 (handle_right);
645 /* don't show shape if its too small */
649 fade_out_shape->hide();
653 if (trackview.session()->config.get_show_region_fades()) {
654 fade_out_shape->show();
657 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
658 double effective_height;
659 float curve[npoints];
661 audio_region()->fade_out()->curve().get_vector (0, audio_region()->fade_out()->back()->when, curve, npoints);
663 if (_height >= NAME_HIGHLIGHT_THRESH) {
664 effective_height = _height - NAME_HIGHLIGHT_SIZE - 2;
666 effective_height = _height - 2;
669 /* points *MUST* be in anti-clockwise order */
674 double xdelta = pwidth/npoints;
676 points.assign (npoints, Duple ());
678 for (pi = 0, pc = 0; pc < npoints; ++pc, ++pi) {
679 points[pi].x = _pixel_width - pwidth + (pc * xdelta);
680 points[pi].y = 2 + (effective_height - (curve[pc] * effective_height));
685 redraw_end_xfade_to (ar, width, points, effective_height);
687 /* fill the polygon*/
689 /* add 3 more points */
691 points.push_back (Duple());
692 points.push_back (Duple());
693 points.push_back (Duple());
697 points[pi].x = _pixel_width;
698 points[pi].y = effective_height;
701 points[pi].x = _pixel_width;
705 /* connect the dots ... */
707 points[pi] = points[0];
709 fade_out_shape->set (points);
711 /* ensure trim handle stays on top */
712 if (frame_handle_end) {
713 frame_handle_end->raise_to_top();
719 AudioRegionView::get_fade_in_shape_width ()
721 return audio_region()->fade_in()->back()->when;
725 AudioRegionView::get_fade_out_shape_width ()
727 return audio_region()->fade_out()->back()->when;
732 AudioRegionView::redraw_start_xfade ()
734 boost::shared_ptr<AudioRegion> ar (audio_region());
736 if (!ar->fade_in() || ar->fade_in()->empty()) {
741 reset_fade_in_shape_width (ar, ar->fade_in()->back()->when);
745 AudioRegionView::redraw_start_xfade_to (boost::shared_ptr<AudioRegion> ar, framecnt_t /*width*/, Points& points, double effective_height)
747 if (points.size() < 3) {
751 if (!start_xfade_in) {
752 start_xfade_in = new ArdourCanvas::PolyLine (group);
753 start_xfade_in->set_outline_color (ARDOUR_UI::config()->get_canvasvar_GainLine());
754 start_xfade_in->set_outline_width (2.5);
757 if (!start_xfade_out) {
758 start_xfade_out = new ArdourCanvas::PolyLine (group);
759 uint32_t col = UINT_RGBA_CHANGE_A (ARDOUR_UI::config()->get_canvasvar_GainLine(), 128);
760 start_xfade_out->set_outline_color (col);
761 start_xfade_out->set_outline_width (2.5);
764 if (!start_xfade_rect) {
765 start_xfade_rect = new ArdourCanvas::Rectangle (group);
766 start_xfade_rect->set_fill (true);
767 start_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
768 start_xfade_rect->set_outline (false);
769 start_xfade_rect->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_start_xfade_event), start_xfade_rect, this));
770 start_xfade_rect->set_data ("regionview", this);
773 start_xfade_rect->set (ArdourCanvas::Rect (points.front().x, 1.0, points.back().x, effective_height));
774 start_xfade_rect->show ();
776 start_xfade_in->set (points);
777 start_xfade_in->show ();
778 start_xfade_in->raise_to_top ();
782 boost::shared_ptr<AutomationList> inverse = ar->inverse_fade_in();
784 Points::size_type npoints = points.size();
786 ipoints.assign (npoints, Duple());
790 for (Points::size_type i = 0, pci = 0; i < npoints; ++i, ++pci) {
791 ArdourCanvas::Duple &p (ipoints[pci]);
793 p.y = effective_height - points[pci].y;
799 inverse->curve().get_vector (0, inverse->back()->when, vec, npoints);
801 for (Points::size_type i = 0, pci = 0; i < npoints; ++i, ++pci) {
802 ArdourCanvas::Duple &p (ipoints[pci]);
804 p.y = 1.0 + effective_height - (effective_height * vec[i]);
808 start_xfade_out->set (ipoints);
809 start_xfade_out->show ();
810 start_xfade_out->raise_to_top ();
812 start_xfade_rect->raise_to_top (); //this needs to be topmost so the lines don't steal mouse focus
818 AudioRegionView::redraw_end_xfade ()
820 boost::shared_ptr<AudioRegion> ar (audio_region());
822 if (!ar->fade_out() || ar->fade_out()->empty()) {
828 reset_fade_out_shape_width (ar, ar->fade_out()->back()->when);
832 AudioRegionView::redraw_end_xfade_to (boost::shared_ptr<AudioRegion> ar, framecnt_t width, Points& points, double effective_height)
834 if (points.size() < 3) {
839 end_xfade_in = new ArdourCanvas::PolyLine (group);
840 end_xfade_in->set_outline_color (ARDOUR_UI::config()->get_canvasvar_GainLine());
841 end_xfade_in->set_outline_width (2.5);
844 if (!end_xfade_out) {
845 end_xfade_out = new ArdourCanvas::PolyLine (group);
846 uint32_t col UINT_RGBA_CHANGE_A (ARDOUR_UI::config()->get_canvasvar_GainLine(), 128);
847 end_xfade_out->set_outline_color (col);
848 end_xfade_out->set_outline_width (2.5);
851 if (!end_xfade_rect) {
852 end_xfade_rect = new ArdourCanvas::Rectangle (group);
853 end_xfade_rect->set_fill (true);
854 end_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
855 end_xfade_rect->set_outline (0);
856 end_xfade_rect->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_end_xfade_event), end_xfade_rect, this));
857 end_xfade_rect->set_data ("regionview", this);
860 end_xfade_rect->set (ArdourCanvas::Rect (points.front().x, 1.0, points.back().x, effective_height));
861 end_xfade_rect->show ();
863 end_xfade_in->set (points);
864 end_xfade_in->show ();
865 end_xfade_in->raise_to_top ();
869 boost::shared_ptr<AutomationList> inverse = ar->inverse_fade_out ();
871 Points::size_type npoints = points.size();
873 ipoints.assign (npoints, Duple());
877 const double rend = trackview.editor().sample_to_pixel (_region->length() - points.back().y);
879 for (Points::size_type i = 0, pci = 0; i < npoints; ++i, ++pci) {
880 ArdourCanvas::Duple &p (ipoints[pci]);
882 p.y = effective_height - points[pci].y;
887 boost::scoped_array<float> vec (new float[npoints]);
888 inverse->curve().get_vector (inverse->front()->when, inverse->back()->when, vec.get(), npoints);
890 const double rend = trackview.editor().sample_to_pixel (_region->length() - width);
892 float* vp = vec.get();
894 for (Points::size_type i = 0, pci = 0; i < npoints; ++i) {
895 ArdourCanvas::Duple& p (ipoints[pci++]);
897 p.y = 1.0 + effective_height - (effective_height * vp[i]);
901 end_xfade_out->set (ipoints);
902 end_xfade_out->show ();
903 end_xfade_out->raise_to_top ();
905 end_xfade_rect->raise_to_top (); //this needs to be topmost so the lines don't steal mouse focus
911 AudioRegionView::hide_xfades ()
918 AudioRegionView::hide_start_xfade ()
920 if (start_xfade_in) {
921 start_xfade_in->hide();
923 if (start_xfade_out) {
924 start_xfade_out->hide();
926 if (start_xfade_rect) {
927 start_xfade_rect->hide ();
930 _start_xfade_visible = false;
934 AudioRegionView::hide_end_xfade ()
937 end_xfade_in->hide();
940 end_xfade_out->hide();
942 if (end_xfade_rect) {
943 end_xfade_rect->hide ();
946 _end_xfade_visible = false;
950 AudioRegionView::show_start_xfade ()
952 if (start_xfade_in) {
953 start_xfade_in->show();
955 if (start_xfade_out) {
956 start_xfade_out->show();
958 if (start_xfade_rect) {
959 start_xfade_rect->show ();
962 _start_xfade_visible = true;
966 AudioRegionView::show_end_xfade ()
969 end_xfade_in->show();
972 end_xfade_out->show();
974 if (end_xfade_rect) {
975 end_xfade_rect->show ();
978 _end_xfade_visible = true;
982 AudioRegionView::set_samples_per_pixel (gdouble fpp)
984 RegionView::set_samples_per_pixel (fpp);
986 if (Config->get_show_waveforms ()) {
987 for (uint32_t n = 0; n < waves.size(); ++n) {
988 waves[n]->set_samples_per_pixel (fpp);
996 reset_fade_shapes ();
1000 AudioRegionView::set_amplitude_above_axis (gdouble a)
1002 for (uint32_t n=0; n < waves.size(); ++n) {
1003 waves[n]->set_amplitude_above_axis (a);
1008 AudioRegionView::compute_colors (Gdk::Color const & basic_color)
1010 RegionView::compute_colors (basic_color);
1012 /* gain color computed in envelope_active_changed() */
1014 fade_color = UINT_RGBA_CHANGE_A (fill_color, 120);
1018 AudioRegionView::set_colors ()
1020 RegionView::set_colors();
1023 gain_line->set_line_color (audio_region()->envelope_active() ?
1024 ARDOUR_UI::config()->get_canvasvar_GainLine() :
1025 ARDOUR_UI::config()->get_canvasvar_GainLineInactive());
1028 for (uint32_t n=0; n < waves.size(); ++n) {
1029 if (_region->muted()) {
1030 waves[n]->set_outline_color (UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_WaveForm(), MUTED_ALPHA));
1032 waves[n]->set_outline_color (ARDOUR_UI::config()->get_canvasvar_WaveForm());
1035 waves[n]->set_clip_color (ARDOUR_UI::config()->get_canvasvar_WaveFormClip());
1036 waves[n]->set_zero_color (ARDOUR_UI::config()->get_canvasvar_ZeroLine());
1039 if (start_xfade_in) {
1040 start_xfade_in->set_outline_color (ARDOUR_UI::config()->get_canvasvar_GainLine());
1042 if (start_xfade_out) {
1043 start_xfade_out->set_outline_color (ARDOUR_UI::config()->get_canvasvar_GainLine());
1046 end_xfade_in->set_outline_color (ARDOUR_UI::config()->get_canvasvar_GainLine());
1048 if (end_xfade_out) {
1049 end_xfade_out->set_outline_color (ARDOUR_UI::config()->get_canvasvar_GainLine());
1051 if (start_xfade_rect) {
1052 start_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
1054 if (end_xfade_rect) {
1055 end_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
1060 AudioRegionView::setup_waveform_visibility ()
1062 if (Config->get_show_waveforms ()) {
1063 for (uint32_t n = 0; n < waves.size(); ++n) {
1064 /* make sure the zoom level is correct, since we don't update
1065 this when waveforms are hidden.
1068 // waves[n]->set_samples_per_pixel (_samples_per_pixel);
1072 for (uint32_t n = 0; n < waves.size(); ++n) {
1079 AudioRegionView::temporarily_hide_envelope ()
1087 AudioRegionView::unhide_envelope ()
1089 update_envelope_visibility ();
1093 AudioRegionView::update_envelope_visibility ()
1099 if (Config->get_show_region_gain() || trackview.editor().current_mouse_mode() == Editing::MouseGain) {
1100 gain_line->add_visibility (AutomationLine::Line);
1107 AudioRegionView::create_waves ()
1109 // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
1110 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
1116 ChanCount nchans = atv.track()->n_channels();
1118 // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data
1119 // << " and channels = " << nchans.n_audio() << endl;
1121 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
1122 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
1123 tmp_waves.push_back (0);
1126 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
1130 _data_ready_connections.clear ();
1132 for (uint32_t i = 0; i < nchans.n_audio(); ++i) {
1133 _data_ready_connections.push_back (0);
1136 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
1138 if (n >= audio_region()->n_channels()) {
1142 // cerr << "\tchannel " << n << endl;
1144 if (wait_for_data) {
1145 if (audio_region()->audio_source(n)->peaks_ready (boost::bind (&AudioRegionView::peaks_ready_handler, this, n), &_data_ready_connections[n], gui_context())) {
1146 // cerr << "\tData is ready\n";
1147 create_one_wave (n, true);
1149 // cerr << "\tdata is not ready\n";
1150 // we'll get a PeaksReady signal from the source in the future
1151 // and will call create_one_wave(n) then.
1155 // cerr << "\tdon't delay, display today!\n";
1156 create_one_wave (n, true);
1163 AudioRegionView::create_one_wave (uint32_t which, bool /*direct*/)
1165 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
1166 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
1167 uint32_t nchans = atv.track()->n_channels().n_audio();
1169 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
1172 if (trackview.current_height() < NAME_HIGHLIGHT_THRESH) {
1173 ht = ((trackview.current_height()) / (double) nchans);
1175 ht = ((trackview.current_height() - NAME_HIGHLIGHT_SIZE) / (double) nchans);
1178 gdouble yoff = which * ht;
1180 WaveView *wave = new WaveView (group, audio_region ());
1182 wave->set_channel (which);
1183 wave->set_x_position (0);
1184 wave->set_y_position (yoff);
1185 wave->set_height (ht);
1186 wave->set_samples_per_pixel (samples_per_pixel);
1189 wave->set_outline_color (_region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_RecWaveForm(), MUTED_ALPHA) : ARDOUR_UI::config()->get_canvasvar_RecWaveForm());
1190 wave->set_fill_color (ARDOUR_UI::config()->get_canvasvar_RecWaveFormFill());
1192 wave->set_outline_color (_region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_WaveForm(), MUTED_ALPHA) : ARDOUR_UI::config()->get_canvasvar_WaveForm());
1193 wave->set_fill_color (ARDOUR_UI::config()->get_canvasvar_WaveFormFill());
1196 wave->set_clip_color (ARDOUR_UI::config()->get_canvasvar_WaveFormClip());
1197 wave->set_zero_color (ARDOUR_UI::config()->get_canvasvar_ZeroLine());
1199 // wave->property_zero_line() = true;
1201 wave->set_region_start (_region->start());
1203 switch (Config->get_waveform_shape()) {
1205 wave->set_shape (WaveView::Rectified);
1208 wave->set_shape (WaveView::Normal);
1211 wave->set_logscaled (Config->get_waveform_scale() == Logarithmic);
1213 if (!Config->get_show_waveforms ()) {
1217 /* note: calling this function is serialized by the lock
1218 held in the peak building thread that signals that
1219 peaks are ready for use *or* by the fact that it is
1220 called one by one from the GUI thread.
1223 if (which < nchans) {
1224 tmp_waves[which] = wave;
1226 /* n-channel track, >n-channel source */
1229 /* see if we're all ready */
1231 for (n = 0; n < nchans; ++n) {
1232 if (tmp_waves[n] == 0) {
1237 if (n == nwaves && waves.empty()) {
1238 /* all waves are ready */
1239 tmp_waves.resize(nwaves);
1244 /* all waves created, don't hook into peaks ready anymore */
1245 delete _data_ready_connections[which];
1246 _data_ready_connections[which] = 0;
1251 AudioRegionView::peaks_ready_handler (uint32_t which)
1253 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AudioRegionView::create_one_wave, this, which, false));
1254 // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
1258 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1266 /* don't create points that can't be seen */
1268 update_envelope_visibility ();
1273 item->canvas_to_item (x, y);
1275 framepos_t fx = trackview.editor().pixel_to_sample (x);
1277 if (fx > _region->length()) {
1281 /* compute vertical fractional position */
1283 y = 1.0 - (y / (_height - NAME_HIGHLIGHT_SIZE));
1285 /* map using gain line */
1287 gain_line->view_to_model_coord (x, y);
1289 /* XXX STATEFUL: can't convert to stateful diff until we
1290 can represent automation data with it.
1293 trackview.session()->begin_reversible_command (_("add gain control point"));
1294 XMLNode &before = audio_region()->envelope()->get_state();
1296 if (!audio_region()->envelope_active()) {
1297 XMLNode ®ion_before = audio_region()->get_state();
1298 audio_region()->set_envelope_active(true);
1299 XMLNode ®ion_after = audio_region()->get_state();
1300 trackview.session()->add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
1303 audio_region()->envelope()->add (fx, y);
1305 XMLNode &after = audio_region()->envelope()->get_state();
1306 trackview.session()->add_command (new MementoCommand<AutomationList>(*audio_region()->envelope().get(), &before, &after));
1307 trackview.session()->commit_reversible_command ();
1311 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent */*ev*/)
1313 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1314 audio_region()->envelope()->erase (cp->model());
1318 AudioRegionView::setup_waveform_shape ()
1320 WaveView::Shape shape;
1322 switch (Config->get_waveform_shape()) {
1324 shape = WaveView::Rectified;
1327 shape = WaveView::Normal;
1329 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1330 (*wave)->set_shape (shape);
1335 AudioRegionView::setup_waveform_scale ()
1337 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1338 (*wave)->set_logscaled (Config->get_waveform_scale() == Logarithmic);
1344 AudioRegionView::add_ghost (TimeAxisView& tv)
1346 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1349 double unit_position = _region->position () / samples_per_pixel;
1350 AudioGhostRegion* ghost = new AudioGhostRegion (tv, trackview, unit_position);
1353 nchans = rtv->track()->n_channels().n_audio();
1355 for (uint32_t n = 0; n < nchans; ++n) {
1357 if (n >= audio_region()->n_channels()) {
1361 WaveView *wave = new WaveView (ghost->group, audio_region());
1363 wave->set_channel (n);
1364 wave->set_x_position (0);
1365 wave->set_samples_per_pixel (samples_per_pixel);
1366 wave->set_amplitude_above_axis (_amplitude_above_axis);
1367 wave->set_region_start (_region->start());
1369 ghost->waves.push_back(wave);
1372 ghost->set_height ();
1373 ghost->set_duration (_region->length() / samples_per_pixel);
1374 ghost->set_colors();
1375 ghosts.push_back (ghost);
1381 AudioRegionView::entered (bool internal_editing)
1383 trackview.editor().set_current_trimmable (_region);
1384 trackview.editor().set_current_movable (_region);
1386 if (gain_line && trackview.editor().current_mouse_mode() == Editing::MouseGain) {
1387 gain_line->add_visibility (AutomationLine::ControlPoints);
1390 if (fade_in_handle && !internal_editing) {
1391 fade_in_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 255));
1392 fade_in_handle->set_fill_color (UINT_RGBA_CHANGE_A (fade_color, 255));
1393 fade_out_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 255));
1394 fade_out_handle->set_fill_color (UINT_RGBA_CHANGE_A (fade_color, 255));
1399 AudioRegionView::exited ()
1401 trackview.editor().set_current_trimmable (boost::shared_ptr<Trimmable>());
1402 trackview.editor().set_current_movable (boost::shared_ptr<Movable>());
1404 if (gain_line && trackview.editor().current_mouse_mode() == Editing::MouseGain) {
1405 gain_line->remove_visibility (AutomationLine::ControlPoints);
1408 if (fade_in_handle) {
1409 fade_in_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 0));
1410 fade_in_handle->set_fill_color (UINT_RGBA_CHANGE_A (fade_color, 0));
1411 fade_out_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 0));
1412 fade_out_handle->set_fill_color (UINT_RGBA_CHANGE_A (fade_color, 0));
1417 AudioRegionView::envelope_active_changed ()
1420 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->get_canvasvar_GainLine() : ARDOUR_UI::config()->get_canvasvar_GainLineInactive());
1425 AudioRegionView::color_handler ()
1427 //case cMutedWaveForm:
1429 //case cWaveFormClip:
1433 //case cGainLineInactive:
1435 envelope_active_changed();
1440 AudioRegionView::set_frame_color ()
1446 if (_region->opaque()) {
1452 TimeAxisViewItem::set_frame_color ();
1458 if (_region->muted()) {
1459 wc = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_SelectedWaveForm(), MUTED_ALPHA);
1461 wc = ARDOUR_UI::config()->get_canvasvar_SelectedWaveForm();
1463 fc = ARDOUR_UI::config()->get_canvasvar_SelectedWaveFormFill();
1466 if (_region->muted()) {
1467 wc = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_RecWaveForm(), MUTED_ALPHA);
1469 wc = ARDOUR_UI::config()->get_canvasvar_RecWaveForm();
1471 fc = ARDOUR_UI::config()->get_canvasvar_RecWaveFormFill();
1473 if (_region->muted()) {
1474 wc = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_WaveForm(), MUTED_ALPHA);
1476 wc = ARDOUR_UI::config()->get_canvasvar_WaveForm();
1478 fc = ARDOUR_UI::config()->get_canvasvar_WaveFormFill();
1482 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1483 (*w)->set_outline_color (wc);
1484 if (!_region->muted()) {
1485 (*w)->set_fill_color (fc);
1491 AudioRegionView::set_fade_visibility (bool yn)
1494 if (fade_in_shape) {
1495 fade_in_shape->show();
1497 if (fade_out_shape) {
1498 fade_out_shape->show ();
1500 if (fade_in_handle) {
1501 fade_in_handle->show ();
1503 if (fade_out_handle) {
1504 fade_out_handle->show ();
1507 if (fade_in_shape) {
1508 fade_in_shape->hide();
1510 if (fade_out_shape) {
1511 fade_out_shape->hide ();
1513 if (fade_in_handle) {
1514 fade_in_handle->hide ();
1516 if (fade_out_handle) {
1517 fade_out_handle->hide ();
1523 AudioRegionView::update_coverage_frames (LayerDisplay d)
1525 RegionView::update_coverage_frames (d);
1527 if (fade_in_handle) {
1528 fade_in_handle->raise_to_top ();
1529 fade_out_handle->raise_to_top ();
1534 AudioRegionView::show_region_editor ()
1537 editor = new AudioRegionEditor (trackview.session(), audio_region());
1541 editor->set_position (Gtk::WIN_POS_MOUSE);
1546 AudioRegionView::transients_changed ()
1548 AnalysisFeatureList analysis_features = _region->transients();
1550 while (feature_lines.size() < analysis_features.size()) {
1552 ArdourCanvas::Line* canvas_item = new ArdourCanvas::Line(group);
1554 canvas_item->set (ArdourCanvas::Duple (-1.0, 2.0),
1555 ArdourCanvas::Duple (1.0, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
1557 canvas_item->property_first_arrowhead() = TRUE;
1558 canvas_item->property_last_arrowhead() = TRUE;
1559 canvas_item->property_arrow_shape_a() = 11.0;
1560 canvas_item->property_arrow_shape_b() = 0.0;
1561 canvas_item->property_arrow_shape_c() = 4.0;
1563 canvas_item->raise_to_top ();
1564 canvas_item->show ();
1566 canvas_item->set_data ("regionview", this);
1567 canvas_item->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_feature_line_event), canvas_item, this));
1569 feature_lines.push_back (make_pair(0, canvas_item));
1572 while (feature_lines.size() > analysis_features.size()) {
1573 ArdourCanvas::Line* line = feature_lines.back().second;
1574 feature_lines.pop_back ();
1578 AnalysisFeatureList::const_iterator i;
1579 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1581 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
1583 float *pos = new float;
1584 *pos = trackview.editor().sample_to_pixel (*i);
1587 ArdourCanvas::Duple (*pos, 2.0),
1588 ArdourCanvas::Duple (*pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1)
1591 (*l).second->set_data ("position", pos);
1597 AudioRegionView::update_transient(float /*old_pos*/, float new_pos)
1599 /* Find frame at old pos, calulate new frame then update region transients*/
1600 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1602 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1604 /* Line has been updated in drag so we compare to new_pos */
1606 float* pos = (float*) (*l).second->get_data ("position");
1608 if (rint(new_pos) == rint(*pos)) {
1610 framepos_t old_frame = (*l).first;
1611 framepos_t new_frame = trackview.editor().pixel_to_sample (new_pos);
1613 _region->update_transient (old_frame, new_frame);
1621 AudioRegionView::remove_transient(float pos)
1623 /* Find frame at old pos, calulate new frame then update region transients*/
1624 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1626 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1628 /* Line has been updated in drag so we compare to new_pos */
1629 float *line_pos = (float*) (*l).second->get_data ("position");
1631 if (rint(pos) == rint(*line_pos)) {
1632 _region->remove_transient ((*l).first);
1639 AudioRegionView::thaw_after_trim ()
1641 RegionView::thaw_after_trim ();
1648 AudioRegionView::show_xfades ()
1650 show_start_xfade ();
1655 AudioRegionView::drag_start ()
1657 TimeAxisViewItem::drag_start ();
1659 //we used to hide xfades here. I don't see the point with the new model, but we can re-implement if needed
1663 AudioRegionView::drag_end ()
1665 TimeAxisViewItem::drag_end ();
1667 //see comment for drag_start
1671 AudioRegionView::parameter_changed (string const & p)
1673 if (p == "show-waveforms") {
1674 setup_waveform_visibility ();
1675 } else if (p == "waveform-scale") {
1676 setup_waveform_scale ();
1677 } else if (p == "waveform-shape") {
1678 setup_waveform_shape ();