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 "ardour/playlist.h"
29 #include "ardour/audioregion.h"
30 #include "ardour/audiosource.h"
31 #include "ardour/profile.h"
32 #include "ardour/session.h"
34 #include "pbd/memento_command.h"
35 #include "pbd/stacktrace.h"
37 #include "evoral/Curve.hpp"
39 #include "gtkmm2ext/gtk_ui.h"
40 #include "gtkmm2ext/utils.h"
41 #include "gtkmm2ext/colors.h"
43 #include "canvas/rectangle.h"
44 #include "canvas/polygon.h"
45 #include "canvas/poly_line.h"
46 #include "canvas/line.h"
47 #include "canvas/text.h"
48 #include "canvas/xfade_curve.h"
49 #include "canvas/debug.h"
51 #include "waveview/debug.h"
53 #include "streamview.h"
54 #include "audio_region_view.h"
55 #include "audio_time_axis.h"
56 #include "enums_convert.h"
57 #include "public_editor.h"
58 #include "audio_region_editor.h"
59 #include "audio_streamview.h"
60 #include "region_gain_line.h"
61 #include "control_point.h"
62 #include "ghostregion.h"
63 #include "audio_time_axis.h"
64 #include "rgb_macros.h"
65 #include "gui_thread.h"
66 #include "ui_config.h"
70 #define MUTED_ALPHA 48
73 using namespace ARDOUR;
75 using namespace Editing;
76 using namespace ArdourCanvas;
78 static double const handle_size = 10; /* height of fade handles */
80 Cairo::RefPtr<Cairo::Pattern> AudioRegionView::pending_peak_pattern;
82 static Cairo::RefPtr<Cairo::Pattern> create_pending_peak_pattern() {
83 cairo_surface_t * is = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 8, 8);
85 // create checker pattern
86 unsigned char *img = cairo_image_surface_get_data (is);
87 cairo_surface_flush (is);
88 const int stride = cairo_image_surface_get_stride (is);
90 for (int y = 0; y < 8; ++y) {
91 for (int x = 0; x < 8; ++x) {
92 const int off = (y * stride + x * 4);
93 uint32_t *pixel = (uint32_t*) &img[off];
94 if ((x < 4) ^ (y < 4)) {
101 cairo_surface_mark_dirty (is);
103 cairo_pattern_t* pat = cairo_pattern_create_for_surface (is);
104 cairo_pattern_set_extend (pat, CAIRO_EXTEND_REPEAT);
105 Cairo::RefPtr<Cairo::Pattern> p (new Cairo::Pattern (pat, false));
106 cairo_surface_destroy (is);
110 AudioRegionView::AudioRegionView (ArdourCanvas::Container *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
111 uint32_t basic_color)
112 : RegionView (parent, tv, r, spu, basic_color)
116 , fade_in_trim_handle(0)
117 , fade_out_trim_handle(0)
118 , pending_peak_data(0)
119 , start_xfade_curve (0)
120 , start_xfade_rect (0)
121 , _start_xfade_visible (false)
122 , end_xfade_curve (0)
124 , _end_xfade_visible (false)
125 , _amplitude_above_axis(1.0)
126 , trim_fade_in_drag_active(false)
127 , trim_fade_out_drag_active(false)
129 UIConfiguration::instance().ParameterChanged.connect (sigc::mem_fun (*this, &AudioRegionView::parameter_changed));
132 AudioRegionView::AudioRegionView (ArdourCanvas::Container *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
133 uint32_t basic_color, bool recording, TimeAxisViewItem::Visibility visibility)
134 : RegionView (parent, tv, r, spu, basic_color, recording, visibility)
138 , fade_in_trim_handle(0)
139 , fade_out_trim_handle(0)
140 , pending_peak_data(0)
141 , start_xfade_curve (0)
142 , start_xfade_rect (0)
143 , _start_xfade_visible (false)
144 , end_xfade_curve (0)
146 , _end_xfade_visible (false)
147 , _amplitude_above_axis(1.0)
148 , trim_fade_in_drag_active(false)
149 , trim_fade_out_drag_active(false)
151 UIConfiguration::instance().ParameterChanged.connect (sigc::mem_fun (*this, &AudioRegionView::parameter_changed));
154 AudioRegionView::AudioRegionView (const AudioRegionView& other, boost::shared_ptr<AudioRegion> other_region)
155 : RegionView (other, boost::shared_ptr<Region> (other_region))
158 , fade_in_trim_handle(0)
159 , fade_out_trim_handle(0)
160 , pending_peak_data(0)
161 , start_xfade_curve (0)
162 , start_xfade_rect (0)
163 , _start_xfade_visible (false)
164 , end_xfade_curve (0)
166 , _end_xfade_visible (false)
167 , _amplitude_above_axis (other._amplitude_above_axis)
168 , trim_fade_in_drag_active(false)
169 , trim_fade_out_drag_active(false)
173 UIConfiguration::instance().ParameterChanged.connect (sigc::mem_fun (*this, &AudioRegionView::parameter_changed));
177 AudioRegionView::init (bool wfd)
179 // FIXME: Some redundancy here with RegionView::init. Need to figure out
180 // where order is important and where it isn't...
182 if (!pending_peak_pattern) {
183 pending_peak_pattern = create_pending_peak_pattern();
186 // needs to be created first, RegionView::init() calls set_height()
187 pending_peak_data = new ArdourCanvas::Rectangle (group);
188 CANVAS_DEBUG_NAME (pending_peak_data, string_compose ("pending peak rectangle for %1", region()->name()));
189 pending_peak_data->set_outline_color (Gtkmm2ext::rgba_to_color (0, 0, 0, 0.0));
190 pending_peak_data->set_pattern (pending_peak_pattern);
191 pending_peak_data->set_data ("regionview", this);
192 pending_peak_data->hide ();
194 RegionView::init (wfd);
196 _amplitude_above_axis = 1.0;
201 fade_in_handle = new ArdourCanvas::Rectangle (group);
202 CANVAS_DEBUG_NAME (fade_in_handle, string_compose ("fade in handle for %1", region()->name()));
203 fade_in_handle->set_outline_color (Gtkmm2ext::rgba_to_color (0, 0, 0, 1.0));
204 fade_in_handle->set_fill_color (UIConfiguration::instance().color ("inactive fade handle"));
205 fade_in_handle->set_data ("regionview", this);
206 fade_in_handle->hide ();
208 fade_out_handle = new ArdourCanvas::Rectangle (group);
209 CANVAS_DEBUG_NAME (fade_out_handle, string_compose ("fade out handle for %1", region()->name()));
210 fade_out_handle->set_outline_color (Gtkmm2ext::rgba_to_color (0, 0, 0, 1.0));
211 fade_out_handle->set_fill_color (UIConfiguration::instance().color ("inactive fade handle"));
212 fade_out_handle->set_data ("regionview", this);
213 fade_out_handle->hide ();
215 fade_in_trim_handle = new ArdourCanvas::Rectangle (group);
216 CANVAS_DEBUG_NAME (fade_in_handle, string_compose ("fade in trim handle for %1", region()->name()));
217 fade_in_trim_handle->set_outline_color (Gtkmm2ext::rgba_to_color (0, 0, 0, 1.0));
218 fade_in_trim_handle->set_fill_color (UIConfiguration::instance().color ("inactive fade handle"));
219 fade_in_trim_handle->set_data ("regionview", this);
220 fade_in_trim_handle->hide ();
222 fade_out_trim_handle = new ArdourCanvas::Rectangle (group);
223 CANVAS_DEBUG_NAME (fade_out_handle, string_compose ("fade out trim handle for %1", region()->name()));
224 fade_out_trim_handle->set_outline_color (Gtkmm2ext::rgba_to_color (0, 0, 0, 1.0));
225 fade_out_trim_handle->set_fill_color (UIConfiguration::instance().color ("inactive fade handle"));
226 fade_out_trim_handle->set_data ("regionview", this);
227 fade_out_trim_handle->hide ();
230 setup_fade_handle_positions ();
232 if (!trackview.session()->config.get_show_region_fades()) {
233 set_fade_visibility (false);
236 const string line_name = _region->name() + ":gain";
238 gain_line.reset (new AudioRegionGainLine (line_name, *this, *group, audio_region()->envelope()));
240 update_envelope_visibility ();
243 /* streamview will call set_height() */
244 //set_height (trackview.current_height()); // XXX not correct for Layered mode, but set_height() will fix later.
247 region_sync_changed ();
249 region_resized (ARDOUR::bounds_change);
250 /* region_resized sets ghost region duration */
252 /* region_locked is a synonym for region_renamed () which is called in region_muted() above */
255 envelope_active_changed ();
256 fade_in_active_changed ();
257 fade_out_active_changed ();
259 reset_width_dependent_items (_pixel_width);
261 if (fade_in_handle) {
262 fade_in_handle->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this, false));
265 if (fade_out_handle) {
266 fade_out_handle->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this, false));
269 if (fade_in_trim_handle) {
270 fade_in_trim_handle->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_trim_handle, this, true));
273 if (fade_out_trim_handle) {
274 fade_out_trim_handle->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_trim_handle, this, true));
279 setup_waveform_visibility ();
281 /* XXX sync mark drag? */
284 AudioRegionView::~AudioRegionView ()
286 in_destructor = true;
288 RegionViewGoingAway (this); /* EMIT_SIGNAL */
290 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
293 _data_ready_connections.clear ();
295 for (list<std::pair<samplepos_t, ArdourCanvas::Line*> >::iterator i = feature_lines.begin(); i != feature_lines.end(); ++i) {
296 delete ((*i).second);
299 /* all waveviews etc will be destroyed when the group is destroyed */
302 boost::shared_ptr<ARDOUR::AudioRegion>
303 AudioRegionView::audio_region() const
305 // "Guaranteed" to succeed...
306 return boost::dynamic_pointer_cast<AudioRegion>(_region);
310 AudioRegionView::region_changed (const PropertyChange& what_changed)
312 ENSURE_GUI_THREAD (*this, &AudioRegionView::region_changed, what_changed);
314 RegionView::region_changed (what_changed);
316 if (what_changed.contains (ARDOUR::Properties::scale_amplitude)) {
317 region_scale_amplitude_changed ();
319 if (what_changed.contains (ARDOUR::Properties::fade_in)) {
322 if (what_changed.contains (ARDOUR::Properties::fade_out)) {
325 if (what_changed.contains (ARDOUR::Properties::fade_in_active)) {
326 fade_in_active_changed ();
328 if (what_changed.contains (ARDOUR::Properties::fade_out_active)) {
329 fade_out_active_changed ();
331 if (what_changed.contains (ARDOUR::Properties::envelope_active)) {
332 envelope_active_changed ();
334 if (what_changed.contains (ARDOUR::Properties::valid_transients)) {
335 transients_changed ();
340 AudioRegionView::fade_in_changed ()
342 reset_fade_in_shape ();
346 AudioRegionView::fade_out_changed ()
348 reset_fade_out_shape ();
352 AudioRegionView::fade_in_active_changed ()
354 if (start_xfade_rect) {
355 if (audio_region()->fade_in_active()) {
356 start_xfade_rect->set_fill (false);
358 start_xfade_rect->set_fill_color (UIConfiguration::instance().color_mod ("inactive crossfade", "inactive crossfade"));
359 start_xfade_rect->set_fill (true);
365 AudioRegionView::fade_out_active_changed ()
367 if (end_xfade_rect) {
368 if (audio_region()->fade_out_active()) {
369 end_xfade_rect->set_fill (false);
371 end_xfade_rect->set_fill_color (UIConfiguration::instance().color_mod ("inactive crossfade", "inactive crossfade"));
372 end_xfade_rect->set_fill (true);
379 AudioRegionView::region_scale_amplitude_changed ()
381 for (uint32_t n = 0; n < waves.size(); ++n) {
382 waves[n]->gain_changed ();
388 AudioRegionView::region_renamed ()
390 std::string str = RegionView::make_name ();
392 if (audio_region()->speed_mismatch (trackview.session()->sample_rate())) {
393 str = string ("*") + str;
396 if (_region->muted()) {
397 str = string ("!") + str;
401 boost::shared_ptr<AudioRegion> ar (audio_region());
402 if (ar->scale_amplitude() != 1.0) {
404 snprintf (tmp, 32, " (%.1fdB)", accurate_coefficient_to_dB (ar->scale_amplitude()));
408 set_item_name (str, this);
413 AudioRegionView::region_resized (const PropertyChange& what_changed)
415 AudioGhostRegion* agr;
417 RegionView::region_resized(what_changed);
418 PropertyChange interesting_stuff;
420 interesting_stuff.add (ARDOUR::Properties::start);
421 interesting_stuff.add (ARDOUR::Properties::length);
423 if (what_changed.contains (interesting_stuff)) {
425 for (uint32_t n = 0; n < waves.size(); ++n) {
426 waves[n]->region_resized ();
429 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
430 if ((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
432 for (vector<ArdourWaveView::WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
433 (*w)->region_resized ();
438 /* hide transient lines that extend beyond the region */
439 list<std::pair<samplepos_t, ArdourCanvas::Line*> >::iterator l;
440 samplepos_t first = _region->first_sample();
441 samplepos_t last = _region->last_sample();
443 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
444 if (l->first < first || l->first >= last) {
454 AudioRegionView::reset_width_dependent_items (double pixel_width)
456 if (pixel_width == _width) {
460 RegionView::reset_width_dependent_items(pixel_width);
461 assert(_pixel_width == pixel_width);
463 pending_peak_data->set_x1(pixel_width);
465 if (pixel_width <= 20.0 || _height < 5.0 || !trackview.session()->config.get_show_region_fades()) {
466 if (fade_in_handle) { fade_in_handle->hide(); }
467 if (fade_out_handle) { fade_out_handle->hide(); }
468 if (fade_in_trim_handle) { fade_in_trim_handle->hide(); }
469 if (fade_out_trim_handle) { fade_out_trim_handle->hide(); }
470 if (start_xfade_rect) { start_xfade_rect->set_outline (false); }
471 if (end_xfade_rect) { end_xfade_rect->set_outline (false); }
474 reset_fade_shapes ();
476 /* Update feature lines */
477 AnalysisFeatureList analysis_features;
478 _region->transients (analysis_features);
480 if (feature_lines.size () != analysis_features.size ()) {
481 cerr << "postponed freature line update.\n"; // XXX
482 // AudioRegionView::transients_changed () will pick up on this
486 samplepos_t position = _region->position();
488 AnalysisFeatureList::const_iterator i;
489 list<std::pair<samplepos_t, ArdourCanvas::Line*> >::iterator l;
491 if (_height >= NAME_HIGHLIGHT_THRESH) {
492 y1 = _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1;
496 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
497 float x_pos = trackview.editor().sample_to_pixel ((*i) - position);
499 (*l).second->set (ArdourCanvas::Duple (x_pos, 2.0),
500 ArdourCanvas::Duple (x_pos, y1));
505 AudioRegionView::region_muted ()
507 RegionView::region_muted();
508 set_waveform_colors ();
512 AudioRegionView::setup_fade_handle_positions()
514 /* position of fade handle offset from the top of the region view */
515 double const handle_pos = 0.0;
517 if (fade_in_handle) {
518 fade_in_handle->set_y0 (handle_pos);
519 fade_in_handle->set_y1 (handle_pos + handle_size);
522 if (fade_out_handle) {
523 fade_out_handle->set_y0 (handle_pos);
524 fade_out_handle->set_y1 (handle_pos + handle_size);
527 if (fade_in_trim_handle) {
528 fade_in_trim_handle->set_y0 (_height - handle_size);
529 fade_in_trim_handle->set_y1 (_height);
532 if (fade_out_trim_handle) {
533 fade_out_trim_handle->set_y0 (_height - handle_size );
534 fade_out_trim_handle->set_y1 (_height);
539 AudioRegionView::set_height (gdouble height)
541 if (height == _height) {
545 RegionView::set_height (height);
546 pending_peak_data->set_y1 (height);
548 uint32_t wcnt = waves.size();
554 if (!UIConfiguration::instance().get_show_name_highlight() || (height < NAME_HIGHLIGHT_THRESH)) {
555 ht = height / (double) wcnt;
557 ht = (height - NAME_HIGHLIGHT_SIZE) / (double) wcnt;
560 for (uint32_t n = 0; n < wcnt; ++n) {
562 gdouble yoff = floor (ht * n);
564 waves[n]->set_height (ht);
565 waves[n]->set_y_position (yoff);
571 if ((height/wcnt) < NAME_HIGHLIGHT_THRESH) {
574 update_envelope_visibility ();
577 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE) - 2);
580 reset_fade_shapes ();
582 /* Update heights for any feature lines */
583 samplepos_t position = _region->position();
584 list<std::pair<samplepos_t, ArdourCanvas::Line*> >::iterator l;
586 if (_height >= NAME_HIGHLIGHT_THRESH) {
587 y1 = _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1;
591 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
592 float pos_x = trackview.editor().sample_to_pixel((*l).first - position);
593 (*l).second->set (ArdourCanvas::Duple (pos_x, 2.0),
594 ArdourCanvas::Duple (pos_x, y1));
598 name_text->raise_to_top();
601 setup_fade_handle_positions();
605 AudioRegionView::reset_fade_shapes ()
607 if (!trim_fade_in_drag_active) { reset_fade_in_shape (); }
608 if (!trim_fade_out_drag_active) { reset_fade_out_shape (); }
612 AudioRegionView::reset_fade_in_shape ()
614 reset_fade_in_shape_width (audio_region(), (samplecnt_t) audio_region()->fade_in()->back()->when);
618 AudioRegionView::reset_fade_in_shape_width (boost::shared_ptr<AudioRegion> ar, samplecnt_t width, bool drag_active)
620 trim_fade_in_drag_active = drag_active;
621 if (fade_in_handle == 0) {
625 /* smallest size for a fade is 64 samples */
627 width = std::max ((samplecnt_t) 64, width);
629 /* round here to prevent little visual glitches with sub-pixel placement */
630 double const pwidth = floor (width / samples_per_pixel);
631 double const handle_left = pwidth;
633 /* Put the fade in handle so that its left side is at the end-of-fade line */
634 fade_in_handle->set_x0 (handle_left);
635 fade_in_handle->set_x1 (handle_left + handle_size);
637 if (fade_in_trim_handle) {
638 fade_in_trim_handle->set_x0 (0);
639 fade_in_trim_handle->set_x1 (handle_size);
642 if (fade_in_handle->visible()) {
643 //see comment for drag_start
652 if (!trackview.session()->config.get_show_region_fades()) {
657 double effective_height;
659 if (_height >= NAME_HIGHLIGHT_THRESH) {
660 effective_height = _height - NAME_HIGHLIGHT_SIZE;
662 effective_height = _height;
665 /* points *MUST* be in anti-clockwise order */
668 Points::size_type pi;
669 boost::shared_ptr<const Evoral::ControlList> list (audio_region()->fade_in());
670 Evoral::ControlList::const_iterator x;
671 double length = list->length();
673 points.assign (list->size(), Duple());
675 for (x = list->begin(), pi = 0; x != list->end(); ++x, ++pi) {
676 points[pi].x = (pwidth * ((*x)->when/length));
677 points[pi].y = effective_height - ((*x)->value * (effective_height - 1.));
682 redraw_start_xfade_to (ar, width, points, effective_height, handle_left);
684 /* ensure trim handle stays on top */
685 if (sample_handle_start) {
686 sample_handle_start->raise_to_top();
691 AudioRegionView::reset_fade_out_shape ()
693 reset_fade_out_shape_width (audio_region(), (samplecnt_t) audio_region()->fade_out()->back()->when);
697 AudioRegionView::reset_fade_out_shape_width (boost::shared_ptr<AudioRegion> ar, samplecnt_t width, bool drag_active)
699 trim_fade_out_drag_active = drag_active;
700 if (fade_out_handle == 0) {
704 /* smallest size for a fade is 64 samples */
706 width = std::max ((samplecnt_t) 64, width);
709 double const pwidth = floor(trackview.editor().sample_to_pixel (width));
711 /* the right edge should be right on the region sample is the pixel
712 * width is zero. Hence the additional + 1.0 at the end.
715 double const handle_right = rint(trackview.editor().sample_to_pixel (_region->length()) - pwidth);
716 double const trim_handle_right = rint(trackview.editor().sample_to_pixel (_region->length()));
718 /* Put the fade out handle so that its right side is at the end-of-fade line;
720 fade_out_handle->set_x0 (handle_right - handle_size);
721 fade_out_handle->set_x1 (handle_right);
722 if (fade_out_trim_handle) {
723 fade_out_trim_handle->set_x0 (1 + trim_handle_right - handle_size);
724 fade_out_trim_handle->set_x1 (1 + trim_handle_right);
727 if (fade_out_handle->visible()) {
728 //see comment for drag_start
731 /* don't show shape if its too small */
738 if (!trackview.session()->config.get_show_region_fades()) {
743 double effective_height;
745 effective_height = _height;
747 if (UIConfiguration::instance().get_show_name_highlight() && effective_height >= NAME_HIGHLIGHT_THRESH) {
748 effective_height -= NAME_HIGHLIGHT_SIZE;
751 /* points *MUST* be in anti-clockwise order */
754 Points::size_type pi;
755 boost::shared_ptr<const Evoral::ControlList> list (audio_region()->fade_out());
756 Evoral::ControlList::const_iterator x;
757 double length = list->length();
759 points.assign (list->size(), Duple());
761 for (x = list->begin(), pi = 0; x != list->end(); ++x, ++pi) {
762 points[pi].x = _pixel_width - pwidth + (pwidth * ((*x)->when/length));
763 points[pi].y = effective_height - ((*x)->value * (effective_height - 1.));
768 redraw_end_xfade_to (ar, width, points, effective_height, handle_right, pwidth);
770 /* ensure trim handle stays on top */
771 if (sample_handle_end) {
772 sample_handle_end->raise_to_top();
777 AudioRegionView::get_fade_in_shape_width ()
779 return audio_region()->fade_in()->back()->when;
783 AudioRegionView::get_fade_out_shape_width ()
785 return audio_region()->fade_out()->back()->when;
790 AudioRegionView::redraw_start_xfade ()
792 boost::shared_ptr<AudioRegion> ar (audio_region());
794 if (!ar->fade_in() || ar->fade_in()->empty()) {
799 reset_fade_in_shape_width (ar, ar->fade_in()->back()->when);
803 AudioRegionView::redraw_start_xfade_to (boost::shared_ptr<AudioRegion> ar, samplecnt_t /*width*/, Points& points, double effective_height,
806 if (points.size() < 2) {
810 if (!start_xfade_curve) {
811 start_xfade_curve = new ArdourCanvas::XFadeCurve (group, ArdourCanvas::XFadeCurve::Start);
812 CANVAS_DEBUG_NAME (start_xfade_curve, string_compose ("xfade start out line for %1", region()->name()));
813 start_xfade_curve->set_fill_color (UIConfiguration::instance().color_mod ("active crossfade", "crossfade alpha"));
814 start_xfade_curve->set_outline_color (UIConfiguration::instance().color ("crossfade line"));
815 start_xfade_curve->set_ignore_events (true);
817 if (!start_xfade_rect) {
818 start_xfade_rect = new ArdourCanvas::Rectangle (group);
819 CANVAS_DEBUG_NAME (start_xfade_rect, string_compose ("xfade start rect for %1", region()->name()));
820 start_xfade_rect->set_outline_color (UIConfiguration::instance().color ("crossfade line"));
821 start_xfade_rect->set_fill (false);
822 start_xfade_rect->set_outline (false);
823 start_xfade_rect->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_start_xfade_event), start_xfade_rect, this));
824 start_xfade_rect->set_data ("regionview", this);
827 start_xfade_rect->set (ArdourCanvas::Rect (0.0, 0.0, rect_width, effective_height));
831 boost::shared_ptr<AutomationList> inverse = ar->inverse_fade_in ();
833 Points::size_type npoints;
837 /* there is no explicit inverse fade in curve, so take the
838 * regular fade in curve given to use as "points" (already a
839 * set of coordinates), and convert to the inverse shape.
842 npoints = points.size();
843 ipoints.assign (npoints, Duple());
845 for (Points::size_type i = 0, pci = 0; i < npoints; ++i, ++pci) {
846 ArdourCanvas::Duple &p (ipoints[pci]);
847 /* leave x-axis alone but invert with respect to y-axis */
848 p.y = effective_height - points[pci].y;
853 /* there is an explicit inverse fade in curve. Grab the points
854 and convert them into coordinates for the inverse fade in
858 npoints = inverse->size();
859 ipoints.assign (npoints, Duple());
861 Evoral::ControlList::const_iterator x;
862 Points::size_type pi;
863 double length = inverse->length();
865 for (x = inverse->begin(), pi = 0; x != inverse->end(); ++x, ++pi) {
866 ArdourCanvas::Duple& p (ipoints[pi]);
867 p.x = (rect_width * ((*x)->when/length));
868 p.y = effective_height - ((*x)->value * (effective_height));
872 start_xfade_curve->set_inout (points, ipoints);
878 AudioRegionView::redraw_end_xfade ()
880 boost::shared_ptr<AudioRegion> ar (audio_region());
882 if (!ar->fade_out() || ar->fade_out()->empty()) {
888 reset_fade_out_shape_width (ar, ar->fade_out()->back()->when);
892 AudioRegionView::redraw_end_xfade_to (boost::shared_ptr<AudioRegion> ar, samplecnt_t width, Points& points, double effective_height,
893 double rect_edge, double rect_width)
895 if (points.size() < 2) {
899 if (!end_xfade_curve) {
900 end_xfade_curve = new ArdourCanvas::XFadeCurve (group, ArdourCanvas::XFadeCurve::End);
901 CANVAS_DEBUG_NAME (end_xfade_curve, string_compose ("xfade end out line for %1", region()->name()));
902 end_xfade_curve->set_fill_color (UIConfiguration::instance().color_mod ("active crossfade", "crossfade alpha"));
903 end_xfade_curve->set_outline_color (UIConfiguration::instance().color ("crossfade line"));
904 end_xfade_curve->set_ignore_events (true);
907 if (!end_xfade_rect) {
908 end_xfade_rect = new ArdourCanvas::Rectangle (group);
909 CANVAS_DEBUG_NAME (end_xfade_rect, string_compose ("xfade end rect for %1", region()->name()));
910 end_xfade_rect->set_outline_color (UIConfiguration::instance().color ("crossfade line"));
911 end_xfade_rect->set_fill (false);
912 end_xfade_rect->set_outline (false);
913 end_xfade_rect->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_end_xfade_event), end_xfade_rect, this));
914 end_xfade_rect->set_data ("regionview", this);
917 end_xfade_rect->set (ArdourCanvas::Rect (rect_edge, 0.0, rect_edge + rect_width, effective_height));
921 boost::shared_ptr<AutomationList> inverse = ar->inverse_fade_out ();
923 Points::size_type npoints;
927 /* there is no explicit inverse fade out curve, so take the
928 * regular fade out curve given to use as "points" (already a
929 * set of coordinates), and convert to the inverse shape.
932 npoints = points.size();
933 ipoints.assign (npoints, Duple());
935 Points::size_type pci;
937 for (pci = 0; pci < npoints; ++pci) {
938 ArdourCanvas::Duple &p (ipoints[pci]);
939 p.y = effective_height - points[pci].y;
944 /* there is an explicit inverse fade out curve. Grab the points
945 and convert them into coordinates for the inverse fade out
949 npoints = inverse->size();
950 ipoints.assign (npoints, Duple());
952 const double rend = trackview.editor().sample_to_pixel (_region->length() - width);
954 Evoral::ControlList::const_iterator x;
955 Points::size_type pi;
956 double length = inverse->length();
958 for (x = inverse->begin(), pi = 0; x != inverse->end(); ++x, ++pi) {
959 ArdourCanvas::Duple& p (ipoints[pi]);
960 p.x = (rect_width * ((*x)->when/length)) + rend;
961 p.y = effective_height - ((*x)->value * (effective_height));
965 end_xfade_curve->set_inout (ipoints, points);
971 AudioRegionView::hide_xfades ()
978 AudioRegionView::hide_start_xfade ()
980 if (start_xfade_curve) {
981 start_xfade_curve->hide();
983 if (start_xfade_rect) {
984 start_xfade_rect->hide ();
987 _start_xfade_visible = false;
991 AudioRegionView::hide_end_xfade ()
993 if (end_xfade_curve) {
994 end_xfade_curve->hide();
996 if (end_xfade_rect) {
997 end_xfade_rect->hide ();
1000 _end_xfade_visible = false;
1004 AudioRegionView::show_start_xfade ()
1006 if (start_xfade_curve) {
1007 start_xfade_curve->show();
1009 if (start_xfade_rect) {
1010 start_xfade_rect->show ();
1013 _start_xfade_visible = true;
1017 AudioRegionView::show_end_xfade ()
1019 if (end_xfade_curve) {
1020 end_xfade_curve->show();
1022 if (end_xfade_rect) {
1023 end_xfade_rect->show ();
1026 _end_xfade_visible = true;
1030 AudioRegionView::set_samples_per_pixel (gdouble fpp)
1032 RegionView::set_samples_per_pixel (fpp);
1034 if (UIConfiguration::instance().get_show_waveforms ()) {
1035 for (uint32_t n = 0; n < waves.size(); ++n) {
1036 waves[n]->set_samples_per_pixel (fpp);
1041 gain_line->reset ();
1044 reset_fade_shapes ();
1048 AudioRegionView::set_amplitude_above_axis (gdouble a)
1050 for (uint32_t n=0; n < waves.size(); ++n) {
1051 waves[n]->set_amplitude_above_axis (a);
1056 AudioRegionView::set_colors ()
1058 RegionView::set_colors();
1061 gain_line->set_line_color (audio_region()->envelope_active() ?
1062 UIConfiguration::instance().color ("gain line") :
1063 UIConfiguration::instance().color_mod ("gain line inactive", "gain line inactive"));
1066 set_waveform_colors ();
1068 if (start_xfade_curve) {
1069 start_xfade_curve->set_fill_color (UIConfiguration::instance().color_mod ("active crossfade", "crossfade alpha"));
1070 start_xfade_curve->set_outline_color (UIConfiguration::instance().color ("crossfade line"));
1072 if (end_xfade_curve) {
1073 end_xfade_curve->set_fill_color (UIConfiguration::instance().color_mod ("active crossfade", "crossfade alpha"));
1074 end_xfade_curve->set_outline_color (UIConfiguration::instance().color ("crossfade line"));
1077 if (start_xfade_rect) {
1078 start_xfade_rect->set_outline_color (UIConfiguration::instance().color ("crossfade line"));
1080 if (end_xfade_rect) {
1081 end_xfade_rect->set_outline_color (UIConfiguration::instance().color ("crossfade line"));
1086 AudioRegionView::setup_waveform_visibility ()
1088 if (UIConfiguration::instance().get_show_waveforms ()) {
1089 for (uint32_t n = 0; n < waves.size(); ++n) {
1090 /* make sure the zoom level is correct, since we don't update
1091 this when waveforms are hidden.
1094 // waves[n]->set_samples_per_pixel (_samples_per_pixel);
1098 for (uint32_t n = 0; n < waves.size(); ++n) {
1105 AudioRegionView::temporarily_hide_envelope ()
1113 AudioRegionView::unhide_envelope ()
1115 update_envelope_visibility ();
1119 AudioRegionView::update_envelope_visibility ()
1125 if (trackview.editor().current_mouse_mode() == Editing::MouseDraw || trackview.editor().current_mouse_mode() == Editing::MouseContent ) {
1126 gain_line->set_visibility (AutomationLine::VisibleAspects(AutomationLine::ControlPoints|AutomationLine::Line));
1127 gain_line->canvas_group().raise_to_top ();
1128 } else if (UIConfiguration::instance().get_show_region_gain() || trackview.editor().current_mouse_mode() == Editing::MouseRange ) {
1129 gain_line->set_visibility (AutomationLine::VisibleAspects(AutomationLine::Line));
1130 gain_line->canvas_group().raise_to_top ();
1132 gain_line->set_visibility (AutomationLine::VisibleAspects(0));
1137 AudioRegionView::delete_waves ()
1139 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
1142 _data_ready_connections.clear ();
1144 for (vector<ArdourWaveView::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1149 pending_peak_data->show ();
1153 AudioRegionView::create_waves ()
1155 // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
1156 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
1162 ChanCount nchans = atv.track()->n_channels();
1164 // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data
1165 // << " and channels = " << nchans.n_audio() << endl;
1167 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
1168 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
1169 tmp_waves.push_back (0);
1172 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
1176 _data_ready_connections.clear ();
1178 for (uint32_t i = 0; i < nchans.n_audio(); ++i) {
1179 _data_ready_connections.push_back (0);
1182 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
1184 if (n >= audio_region()->n_channels()) {
1188 // cerr << "\tchannel " << n << endl;
1190 if (wait_for_data) {
1191 if (audio_region()->audio_source(n)->peaks_ready (boost::bind (&AudioRegionView::peaks_ready_handler, this, n), &_data_ready_connections[n], gui_context())) {
1192 // cerr << "\tData is ready\n";
1193 create_one_wave (n, true);
1195 // cerr << "\tdata is not ready\n";
1196 // we'll get a PeaksReady signal from the source in the future
1197 // and will call create_one_wave(n) then.
1198 pending_peak_data->show ();
1202 // cerr << "\tdon't delay, display today!\n";
1203 create_one_wave (n, true);
1210 AudioRegionView::create_one_wave (uint32_t which, bool /*direct*/)
1212 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
1213 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
1214 if (!trackview.session() || trackview.session()->deletion_in_progress () || !atv.track()) {
1215 /* peaks_ready_handler() may be called from peak_thread_work() while
1216 * session deletion is in progress.
1217 * Since session-unload happens in the GUI thread, we need to test
1222 uint32_t nchans = atv.track()->n_channels().n_audio();
1224 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
1227 /* compare to set_height(), use _height as set by streamview (child_height),
1228 * not trackview.current_height() to take stacked layering into acconnt
1230 if (!UIConfiguration::instance().get_show_name_highlight() || (_height < NAME_HIGHLIGHT_THRESH)) {
1231 ht = _height / (double) nchans;
1233 ht = (_height - NAME_HIGHLIGHT_SIZE) / (double) nchans;
1236 /* first waveview starts at 1.0, not 0.0 since that will overlap the
1240 gdouble yoff = which * ht;
1242 ArdourWaveView::WaveView *wave = new ArdourWaveView::WaveView (group, audio_region ());
1243 CANVAS_DEBUG_NAME (wave, string_compose ("wave view for chn %1 of %2", which, get_item_name()));
1245 wave->set_channel (which);
1246 wave->set_y_position (yoff);
1247 wave->set_height (ht);
1248 wave->set_samples_per_pixel (samples_per_pixel);
1249 wave->set_show_zero_line (true);
1250 wave->set_clip_level (UIConfiguration::instance().get_waveform_clip_level ());
1251 wave->set_start_shift (1.0);
1253 wave->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_wave_view_event), wave, this));
1255 switch (UIConfiguration::instance().get_waveform_shape()) {
1257 wave->set_shape (ArdourWaveView::WaveView::Rectified);
1260 wave->set_shape (ArdourWaveView::WaveView::Normal);
1263 wave->set_logscaled (UIConfiguration::instance().get_waveform_scale() == Logarithmic);
1265 vector<ArdourWaveView::WaveView*> v;
1267 set_some_waveform_colors (v);
1269 if (!UIConfiguration::instance().get_show_waveforms ()) {
1273 /* note: calling this function is serialized by the lock
1274 held in the peak building thread that signals that
1275 peaks are ready for use *or* by the fact that it is
1276 called one by one from the GUI thread.
1279 if (which < nchans) {
1280 tmp_waves[which] = wave;
1282 /* n-channel track, >n-channel source */
1285 /* see if we're all ready */
1287 for (n = 0; n < nchans; ++n) {
1288 if (tmp_waves[n] == 0) {
1293 if (n == nwaves && waves.empty()) {
1294 /* all waves are ready */
1295 tmp_waves.resize(nwaves);
1300 /* indicate peak-completed */
1301 pending_peak_data->hide ();
1303 /* Restore stacked coverage */
1304 LayerDisplay layer_display;
1305 if (trackview.get_gui_property ("layer-display", layer_display)) {
1306 update_coverage_samples (layer_display);
1310 /* channel wave created, don't hook into peaks ready anymore */
1311 delete _data_ready_connections[which];
1312 _data_ready_connections[which] = 0;
1316 AudioRegionView::peaks_ready_handler (uint32_t which)
1318 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AudioRegionView::create_one_wave, this, which, false));
1319 // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
1323 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev, bool with_guard_points)
1329 uint32_t before_p, after_p;
1330 double mx = ev->button.x;
1331 double my = ev->button.y;
1333 item->canvas_to_item (mx, my);
1335 samplecnt_t const sample_within_region = (samplecnt_t) floor (mx * samples_per_pixel);
1337 if (!gain_line->control_points_adjacent (sample_within_region, before_p, after_p)) {
1338 /* no adjacent points */
1342 /*y is in item sample */
1343 double const bx = gain_line->nth (before_p)->get_x();
1344 double const ax = gain_line->nth (after_p)->get_x();
1345 double const click_ratio = (ax - mx) / (ax - bx);
1347 double y = ((gain_line->nth (before_p)->get_y() * click_ratio) + (gain_line->nth (after_p)->get_y() * (1 - click_ratio)));
1349 /* don't create points that can't be seen */
1351 update_envelope_visibility ();
1352 samplepos_t rpos = region ()->position ();
1353 MusicSample snap_pos (trackview.editor().pixel_to_sample (mx) + rpos, 0);
1354 trackview.editor ().snap_to_with_modifier (snap_pos, ev);
1355 samplepos_t fx = snap_pos.sample - rpos;
1357 if (fx > _region->length()) {
1361 /* compute vertical fractional position */
1363 y = 1.0 - (y / (gain_line->height()));
1365 /* map using gain line */
1367 gain_line->view_to_model_coord (mx, y);
1369 /* XXX STATEFUL: can't convert to stateful diff until we
1370 can represent automation data with it.
1373 XMLNode &before = audio_region()->envelope()->get_state();
1374 MementoCommand<AudioRegion>* region_memento = 0;
1376 if (!audio_region()->envelope_active()) {
1377 XMLNode ®ion_before = audio_region()->get_state();
1378 audio_region()->set_envelope_active(true);
1379 XMLNode ®ion_after = audio_region()->get_state();
1380 region_memento = new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after);
1383 if (audio_region()->envelope()->editor_add (fx, y, with_guard_points)) {
1384 XMLNode &after = audio_region()->envelope()->get_state();
1385 std::list<Selectable*> results;
1387 trackview.editor().begin_reversible_command (_("add gain control point"));
1389 if (region_memento) {
1390 trackview.session()->add_command (region_memento);
1393 trackview.session()->add_command (new MementoCommand<AutomationList>(*audio_region()->envelope().get(), &before, &after));
1395 gain_line->get_selectables (fx + region ()->position (), fx + region ()->position (), 0.0, 1.0, results);
1396 trackview.editor ().get_selection ().set (results);
1398 trackview.editor ().commit_reversible_command ();
1399 trackview.session ()->set_dirty ();
1401 delete region_memento;
1406 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent* /*ev*/)
1408 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1409 audio_region()->envelope()->erase (cp->model());
1413 AudioRegionView::add_ghost (TimeAxisView& tv)
1415 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1421 double unit_position = _region->position () / samples_per_pixel;
1422 AudioGhostRegion* ghost = new AudioGhostRegion (*this, tv, trackview, unit_position);
1425 nchans = rtv->track()->n_channels().n_audio();
1427 for (uint32_t n = 0; n < nchans; ++n) {
1429 if (n >= audio_region()->n_channels()) {
1433 ArdourWaveView::WaveView *wave = new ArdourWaveView::WaveView (ghost->group, audio_region());
1434 CANVAS_DEBUG_NAME (wave, string_compose ("ghost wave for %1", get_item_name()));
1436 wave->set_channel (n);
1437 wave->set_samples_per_pixel (samples_per_pixel);
1438 wave->set_amplitude_above_axis (_amplitude_above_axis);
1440 ghost->waves.push_back(wave);
1443 ghost->set_height ();
1444 ghost->set_duration (_region->length() / samples_per_pixel);
1445 ghost->set_colors();
1446 ghosts.push_back (ghost);
1452 AudioRegionView::entered ()
1454 trackview.editor().set_current_trimmable (_region);
1455 trackview.editor().set_current_movable (_region);
1457 update_envelope_visibility();
1459 if ((trackview.editor().current_mouse_mode() == Editing::MouseObject)) {
1460 if (start_xfade_rect) {
1461 start_xfade_rect->set_outline (true);
1463 if (end_xfade_rect) {
1464 end_xfade_rect->set_outline (true);
1466 if (fade_in_handle) {
1467 fade_in_handle->show ();
1468 fade_in_handle->raise_to_top ();
1470 if (fade_out_handle) {
1471 fade_out_handle->show ();
1472 fade_out_handle->raise_to_top ();
1474 if (fade_in_trim_handle) {
1475 boost::shared_ptr<AudioRegion> ar (audio_region());
1476 if (!ar->locked() && (ar->fade_in()->back()->when > 64 || (ar->can_trim() & Trimmable::FrontTrimEarlier))) {
1477 fade_in_trim_handle->show ();
1478 fade_in_trim_handle->raise_to_top ();
1480 fade_in_trim_handle->hide ();
1483 if (fade_out_trim_handle) {
1484 boost::shared_ptr<AudioRegion> ar (audio_region());
1485 if (!ar->locked() && (ar->fade_out()->back()->when > 64 || (ar->can_trim() & Trimmable::EndTrimLater))) {
1486 fade_out_trim_handle->show ();
1487 fade_out_trim_handle->raise_to_top ();
1489 fade_out_trim_handle->hide ();
1492 } else { //this happens when we switch tools; if we switch away from Grab mode, hide all the fade handles
1493 if (fade_in_handle) { fade_in_handle->hide(); }
1494 if (fade_out_handle) { fade_out_handle->hide(); }
1495 if (fade_in_trim_handle) { fade_in_trim_handle->hide(); }
1496 if (fade_out_trim_handle) { fade_out_trim_handle->hide(); }
1497 if (start_xfade_rect) { start_xfade_rect->set_outline (false); }
1498 if (end_xfade_rect) { end_xfade_rect->set_outline (false); }
1503 AudioRegionView::exited ()
1505 trackview.editor().set_current_trimmable (boost::shared_ptr<Trimmable>());
1506 trackview.editor().set_current_movable (boost::shared_ptr<Movable>());
1509 // gain_line->remove_visibility (AutomationLine::ControlPoints);
1512 if (fade_in_handle) { fade_in_handle->hide(); }
1513 if (fade_out_handle) { fade_out_handle->hide(); }
1514 if (fade_in_trim_handle) { fade_in_trim_handle->hide(); }
1515 if (fade_out_trim_handle) { fade_out_trim_handle->hide(); }
1516 if (start_xfade_rect) { start_xfade_rect->set_outline (false); }
1517 if (end_xfade_rect) { end_xfade_rect->set_outline (false); }
1521 AudioRegionView::envelope_active_changed ()
1524 gain_line->set_line_color (audio_region()->envelope_active() ?
1525 UIConfiguration::instance().color ("gain line") :
1526 UIConfiguration::instance().color_mod ("gain line inactive", "gain line inactive"));
1527 update_envelope_visibility ();
1532 AudioRegionView::color_handler ()
1534 //case cMutedWaveForm:
1536 //case cWaveFormClip:
1540 //case cGainLineInactive:
1542 envelope_active_changed();
1547 AudioRegionView::set_waveform_colors ()
1549 set_some_waveform_colors (waves);
1553 AudioRegionView::set_some_waveform_colors (vector<ArdourWaveView::WaveView*>& waves_to_color)
1555 Gtkmm2ext::Color fill;
1556 Gtkmm2ext::Color outline;
1557 Gtkmm2ext::Color clip = UIConfiguration::instance().color ("clipped waveform");
1558 Gtkmm2ext::Color zero = UIConfiguration::instance().color ("zero line");
1561 if (_region->muted()) {
1562 /* hide outline with zero alpha */
1563 outline = UINT_RGBA_CHANGE_A(UIConfiguration::instance().color ("selected waveform outline"), 0);
1564 fill = UINT_RGBA_CHANGE_A(UIConfiguration::instance().color ("selected waveform fill"), MUTED_ALPHA);
1566 outline = UIConfiguration::instance().color ("selected waveform outline");
1567 fill = UIConfiguration::instance().color ("selected waveform fill");
1571 outline = UIConfiguration::instance().color ("recording waveform outline");
1572 fill = UIConfiguration::instance().color ("recording waveform fill");
1574 if (_region->muted()) {
1575 /* hide outline with zero alpha */
1576 outline = UINT_RGBA_CHANGE_A(UIConfiguration::instance().color ("waveform outline"), 0);
1577 fill = UINT_RGBA_CHANGE_A(UIConfiguration::instance().color ("waveform fill"), MUTED_ALPHA);
1579 outline = UIConfiguration::instance().color ("waveform outline");
1580 fill = UIConfiguration::instance().color ("waveform fill");
1585 for (vector<ArdourWaveView::WaveView*>::iterator w = waves_to_color.begin(); w != waves_to_color.end(); ++w) {
1586 (*w)->set_fill_color (fill);
1587 (*w)->set_outline_color (outline);
1588 (*w)->set_clip_color (clip);
1589 (*w)->set_zero_color (zero);
1594 AudioRegionView::set_sample_color ()
1600 RegionView::set_sample_color ();
1602 set_waveform_colors ();
1606 AudioRegionView::set_fade_visibility (bool yn)
1609 if (start_xfade_curve) { start_xfade_curve->show (); }
1610 if (end_xfade_curve) { end_xfade_curve->show (); }
1611 if (start_xfade_rect) { start_xfade_rect->show (); }
1612 if (end_xfade_rect) { end_xfade_rect->show (); }
1614 if (start_xfade_curve) { start_xfade_curve->hide(); }
1615 if (end_xfade_curve) { end_xfade_curve->hide(); }
1616 if (fade_in_handle) { fade_in_handle->hide(); }
1617 if (fade_out_handle) { fade_out_handle->hide(); }
1618 if (fade_in_trim_handle) { fade_in_trim_handle->hide(); }
1619 if (fade_out_trim_handle) { fade_out_trim_handle->hide(); }
1620 if (start_xfade_rect) { start_xfade_rect->hide (); }
1621 if (end_xfade_rect) { end_xfade_rect->hide (); }
1622 if (start_xfade_rect) { start_xfade_rect->set_outline (false); }
1623 if (end_xfade_rect) { end_xfade_rect->set_outline (false); }
1628 AudioRegionView::update_coverage_samples (LayerDisplay d)
1630 RegionView::update_coverage_samples (d);
1633 if (fade_in_handle) { fade_in_handle->raise_to_top (); }
1634 if (fade_out_handle) { fade_out_handle->raise_to_top (); }
1635 if (fade_in_trim_handle) { fade_in_trim_handle->raise_to_top (); }
1636 if (fade_out_trim_handle) { fade_out_trim_handle->raise_to_top (); }
1641 AudioRegionView::show_region_editor ()
1644 editor = new AudioRegionEditor (trackview.session(), audio_region());
1652 AudioRegionView::transients_changed ()
1654 AnalysisFeatureList analysis_features;
1655 _region->transients (analysis_features);
1656 samplepos_t position = _region->position();
1657 samplepos_t first = _region->first_sample();
1658 samplepos_t last = _region->last_sample();
1661 if (_height >= NAME_HIGHLIGHT_THRESH) {
1662 y1 = _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1;
1667 while (feature_lines.size() < analysis_features.size()) {
1668 ArdourCanvas::Line* canvas_item = new ArdourCanvas::Line(group);
1669 CANVAS_DEBUG_NAME (canvas_item, string_compose ("transient group for %1", region()->name()));
1670 canvas_item->set_outline_color (UIConfiguration::instance().color ("zero line")); // also in Editor::leave_handler()
1672 canvas_item->set (ArdourCanvas::Duple (-1.0, 2.0),
1673 ArdourCanvas::Duple (1.0, y1));
1675 canvas_item->raise_to_top ();
1676 canvas_item->show ();
1678 canvas_item->set_data ("regionview", this);
1679 canvas_item->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_feature_line_event), canvas_item, this));
1681 feature_lines.push_back (make_pair(0, canvas_item));
1684 while (feature_lines.size() > analysis_features.size()) {
1685 ArdourCanvas::Line* line = feature_lines.back().second;
1686 feature_lines.pop_back ();
1690 AnalysisFeatureList::const_iterator i;
1691 list<std::pair<samplepos_t, ArdourCanvas::Line*> >::iterator l;
1693 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
1695 float *pos = new float;
1696 *pos = trackview.editor().sample_to_pixel (*i - position);
1699 ArdourCanvas::Duple (*pos, 2.0),
1700 ArdourCanvas::Duple (*pos, y1)
1703 (*l).second->set_data ("position", pos); // is this *modified* (drag?), if not use *i
1706 if (l->first < first || l->first >= last) {
1715 AudioRegionView::update_transient(float /*old_pos*/, float new_pos)
1717 /* Find sample at old pos, calulate new sample then update region transients*/
1718 list<std::pair<samplepos_t, ArdourCanvas::Line*> >::iterator l;
1720 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1722 /* Line has been updated in drag so we compare to new_pos */
1724 float* pos = (float*) (*l).second->get_data ("position");
1726 if (rint(new_pos) == rint(*pos)) {
1727 samplepos_t position = _region->position();
1728 samplepos_t old_sample = (*l).first;
1729 samplepos_t new_sample = trackview.editor().pixel_to_sample (new_pos) + position;
1730 _region->update_transient (old_sample, new_sample);
1737 AudioRegionView::remove_transient (float pos)
1739 /* this is called from Editor::remove_transient () with pos == get_data ("position")
1740 * which is the item's x-coordinate inside the ARV.
1742 * Find sample at old pos, calulate new sample then update region transients
1744 list<std::pair<samplepos_t, ArdourCanvas::Line*> >::iterator l;
1746 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1747 float *line_pos = (float*) (*l).second->get_data ("position");
1748 if (rint(pos) == rint(*line_pos)) {
1749 _region->remove_transient ((*l).first);
1756 AudioRegionView::thaw_after_trim ()
1758 RegionView::thaw_after_trim ();
1765 AudioRegionView::show_xfades ()
1767 show_start_xfade ();
1772 AudioRegionView::drag_start ()
1774 TimeAxisViewItem::drag_start ();
1776 //we used to hide xfades here. I don't see the point with the new model, but we can re-implement if needed
1780 AudioRegionView::drag_end ()
1782 TimeAxisViewItem::drag_end ();
1783 //see comment for drag_start
1785 if (fade_in_handle && fade_in_handle->visible()) {
1786 // lenght of region or fade changed, re-check
1787 // if fade_in_trim_handle or fade_out_trim_handle should
1788 // be visible. -- If the fade_in_handle is visible
1789 // we have focus and are not in internal edit mode.
1795 AudioRegionView::parameter_changed (string const & p)
1797 if (p == "show-waveforms") {
1798 setup_waveform_visibility ();