2 Copyright (C) 2001-2006 Paul Davis
4 This program is free software; you can r>edistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <boost/scoped_array.hpp>
27 #include <gtkmm2ext/gtk_ui.h>
29 #include "ardour/playlist.h"
30 #include "ardour/audioregion.h"
31 #include "ardour/audiosource.h"
32 #include "ardour/profile.h"
33 #include "ardour/session.h"
35 #include "pbd/memento_command.h"
36 #include "pbd/stacktrace.h"
38 #include "evoral/Curve.hpp"
40 #include "canvas/rectangle.h"
41 #include "canvas/polygon.h"
42 #include "canvas/poly_line.h"
43 #include "canvas/pixbuf.h"
45 #include "streamview.h"
46 #include "audio_region_view.h"
47 #include "audio_time_axis.h"
48 #include "public_editor.h"
49 #include "audio_region_editor.h"
50 #include "audio_streamview.h"
51 #include "region_gain_line.h"
52 #include "control_point.h"
53 #include "ghostregion.h"
54 #include "audio_time_axis.h"
56 #include "rgb_macros.h"
57 #include "gui_thread.h"
58 #include "ardour_ui.h"
62 #define MUTED_ALPHA 10
65 using namespace ARDOUR;
67 using namespace Editing;
68 using namespace ArdourCanvas;
70 static const int32_t sync_mark_width = 9;
71 static double const handle_size = 6; /* height of fade handles */
73 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
74 Gdk::Color const & basic_color)
75 : RegionView (parent, tv, r, spu, basic_color)
83 , start_xfade_rect (0)
84 , _start_xfade_visible (false)
88 , _end_xfade_visible (false)
89 , _amplitude_above_axis(1.0)
92 Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&AudioRegionView::parameter_changed, this, _1), gui_context());
95 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
96 Gdk::Color const & basic_color, bool recording, TimeAxisViewItem::Visibility visibility)
97 : RegionView (parent, tv, r, spu, basic_color, recording, visibility)
104 , start_xfade_out (0)
105 , start_xfade_rect (0)
106 , _start_xfade_visible (false)
110 , _end_xfade_visible (false)
111 , _amplitude_above_axis(1.0)
114 Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&AudioRegionView::parameter_changed, this, _1), gui_context());
117 AudioRegionView::AudioRegionView (const AudioRegionView& other, boost::shared_ptr<AudioRegion> other_region)
118 : RegionView (other, boost::shared_ptr<Region> (other_region))
124 , start_xfade_out (0)
125 , start_xfade_rect (0)
126 , _start_xfade_visible (false)
130 , _end_xfade_visible (false)
131 , _amplitude_above_axis (other._amplitude_above_axis)
137 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
138 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
142 Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&AudioRegionView::parameter_changed, this, _1), gui_context());
146 AudioRegionView::init (Gdk::Color const & basic_color, bool wfd)
148 // FIXME: Some redundancy here with RegionView::init. Need to figure out
149 // where order is important and where it isn't...
151 RegionView::init (basic_color, wfd);
153 _amplitude_above_axis = 1.0;
155 compute_colors (basic_color);
159 fade_in_shape = new ArdourCanvas::Polygon (group);
160 fade_in_shape->set_fill_color (fade_color);
161 fade_in_shape->set_data ("regionview", this);
163 fade_out_shape = new ArdourCanvas::Polygon (group);
164 fade_out_shape->set_fill_color (fade_color);
165 fade_out_shape->set_data ("regionview", this);
168 fade_in_handle = new ArdourCanvas::Rectangle (group);
169 fade_in_handle->set_fill_color (UINT_RGBA_CHANGE_A (fill_color, 0));
170 fade_in_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 0));
172 fade_in_handle->set_data ("regionview", this);
174 fade_out_handle = new ArdourCanvas::Rectangle (group);
175 fade_out_handle->set_fill_color (UINT_RGBA_CHANGE_A (fill_color, 0));
176 fade_out_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 0));
178 fade_out_handle->set_data ("regionview", this);
181 setup_fade_handle_positions ();
183 if (!trackview.session()->config.get_show_region_fades()) {
184 set_fade_visibility (false);
187 const string line_name = _region->name() + ":gain";
189 if (!Profile->get_sae()) {
190 gain_line.reset (new AudioRegionGainLine (line_name, *this, *group, audio_region()->envelope()));
193 update_envelope_visibility ();
196 set_height (trackview.current_height());
199 region_sync_changed ();
201 region_resized (ARDOUR::bounds_change);
203 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
204 (*i)->set_duration (_region->length() / frames_per_pixel);
208 envelope_active_changed ();
209 fade_in_active_changed ();
210 fade_out_active_changed ();
212 reset_width_dependent_items (_pixel_width);
214 fade_in_shape->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
215 if (fade_in_handle) {
216 fade_in_handle->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
219 fade_out_shape->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
221 if (fade_out_handle) {
222 fade_out_handle->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
227 setup_waveform_visibility ();
228 setup_waveform_shape ();
229 setup_waveform_scale ();
231 /* XXX sync mark drag? */
234 AudioRegionView::~AudioRegionView ()
236 in_destructor = true;
238 RegionViewGoingAway (this); /* EMIT_SIGNAL */
240 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
244 for (list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator i = feature_lines.begin(); i != feature_lines.end(); ++i) {
245 delete ((*i).second);
248 /* all waveviews etc will be destroyed when the group is destroyed */
251 boost::shared_ptr<ARDOUR::AudioRegion>
252 AudioRegionView::audio_region() const
254 // "Guaranteed" to succeed...
255 return boost::dynamic_pointer_cast<AudioRegion>(_region);
259 AudioRegionView::region_changed (const PropertyChange& what_changed)
261 ENSURE_GUI_THREAD (*this, &AudioRegionView::region_changed, what_changed);
263 RegionView::region_changed (what_changed);
265 if (what_changed.contains (ARDOUR::Properties::scale_amplitude)) {
266 region_scale_amplitude_changed ();
268 if (what_changed.contains (ARDOUR::Properties::fade_in)) {
271 if (what_changed.contains (ARDOUR::Properties::fade_out)) {
274 if (what_changed.contains (ARDOUR::Properties::fade_in_active)) {
275 fade_in_active_changed ();
277 if (what_changed.contains (ARDOUR::Properties::fade_out_active)) {
278 fade_out_active_changed ();
280 if (what_changed.contains (ARDOUR::Properties::envelope_active)) {
281 envelope_active_changed ();
283 if (what_changed.contains (ARDOUR::Properties::valid_transients)) {
284 transients_changed ();
289 AudioRegionView::fade_in_changed ()
291 reset_fade_in_shape ();
295 AudioRegionView::fade_out_changed ()
297 reset_fade_out_shape ();
301 AudioRegionView::fade_in_active_changed ()
303 if (audio_region()->fade_in_active()) {
304 /* XXX: make a themable colour */
305 fade_in_shape->set_fill_color (RGBA_TO_UINT (45, 45, 45, 90));
306 fade_in_shape->set_outline_width (1);
308 /* XXX: make a themable colour */
309 fade_in_shape->set_fill_color (RGBA_TO_UINT (45, 45, 45, 20));
310 fade_in_shape->set_outline_width (1);
315 AudioRegionView::fade_out_active_changed ()
317 if (audio_region()->fade_out_active()) {
318 /* XXX: make a themable colour */
319 fade_out_shape->set_fill_color (RGBA_TO_UINT (45, 45, 45, 90));
320 fade_out_shape->set_outline_width (1);
322 /* XXX: make a themable colour */
323 fade_out_shape->set_fill_color (RGBA_TO_UINT (45, 45, 45, 20));
324 fade_out_shape->set_outline_width (1);
330 AudioRegionView::region_scale_amplitude_changed ()
332 ENSURE_GUI_THREAD (*this, &AudioRegionView::region_scale_amplitude_changed)
334 for (uint32_t n = 0; n < waves.size(); ++n) {
335 waves[n]->rebuild ();
340 AudioRegionView::region_renamed ()
342 std::string str = RegionView::make_name ();
344 if (audio_region()->speed_mismatch (trackview.session()->frame_rate())) {
345 str = string ("*") + str;
348 if (_region->muted()) {
349 str = string ("!") + str;
352 set_item_name (str, this);
357 AudioRegionView::region_resized (const PropertyChange& what_changed)
359 AudioGhostRegion* agr;
361 RegionView::region_resized(what_changed);
362 PropertyChange interesting_stuff;
364 interesting_stuff.add (ARDOUR::Properties::start);
365 interesting_stuff.add (ARDOUR::Properties::length);
367 if (what_changed.contains (interesting_stuff)) {
369 for (uint32_t n = 0; n < waves.size(); ++n) {
370 waves[n]->region_resized ();
371 waves[n]->set_region_start (region()->start ());
374 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
375 if ((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
377 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
378 (*w)->region_resized ();
379 (*w)->set_region_start (region()->start ());
384 /* hide transient lines that extend beyond the region end */
386 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
388 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
389 if (l->first > _region->length() - 1) {
399 AudioRegionView::reset_width_dependent_items (double pixel_width)
401 RegionView::reset_width_dependent_items(pixel_width);
402 assert(_pixel_width == pixel_width);
404 if (fade_in_handle) {
405 if (pixel_width <= 6.0 || _height < 5.0 || !trackview.session()->config.get_show_region_fades()) {
406 fade_in_handle->hide();
407 fade_out_handle->hide();
410 fade_in_handle->show();
411 fade_out_handle->show();
415 AnalysisFeatureList analysis_features = _region->transients();
416 AnalysisFeatureList::const_iterator i;
418 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
420 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
422 float x_pos = trackview.editor().frame_to_pixel (*i);
424 (*l).second->set (ArdourCanvas::Duple (x_pos, 2.0),
425 ArdourCanvas::Duple (x_pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
429 (*l).second->set (ArdourCanvas::Duple (x_pos, 2.0),
430 ArdourCanvas::Duple (x_pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
433 reset_fade_shapes ();
437 AudioRegionView::region_muted ()
439 RegionView::region_muted();
441 for (uint32_t n=0; n < waves.size(); ++n) {
442 if (_region->muted()) {
443 waves[n]->set_outline_color (UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA));
445 waves[n]->set_outline_color (ARDOUR_UI::config()->canvasvar_WaveForm.get());
451 AudioRegionView::setup_fade_handle_positions()
453 /* position of fade handle offset from the top of the region view */
454 double const handle_pos = 2;
456 if (fade_in_handle) {
457 fade_in_handle->set_y0 (handle_pos);
458 fade_in_handle->set_y1 (handle_pos + handle_size);
461 if (fade_out_handle) {
462 fade_out_handle->set_y0 (handle_pos);
463 fade_out_handle->set_y1 (handle_pos + handle_size);
468 AudioRegionView::set_height (gdouble height)
470 RegionView::set_height (height);
472 uint32_t wcnt = waves.size();
474 for (uint32_t n = 0; n < wcnt; ++n) {
477 if (height < NAME_HIGHLIGHT_THRESH) {
478 ht = ((height - 2 * wcnt) / (double) wcnt);
480 ht = (((height - 2 * wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
483 gdouble yoff = n * (ht + 1);
485 waves[n]->set_height (ht);
486 waves[n]->set_y_position (yoff + 2);
491 if ((height/wcnt) < NAME_HIGHLIGHT_THRESH) {
494 update_envelope_visibility ();
497 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE) - 2);
500 reset_fade_shapes ();
502 /* Update hights for any active feature lines */
503 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
505 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
507 float pos_x = trackview.editor().frame_to_pixel((*l).first);
509 (*l).second->set (ArdourCanvas::Duple (pos_x, 2.0),
510 ArdourCanvas::Duple (pos_x, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
514 name_pixbuf->raise_to_top();
519 AudioRegionView::reset_fade_shapes ()
521 reset_fade_in_shape ();
522 reset_fade_out_shape ();
526 AudioRegionView::reset_fade_in_shape ()
528 reset_fade_in_shape_width (audio_region(), (framecnt_t) audio_region()->fade_in()->back()->when);
532 AudioRegionView::reset_fade_in_shape_width (boost::shared_ptr<AudioRegion> ar, framecnt_t width)
534 if (fade_in_handle == 0) {
538 fade_in_handle->show ();
540 /* smallest size for a fade is 64 frames */
542 width = std::max ((framecnt_t) 64, width);
546 /* round here to prevent little visual glitches with sub-pixel placement */
547 double const pwidth = rint (width / frames_per_pixel);
548 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
551 double const handle_center = pwidth;
553 /* Put the fade in handle so that its left side is at the end-of-fade line */
554 fade_in_handle->set_x0 (handle_center);
555 fade_in_handle->set_x1 (handle_center + handle_size);
559 fade_in_shape->hide();
563 if (trackview.session()->config.get_show_region_fades()) {
564 fade_in_shape->show();
567 float curve[npoints];
568 audio_region()->fade_in()->curve().get_vector (0, audio_region()->fade_in()->back()->when, curve, npoints);
570 points = get_canvas_points ("fade in shape", npoints + 3);
572 if (_height >= NAME_HIGHLIGHT_THRESH) {
573 h = _height - NAME_HIGHLIGHT_SIZE - 2;
578 /* points *MUST* be in anti-clockwise order */
581 double xdelta = pwidth/npoints;
583 for (pi = 0, pc = 0; pc < npoints; ++pc) {
584 (*points)[pi].x = 1 + (pc * xdelta);
585 (*points)[pi++].y = 2 + (h - (curve[pc] * h));
590 (*points)[pi].x = pwidth;
591 (*points)[pi++].y = 2;
594 (*points)[pi++].y = 2;
596 /* connect the dots ... */
598 (*points)[pi] = (*points)[0];
600 fade_in_shape->set (*points);
603 redraw_start_xfade_to ( ar, width);
605 /* ensure trim handle stays on top */
606 if (frame_handle_start) {
607 frame_handle_start->raise_to_top();
613 AudioRegionView::reset_fade_out_shape ()
615 reset_fade_out_shape_width (audio_region(), (framecnt_t) audio_region()->fade_out()->back()->when);
619 AudioRegionView::reset_fade_out_shape_width (boost::shared_ptr<AudioRegion> ar, framecnt_t width)
621 if (fade_out_handle == 0) {
625 fade_out_handle->show ();
627 /* smallest size for a fade is 64 frames */
629 width = std::max ((framecnt_t) 64, width);
633 /* round here to prevent little visual glitches with sub-pixel placement */
634 double const pwidth = rint (width / frames_per_pixel);
635 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
638 double const handle_center = (_region->length() - width) / frames_per_pixel;
640 /* Put the fade out handle so that its right side is at the end-of-fade line;
641 * it's `one out' for precise pixel accuracy.
643 fade_out_handle->set_x0 (handle_center - 5);
644 fade_out_handle->set_x1 (handle_center + 1);
646 /* don't show shape if its too small */
650 fade_out_shape->hide();
654 if (trackview.session()->config.get_show_region_fades()) {
655 fade_out_shape->show();
658 float curve[npoints];
659 audio_region()->fade_out()->curve().get_vector (0, audio_region()->fade_out()->back()->when, curve, npoints);
661 if (_height >= NAME_HIGHLIGHT_THRESH) {
662 h = _height - NAME_HIGHLIGHT_SIZE - 2;
667 /* points *MUST* be in anti-clockwise order */
669 points = get_canvas_points ("fade out shape", npoints + 3);
672 double xdelta = pwidth/npoints;
674 for (pi = 0, pc = 0; pc < npoints; ++pc) {
675 (*points)[pi].x = _pixel_width - pwidth + (pc * xdelta);
676 (*points)[pi++].y = 2 + (h - (curve[pc] * h));
681 (*points)[pi].x = _pixel_width;
682 (*points)[pi++].y = h;
684 (*points)[pi].x = _pixel_width;
685 (*points)[pi++].y = 2;
687 /* connect the dots ... */
689 (*points)[pi] = (*points)[0];
691 fade_out_shape->set (*points);
694 redraw_end_xfade_to (ar, width);
696 /* ensure trim handle stays on top */
697 if (frame_handle_end) {
698 frame_handle_end->raise_to_top();
704 AudioRegionView::get_fade_in_shape_width ()
706 return audio_region()->fade_in()->back()->when;
710 AudioRegionView::get_fade_out_shape_width ()
712 return audio_region()->fade_out()->back()->when;
717 AudioRegionView::set_frames_per_pixel (gdouble fpp)
719 RegionView::set_frames_per_pixel (fpp);
721 if (Config->get_show_waveforms ()) {
722 for (uint32_t n = 0; n < waves.size(); ++n) {
723 waves[n]->set_frames_per_pixel (fpp);
731 reset_fade_shapes ();
735 AudioRegionView::set_amplitude_above_axis (gdouble spp)
737 for (uint32_t n=0; n < waves.size(); ++n) {
738 waves[n]->property_amplitude_above_axis() = spp;
743 AudioRegionView::compute_colors (Gdk::Color const & basic_color)
745 RegionView::compute_colors (basic_color);
747 /* gain color computed in envelope_active_changed() */
749 fade_color = UINT_RGBA_CHANGE_A (fill_color, 120);
753 AudioRegionView::set_colors ()
755 RegionView::set_colors();
758 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
761 for (uint32_t n=0; n < waves.size(); ++n) {
762 if (_region->muted()) {
763 waves[n]->set_outline_color (UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA));
765 waves[n]->set_outline_color (ARDOUR_UI::config()->canvasvar_WaveForm.get());
768 waves[n]->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
769 waves[n]->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
774 AudioRegionView::setup_waveform_visibility ()
776 if (Config->get_show_waveforms ()) {
777 for (uint32_t n = 0; n < waves.size(); ++n) {
778 /* make sure the zoom level is correct, since we don't update
779 this when waveforms are hidden.
782 //waves[n]->set_frames_per_pixel (_frames_per_pixel);
786 for (uint32_t n = 0; n < waves.size(); ++n) {
793 AudioRegionView::temporarily_hide_envelope ()
801 AudioRegionView::unhide_envelope ()
803 update_envelope_visibility ();
807 AudioRegionView::update_envelope_visibility ()
813 if (Config->get_show_region_gain() || trackview.editor().current_mouse_mode() == Editing::MouseGain) {
814 gain_line->add_visibility (AutomationLine::Line);
821 AudioRegionView::create_waves ()
823 // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
824 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
830 ChanCount nchans = atv.track()->n_channels();
832 // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data
833 // << " and channels = " << nchans.n_audio() << endl;
835 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
836 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
837 tmp_waves.push_back (0);
840 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
844 _data_ready_connections.clear ();
846 for (uint32_t i = 0; i < nchans.n_audio(); ++i) {
847 _data_ready_connections.push_back (0);
850 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
852 if (n >= audio_region()->n_channels()) {
856 // cerr << "\tchannel " << n << endl;
859 if (audio_region()->audio_source(n)->peaks_ready (boost::bind (&AudioRegionView::peaks_ready_handler, this, n), &_data_ready_connections[n], gui_context())) {
860 // cerr << "\tData is ready\n";
861 create_one_wave (n, true);
863 // cerr << "\tdata is not ready\n";
864 // we'll get a PeaksReady signal from the source in the future
865 // and will call create_one_wave(n) then.
869 // cerr << "\tdon't delay, display today!\n";
870 create_one_wave (n, true);
877 AudioRegionView::create_one_wave (uint32_t which, bool /*direct*/)
879 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
880 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
881 uint32_t nchans = atv.track()->n_channels().n_audio();
883 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
886 if (trackview.current_height() < NAME_HIGHLIGHT_THRESH) {
887 ht = ((trackview.current_height()) / (double) nchans);
889 ht = ((trackview.current_height() - NAME_HIGHLIGHT_SIZE) / (double) nchans);
892 gdouble yoff = which * ht;
894 WaveView *wave = new WaveView (group, audio_region ());
896 wave->set_channel (which);
897 wave->set_x_position (0);
898 wave->set_y_position (yoff);
899 wave->set_height (ht);
900 wave->set_frames_per_pixel (frames_per_pixel);
901 wave->property_amplitude_above_axis() = _amplitude_above_axis;
904 wave->set_outline_color (_region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_RecWaveForm.get());
905 wave->set_fill_color (ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get());
907 wave->set_outline_color (_region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_WaveForm.get());
908 wave->set_fill_color (ARDOUR_UI::config()->canvasvar_WaveFormFill.get());
911 wave->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
912 wave->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
914 // wave->property_zero_line() = true;
916 wave->set_region_start (_region->start());
917 wave->property_rectified() = Config->get_waveform_shape() == Rectified;
918 wave->property_logscaled() = Config->get_waveform_scale() == Logarithmic;
920 if (!Config->get_show_waveforms ()) {
924 /* note: calling this function is serialized by the lock
925 held in the peak building thread that signals that
926 peaks are ready for use *or* by the fact that it is
927 called one by one from the GUI thread.
930 if (which < nchans) {
931 tmp_waves[which] = wave;
933 /* n-channel track, >n-channel source */
936 /* see if we're all ready */
938 for (n = 0; n < nchans; ++n) {
939 if (tmp_waves[n] == 0) {
944 if (n == nwaves && waves.empty()) {
945 /* all waves are ready */
946 tmp_waves.resize(nwaves);
951 /* all waves created, don't hook into peaks ready anymore */
952 delete _data_ready_connections[which];
953 _data_ready_connections[which] = 0;
958 AudioRegionView::peaks_ready_handler (uint32_t which)
960 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AudioRegionView::create_one_wave, this, which, false));
961 // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
965 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
973 /* don't create points that can't be seen */
975 update_envelope_visibility ();
980 item->canvas_to_item (x, y);
982 framepos_t fx = trackview.editor().pixel_to_frame (x);
984 if (fx > _region->length()) {
988 /* compute vertical fractional position */
990 y = 1.0 - (y / (_height - NAME_HIGHLIGHT_SIZE));
992 /* map using gain line */
994 gain_line->view_to_model_coord (x, y);
996 /* XXX STATEFUL: can't convert to stateful diff until we
997 can represent automation data with it.
1000 trackview.session()->begin_reversible_command (_("add gain control point"));
1001 XMLNode &before = audio_region()->envelope()->get_state();
1003 if (!audio_region()->envelope_active()) {
1004 XMLNode ®ion_before = audio_region()->get_state();
1005 audio_region()->set_envelope_active(true);
1006 XMLNode ®ion_after = audio_region()->get_state();
1007 trackview.session()->add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
1010 audio_region()->envelope()->add (fx, y);
1012 XMLNode &after = audio_region()->envelope()->get_state();
1013 trackview.session()->add_command (new MementoCommand<AutomationList>(*audio_region()->envelope().get(), &before, &after));
1014 trackview.session()->commit_reversible_command ();
1018 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent */*ev*/)
1020 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1021 audio_region()->envelope()->erase (cp->model());
1025 AudioRegionView::setup_waveform_shape ()
1027 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1028 (*wave)->property_rectified() = Config->get_waveform_shape() == Rectified;
1033 AudioRegionView::setup_waveform_scale ()
1035 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1036 (*wave)->property_logscaled() = Config->get_waveform_scale() == Logarithmic;
1042 AudioRegionView::add_ghost (TimeAxisView& tv)
1044 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1047 double unit_position = _region->position () / frames_per_pixel;
1048 AudioGhostRegion* ghost = new AudioGhostRegion (tv, trackview, unit_position);
1051 nchans = rtv->track()->n_channels().n_audio();
1053 for (uint32_t n = 0; n < nchans; ++n) {
1055 if (n >= audio_region()->n_channels()) {
1059 WaveView *wave = new WaveView (ghost->group, audio_region());
1061 wave->set_channel (n);
1062 wave->set_x_position (0);
1063 wave->set_frames_per_pixel (frames_per_pixel);
1064 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1065 wave->set_region_start (_region->start());
1067 ghost->waves.push_back(wave);
1070 ghost->set_height ();
1071 ghost->set_duration (_region->length() / frames_per_pixel);
1072 ghost->set_colors();
1073 ghosts.push_back (ghost);
1079 AudioRegionView::entered (bool internal_editing)
1081 trackview.editor().set_current_trimmable (_region);
1082 trackview.editor().set_current_movable (_region);
1084 if (gain_line && trackview.editor().current_mouse_mode() == Editing::MouseGain) {
1085 gain_line->add_visibility (AutomationLine::ControlPoints);
1088 if (fade_in_handle && !internal_editing) {
1089 fade_in_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 255));
1090 fade_in_handle->set_fill_color (UINT_RGBA_CHANGE_A (fade_color, 255));
1091 fade_out_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 255));
1092 fade_out_handle->set_fill_color (UINT_RGBA_CHANGE_A (fade_color, 255));
1097 AudioRegionView::exited ()
1099 trackview.editor().set_current_trimmable (boost::shared_ptr<Trimmable>());
1100 trackview.editor().set_current_movable (boost::shared_ptr<Movable>());
1102 if (gain_line && trackview.editor().current_mouse_mode() == Editing::MouseGain) {
1103 gain_line->remove_visibility (AutomationLine::ControlPoints);
1106 if (fade_in_handle) {
1107 fade_in_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 0));
1108 fade_in_handle->set_fill_color (UINT_RGBA_CHANGE_A (fade_color, 0));
1109 fade_out_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 0));
1110 fade_out_handle->set_fill_color (UINT_RGBA_CHANGE_A (fade_color, 0));
1115 AudioRegionView::envelope_active_changed ()
1118 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
1123 AudioRegionView::color_handler ()
1125 //case cMutedWaveForm:
1127 //case cWaveFormClip:
1131 //case cGainLineInactive:
1133 envelope_active_changed();
1138 AudioRegionView::set_frame_color ()
1144 if (_region->opaque()) {
1150 TimeAxisViewItem::set_frame_color ();
1156 if (_region->muted()) {
1157 wc = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get(), MUTED_ALPHA);
1159 wc = ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get();
1161 fc = ARDOUR_UI::config()->canvasvar_SelectedWaveFormFill.get();
1164 if (_region->muted()) {
1165 wc = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA);
1167 wc = ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
1169 fc = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
1171 if (_region->muted()) {
1172 wc = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
1174 wc = ARDOUR_UI::config()->canvasvar_WaveForm.get();
1176 fc = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
1180 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1181 (*w)->set_outline_color (wc);
1182 if (!_region->muted()) {
1183 (*w)->set_fill_color (fc);
1189 AudioRegionView::set_fade_visibility (bool yn)
1192 if (fade_in_shape) {
1193 fade_in_shape->show();
1195 if (fade_out_shape) {
1196 fade_out_shape->show ();
1198 if (fade_in_handle) {
1199 fade_in_handle->show ();
1201 if (fade_out_handle) {
1202 fade_out_handle->show ();
1205 if (fade_in_shape) {
1206 fade_in_shape->hide();
1208 if (fade_out_shape) {
1209 fade_out_shape->hide ();
1211 if (fade_in_handle) {
1212 fade_in_handle->hide ();
1214 if (fade_out_handle) {
1215 fade_out_handle->hide ();
1221 AudioRegionView::update_coverage_frames (LayerDisplay d)
1223 RegionView::update_coverage_frames (d);
1225 if (fade_in_handle) {
1226 fade_in_handle->raise_to_top ();
1227 fade_out_handle->raise_to_top ();
1232 AudioRegionView::show_region_editor ()
1235 editor = new AudioRegionEditor (trackview.session(), audio_region());
1239 editor->set_position (Gtk::WIN_POS_MOUSE);
1244 AudioRegionView::transients_changed ()
1246 AnalysisFeatureList analysis_features = _region->transients();
1248 while (feature_lines.size() < analysis_features.size()) {
1250 ArdourCanvas::Line* canvas_item = new ArdourCanvas::Line(group);
1252 canvas_item->set (ArdourCanvas::Duple (-1.0, 2.0),
1253 ArdourCanvas::Duple (1.0, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
1255 canvas_item->set_outline_width (1);
1256 canvas_item->property_first_arrowhead() = TRUE;
1257 canvas_item->property_last_arrowhead() = TRUE;
1258 canvas_item->property_arrow_shape_a() = 11.0;
1259 canvas_item->property_arrow_shape_b() = 0.0;
1260 canvas_item->property_arrow_shape_c() = 4.0;
1262 canvas_item->raise_to_top ();
1263 canvas_item->show ();
1265 canvas_item->set_data ("regionview", this);
1266 canvas_item->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_feature_line_event), canvas_item, this));
1268 feature_lines.push_back (make_pair(0, canvas_item));
1271 while (feature_lines.size() > analysis_features.size()) {
1272 ArdourCanvas::Line* line = feature_lines.back().second;
1273 feature_lines.pop_back ();
1277 AnalysisFeatureList::const_iterator i;
1278 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1280 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
1282 float *pos = new float;
1283 *pos = trackview.editor().frame_to_pixel (*i);
1286 ArdourCanvas::Duple (*pos, 2.0),
1287 ArdourCanvas::Duple (*pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1)
1290 (*l).second->set_data ("position", pos);
1296 AudioRegionView::update_transient(float /*old_pos*/, float new_pos)
1298 /* Find frame at old pos, calulate new frame then update region transients*/
1299 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1301 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1303 /* Line has been updated in drag so we compare to new_pos */
1305 float* pos = (float*) (*l).second->get_data ("position");
1307 if (rint(new_pos) == rint(*pos)) {
1309 framepos_t old_frame = (*l).first;
1310 framepos_t new_frame = trackview.editor().pixel_to_frame (new_pos);
1312 _region->update_transient (old_frame, new_frame);
1320 AudioRegionView::remove_transient(float pos)
1322 /* Find frame at old pos, calulate new frame then update region transients*/
1323 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1325 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1327 /* Line has been updated in drag so we compare to new_pos */
1328 float *line_pos = (float*) (*l).second->get_data ("position");
1330 if (rint(pos) == rint(*line_pos)) {
1331 _region->remove_transient ((*l).first);
1338 AudioRegionView::thaw_after_trim ()
1340 RegionView::thaw_after_trim ();
1346 AudioRegionView::redraw_start_xfade ()
1348 boost::shared_ptr<AudioRegion> ar (audio_region());
1350 if (!ar->fade_in() || ar->fade_in()->empty()) {
1356 redraw_start_xfade_to (ar, ar->fade_in()->back()->when);
1360 AudioRegionView::redraw_start_xfade_to (boost::shared_ptr<AudioRegion> ar, framecnt_t len)
1362 int32_t const npoints = trackview.editor().frame_to_pixel (len);
1368 if (!start_xfade_in) {
1369 start_xfade_in = new ArdourCanvas::PolyLine (group);
1371 // start_xfade_in->set_width_pixels (1);
1372 start_xfade_in->set_outline_color (ARDOUR_UI::config()->canvasvar_GainLine.get());
1375 if (!start_xfade_out) {
1376 start_xfade_out = new ArdourCanvas::PolyLine (group);
1378 // start_xfade_out->set_width_pixels (1);
1379 uint32_t col = UINT_RGBA_CHANGE_A (ARDOUR_UI::config()->canvasvar_GainLine.get(), 128);
1380 start_xfade_out->set_outline_color (col);
1383 if (!start_xfade_rect) {
1384 start_xfade_rect = new ArdourCanvas::Rectangle (group);
1386 // start_xfade_rect->property_draw() = true;
1387 start_xfade_rect->set_fill (true);
1388 start_xfade_rect->set_fill_color (ARDOUR_UI::config()->canvasvar_ActiveCrossfade.get());
1389 start_xfade_rect->set_outline (false);
1390 start_xfade_rect->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_start_xfade_event), start_xfade_rect, this));
1391 start_xfade_rect->set_data ("regionview", this);
1394 ArdourCanvas::Points* points = get_canvas_points ("xfade edit redraw", npoints);
1395 boost::scoped_array<float> vec (new float[npoints]);
1397 double effective_height;
1398 if (_height >= NAME_HIGHLIGHT_THRESH) {
1399 effective_height = _height - NAME_HIGHLIGHT_SIZE - 2;
1401 effective_height = _height - 2;
1404 ar->fade_in()->curve().get_vector (0, ar->fade_in()->back()->when, vec.get(), npoints);
1406 for (int i = 0, pci = 0; i < npoints; ++i) {
1407 ArdourCanvas::Duple &p ((*points)[pci++]);
1409 p.y = 1.0 + effective_height - (effective_height * vec.get()[i]);
1412 start_xfade_rect->set (ArdourCanvas::Rect (((*points)[0]).x, 1.0, ((*points)[npoints-1]).x, effective_height));
1413 start_xfade_rect->show ();
1415 start_xfade_in->set (*points);
1416 start_xfade_in->show ();
1417 start_xfade_in->raise_to_top ();
1421 boost::shared_ptr<AutomationList> inverse = ar->inverse_fade_in();
1425 for (int i = 0, pci = 0; i < npoints; ++i) {
1426 ArdourCanvas::Duple &p ((*points)[pci++]);
1428 p.y = 1.0 + effective_height - (effective_height * (1.0 - vec.get()[i]));
1433 inverse->curve().get_vector (0, inverse->back()->when, vec.get(), npoints);
1435 for (int i = 0, pci = 0; i < npoints; ++i) {
1436 ArdourCanvas::Duple &p ((*points)[pci++]);
1438 p.y = 1.0 + effective_height - (effective_height * vec.get()[i]);
1442 start_xfade_out->set (*points);
1443 start_xfade_out->show ();
1444 start_xfade_out->raise_to_top ();
1446 start_xfade_rect->raise_to_top (); //this needs to be topmost so the lines don't steal mouse focus
1454 AudioRegionView::redraw_end_xfade ()
1456 boost::shared_ptr<AudioRegion> ar (audio_region());
1458 if (!ar->fade_out() || ar->fade_out()->empty()) {
1464 redraw_end_xfade_to (ar, ar->fade_out()->back()->when);
1468 AudioRegionView::redraw_end_xfade_to (boost::shared_ptr<AudioRegion> ar, framecnt_t len)
1470 int32_t const npoints = trackview.editor().frame_to_pixel (len);
1476 if (!end_xfade_in) {
1477 end_xfade_in = new ArdourCanvas::PolyLine (group);
1479 // end_xfade_in->property_width_pixels() = 1;
1480 end_xfade_in->set_outline_color (ARDOUR_UI::config()->canvasvar_GainLine.get());
1483 if (!end_xfade_out) {
1484 end_xfade_out = new ArdourCanvas::PolyLine (group);
1486 // end_xfade_out->property_width_pixels() = 1;
1487 uint32_t col UINT_RGBA_CHANGE_A (ARDOUR_UI::config()->canvasvar_GainLine.get(), 128);
1488 end_xfade_out->set_outline_color (col);
1491 if (!end_xfade_rect) {
1492 end_xfade_rect = new ArdourCanvas::Rectangle (group);
1494 // end_xfade_rect->property_draw() = true;
1495 end_xfade_rect->set_fill (true);
1496 end_xfade_rect->set_fill_color (ARDOUR_UI::config()->canvasvar_ActiveCrossfade.get());
1497 end_xfade_rect->set_outline (0);
1498 end_xfade_rect->Event.connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_end_xfade_event), end_xfade_rect, this));
1499 end_xfade_rect->set_data ("regionview", this);
1502 Points* points = get_canvas_points ("xfade edit redraw", npoints);
1503 boost::scoped_array<float> vec (new float[npoints]);
1505 ar->fade_out()->curve().get_vector (0, ar->fade_out()->back()->when, vec.get(), npoints);
1507 double rend = trackview.editor().frame_to_pixel (_region->length() - len);
1509 double effective_height;
1510 if (_height >= NAME_HIGHLIGHT_THRESH) {
1511 effective_height = _height - NAME_HIGHLIGHT_SIZE - 2;
1513 effective_height = _height - 2;
1516 for (int i = 0, pci = 0; i < npoints; ++i) {
1517 ArdourCanvas::Duple &p ((*points)[pci++]);
1519 p.y = 1.0 + effective_height - (effective_height * vec.get()[i]);
1522 end_xfade_rect->set (ArdourCanvas::Rect (((*points)[0]).x, 1.0, ((*points)[npoints-1]).x, effective_height));
1523 end_xfade_rect->show ();
1525 end_xfade_in->set (*points);
1526 end_xfade_in->show ();
1527 end_xfade_in->raise_to_top ();
1531 boost::shared_ptr<AutomationList> inverse = ar->inverse_fade_out ();
1535 for (int i = 0, pci = 0; i < npoints; ++i) {
1536 ArdourCanvas::Duple &p ((*points)[pci++]);
1538 p.y = 1.0 + effective_height - (effective_height * (1.0 - vec.get()[i]));
1543 inverse->curve().get_vector (inverse->front()->when, inverse->back()->when, vec.get(), npoints);
1545 for (int i = 0, pci = 0; i < npoints; ++i) {
1546 ArdourCanvas::Duple &p ((*points)[pci++]);
1548 p.y = 1.0 + effective_height - (effective_height * vec.get()[i]);
1552 end_xfade_out->set (*points);
1553 end_xfade_out->show ();
1554 end_xfade_out->raise_to_top ();
1556 end_xfade_rect->raise_to_top (); //this needs to be topmost so the lines don't steal mouse focus
1564 AudioRegionView::hide_xfades ()
1566 hide_start_xfade ();
1571 AudioRegionView::hide_start_xfade ()
1573 if (start_xfade_in) {
1574 start_xfade_in->hide();
1576 if (start_xfade_out) {
1577 start_xfade_out->hide();
1579 if (start_xfade_rect) {
1580 start_xfade_rect->hide ();
1583 _start_xfade_visible = false;
1587 AudioRegionView::hide_end_xfade ()
1590 end_xfade_in->hide();
1592 if (end_xfade_out) {
1593 end_xfade_out->hide();
1595 if (end_xfade_rect) {
1596 end_xfade_rect->hide ();
1599 _end_xfade_visible = false;
1603 AudioRegionView::show_start_xfade ()
1605 if (start_xfade_in) {
1606 start_xfade_in->show();
1608 if (start_xfade_out) {
1609 start_xfade_out->show();
1611 if (start_xfade_rect) {
1612 start_xfade_rect->show ();
1615 _start_xfade_visible = true;
1619 AudioRegionView::show_end_xfade ()
1622 end_xfade_in->show();
1624 if (end_xfade_out) {
1625 end_xfade_out->show();
1627 if (end_xfade_rect) {
1628 end_xfade_rect->show ();
1631 _end_xfade_visible = true;
1635 AudioRegionView::show_xfades ()
1637 show_start_xfade ();
1642 AudioRegionView::drag_start ()
1644 TimeAxisViewItem::drag_start ();
1646 //we used to hide xfades here. I don't see the point with the new model, but we can re-implement if needed
1650 AudioRegionView::drag_end ()
1652 TimeAxisViewItem::drag_end ();
1654 //see comment for drag_start
1658 AudioRegionView::parameter_changed (string const & p)
1660 if (p == "show-waveforms") {
1661 setup_waveform_visibility ();
1662 } else if (p == "waveform-scale") {
1663 setup_waveform_scale ();
1664 } else if (p == "waveform-shape") {
1665 setup_waveform_shape ();