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/debug.h"
47 #include "canvas/utils.h"
49 #include "streamview.h"
50 #include "audio_region_view.h"
51 #include "audio_time_axis.h"
52 #include "public_editor.h"
53 #include "audio_region_editor.h"
54 #include "audio_streamview.h"
55 #include "region_gain_line.h"
56 #include "control_point.h"
57 #include "ghostregion.h"
58 #include "audio_time_axis.h"
60 #include "rgb_macros.h"
61 #include "gui_thread.h"
62 #include "ardour_ui.h"
66 #define MUTED_ALPHA 48
69 using namespace ARDOUR;
71 using namespace Editing;
72 using namespace ArdourCanvas;
74 static const int32_t sync_mark_width = 9;
75 static double const handle_size = 15; /* height of fade handles */
77 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
78 Gdk::Color const & basic_color)
79 : RegionView (parent, tv, r, spu, basic_color)
87 , start_xfade_rect (0)
88 , _start_xfade_visible (false)
92 , _end_xfade_visible (false)
93 , _amplitude_above_axis(1.0)
96 Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&AudioRegionView::parameter_changed, this, _1), gui_context());
99 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
100 Gdk::Color const & basic_color, bool recording, TimeAxisViewItem::Visibility visibility)
101 : RegionView (parent, tv, r, spu, basic_color, recording, visibility)
108 , start_xfade_out (0)
109 , start_xfade_rect (0)
110 , _start_xfade_visible (false)
114 , _end_xfade_visible (false)
115 , _amplitude_above_axis(1.0)
118 Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&AudioRegionView::parameter_changed, this, _1), gui_context());
121 AudioRegionView::AudioRegionView (const AudioRegionView& other, boost::shared_ptr<AudioRegion> other_region)
122 : RegionView (other, boost::shared_ptr<Region> (other_region))
128 , start_xfade_out (0)
129 , start_xfade_rect (0)
130 , _start_xfade_visible (false)
134 , _end_xfade_visible (false)
135 , _amplitude_above_axis (other._amplitude_above_axis)
141 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
142 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
146 Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&AudioRegionView::parameter_changed, this, _1), gui_context());
150 AudioRegionView::init (Gdk::Color const & basic_color, bool wfd)
152 // FIXME: Some redundancy here with RegionView::init. Need to figure out
153 // where order is important and where it isn't...
155 RegionView::init (basic_color, wfd);
157 _amplitude_above_axis = 1.0;
159 compute_colors (basic_color);
163 fade_in_shape = new ArdourCanvas::PolyLine (group);
164 CANVAS_DEBUG_NAME (fade_in_shape, string_compose ("fade in shape for %1", region()->name()));
165 fade_in_shape->set_outline_color (fade_color);
166 fade_in_shape->set_data ("regionview", this);
168 fade_out_shape = new ArdourCanvas::PolyLine (group);
169 CANVAS_DEBUG_NAME (fade_out_shape, string_compose ("fade out shape for %1", region()->name()));
170 fade_out_shape->set_outline_color (fade_color);
171 fade_out_shape->set_data ("regionview", this);
174 fade_in_handle = new ArdourCanvas::Rectangle (group);
175 CANVAS_DEBUG_NAME (fade_in_handle, string_compose ("fade in handle for %1", region()->name()));
176 fade_in_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 255));
177 fade_in_handle->set_fill_color (ARDOUR_UI::config()->get_canvasvar_InactiveFadeHandle());
178 fade_in_handle->set_data ("regionview", this);
179 fade_in_handle->hide ();
181 fade_out_handle = new ArdourCanvas::Rectangle (group);
182 CANVAS_DEBUG_NAME (fade_out_handle, string_compose ("fade out handle for %1", region()->name()));
183 fade_out_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 255));
184 fade_out_handle->set_fill_color (ARDOUR_UI::config()->get_canvasvar_InactiveFadeHandle());
185 fade_out_handle->set_data ("regionview", this);
186 fade_out_handle->hide ();
189 setup_fade_handle_positions ();
191 if (!trackview.session()->config.get_show_region_fades()) {
192 set_fade_visibility (false);
195 const string line_name = _region->name() + ":gain";
197 if (!Profile->get_sae()) {
198 gain_line.reset (new AudioRegionGainLine (line_name, *this, *group, audio_region()->envelope()));
201 update_envelope_visibility ();
204 set_height (trackview.current_height());
207 region_sync_changed ();
209 region_resized (ARDOUR::bounds_change);
211 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
212 (*i)->set_duration (_region->length() / samples_per_pixel);
216 envelope_active_changed ();
217 fade_in_active_changed ();
218 fade_out_active_changed ();
220 reset_width_dependent_items (_pixel_width);
222 fade_in_shape->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
223 if (fade_in_handle) {
224 fade_in_handle->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
227 fade_out_shape->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
229 if (fade_out_handle) {
230 fade_out_handle->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
235 setup_waveform_visibility ();
236 setup_waveform_shape ();
238 if (frame_handle_start) {
239 frame_handle_start->raise_to_top ();
241 if (frame_handle_end) {
242 frame_handle_end->raise_to_top ();
245 /* XXX sync mark drag? */
248 AudioRegionView::~AudioRegionView ()
250 in_destructor = true;
252 RegionViewGoingAway (this); /* EMIT_SIGNAL */
254 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
258 for (list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator i = feature_lines.begin(); i != feature_lines.end(); ++i) {
259 delete ((*i).second);
262 /* all waveviews etc will be destroyed when the group is destroyed */
265 boost::shared_ptr<ARDOUR::AudioRegion>
266 AudioRegionView::audio_region() const
268 // "Guaranteed" to succeed...
269 return boost::dynamic_pointer_cast<AudioRegion>(_region);
273 AudioRegionView::region_changed (const PropertyChange& what_changed)
275 ENSURE_GUI_THREAD (*this, &AudioRegionView::region_changed, what_changed);
277 RegionView::region_changed (what_changed);
279 if (what_changed.contains (ARDOUR::Properties::scale_amplitude)) {
280 region_scale_amplitude_changed ();
282 if (what_changed.contains (ARDOUR::Properties::fade_in)) {
285 if (what_changed.contains (ARDOUR::Properties::fade_out)) {
288 if (what_changed.contains (ARDOUR::Properties::fade_in_active)) {
289 fade_in_active_changed ();
291 if (what_changed.contains (ARDOUR::Properties::fade_out_active)) {
292 fade_out_active_changed ();
294 if (what_changed.contains (ARDOUR::Properties::envelope_active)) {
295 envelope_active_changed ();
297 if (what_changed.contains (ARDOUR::Properties::valid_transients)) {
298 transients_changed ();
303 AudioRegionView::fade_in_changed ()
305 reset_fade_in_shape ();
309 AudioRegionView::fade_out_changed ()
311 reset_fade_out_shape ();
315 AudioRegionView::fade_in_active_changed ()
317 if (audio_region()->fade_in_active()) {
318 /* XXX: make a themable colour */
319 fade_in_shape->set_outline_color (RGBA_TO_UINT (45, 45, 45, 90));
321 /* XXX: make a themable colour */
322 fade_in_shape->set_outline_color (RGBA_TO_UINT (45, 45, 45, 20));
327 AudioRegionView::fade_out_active_changed ()
329 if (audio_region()->fade_out_active()) {
330 /* XXX: make a themable colour */
331 fade_out_shape->set_outline_color (RGBA_TO_UINT (45, 45, 45, 90));
333 /* XXX: make a themable colour */
334 fade_out_shape->set_outline_color (RGBA_TO_UINT (45, 45, 45, 20));
340 AudioRegionView::region_scale_amplitude_changed ()
342 for (uint32_t n = 0; n < waves.size(); ++n) {
343 waves[n]->gain_changed ();
348 AudioRegionView::region_renamed ()
350 std::string str = RegionView::make_name ();
352 if (audio_region()->speed_mismatch (trackview.session()->frame_rate())) {
353 str = string ("*") + str;
356 if (_region->muted()) {
357 str = string ("!") + str;
360 set_item_name (str, this);
365 AudioRegionView::region_resized (const PropertyChange& what_changed)
367 AudioGhostRegion* agr;
369 RegionView::region_resized(what_changed);
370 PropertyChange interesting_stuff;
372 interesting_stuff.add (ARDOUR::Properties::start);
373 interesting_stuff.add (ARDOUR::Properties::length);
375 if (what_changed.contains (interesting_stuff)) {
377 for (uint32_t n = 0; n < waves.size(); ++n) {
378 waves[n]->region_resized ();
381 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
382 if ((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
384 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
385 (*w)->region_resized ();
390 /* hide transient lines that extend beyond the region end */
392 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
394 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
395 if (l->first > _region->length() - 1) {
405 AudioRegionView::reset_width_dependent_items (double pixel_width)
407 RegionView::reset_width_dependent_items(pixel_width);
408 assert(_pixel_width == pixel_width);
410 if (fade_in_handle) {
411 if (pixel_width <= 6.0 || _height < 5.0 || !trackview.session()->config.get_show_region_fades()) {
412 fade_in_handle->hide();
413 fade_out_handle->hide();
415 //fade_in_handle->show();
416 //fade_out_handle->show();
420 AnalysisFeatureList analysis_features = _region->transients();
421 AnalysisFeatureList::const_iterator i;
423 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
425 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
427 float x_pos = trackview.editor().sample_to_pixel (*i);
429 (*l).second->set (ArdourCanvas::Duple (x_pos, 2.0),
430 ArdourCanvas::Duple (x_pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
434 (*l).second->set (ArdourCanvas::Duple (x_pos, 2.0),
435 ArdourCanvas::Duple (x_pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
438 reset_fade_shapes ();
442 AudioRegionView::region_muted ()
444 RegionView::region_muted();
445 set_waveform_colors ();
449 AudioRegionView::setup_fade_handle_positions()
451 /* position of fade handle offset from the top of the region view */
452 double const handle_pos = 0.0;
454 if (fade_in_handle) {
455 fade_in_handle->set_y0 (handle_pos);
456 fade_in_handle->set_y1 (handle_pos + handle_size);
459 if (fade_out_handle) {
460 fade_out_handle->set_y0 (handle_pos);
461 fade_out_handle->set_y1 (handle_pos + handle_size);
466 AudioRegionView::set_height (gdouble height)
468 RegionView::set_height (height);
470 uint32_t wcnt = waves.size();
472 for (uint32_t n = 0; n < wcnt; ++n) {
475 if (height < NAME_HIGHLIGHT_THRESH) {
476 ht = ((height - 2 * wcnt) / (double) wcnt);
478 ht = (((height - 2 * wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
481 gdouble yoff = n * (ht + 1);
483 waves[n]->set_height (ht);
484 waves[n]->set_y_position (yoff + 2);
489 if ((height/wcnt) < NAME_HIGHLIGHT_THRESH) {
492 update_envelope_visibility ();
495 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE) - 2);
498 reset_fade_shapes ();
500 /* Update hights for any active feature lines */
501 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
503 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
505 float pos_x = trackview.editor().sample_to_pixel((*l).first);
507 if (height >= NAME_HIGHLIGHT_THRESH) {
508 (*l).second->set (ArdourCanvas::Duple (pos_x, 2.0),
509 ArdourCanvas::Duple (pos_x, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
511 (*l).second->set (ArdourCanvas::Duple (pos_x, 2.0),
512 ArdourCanvas::Duple (pos_x, _height - 1));
517 name_text->raise_to_top();
522 AudioRegionView::reset_fade_shapes ()
524 reset_fade_in_shape ();
525 reset_fade_out_shape ();
529 AudioRegionView::reset_fade_in_shape ()
531 reset_fade_in_shape_width (audio_region(), (framecnt_t) audio_region()->fade_in()->back()->when);
535 AudioRegionView::reset_fade_in_shape_width (boost::shared_ptr<AudioRegion> ar, framecnt_t width)
537 if (fade_in_handle == 0) {
541 /* smallest size for a fade is 64 frames */
543 width = std::max ((framecnt_t) 64, width);
545 /* round here to prevent little visual glitches with sub-pixel placement */
546 double const pwidth = rint (width / samples_per_pixel);
547 double const handle_left = pwidth;
549 /* Put the fade in handle so that its left side is at the end-of-fade line */
550 fade_in_handle->set_x0 (handle_left);
551 fade_in_handle->set_x1 (handle_left + handle_size);
555 fade_in_shape->hide();
559 if (trackview.session()->config.get_show_region_fades()) {
560 fade_in_shape->show();
563 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
564 double effective_height;
565 std::vector<float> curve(npoints);
567 audio_region()->fade_in()->curve().get_vector (0, audio_region()->fade_in()->back()->when, &curve[0], npoints);
569 if (_height >= NAME_HIGHLIGHT_THRESH) {
570 effective_height = _height - NAME_HIGHLIGHT_SIZE;
572 effective_height = _height;
575 effective_height -= 1.0;
579 points.assign (npoints, Duple());
581 /* points *MUST* be in anti-clockwise order */
584 double xdelta = pwidth/npoints;
586 for (pi = 0, pc = 0; pc < npoints; ++pc) {
587 points[pi].x = 1.0 + (pc * xdelta);
588 points[pi++].y = 1.0 + effective_height - (curve[pc] * effective_height);
593 redraw_start_xfade_to (ar, width, points, effective_height, handle_left);
595 // fade_in_shape->set (points);
597 /* ensure trim handle stays on top */
598 if (frame_handle_start) {
599 frame_handle_start->raise_to_top();
605 AudioRegionView::reset_fade_out_shape ()
607 reset_fade_out_shape_width (audio_region(), (framecnt_t) audio_region()->fade_out()->back()->when);
611 AudioRegionView::reset_fade_out_shape_width (boost::shared_ptr<AudioRegion> ar, framecnt_t width)
613 if (fade_out_handle == 0) {
617 /* smallest size for a fade is 64 frames */
619 width = std::max ((framecnt_t) 64, width);
621 double const pwidth = trackview.editor().sample_to_pixel (width);
623 /* the right edge should be right on the region frame is the pixel
624 * width is zero. Hence the additional + 1.0 at the end.
627 double const handle_right = trackview.editor().sample_to_pixel (_region->length()) + TimeAxisViewItem::RIGHT_EDGE_SHIFT - pwidth + 1.0;
629 /* Put the fade out handle so that its right side is at the end-of-fade line;
631 fade_out_handle->set_x0 (handle_right - handle_size);
632 fade_out_handle->set_x1 (handle_right);
634 /* don't show shape if its too small */
638 fade_out_shape->hide();
642 if (trackview.session()->config.get_show_region_fades()) {
643 fade_out_shape->show();
646 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
647 double effective_height;
648 std::vector<float> curve(npoints);
650 audio_region()->fade_out()->curve().get_vector (0, audio_region()->fade_out()->back()->when, &curve[0], npoints);
652 if (_height >= NAME_HIGHLIGHT_THRESH) {
653 effective_height = _height - NAME_HIGHLIGHT_SIZE;
655 effective_height = _height;
658 effective_height -= 1.0;
660 /* points *MUST* be in anti-clockwise order */
665 double xdelta = pwidth/npoints;
667 points.assign (npoints, Duple ());
669 for (pi = 0, pc = 0; pc < npoints; ++pc, ++pi) {
670 points[pi].x = 1.0 + _pixel_width - pwidth + (pc * xdelta);
671 points[pi].y = 1.0 + effective_height - (curve[pc] * effective_height);
676 redraw_end_xfade_to (ar, width, points, effective_height, handle_right, pwidth-1);
678 // fade_out_shape->set (points);
680 /* ensure trim handle stays on top */
681 if (frame_handle_end) {
682 frame_handle_end->raise_to_top();
688 AudioRegionView::get_fade_in_shape_width ()
690 return audio_region()->fade_in()->back()->when;
694 AudioRegionView::get_fade_out_shape_width ()
696 return audio_region()->fade_out()->back()->when;
701 AudioRegionView::redraw_start_xfade ()
703 boost::shared_ptr<AudioRegion> ar (audio_region());
705 if (!ar->fade_in() || ar->fade_in()->empty()) {
710 reset_fade_in_shape_width (ar, ar->fade_in()->back()->when);
714 AudioRegionView::redraw_start_xfade_to (boost::shared_ptr<AudioRegion> ar, framecnt_t /*width*/, Points& points, double effective_height,
717 if (points.size() < 3) {
721 if (!start_xfade_in) {
722 start_xfade_in = new ArdourCanvas::PolyLine (group);
723 CANVAS_DEBUG_NAME (start_xfade_in, string_compose ("xfade start in line for %1", region()->name()));
724 start_xfade_in->set_outline_color (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine());
725 start_xfade_in->set_outline_width (1.5);
728 if (!start_xfade_out) {
729 start_xfade_out = new ArdourCanvas::PolyLine (group);
730 CANVAS_DEBUG_NAME (start_xfade_out, string_compose ("xfade start out line for %1", region()->name()));
731 uint32_t col = UINT_RGBA_CHANGE_A (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine(), 128);
732 start_xfade_out->set_outline_color (col);
733 start_xfade_out->set_outline_width (2.0);
736 if (!start_xfade_rect) {
737 start_xfade_rect = new ArdourCanvas::Rectangle (group);
738 CANVAS_DEBUG_NAME (start_xfade_rect, string_compose ("xfade start rect for %1", region()->name()));
739 start_xfade_rect->set_fill (true);
740 start_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
741 start_xfade_rect->set_outline (false);
742 start_xfade_rect->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_start_xfade_event), start_xfade_rect, this));
743 start_xfade_rect->set_data ("regionview", this);
746 start_xfade_rect->set (ArdourCanvas::Rect (1.0, 0.0, rect_width, effective_height));
747 start_xfade_rect->show ();
749 start_xfade_in->set (points);
750 start_xfade_in->show ();
754 boost::shared_ptr<AutomationList> inverse = ar->inverse_fade_in();
756 Points::size_type npoints = points.size();
758 ipoints.assign (npoints, Duple());
762 /* no inverse curve defined, show the inverse of the normal one */
764 for (Points::size_type i = 0, pci = 0; i < npoints; ++i, ++pci) {
765 ArdourCanvas::Duple &p (ipoints[pci]);
767 /* invert with respect to y-axis */
768 p.y = 1.0 + effective_height - points[pci].y;
773 std::vector<float> vec(npoints);
774 inverse->curve().get_vector (0, inverse->back()->when, &vec[0], npoints);
776 for (Points::size_type i = 0, pci = 0; i < npoints; ++i, ++pci) {
777 ArdourCanvas::Duple &p (ipoints[pci]);
779 p.y = 1.0 + effective_height - (effective_height * vec[i]);
783 start_xfade_out->set (ipoints);
784 start_xfade_out->show ();
790 AudioRegionView::redraw_end_xfade ()
792 boost::shared_ptr<AudioRegion> ar (audio_region());
794 if (!ar->fade_out() || ar->fade_out()->empty()) {
800 reset_fade_out_shape_width (ar, ar->fade_out()->back()->when);
804 AudioRegionView::redraw_end_xfade_to (boost::shared_ptr<AudioRegion> ar, framecnt_t width, Points& points, double effective_height,
805 double rect_edge, double rect_width)
807 if (points.size() < 3) {
812 end_xfade_in = new ArdourCanvas::PolyLine (group);
813 CANVAS_DEBUG_NAME (end_xfade_in, string_compose ("xfade end in line for %1", region()->name()));
814 uint32_t col UINT_RGBA_CHANGE_A (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine(), 128);
815 end_xfade_in->set_outline_color (col);
816 end_xfade_in->set_outline_width (1.5);
819 if (!end_xfade_out) {
820 end_xfade_out = new ArdourCanvas::PolyLine (group);
821 CANVAS_DEBUG_NAME (end_xfade_out, string_compose ("xfade end out line for %1", region()->name()));
822 end_xfade_out->set_outline_color (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine());
823 end_xfade_out->set_outline_width (2.0);
826 if (!end_xfade_rect) {
827 end_xfade_rect = new ArdourCanvas::Rectangle (group);
828 CANVAS_DEBUG_NAME (end_xfade_rect, string_compose ("xfade end rect for %1", region()->name()));
829 end_xfade_rect->set_fill (true);
830 end_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
831 end_xfade_rect->set_outline (0);
832 end_xfade_rect->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_end_xfade_event), end_xfade_rect, this));
833 end_xfade_rect->set_data ("regionview", this);
836 end_xfade_rect->set (ArdourCanvas::Rect (rect_edge, 0.0, rect_edge + rect_width + TimeAxisViewItem::RIGHT_EDGE_SHIFT, effective_height));
837 end_xfade_rect->show ();
839 end_xfade_in->set (points);
840 end_xfade_in->show ();
841 end_xfade_in->raise_to_top ();
845 boost::shared_ptr<AutomationList> inverse = ar->inverse_fade_out ();
847 Points::size_type npoints = points.size();
849 ipoints.assign (npoints, Duple());
853 const double rend = trackview.editor().sample_to_pixel (_region->length() - points.back().y);
855 for (Points::size_type i = 0, pci = 0; i < npoints; ++i, ++pci) {
856 ArdourCanvas::Duple &p (ipoints[pci]);
857 p.x = 1.0 + rend + i;
858 p.y = 1.0 + effective_height - points[pci].y;
863 boost::scoped_array<float> vec (new float[npoints]);
864 inverse->curve().get_vector (inverse->front()->when, inverse->back()->when, vec.get(), npoints);
866 const double rend = trackview.editor().sample_to_pixel (_region->length() - width);
868 float* vp = vec.get();
870 for (Points::size_type i = 0, pci = 0; i < npoints; ++i) {
871 ArdourCanvas::Duple& p (ipoints[pci++]);
872 p.x = 1.0 + rend + i;
873 p.y = 1.0 + effective_height - (effective_height * vp[i]);
877 end_xfade_out->set (ipoints);
878 end_xfade_out->show ();
879 end_xfade_out->raise_to_top ();
881 end_xfade_rect->raise_to_top (); //this needs to be topmost so the lines don't steal mouse focus
887 AudioRegionView::hide_xfades ()
894 AudioRegionView::hide_start_xfade ()
896 if (start_xfade_in) {
897 start_xfade_in->hide();
899 if (start_xfade_out) {
900 start_xfade_out->hide();
902 if (start_xfade_rect) {
903 start_xfade_rect->hide ();
906 _start_xfade_visible = false;
910 AudioRegionView::hide_end_xfade ()
913 end_xfade_in->hide();
916 end_xfade_out->hide();
918 if (end_xfade_rect) {
919 end_xfade_rect->hide ();
922 _end_xfade_visible = false;
926 AudioRegionView::show_start_xfade ()
928 if (start_xfade_in) {
929 start_xfade_in->show();
931 if (start_xfade_out) {
932 start_xfade_out->show();
934 if (start_xfade_rect) {
935 start_xfade_rect->show ();
938 _start_xfade_visible = true;
942 AudioRegionView::show_end_xfade ()
945 end_xfade_in->show();
948 end_xfade_out->show();
950 if (end_xfade_rect) {
951 end_xfade_rect->show ();
954 _end_xfade_visible = true;
958 AudioRegionView::set_samples_per_pixel (gdouble fpp)
960 RegionView::set_samples_per_pixel (fpp);
962 if (Config->get_show_waveforms ()) {
963 for (uint32_t n = 0; n < waves.size(); ++n) {
964 waves[n]->set_samples_per_pixel (fpp);
972 reset_fade_shapes ();
976 AudioRegionView::set_amplitude_above_axis (gdouble a)
978 for (uint32_t n=0; n < waves.size(); ++n) {
979 waves[n]->set_amplitude_above_axis (a);
984 AudioRegionView::compute_colors (Gdk::Color const & basic_color)
986 RegionView::compute_colors (basic_color);
988 /* gain color computed in envelope_active_changed() */
990 fade_color = UINT_RGBA_CHANGE_A (fill_color, 120);
994 AudioRegionView::set_colors ()
996 RegionView::set_colors();
999 gain_line->set_line_color (audio_region()->envelope_active() ?
1000 ARDOUR_UI::config()->get_canvasvar_GainLine() :
1001 ARDOUR_UI::config()->get_canvasvar_GainLineInactive());
1004 set_waveform_colors ();
1006 if (start_xfade_in) {
1007 start_xfade_in->set_outline_color (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine());
1009 if (start_xfade_out) {
1010 uint32_t col UINT_RGBA_CHANGE_A (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine(), 128);
1011 start_xfade_out->set_outline_color (col);
1014 end_xfade_in->set_outline_color (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine());
1016 if (end_xfade_out) {
1017 uint32_t col UINT_RGBA_CHANGE_A (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine(), 128);
1018 end_xfade_out->set_outline_color (col);
1021 if (start_xfade_rect) {
1022 start_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
1024 if (end_xfade_rect) {
1025 end_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
1030 AudioRegionView::setup_waveform_visibility ()
1032 if (Config->get_show_waveforms ()) {
1033 for (uint32_t n = 0; n < waves.size(); ++n) {
1034 /* make sure the zoom level is correct, since we don't update
1035 this when waveforms are hidden.
1038 // waves[n]->set_samples_per_pixel (_samples_per_pixel);
1042 for (uint32_t n = 0; n < waves.size(); ++n) {
1049 AudioRegionView::temporarily_hide_envelope ()
1057 AudioRegionView::unhide_envelope ()
1059 update_envelope_visibility ();
1063 AudioRegionView::update_envelope_visibility ()
1069 if (Config->get_show_region_gain() || trackview.editor().current_mouse_mode() == Editing::MouseGain) {
1070 gain_line->add_visibility (AutomationLine::Line);
1077 AudioRegionView::create_waves ()
1079 // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
1080 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
1086 ChanCount nchans = atv.track()->n_channels();
1088 // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data
1089 // << " and channels = " << nchans.n_audio() << endl;
1091 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
1092 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
1093 tmp_waves.push_back (0);
1096 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
1100 _data_ready_connections.clear ();
1102 for (uint32_t i = 0; i < nchans.n_audio(); ++i) {
1103 _data_ready_connections.push_back (0);
1106 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
1108 if (n >= audio_region()->n_channels()) {
1112 // cerr << "\tchannel " << n << endl;
1114 if (wait_for_data) {
1115 if (audio_region()->audio_source(n)->peaks_ready (boost::bind (&AudioRegionView::peaks_ready_handler, this, n), &_data_ready_connections[n], gui_context())) {
1116 // cerr << "\tData is ready\n";
1117 create_one_wave (n, true);
1119 // cerr << "\tdata is not ready\n";
1120 // we'll get a PeaksReady signal from the source in the future
1121 // and will call create_one_wave(n) then.
1125 // cerr << "\tdon't delay, display today!\n";
1126 create_one_wave (n, true);
1133 AudioRegionView::create_one_wave (uint32_t which, bool /*direct*/)
1135 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
1136 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
1137 uint32_t nchans = atv.track()->n_channels().n_audio();
1139 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
1142 if (trackview.current_height() < NAME_HIGHLIGHT_THRESH) {
1143 ht = ((trackview.current_height()) / (double) nchans);
1145 ht = ((trackview.current_height() - NAME_HIGHLIGHT_SIZE) / (double) nchans);
1148 gdouble yoff = which * ht;
1150 WaveView *wave = new WaveView (group, audio_region ());
1151 CANVAS_DEBUG_NAME (wave, string_compose ("wave view for chn %1 of %2", which, get_item_name()));
1153 wave->set_channel (which);
1154 wave->set_y_position (yoff);
1155 wave->set_height (ht);
1156 wave->set_samples_per_pixel (samples_per_pixel);
1157 wave->set_show_zero_line (true);
1159 switch (Config->get_waveform_shape()) {
1161 wave->set_shape (WaveView::Rectified);
1164 wave->set_shape (WaveView::Normal);
1167 wave->set_logscaled (Config->get_waveform_scale() == Logarithmic);
1169 if (!Config->get_show_waveforms ()) {
1173 /* note: calling this function is serialized by the lock
1174 held in the peak building thread that signals that
1175 peaks are ready for use *or* by the fact that it is
1176 called one by one from the GUI thread.
1179 if (which < nchans) {
1180 tmp_waves[which] = wave;
1182 /* n-channel track, >n-channel source */
1185 /* see if we're all ready */
1187 for (n = 0; n < nchans; ++n) {
1188 if (tmp_waves[n] == 0) {
1193 if (n == nwaves && waves.empty()) {
1194 /* all waves are ready */
1195 tmp_waves.resize(nwaves);
1200 /* all waves created, don't hook into peaks ready anymore */
1201 delete _data_ready_connections[which];
1202 _data_ready_connections[which] = 0;
1207 AudioRegionView::peaks_ready_handler (uint32_t which)
1209 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AudioRegionView::create_one_wave, this, which, false));
1210 // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
1214 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev, bool with_guard_points)
1222 /* don't create points that can't be seen */
1224 update_envelope_visibility ();
1229 item->canvas_to_item (x, y);
1231 framepos_t fx = trackview.editor().pixel_to_sample (x);
1233 if (fx > _region->length()) {
1237 /* compute vertical fractional position */
1239 y = 1.0 - (y / (_height - NAME_HIGHLIGHT_SIZE));
1241 /* map using gain line */
1243 gain_line->view_to_model_coord (x, y);
1245 /* XXX STATEFUL: can't convert to stateful diff until we
1246 can represent automation data with it.
1249 trackview.session()->begin_reversible_command (_("add gain control point"));
1250 XMLNode &before = audio_region()->envelope()->get_state();
1252 if (!audio_region()->envelope_active()) {
1253 XMLNode ®ion_before = audio_region()->get_state();
1254 audio_region()->set_envelope_active(true);
1255 XMLNode ®ion_after = audio_region()->get_state();
1256 trackview.session()->add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
1259 audio_region()->envelope()->add (fx, y, with_guard_points);
1261 XMLNode &after = audio_region()->envelope()->get_state();
1262 trackview.session()->add_command (new MementoCommand<AutomationList>(*audio_region()->envelope().get(), &before, &after));
1263 trackview.session()->commit_reversible_command ();
1267 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent* /*ev*/)
1269 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1270 audio_region()->envelope()->erase (cp->model());
1274 AudioRegionView::setup_waveform_shape ()
1276 WaveView::Shape shape;
1278 switch (Config->get_waveform_shape()) {
1280 shape = WaveView::Rectified;
1283 shape = WaveView::Normal;
1285 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1286 (*wave)->set_shape (shape);
1291 AudioRegionView::setup_waveform_scale ()
1293 WaveView::set_global_logscaled (Config->get_waveform_scale() == Logarithmic);
1297 AudioRegionView::setup_waveform_clipping ()
1299 WaveView::set_global_show_waveform_clipping (ARDOUR_UI::config()->get_show_waveform_clipping());
1303 AudioRegionView::add_ghost (TimeAxisView& tv)
1305 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1308 double unit_position = _region->position () / samples_per_pixel;
1309 AudioGhostRegion* ghost = new AudioGhostRegion (tv, trackview, unit_position);
1312 nchans = rtv->track()->n_channels().n_audio();
1314 for (uint32_t n = 0; n < nchans; ++n) {
1316 if (n >= audio_region()->n_channels()) {
1320 WaveView *wave = new WaveView (ghost->group, audio_region());
1321 CANVAS_DEBUG_NAME (wave, string_compose ("ghost wave for %1", get_item_name()));
1323 wave->set_channel (n);
1324 wave->set_samples_per_pixel (samples_per_pixel);
1325 wave->set_amplitude_above_axis (_amplitude_above_axis);
1327 ghost->waves.push_back(wave);
1330 ghost->set_height ();
1331 ghost->set_duration (_region->length() / samples_per_pixel);
1332 ghost->set_colors();
1333 ghosts.push_back (ghost);
1339 AudioRegionView::entered (bool internal_editing)
1341 trackview.editor().set_current_trimmable (_region);
1342 trackview.editor().set_current_movable (_region);
1345 /* these may or may not be visible depending on mouse mode */
1346 gain_line->add_visibility (AutomationLine::ControlPoints);
1349 if (fade_in_handle && !internal_editing) {
1350 fade_in_handle->show ();
1351 fade_out_handle->show ();
1352 fade_out_handle->raise_to_top ();
1353 fade_in_handle->raise_to_top ();
1358 AudioRegionView::exited ()
1360 trackview.editor().set_current_trimmable (boost::shared_ptr<Trimmable>());
1361 trackview.editor().set_current_movable (boost::shared_ptr<Movable>());
1364 gain_line->remove_visibility (AutomationLine::ControlPoints);
1367 if (fade_in_handle) {
1368 fade_in_handle->hide ();
1369 fade_out_handle->hide ();
1374 AudioRegionView::envelope_active_changed ()
1377 gain_line->set_line_color (audio_region()->envelope_active() ?
1378 ARDOUR_UI::config()->get_canvasvar_GainLine() :
1379 ARDOUR_UI::config()->get_canvasvar_GainLineInactive());
1380 update_envelope_visibility ();
1385 AudioRegionView::color_handler ()
1387 //case cMutedWaveForm:
1389 //case cWaveFormClip:
1393 //case cGainLineInactive:
1395 envelope_active_changed();
1400 AudioRegionView::set_waveform_colors ()
1402 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1403 set_one_waveform_color (*w);
1408 AudioRegionView::set_one_waveform_color (ArdourCanvas::WaveView* wave)
1410 ArdourCanvas::Color fill;
1411 ArdourCanvas::Color outline;
1414 if (_region->muted()) {
1415 /* hide outline with zero alpha */
1416 outline = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_SelectedWaveForm(), 0);
1417 fill = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_SelectedWaveFormFill(), MUTED_ALPHA);
1419 outline = ARDOUR_UI::config()->get_canvasvar_SelectedWaveForm();
1420 fill = ARDOUR_UI::config()->get_canvasvar_SelectedWaveFormFill();
1424 outline = ARDOUR_UI::config()->get_canvasvar_RecWaveForm();
1425 fill = ARDOUR_UI::config()->get_canvasvar_RecWaveFormFill();
1427 if (_region->muted()) {
1428 /* hide outline with zero alpha */
1429 outline = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_WaveForm(), 0);
1430 fill = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_WaveFormFill(), MUTED_ALPHA);
1432 outline = ARDOUR_UI::config()->get_canvasvar_WaveForm();
1433 fill = ARDOUR_UI::config()->get_canvasvar_WaveFormFill();
1438 if (ARDOUR_UI::config()->get_color_regions_using_track_color()) {
1440 /* just use a slightly transparent version of the selected
1441 * color so that some of the track color bleeds through
1445 ArdourCanvas::color_to_rgba (fill, r, g, b, a);
1446 fill = ArdourCanvas::rgba_to_color (r, g, b, 0.85); /* magic number, not user controllable */
1447 outline = ARDOUR_UI::config()->get_canvasvar_WaveForm();
1450 wave->set_fill_color (fill);
1451 wave->set_outline_color (outline);
1452 wave->set_clip_color (ARDOUR_UI::config()->get_canvasvar_WaveFormClip());
1453 wave->set_zero_color (ARDOUR_UI::config()->get_canvasvar_ZeroLine());
1457 AudioRegionView::set_frame_color ()
1463 if (_region->opaque()) {
1469 TimeAxisViewItem::set_frame_color ();
1471 set_waveform_colors ();
1475 AudioRegionView::set_fade_visibility (bool yn)
1478 if (fade_in_shape) {
1479 fade_in_shape->show();
1481 if (fade_out_shape) {
1482 fade_out_shape->show ();
1484 if (fade_in_handle) {
1485 fade_in_handle->show ();
1487 if (fade_out_handle) {
1488 fade_out_handle->show ();
1491 if (fade_in_shape) {
1492 fade_in_shape->hide();
1494 if (fade_out_shape) {
1495 fade_out_shape->hide ();
1497 if (fade_in_handle) {
1498 fade_in_handle->hide ();
1500 if (fade_out_handle) {
1501 fade_out_handle->hide ();
1507 AudioRegionView::update_coverage_frames (LayerDisplay d)
1509 RegionView::update_coverage_frames (d);
1511 if (fade_in_handle) {
1512 fade_in_handle->raise_to_top ();
1513 fade_out_handle->raise_to_top ();
1518 AudioRegionView::show_region_editor ()
1521 editor = new AudioRegionEditor (trackview.session(), audio_region());
1529 AudioRegionView::transients_changed ()
1531 AnalysisFeatureList analysis_features = _region->transients();
1533 while (feature_lines.size() < analysis_features.size()) {
1535 ArdourCanvas::Line* canvas_item = new ArdourCanvas::Line(group);
1536 CANVAS_DEBUG_NAME (canvas_item, string_compose ("transient group for %1", region()->name()));
1538 canvas_item->set (ArdourCanvas::Duple (-1.0, 2.0),
1539 ArdourCanvas::Duple (1.0, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
1541 canvas_item->raise_to_top ();
1542 canvas_item->show ();
1544 canvas_item->set_data ("regionview", this);
1545 canvas_item->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_feature_line_event), canvas_item, this));
1547 feature_lines.push_back (make_pair(0, canvas_item));
1550 while (feature_lines.size() > analysis_features.size()) {
1551 ArdourCanvas::Line* line = feature_lines.back().second;
1552 feature_lines.pop_back ();
1556 AnalysisFeatureList::const_iterator i;
1557 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1559 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
1561 float *pos = new float;
1562 *pos = trackview.editor().sample_to_pixel (*i);
1565 ArdourCanvas::Duple (*pos, 2.0),
1566 ArdourCanvas::Duple (*pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1)
1569 (*l).second->set_data ("position", pos);
1575 AudioRegionView::update_transient(float /*old_pos*/, float new_pos)
1577 /* Find frame at old pos, calulate new frame then update region transients*/
1578 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1580 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1582 /* Line has been updated in drag so we compare to new_pos */
1584 float* pos = (float*) (*l).second->get_data ("position");
1586 if (rint(new_pos) == rint(*pos)) {
1588 framepos_t old_frame = (*l).first;
1589 framepos_t new_frame = trackview.editor().pixel_to_sample (new_pos);
1591 _region->update_transient (old_frame, new_frame);
1599 AudioRegionView::remove_transient(float pos)
1601 /* Find frame at old pos, calulate new frame then update region transients*/
1602 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1604 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1606 /* Line has been updated in drag so we compare to new_pos */
1607 float *line_pos = (float*) (*l).second->get_data ("position");
1609 if (rint(pos) == rint(*line_pos)) {
1610 _region->remove_transient ((*l).first);
1617 AudioRegionView::thaw_after_trim ()
1619 RegionView::thaw_after_trim ();
1626 AudioRegionView::show_xfades ()
1628 show_start_xfade ();
1633 AudioRegionView::drag_start ()
1635 TimeAxisViewItem::drag_start ();
1637 //we used to hide xfades here. I don't see the point with the new model, but we can re-implement if needed
1641 AudioRegionView::drag_end ()
1643 TimeAxisViewItem::drag_end ();
1645 //see comment for drag_start
1649 AudioRegionView::parameter_changed (string const & p)
1651 if (p == "show-waveforms") {
1652 setup_waveform_visibility ();
1653 } else if (p == "waveform-scale") {
1654 setup_waveform_scale ();
1655 } else if (p == "waveform-shape") {
1656 setup_waveform_shape ();
1657 } else if (p == "show-waveform-clipping") {
1658 setup_waveform_clipping ();