2 Copyright (C) 2001-2006 Paul Davis
4 This program is free software; you can r>edistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <boost/scoped_array.hpp>
28 #include <gtkmm2ext/gtk_ui.h>
30 #include "ardour/playlist.h"
31 #include "ardour/audioregion.h"
32 #include "ardour/audiosource.h"
33 #include "ardour/profile.h"
34 #include "ardour/session.h"
36 #include "pbd/memento_command.h"
37 #include "pbd/stacktrace.h"
39 #include "evoral/Curve.hpp"
41 #include "canvas/rectangle.h"
42 #include "canvas/polygon.h"
43 #include "canvas/poly_line.h"
44 #include "canvas/line.h"
45 #include "canvas/text.h"
46 #include "canvas/xfade_curve.h"
47 #include "canvas/debug.h"
48 #include "canvas/utils.h"
49 #include "canvas/colors.h"
51 #include "streamview.h"
52 #include "audio_region_view.h"
53 #include "audio_time_axis.h"
54 #include "public_editor.h"
55 #include "audio_region_editor.h"
56 #include "audio_streamview.h"
57 #include "region_gain_line.h"
58 #include "control_point.h"
59 #include "ghostregion.h"
60 #include "audio_time_axis.h"
61 #include "rgb_macros.h"
62 #include "gui_thread.h"
63 #include "ui_config.h"
67 #define MUTED_ALPHA 48
70 using namespace ARDOUR;
72 using namespace Editing;
73 using namespace ArdourCanvas;
75 static double const handle_size = 10; /* height of fade handles */
77 Cairo::RefPtr<Cairo::Pattern> AudioRegionView::pending_peak_pattern;
79 static Cairo::RefPtr<Cairo::Pattern> create_pending_peak_pattern() {
80 cairo_surface_t * is = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 8, 8);
82 // create checker pattern
83 unsigned char *img = cairo_image_surface_get_data (is);
84 cairo_surface_flush (is);
85 const int stride = cairo_image_surface_get_stride (is);
87 for (int y = 0; y < 8; ++y) {
88 for (int x = 0; x < 8; ++x) {
89 const int off = (y * stride + x * 4);
90 uint32_t *pixel = (uint32_t*) &img[off];
91 if ((x < 4) ^ (y < 4)) {
98 cairo_surface_mark_dirty (is);
100 cairo_pattern_t* pat = cairo_pattern_create_for_surface (is);
101 cairo_pattern_set_extend (pat, CAIRO_EXTEND_REPEAT);
102 Cairo::RefPtr<Cairo::Pattern> p (new Cairo::Pattern (pat, false));
103 cairo_surface_destroy (is);
107 AudioRegionView::AudioRegionView (ArdourCanvas::Container *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
108 uint32_t basic_color)
109 : RegionView (parent, tv, r, spu, basic_color)
113 , fade_in_trim_handle(0)
114 , fade_out_trim_handle(0)
115 , pending_peak_data(0)
116 , start_xfade_curve (0)
117 , start_xfade_rect (0)
118 , _start_xfade_visible (false)
119 , end_xfade_curve (0)
121 , _end_xfade_visible (false)
122 , _amplitude_above_axis(1.0)
123 , trim_fade_in_drag_active(false)
124 , trim_fade_out_drag_active(false)
126 UIConfiguration::instance().ParameterChanged.connect (sigc::mem_fun (*this, &AudioRegionView::parameter_changed));
129 AudioRegionView::AudioRegionView (ArdourCanvas::Container *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
130 uint32_t basic_color, bool recording, TimeAxisViewItem::Visibility visibility)
131 : RegionView (parent, tv, r, spu, basic_color, recording, visibility)
135 , fade_in_trim_handle(0)
136 , fade_out_trim_handle(0)
137 , pending_peak_data(0)
138 , start_xfade_curve (0)
139 , start_xfade_rect (0)
140 , _start_xfade_visible (false)
141 , end_xfade_curve (0)
143 , _end_xfade_visible (false)
144 , _amplitude_above_axis(1.0)
145 , trim_fade_in_drag_active(false)
146 , trim_fade_out_drag_active(false)
148 UIConfiguration::instance().ParameterChanged.connect (sigc::mem_fun (*this, &AudioRegionView::parameter_changed));
151 AudioRegionView::AudioRegionView (const AudioRegionView& other, boost::shared_ptr<AudioRegion> other_region)
152 : RegionView (other, boost::shared_ptr<Region> (other_region))
155 , fade_in_trim_handle(0)
156 , fade_out_trim_handle(0)
157 , pending_peak_data(0)
158 , start_xfade_curve (0)
159 , start_xfade_rect (0)
160 , _start_xfade_visible (false)
161 , end_xfade_curve (0)
163 , _end_xfade_visible (false)
164 , _amplitude_above_axis (other._amplitude_above_axis)
165 , trim_fade_in_drag_active(false)
166 , trim_fade_out_drag_active(false)
170 UIConfiguration::instance().ParameterChanged.connect (sigc::mem_fun (*this, &AudioRegionView::parameter_changed));
174 AudioRegionView::init (bool wfd)
176 // FIXME: Some redundancy here with RegionView::init. Need to figure out
177 // where order is important and where it isn't...
179 if (!pending_peak_pattern) {
180 pending_peak_pattern = create_pending_peak_pattern();
183 // needs to be created first, RegionView::init() calls set_height()
184 pending_peak_data = new ArdourCanvas::Rectangle (group);
185 CANVAS_DEBUG_NAME (pending_peak_data, string_compose ("pending peak rectangle for %1", region()->name()));
186 pending_peak_data->set_outline_color (ArdourCanvas::rgba_to_color (0, 0, 0, 0.0));
187 pending_peak_data->set_pattern (pending_peak_pattern);
188 pending_peak_data->set_data ("regionview", this);
189 pending_peak_data->hide ();
191 RegionView::init (wfd);
193 _amplitude_above_axis = 1.0;
198 fade_in_handle = new ArdourCanvas::Rectangle (group);
199 CANVAS_DEBUG_NAME (fade_in_handle, string_compose ("fade in handle for %1", region()->name()));
200 fade_in_handle->set_outline_color (ArdourCanvas::rgba_to_color (0, 0, 0, 1.0));
201 fade_in_handle->set_fill_color (UIConfiguration::instance().color ("inactive fade handle"));
202 fade_in_handle->set_data ("regionview", this);
203 fade_in_handle->hide ();
205 fade_out_handle = new ArdourCanvas::Rectangle (group);
206 CANVAS_DEBUG_NAME (fade_out_handle, string_compose ("fade out handle for %1", region()->name()));
207 fade_out_handle->set_outline_color (ArdourCanvas::rgba_to_color (0, 0, 0, 1.0));
208 fade_out_handle->set_fill_color (UIConfiguration::instance().color ("inactive fade handle"));
209 fade_out_handle->set_data ("regionview", this);
210 fade_out_handle->hide ();
212 fade_in_trim_handle = new ArdourCanvas::Rectangle (group);
213 CANVAS_DEBUG_NAME (fade_in_handle, string_compose ("fade in trim handle for %1", region()->name()));
214 fade_in_trim_handle->set_outline_color (ArdourCanvas::rgba_to_color (0, 0, 0, 1.0));
215 fade_in_trim_handle->set_fill_color (UIConfiguration::instance().color ("inactive fade handle"));
216 fade_in_trim_handle->set_data ("regionview", this);
217 fade_in_trim_handle->hide ();
219 fade_out_trim_handle = new ArdourCanvas::Rectangle (group);
220 CANVAS_DEBUG_NAME (fade_out_handle, string_compose ("fade out trim handle for %1", region()->name()));
221 fade_out_trim_handle->set_outline_color (ArdourCanvas::rgba_to_color (0, 0, 0, 1.0));
222 fade_out_trim_handle->set_fill_color (UIConfiguration::instance().color ("inactive fade handle"));
223 fade_out_trim_handle->set_data ("regionview", this);
224 fade_out_trim_handle->hide ();
227 setup_fade_handle_positions ();
229 if (!trackview.session()->config.get_show_region_fades()) {
230 set_fade_visibility (false);
233 const string line_name = _region->name() + ":gain";
235 gain_line.reset (new AudioRegionGainLine (line_name, *this, *group, audio_region()->envelope()));
237 update_envelope_visibility ();
240 /* streamview will call set_height() */
241 //set_height (trackview.current_height()); // XXX not correct for Layered mode, but set_height() will fix later.
244 region_sync_changed ();
246 region_resized (ARDOUR::bounds_change);
247 /* region_resized sets ghost region duration */
249 /* region_locked is a synonym for region_renamed () which is called in region_muted() above */
252 envelope_active_changed ();
253 fade_in_active_changed ();
254 fade_out_active_changed ();
256 reset_width_dependent_items (_pixel_width);
258 if (fade_in_handle) {
259 fade_in_handle->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this, false));
262 if (fade_out_handle) {
263 fade_out_handle->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this, false));
266 if (fade_in_trim_handle) {
267 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));
270 if (fade_out_trim_handle) {
271 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));
276 setup_waveform_visibility ();
278 /* XXX sync mark drag? */
281 AudioRegionView::~AudioRegionView ()
283 in_destructor = true;
285 RegionViewGoingAway (this); /* EMIT_SIGNAL */
287 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
290 _data_ready_connections.clear ();
292 for (list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator i = feature_lines.begin(); i != feature_lines.end(); ++i) {
293 delete ((*i).second);
296 /* all waveviews etc will be destroyed when the group is destroyed */
299 boost::shared_ptr<ARDOUR::AudioRegion>
300 AudioRegionView::audio_region() const
302 // "Guaranteed" to succeed...
303 return boost::dynamic_pointer_cast<AudioRegion>(_region);
307 AudioRegionView::region_changed (const PropertyChange& what_changed)
309 ENSURE_GUI_THREAD (*this, &AudioRegionView::region_changed, what_changed);
311 RegionView::region_changed (what_changed);
313 if (what_changed.contains (ARDOUR::Properties::scale_amplitude)) {
314 region_scale_amplitude_changed ();
316 if (what_changed.contains (ARDOUR::Properties::fade_in)) {
319 if (what_changed.contains (ARDOUR::Properties::fade_out)) {
322 if (what_changed.contains (ARDOUR::Properties::fade_in_active)) {
323 fade_in_active_changed ();
325 if (what_changed.contains (ARDOUR::Properties::fade_out_active)) {
326 fade_out_active_changed ();
328 if (what_changed.contains (ARDOUR::Properties::envelope_active)) {
329 envelope_active_changed ();
331 if (what_changed.contains (ARDOUR::Properties::valid_transients)) {
332 transients_changed ();
337 AudioRegionView::fade_in_changed ()
339 reset_fade_in_shape ();
343 AudioRegionView::fade_out_changed ()
345 reset_fade_out_shape ();
349 AudioRegionView::fade_in_active_changed ()
351 if (start_xfade_rect) {
352 if (audio_region()->fade_in_active()) {
353 start_xfade_rect->set_fill (false);
355 start_xfade_rect->set_fill_color (UIConfiguration::instance().color_mod ("inactive crossfade", "inactive crossfade"));
356 start_xfade_rect->set_fill (true);
362 AudioRegionView::fade_out_active_changed ()
364 if (end_xfade_rect) {
365 if (audio_region()->fade_out_active()) {
366 end_xfade_rect->set_fill (false);
368 end_xfade_rect->set_fill_color (UIConfiguration::instance().color_mod ("inactive crossfade", "inactive crossfade"));
369 end_xfade_rect->set_fill (true);
376 AudioRegionView::region_scale_amplitude_changed ()
378 for (uint32_t n = 0; n < waves.size(); ++n) {
379 waves[n]->gain_changed ();
385 AudioRegionView::region_renamed ()
387 std::string str = RegionView::make_name ();
389 if (audio_region()->speed_mismatch (trackview.session()->frame_rate())) {
390 str = string ("*") + str;
393 if (_region->muted()) {
394 str = string ("!") + str;
398 boost::shared_ptr<AudioRegion> ar (audio_region());
399 if (ar->scale_amplitude() != 1.0) {
401 snprintf (tmp, 32, " (%.1fdB)", accurate_coefficient_to_dB (ar->scale_amplitude()));
405 set_item_name (str, this);
410 AudioRegionView::region_resized (const PropertyChange& what_changed)
412 AudioGhostRegion* agr;
414 RegionView::region_resized(what_changed);
415 PropertyChange interesting_stuff;
417 interesting_stuff.add (ARDOUR::Properties::start);
418 interesting_stuff.add (ARDOUR::Properties::length);
420 if (what_changed.contains (interesting_stuff)) {
422 for (uint32_t n = 0; n < waves.size(); ++n) {
423 waves[n]->region_resized ();
426 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
427 if ((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
429 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
430 (*w)->region_resized ();
435 /* hide transient lines that extend beyond the region */
436 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
437 framepos_t first = _region->first_frame();
438 framepos_t last = _region->last_frame();
440 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
441 if (l->first < first || l->first >= last) {
451 AudioRegionView::reset_width_dependent_items (double pixel_width)
453 if (pixel_width == _width) {
457 RegionView::reset_width_dependent_items(pixel_width);
458 assert(_pixel_width == pixel_width);
460 pending_peak_data->set_x1(pixel_width);
462 if (pixel_width <= 20.0 || _height < 5.0 || !trackview.session()->config.get_show_region_fades()) {
463 if (fade_in_handle) { fade_in_handle->hide(); }
464 if (fade_out_handle) { fade_out_handle->hide(); }
465 if (fade_in_trim_handle) { fade_in_trim_handle->hide(); }
466 if (fade_out_trim_handle) { fade_out_trim_handle->hide(); }
467 if (start_xfade_rect) { start_xfade_rect->set_outline (false); }
468 if (end_xfade_rect) { end_xfade_rect->set_outline (false); }
471 reset_fade_shapes ();
473 /* Update feature lines */
474 AnalysisFeatureList analysis_features;
475 _region->transients (analysis_features);
477 if (feature_lines.size () != analysis_features.size ()) {
478 cerr << "postponed freature line update.\n"; // XXX
479 // AudioRegionView::transients_changed () will pick up on this
483 framepos_t position = _region->position();
485 AnalysisFeatureList::const_iterator i;
486 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
488 if (_height >= NAME_HIGHLIGHT_THRESH) {
489 y1 = _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1;
493 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
494 float x_pos = trackview.editor().sample_to_pixel ((*i) - position);
496 (*l).second->set (ArdourCanvas::Duple (x_pos, 2.0),
497 ArdourCanvas::Duple (x_pos, y1));
502 AudioRegionView::region_muted ()
504 RegionView::region_muted();
505 set_waveform_colors ();
509 AudioRegionView::setup_fade_handle_positions()
511 /* position of fade handle offset from the top of the region view */
512 double const handle_pos = 0.0;
514 if (fade_in_handle) {
515 fade_in_handle->set_y0 (handle_pos);
516 fade_in_handle->set_y1 (handle_pos + handle_size);
519 if (fade_out_handle) {
520 fade_out_handle->set_y0 (handle_pos);
521 fade_out_handle->set_y1 (handle_pos + handle_size);
524 if (fade_in_trim_handle) {
525 fade_in_trim_handle->set_y0 (_height - handle_size);
526 fade_in_trim_handle->set_y1 (_height);
529 if (fade_out_trim_handle) {
530 fade_out_trim_handle->set_y0 (_height - handle_size );
531 fade_out_trim_handle->set_y1 (_height);
536 AudioRegionView::set_height (gdouble height)
538 if (height == _height) {
542 RegionView::set_height (height);
543 pending_peak_data->set_y1 (height);
545 uint32_t wcnt = waves.size();
551 if (!UIConfiguration::instance().get_show_name_highlight() || (height < NAME_HIGHLIGHT_THRESH)) {
552 ht = height / (double) wcnt;
554 ht = (height - NAME_HIGHLIGHT_SIZE) / (double) wcnt;
557 for (uint32_t n = 0; n < wcnt; ++n) {
559 gdouble yoff = floor (ht * n);
561 waves[n]->set_height (ht);
562 waves[n]->set_y_position (yoff);
568 if ((height/wcnt) < NAME_HIGHLIGHT_THRESH) {
571 update_envelope_visibility ();
574 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE) - 2);
577 reset_fade_shapes ();
579 /* Update heights for any feature lines */
580 framepos_t position = _region->position();
581 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
583 if (_height >= NAME_HIGHLIGHT_THRESH) {
584 y1 = _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1;
588 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
589 float pos_x = trackview.editor().sample_to_pixel((*l).first - position);
590 (*l).second->set (ArdourCanvas::Duple (pos_x, 2.0),
591 ArdourCanvas::Duple (pos_x, y1));
595 name_text->raise_to_top();
598 setup_fade_handle_positions();
602 AudioRegionView::reset_fade_shapes ()
604 if (!trim_fade_in_drag_active) { reset_fade_in_shape (); }
605 if (!trim_fade_out_drag_active) { reset_fade_out_shape (); }
609 AudioRegionView::reset_fade_in_shape ()
611 reset_fade_in_shape_width (audio_region(), (framecnt_t) audio_region()->fade_in()->back()->when);
615 AudioRegionView::reset_fade_in_shape_width (boost::shared_ptr<AudioRegion> ar, framecnt_t width, bool drag_active)
617 trim_fade_in_drag_active = drag_active;
618 if (fade_in_handle == 0) {
622 /* smallest size for a fade is 64 frames */
624 width = std::max ((framecnt_t) 64, width);
626 /* round here to prevent little visual glitches with sub-pixel placement */
627 double const pwidth = floor (width / samples_per_pixel);
628 double const handle_left = pwidth;
630 /* Put the fade in handle so that its left side is at the end-of-fade line */
631 fade_in_handle->set_x0 (handle_left);
632 fade_in_handle->set_x1 (handle_left + handle_size);
634 if (fade_in_trim_handle) {
635 fade_in_trim_handle->set_x0 (0);
636 fade_in_trim_handle->set_x1 (handle_size);
639 if (fade_in_handle->visible()) {
640 //see comment for drag_start
649 if (!trackview.session()->config.get_show_region_fades()) {
654 double effective_height;
656 if (_height >= NAME_HIGHLIGHT_THRESH) {
657 effective_height = _height - NAME_HIGHLIGHT_SIZE;
659 effective_height = _height;
662 /* points *MUST* be in anti-clockwise order */
665 Points::size_type pi;
666 boost::shared_ptr<const Evoral::ControlList> list (audio_region()->fade_in());
667 Evoral::ControlList::const_iterator x;
668 double length = list->length();
670 points.assign (list->size(), Duple());
672 for (x = list->begin(), pi = 0; x != list->end(); ++x, ++pi) {
673 points[pi].x = (pwidth * ((*x)->when/length));
674 points[pi].y = effective_height - ((*x)->value * (effective_height - 1.));
679 redraw_start_xfade_to (ar, width, points, effective_height, handle_left);
681 /* ensure trim handle stays on top */
682 if (frame_handle_start) {
683 frame_handle_start->raise_to_top();
688 AudioRegionView::reset_fade_out_shape ()
690 reset_fade_out_shape_width (audio_region(), (framecnt_t) audio_region()->fade_out()->back()->when);
694 AudioRegionView::reset_fade_out_shape_width (boost::shared_ptr<AudioRegion> ar, framecnt_t width, bool drag_active)
696 trim_fade_out_drag_active = drag_active;
697 if (fade_out_handle == 0) {
701 /* smallest size for a fade is 64 frames */
703 width = std::max ((framecnt_t) 64, width);
706 double const pwidth = floor(trackview.editor().sample_to_pixel (width));
708 /* the right edge should be right on the region frame is the pixel
709 * width is zero. Hence the additional + 1.0 at the end.
712 double const handle_right = rint(trackview.editor().sample_to_pixel (_region->length()) - pwidth);
713 double const trim_handle_right = rint(trackview.editor().sample_to_pixel (_region->length()));
715 /* Put the fade out handle so that its right side is at the end-of-fade line;
717 fade_out_handle->set_x0 (handle_right - handle_size);
718 fade_out_handle->set_x1 (handle_right);
719 if (fade_out_trim_handle) {
720 fade_out_trim_handle->set_x0 (1 + trim_handle_right - handle_size);
721 fade_out_trim_handle->set_x1 (1 + trim_handle_right);
724 if (fade_out_handle->visible()) {
725 //see comment for drag_start
728 /* don't show shape if its too small */
735 if (!trackview.session()->config.get_show_region_fades()) {
740 double effective_height;
742 effective_height = _height;
744 if (UIConfiguration::instance().get_show_name_highlight() && effective_height >= NAME_HIGHLIGHT_THRESH) {
745 effective_height -= NAME_HIGHLIGHT_SIZE;
748 /* points *MUST* be in anti-clockwise order */
751 Points::size_type pi;
752 boost::shared_ptr<const Evoral::ControlList> list (audio_region()->fade_out());
753 Evoral::ControlList::const_iterator x;
754 double length = list->length();
756 points.assign (list->size(), Duple());
758 for (x = list->begin(), pi = 0; x != list->end(); ++x, ++pi) {
759 points[pi].x = _pixel_width - pwidth + (pwidth * ((*x)->when/length));
760 points[pi].y = effective_height - ((*x)->value * (effective_height - 1.));
765 redraw_end_xfade_to (ar, width, points, effective_height, handle_right, pwidth);
767 /* ensure trim handle stays on top */
768 if (frame_handle_end) {
769 frame_handle_end->raise_to_top();
774 AudioRegionView::get_fade_in_shape_width ()
776 return audio_region()->fade_in()->back()->when;
780 AudioRegionView::get_fade_out_shape_width ()
782 return audio_region()->fade_out()->back()->when;
787 AudioRegionView::redraw_start_xfade ()
789 boost::shared_ptr<AudioRegion> ar (audio_region());
791 if (!ar->fade_in() || ar->fade_in()->empty()) {
796 reset_fade_in_shape_width (ar, ar->fade_in()->back()->when);
800 AudioRegionView::redraw_start_xfade_to (boost::shared_ptr<AudioRegion> ar, framecnt_t /*width*/, Points& points, double effective_height,
803 if (points.size() < 2) {
807 if (!start_xfade_curve) {
808 start_xfade_curve = new ArdourCanvas::XFadeCurve (group, ArdourCanvas::XFadeCurve::Start);
809 CANVAS_DEBUG_NAME (start_xfade_curve, string_compose ("xfade start out line for %1", region()->name()));
810 start_xfade_curve->set_fill_color (UIConfiguration::instance().color_mod ("active crossfade", "crossfade alpha"));
811 start_xfade_curve->set_outline_color (UIConfiguration::instance().color ("crossfade line"));
812 start_xfade_curve->set_ignore_events (true);
814 if (!start_xfade_rect) {
815 start_xfade_rect = new ArdourCanvas::Rectangle (group);
816 CANVAS_DEBUG_NAME (start_xfade_rect, string_compose ("xfade start rect for %1", region()->name()));
817 start_xfade_rect->set_outline_color (UIConfiguration::instance().color ("crossfade line"));
818 start_xfade_rect->set_fill (false);
819 start_xfade_rect->set_outline (false);
820 start_xfade_rect->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_start_xfade_event), start_xfade_rect, this));
821 start_xfade_rect->set_data ("regionview", this);
824 start_xfade_rect->set (ArdourCanvas::Rect (0.0, 0.0, rect_width, effective_height));
828 boost::shared_ptr<AutomationList> inverse = ar->inverse_fade_in ();
830 Points::size_type npoints;
834 /* there is no explicit inverse fade in curve, so take the
835 * regular fade in curve given to use as "points" (already a
836 * set of coordinates), and convert to the inverse shape.
839 npoints = points.size();
840 ipoints.assign (npoints, Duple());
842 for (Points::size_type i = 0, pci = 0; i < npoints; ++i, ++pci) {
843 ArdourCanvas::Duple &p (ipoints[pci]);
844 /* leave x-axis alone but invert with respect to y-axis */
845 p.y = effective_height - points[pci].y;
850 /* there is an explicit inverse fade in curve. Grab the points
851 and convert them into coordinates for the inverse fade in
855 npoints = inverse->size();
856 ipoints.assign (npoints, Duple());
858 Evoral::ControlList::const_iterator x;
859 Points::size_type pi;
860 double length = inverse->length();
862 for (x = inverse->begin(), pi = 0; x != inverse->end(); ++x, ++pi) {
863 ArdourCanvas::Duple& p (ipoints[pi]);
864 p.x = (rect_width * ((*x)->when/length));
865 p.y = effective_height - ((*x)->value * (effective_height));
869 start_xfade_curve->set_inout (points, ipoints);
875 AudioRegionView::redraw_end_xfade ()
877 boost::shared_ptr<AudioRegion> ar (audio_region());
879 if (!ar->fade_out() || ar->fade_out()->empty()) {
885 reset_fade_out_shape_width (ar, ar->fade_out()->back()->when);
889 AudioRegionView::redraw_end_xfade_to (boost::shared_ptr<AudioRegion> ar, framecnt_t width, Points& points, double effective_height,
890 double rect_edge, double rect_width)
892 if (points.size() < 2) {
896 if (!end_xfade_curve) {
897 end_xfade_curve = new ArdourCanvas::XFadeCurve (group, ArdourCanvas::XFadeCurve::End);
898 CANVAS_DEBUG_NAME (end_xfade_curve, string_compose ("xfade end out line for %1", region()->name()));
899 end_xfade_curve->set_fill_color (UIConfiguration::instance().color_mod ("active crossfade", "crossfade alpha"));
900 end_xfade_curve->set_outline_color (UIConfiguration::instance().color ("crossfade line"));
901 end_xfade_curve->set_ignore_events (true);
904 if (!end_xfade_rect) {
905 end_xfade_rect = new ArdourCanvas::Rectangle (group);
906 CANVAS_DEBUG_NAME (end_xfade_rect, string_compose ("xfade end rect for %1", region()->name()));
907 end_xfade_rect->set_outline_color (UIConfiguration::instance().color ("crossfade line"));
908 end_xfade_rect->set_fill (false);
909 end_xfade_rect->set_outline (false);
910 end_xfade_rect->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_end_xfade_event), end_xfade_rect, this));
911 end_xfade_rect->set_data ("regionview", this);
914 end_xfade_rect->set (ArdourCanvas::Rect (rect_edge, 0.0, rect_edge + rect_width, effective_height));
918 boost::shared_ptr<AutomationList> inverse = ar->inverse_fade_out ();
920 Points::size_type npoints;
924 /* there is no explicit inverse fade out curve, so take the
925 * regular fade out curve given to use as "points" (already a
926 * set of coordinates), and convert to the inverse shape.
929 npoints = points.size();
930 ipoints.assign (npoints, Duple());
932 Points::size_type pci;
934 for (pci = 0; pci < npoints; ++pci) {
935 ArdourCanvas::Duple &p (ipoints[pci]);
936 p.y = effective_height - points[pci].y;
941 /* there is an explicit inverse fade out curve. Grab the points
942 and convert them into coordinates for the inverse fade out
946 npoints = inverse->size();
947 ipoints.assign (npoints, Duple());
949 const double rend = trackview.editor().sample_to_pixel (_region->length() - width);
951 Evoral::ControlList::const_iterator x;
952 Points::size_type pi;
953 double length = inverse->length();
955 for (x = inverse->begin(), pi = 0; x != inverse->end(); ++x, ++pi) {
956 ArdourCanvas::Duple& p (ipoints[pi]);
957 p.x = (rect_width * ((*x)->when/length)) + rend;
958 p.y = effective_height - ((*x)->value * (effective_height));
962 end_xfade_curve->set_inout (ipoints, points);
968 AudioRegionView::hide_xfades ()
975 AudioRegionView::hide_start_xfade ()
977 if (start_xfade_curve) {
978 start_xfade_curve->hide();
980 if (start_xfade_rect) {
981 start_xfade_rect->hide ();
984 _start_xfade_visible = false;
988 AudioRegionView::hide_end_xfade ()
990 if (end_xfade_curve) {
991 end_xfade_curve->hide();
993 if (end_xfade_rect) {
994 end_xfade_rect->hide ();
997 _end_xfade_visible = false;
1001 AudioRegionView::show_start_xfade ()
1003 if (start_xfade_curve) {
1004 start_xfade_curve->show();
1006 if (start_xfade_rect) {
1007 start_xfade_rect->show ();
1010 _start_xfade_visible = true;
1014 AudioRegionView::show_end_xfade ()
1016 if (end_xfade_curve) {
1017 end_xfade_curve->show();
1019 if (end_xfade_rect) {
1020 end_xfade_rect->show ();
1023 _end_xfade_visible = true;
1027 AudioRegionView::set_samples_per_pixel (gdouble fpp)
1029 RegionView::set_samples_per_pixel (fpp);
1031 if (UIConfiguration::instance().get_show_waveforms ()) {
1032 for (uint32_t n = 0; n < waves.size(); ++n) {
1033 waves[n]->set_samples_per_pixel (fpp);
1038 gain_line->reset ();
1041 reset_fade_shapes ();
1045 AudioRegionView::set_amplitude_above_axis (gdouble a)
1047 for (uint32_t n=0; n < waves.size(); ++n) {
1048 waves[n]->set_amplitude_above_axis (a);
1053 AudioRegionView::set_colors ()
1055 RegionView::set_colors();
1058 gain_line->set_line_color (audio_region()->envelope_active() ?
1059 UIConfiguration::instance().color ("gain line") :
1060 UIConfiguration::instance().color_mod ("gain line inactive", "gain line inactive"));
1063 set_waveform_colors ();
1065 if (start_xfade_curve) {
1066 start_xfade_curve->set_fill_color (UIConfiguration::instance().color_mod ("active crossfade", "crossfade alpha"));
1067 start_xfade_curve->set_outline_color (UIConfiguration::instance().color ("crossfade line"));
1069 if (end_xfade_curve) {
1070 end_xfade_curve->set_fill_color (UIConfiguration::instance().color_mod ("active crossfade", "crossfade alpha"));
1071 end_xfade_curve->set_outline_color (UIConfiguration::instance().color ("crossfade line"));
1074 if (start_xfade_rect) {
1075 start_xfade_rect->set_outline_color (UIConfiguration::instance().color ("crossfade line"));
1077 if (end_xfade_rect) {
1078 end_xfade_rect->set_outline_color (UIConfiguration::instance().color ("crossfade line"));
1083 AudioRegionView::setup_waveform_visibility ()
1085 if (UIConfiguration::instance().get_show_waveforms ()) {
1086 for (uint32_t n = 0; n < waves.size(); ++n) {
1087 /* make sure the zoom level is correct, since we don't update
1088 this when waveforms are hidden.
1091 // waves[n]->set_samples_per_pixel (_samples_per_pixel);
1095 for (uint32_t n = 0; n < waves.size(); ++n) {
1102 AudioRegionView::temporarily_hide_envelope ()
1110 AudioRegionView::unhide_envelope ()
1112 update_envelope_visibility ();
1116 AudioRegionView::update_envelope_visibility ()
1122 if (trackview.editor().current_mouse_mode() == Editing::MouseDraw || trackview.editor().current_mouse_mode() == Editing::MouseContent ) {
1123 gain_line->set_visibility (AutomationLine::VisibleAspects(AutomationLine::ControlPoints|AutomationLine::Line));
1124 gain_line->canvas_group().raise_to_top ();
1125 } else if (UIConfiguration::instance().get_show_region_gain() || trackview.editor().current_mouse_mode() == Editing::MouseRange ) {
1126 gain_line->set_visibility (AutomationLine::VisibleAspects(AutomationLine::Line));
1127 gain_line->canvas_group().raise_to_top ();
1129 gain_line->set_visibility (AutomationLine::VisibleAspects(0));
1134 AudioRegionView::delete_waves ()
1136 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
1139 _data_ready_connections.clear ();
1141 for (vector<WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1146 pending_peak_data->show ();
1150 AudioRegionView::create_waves ()
1152 // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
1153 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
1159 ChanCount nchans = atv.track()->n_channels();
1161 // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data
1162 // << " and channels = " << nchans.n_audio() << endl;
1164 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
1165 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
1166 tmp_waves.push_back (0);
1169 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
1173 _data_ready_connections.clear ();
1175 for (uint32_t i = 0; i < nchans.n_audio(); ++i) {
1176 _data_ready_connections.push_back (0);
1179 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
1181 if (n >= audio_region()->n_channels()) {
1185 // cerr << "\tchannel " << n << endl;
1187 if (wait_for_data) {
1188 if (audio_region()->audio_source(n)->peaks_ready (boost::bind (&AudioRegionView::peaks_ready_handler, this, n), &_data_ready_connections[n], gui_context())) {
1189 // cerr << "\tData is ready\n";
1190 create_one_wave (n, true);
1192 // cerr << "\tdata is not ready\n";
1193 // we'll get a PeaksReady signal from the source in the future
1194 // and will call create_one_wave(n) then.
1195 pending_peak_data->show ();
1199 // cerr << "\tdon't delay, display today!\n";
1200 create_one_wave (n, true);
1207 AudioRegionView::create_one_wave (uint32_t which, bool /*direct*/)
1209 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
1210 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
1211 if (!trackview.session() || trackview.session()->deletion_in_progress () || !atv.track()) {
1212 /* peaks_ready_handler() may be called from peak_thread_work() while
1213 * session deletion is in progress.
1214 * Since session-unload happens in the GUI thread, we need to test
1219 uint32_t nchans = atv.track()->n_channels().n_audio();
1221 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
1224 /* compare to set_height(), use _height as set by streamview (child_height),
1225 * not trackview.current_height() to take stacked layering into acconnt
1227 if (!UIConfiguration::instance().get_show_name_highlight() || (_height < NAME_HIGHLIGHT_THRESH)) {
1228 ht = _height / (double) nchans;
1230 ht = (_height - NAME_HIGHLIGHT_SIZE) / (double) nchans;
1233 /* first waveview starts at 1.0, not 0.0 since that will overlap the
1237 gdouble yoff = which * ht;
1239 WaveView *wave = new WaveView (group, audio_region ());
1240 CANVAS_DEBUG_NAME (wave, string_compose ("wave view for chn %1 of %2", which, get_item_name()));
1242 wave->set_channel (which);
1243 wave->set_y_position (yoff);
1244 wave->set_height (ht);
1245 wave->set_samples_per_pixel (samples_per_pixel);
1246 wave->set_show_zero_line (true);
1247 wave->set_clip_level (UIConfiguration::instance().get_waveform_clip_level ());
1248 wave->set_start_shift (1.0);
1250 wave->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_wave_view_event), wave, this));
1252 switch (UIConfiguration::instance().get_waveform_shape()) {
1254 wave->set_shape (WaveView::Rectified);
1257 wave->set_shape (WaveView::Normal);
1260 wave->set_logscaled (UIConfiguration::instance().get_waveform_scale() == Logarithmic);
1262 vector<ArdourCanvas::WaveView*> v;
1264 set_some_waveform_colors (v);
1266 if (!UIConfiguration::instance().get_show_waveforms ()) {
1270 /* note: calling this function is serialized by the lock
1271 held in the peak building thread that signals that
1272 peaks are ready for use *or* by the fact that it is
1273 called one by one from the GUI thread.
1276 if (which < nchans) {
1277 tmp_waves[which] = wave;
1279 /* n-channel track, >n-channel source */
1282 /* see if we're all ready */
1284 for (n = 0; n < nchans; ++n) {
1285 if (tmp_waves[n] == 0) {
1290 if (n == nwaves && waves.empty()) {
1291 /* all waves are ready */
1292 tmp_waves.resize(nwaves);
1297 /* indicate peak-completed */
1298 pending_peak_data->hide ();
1300 /* Restore stacked coverage */
1301 std::string str = trackview.gui_property ("layer-display");
1303 LayerDisplay layer_display;
1304 update_coverage_frames (LayerDisplay (string_2_enum (str, layer_display)));
1308 /* channel wave created, don't hook into peaks ready anymore */
1309 delete _data_ready_connections[which];
1310 _data_ready_connections[which] = 0;
1314 AudioRegionView::peaks_ready_handler (uint32_t which)
1316 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AudioRegionView::create_one_wave, this, which, false));
1317 // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
1321 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev, bool with_guard_points)
1327 uint32_t before_p, after_p;
1328 double mx = ev->button.x;
1329 double my = ev->button.y;
1331 item->canvas_to_item (mx, my);
1333 framecnt_t const frame_within_region = (framecnt_t) floor (mx * samples_per_pixel);
1335 if (!gain_line->control_points_adjacent (frame_within_region, before_p, after_p)) {
1336 /* no adjacent points */
1340 /*y is in item frame */
1341 double const bx = gain_line->nth (before_p)->get_x();
1342 double const ax = gain_line->nth (after_p)->get_x();
1343 double const click_ratio = (ax - mx) / (ax - bx);
1345 double y = ((gain_line->nth (before_p)->get_y() * click_ratio) + (gain_line->nth (after_p)->get_y() * (1 - click_ratio)));
1347 /* don't create points that can't be seen */
1349 update_envelope_visibility ();
1351 framepos_t rpos = region ()->position ();
1352 framepos_t fx = trackview.editor().pixel_to_sample (mx) + rpos;
1353 trackview.editor ().snap_to_with_modifier (fx, ev);
1356 if (fx > _region->length()) {
1360 /* compute vertical fractional position */
1362 y = 1.0 - (y / (gain_line->height()));
1364 /* map using gain line */
1366 gain_line->view_to_model_coord (mx, y);
1368 /* XXX STATEFUL: can't convert to stateful diff until we
1369 can represent automation data with it.
1372 XMLNode &before = audio_region()->envelope()->get_state();
1373 MementoCommand<AudioRegion>* region_memento = 0;
1375 if (!audio_region()->envelope_active()) {
1376 XMLNode ®ion_before = audio_region()->get_state();
1377 audio_region()->set_envelope_active(true);
1378 XMLNode ®ion_after = audio_region()->get_state();
1379 region_memento = new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after);
1382 if (audio_region()->envelope()->editor_add (fx, y, with_guard_points)) {
1383 XMLNode &after = audio_region()->envelope()->get_state();
1384 std::list<Selectable*> results;
1386 trackview.editor().begin_reversible_command (_("add gain control point"));
1388 if (region_memento) {
1389 trackview.session()->add_command (region_memento);
1392 trackview.session()->add_command (new MementoCommand<AutomationList>(*audio_region()->envelope().get(), &before, &after));
1394 gain_line->get_selectables (fx + region ()->position (), fx + region ()->position (), 0.0, 1.0, results);
1395 trackview.editor ().get_selection ().set (results);
1397 trackview.editor ().commit_reversible_command ();
1398 trackview.session ()->set_dirty ();
1403 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent* /*ev*/)
1405 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1406 audio_region()->envelope()->erase (cp->model());
1410 AudioRegionView::add_ghost (TimeAxisView& tv)
1412 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1418 double unit_position = _region->position () / samples_per_pixel;
1419 AudioGhostRegion* ghost = new AudioGhostRegion (*this, tv, trackview, unit_position);
1422 nchans = rtv->track()->n_channels().n_audio();
1424 for (uint32_t n = 0; n < nchans; ++n) {
1426 if (n >= audio_region()->n_channels()) {
1430 WaveView *wave = new WaveView (ghost->group, audio_region());
1431 CANVAS_DEBUG_NAME (wave, string_compose ("ghost wave for %1", get_item_name()));
1433 wave->set_channel (n);
1434 wave->set_samples_per_pixel (samples_per_pixel);
1435 wave->set_amplitude_above_axis (_amplitude_above_axis);
1437 ghost->waves.push_back(wave);
1440 ghost->set_height ();
1441 ghost->set_duration (_region->length() / samples_per_pixel);
1442 ghost->set_colors();
1443 ghosts.push_back (ghost);
1449 AudioRegionView::entered ()
1451 trackview.editor().set_current_trimmable (_region);
1452 trackview.editor().set_current_movable (_region);
1454 update_envelope_visibility();
1456 if ((trackview.editor().current_mouse_mode() == Editing::MouseObject)) {
1457 if (start_xfade_rect) {
1458 start_xfade_rect->set_outline (true);
1460 if (end_xfade_rect) {
1461 end_xfade_rect->set_outline (true);
1463 if (fade_in_handle) {
1464 fade_in_handle->show ();
1465 fade_in_handle->raise_to_top ();
1467 if (fade_out_handle) {
1468 fade_out_handle->show ();
1469 fade_out_handle->raise_to_top ();
1471 if (fade_in_trim_handle) {
1472 boost::shared_ptr<AudioRegion> ar (audio_region());
1473 if (!ar->locked() && (ar->fade_in()->back()->when > 64 || (ar->can_trim() & Trimmable::FrontTrimEarlier))) {
1474 fade_in_trim_handle->show ();
1475 fade_in_trim_handle->raise_to_top ();
1477 fade_in_trim_handle->hide ();
1480 if (fade_out_trim_handle) {
1481 boost::shared_ptr<AudioRegion> ar (audio_region());
1482 if (!ar->locked() && (ar->fade_out()->back()->when > 64 || (ar->can_trim() & Trimmable::EndTrimLater))) {
1483 fade_out_trim_handle->show ();
1484 fade_out_trim_handle->raise_to_top ();
1486 fade_out_trim_handle->hide ();
1489 } else { //this happens when we switch tools; if we switch away from Grab mode, hide all the fade handles
1490 if (fade_in_handle) { fade_in_handle->hide(); }
1491 if (fade_out_handle) { fade_out_handle->hide(); }
1492 if (fade_in_trim_handle) { fade_in_trim_handle->hide(); }
1493 if (fade_out_trim_handle) { fade_out_trim_handle->hide(); }
1494 if (start_xfade_rect) { start_xfade_rect->set_outline (false); }
1495 if (end_xfade_rect) { end_xfade_rect->set_outline (false); }
1500 AudioRegionView::exited ()
1502 trackview.editor().set_current_trimmable (boost::shared_ptr<Trimmable>());
1503 trackview.editor().set_current_movable (boost::shared_ptr<Movable>());
1506 // gain_line->remove_visibility (AutomationLine::ControlPoints);
1509 if (fade_in_handle) { fade_in_handle->hide(); }
1510 if (fade_out_handle) { fade_out_handle->hide(); }
1511 if (fade_in_trim_handle) { fade_in_trim_handle->hide(); }
1512 if (fade_out_trim_handle) { fade_out_trim_handle->hide(); }
1513 if (start_xfade_rect) { start_xfade_rect->set_outline (false); }
1514 if (end_xfade_rect) { end_xfade_rect->set_outline (false); }
1518 AudioRegionView::envelope_active_changed ()
1521 gain_line->set_line_color (audio_region()->envelope_active() ?
1522 UIConfiguration::instance().color ("gain line") :
1523 UIConfiguration::instance().color_mod ("gain line inactive", "gain line inactive"));
1524 update_envelope_visibility ();
1529 AudioRegionView::color_handler ()
1531 //case cMutedWaveForm:
1533 //case cWaveFormClip:
1537 //case cGainLineInactive:
1539 envelope_active_changed();
1544 AudioRegionView::set_waveform_colors ()
1546 set_some_waveform_colors (waves);
1550 AudioRegionView::set_some_waveform_colors (vector<ArdourCanvas::WaveView*>& waves_to_color)
1552 ArdourCanvas::Color fill;
1553 ArdourCanvas::Color outline;
1554 ArdourCanvas::Color clip = UIConfiguration::instance().color ("clipped waveform");
1555 ArdourCanvas::Color zero = UIConfiguration::instance().color ("zero line");
1558 if (_region->muted()) {
1559 /* hide outline with zero alpha */
1560 outline = UINT_RGBA_CHANGE_A(UIConfiguration::instance().color ("selected waveform outline"), 0);
1561 fill = UINT_RGBA_CHANGE_A(UIConfiguration::instance().color ("selected waveform fill"), MUTED_ALPHA);
1563 outline = UIConfiguration::instance().color ("selected waveform outline");
1564 fill = UIConfiguration::instance().color ("selected waveform fill");
1568 outline = UIConfiguration::instance().color ("recording waveform outline");
1569 fill = UIConfiguration::instance().color ("recording waveform fill");
1571 if (_region->muted()) {
1572 /* hide outline with zero alpha */
1573 outline = UINT_RGBA_CHANGE_A(UIConfiguration::instance().color ("waveform outline"), 0);
1574 fill = UINT_RGBA_CHANGE_A(UIConfiguration::instance().color ("waveform fill"), MUTED_ALPHA);
1576 outline = UIConfiguration::instance().color ("waveform outline");
1577 fill = UIConfiguration::instance().color ("waveform fill");
1582 for (vector<ArdourCanvas::WaveView*>::iterator w = waves_to_color.begin(); w != waves_to_color.end(); ++w) {
1583 (*w)->set_fill_color (fill);
1584 (*w)->set_outline_color (outline);
1585 (*w)->set_clip_color (clip);
1586 (*w)->set_zero_color (zero);
1591 AudioRegionView::set_frame_color ()
1597 RegionView::set_frame_color ();
1599 set_waveform_colors ();
1603 AudioRegionView::set_fade_visibility (bool yn)
1606 if (start_xfade_curve) { start_xfade_curve->show (); }
1607 if (end_xfade_curve) { end_xfade_curve->show (); }
1608 if (start_xfade_rect) { start_xfade_rect->show (); }
1609 if (end_xfade_rect) { end_xfade_rect->show (); }
1611 if (start_xfade_curve) { start_xfade_curve->hide(); }
1612 if (end_xfade_curve) { end_xfade_curve->hide(); }
1613 if (fade_in_handle) { fade_in_handle->hide(); }
1614 if (fade_out_handle) { fade_out_handle->hide(); }
1615 if (fade_in_trim_handle) { fade_in_trim_handle->hide(); }
1616 if (fade_out_trim_handle) { fade_out_trim_handle->hide(); }
1617 if (start_xfade_rect) { start_xfade_rect->hide (); }
1618 if (end_xfade_rect) { end_xfade_rect->hide (); }
1619 if (start_xfade_rect) { start_xfade_rect->set_outline (false); }
1620 if (end_xfade_rect) { end_xfade_rect->set_outline (false); }
1625 AudioRegionView::update_coverage_frames (LayerDisplay d)
1627 RegionView::update_coverage_frames (d);
1630 if (fade_in_handle) { fade_in_handle->raise_to_top (); }
1631 if (fade_out_handle) { fade_out_handle->raise_to_top (); }
1632 if (fade_in_trim_handle) { fade_in_trim_handle->raise_to_top (); }
1633 if (fade_out_trim_handle) { fade_out_trim_handle->raise_to_top (); }
1638 AudioRegionView::show_region_editor ()
1641 editor = new AudioRegionEditor (trackview.session(), audio_region());
1649 AudioRegionView::transients_changed ()
1651 AnalysisFeatureList analysis_features;
1652 _region->transients (analysis_features);
1653 framepos_t position = _region->position();
1654 framepos_t first = _region->first_frame();
1655 framepos_t last = _region->last_frame();
1658 if (_height >= NAME_HIGHLIGHT_THRESH) {
1659 y1 = _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1;
1664 while (feature_lines.size() < analysis_features.size()) {
1665 ArdourCanvas::Line* canvas_item = new ArdourCanvas::Line(group);
1666 CANVAS_DEBUG_NAME (canvas_item, string_compose ("transient group for %1", region()->name()));
1667 canvas_item->set_outline_color (UIConfiguration::instance().color ("zero line")); // also in Editor::leave_handler()
1669 canvas_item->set (ArdourCanvas::Duple (-1.0, 2.0),
1670 ArdourCanvas::Duple (1.0, y1));
1672 canvas_item->raise_to_top ();
1673 canvas_item->show ();
1675 canvas_item->set_data ("regionview", this);
1676 canvas_item->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_feature_line_event), canvas_item, this));
1678 feature_lines.push_back (make_pair(0, canvas_item));
1681 while (feature_lines.size() > analysis_features.size()) {
1682 ArdourCanvas::Line* line = feature_lines.back().second;
1683 feature_lines.pop_back ();
1687 AnalysisFeatureList::const_iterator i;
1688 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1690 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
1692 float *pos = new float;
1693 *pos = trackview.editor().sample_to_pixel (*i - position);
1696 ArdourCanvas::Duple (*pos, 2.0),
1697 ArdourCanvas::Duple (*pos, y1)
1700 (*l).second->set_data ("position", pos); // is this *modified* (drag?), if not use *i
1703 if (l->first < first || l->first >= last) {
1712 AudioRegionView::update_transient(float /*old_pos*/, float new_pos)
1714 /* Find frame at old pos, calulate new frame then update region transients*/
1715 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1717 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1719 /* Line has been updated in drag so we compare to new_pos */
1721 float* pos = (float*) (*l).second->get_data ("position");
1723 if (rint(new_pos) == rint(*pos)) {
1724 framepos_t position = _region->position();
1725 framepos_t old_frame = (*l).first;
1726 framepos_t new_frame = trackview.editor().pixel_to_sample (new_pos) + position;
1727 _region->update_transient (old_frame, new_frame);
1734 AudioRegionView::remove_transient (float pos)
1736 /* this is called from Editor::remove_transient () with pos == get_data ("position")
1737 * which is the item's x-coordinate inside the ARV.
1739 * Find frame at old pos, calulate new frame then update region transients
1741 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1743 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1744 float *line_pos = (float*) (*l).second->get_data ("position");
1745 if (rint(pos) == rint(*line_pos)) {
1746 _region->remove_transient ((*l).first);
1753 AudioRegionView::thaw_after_trim ()
1755 RegionView::thaw_after_trim ();
1762 AudioRegionView::show_xfades ()
1764 show_start_xfade ();
1769 AudioRegionView::drag_start ()
1771 TimeAxisViewItem::drag_start ();
1773 //we used to hide xfades here. I don't see the point with the new model, but we can re-implement if needed
1777 AudioRegionView::drag_end ()
1779 TimeAxisViewItem::drag_end ();
1780 //see comment for drag_start
1782 if (fade_in_handle && fade_in_handle->visible()) {
1783 // lenght of region or fade changed, re-check
1784 // if fade_in_trim_handle or fade_out_trim_handle should
1785 // be visible. -- If the fade_in_handle is visible
1786 // we have focus and are not in internal edit mode.
1792 AudioRegionView::parameter_changed (string const & p)
1794 if (p == "show-waveforms") {
1795 setup_waveform_visibility ();