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.
25 #include <gtkmm2ext/gtk_ui.h>
27 #include "ardour/playlist.h"
28 #include "ardour/audioregion.h"
29 #include "ardour/audiosource.h"
30 #include "ardour/profile.h"
31 #include "ardour/session.h"
33 #include "pbd/memento_command.h"
34 #include "pbd/stacktrace.h"
36 #include "evoral/Curve.hpp"
38 #include "streamview.h"
39 #include "audio_region_view.h"
40 #include "audio_time_axis.h"
41 #include "simplerect.h"
42 #include "simpleline.h"
44 #include "public_editor.h"
45 #include "audio_region_editor.h"
46 #include "region_gain_line.h"
47 #include "control_point.h"
48 #include "ghostregion.h"
49 #include "audio_time_axis.h"
51 #include "rgb_macros.h"
52 #include "gui_thread.h"
53 #include "ardour_ui.h"
57 #define MUTED_ALPHA 10
60 using namespace ARDOUR;
62 using namespace Editing;
63 using namespace ArdourCanvas;
65 static const int32_t sync_mark_width = 9;
67 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
68 Gdk::Color const & basic_color)
69 : RegionView (parent, tv, r, spu, basic_color)
75 , fade_position_line(0)
77 , _amplitude_above_axis(1.0)
84 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
85 Gdk::Color const & basic_color, bool recording, TimeAxisViewItem::Visibility visibility)
86 : RegionView (parent, tv, r, spu, basic_color, recording, visibility)
92 , fade_position_line(0)
94 , _amplitude_above_axis(1.0)
100 AudioRegionView::AudioRegionView (const AudioRegionView& other, boost::shared_ptr<AudioRegion> other_region)
101 : RegionView (other, boost::shared_ptr<Region> (other_region))
106 , fade_position_line(0)
108 , _amplitude_above_axis (other._amplitude_above_axis)
109 , _flags (other._flags)
115 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
116 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
122 AudioRegionView::init (Gdk::Color const & basic_color, bool wfd)
124 // FIXME: Some redundancy here with RegionView::init. Need to figure out
125 // where order is important and where it isn't...
127 RegionView::init (basic_color, wfd);
131 _amplitude_above_axis = 1.0;
134 if ((node = _region->extra_xml ("GUI")) != 0) {
137 _flags = WaveformVisible;
141 compute_colors (basic_color);
145 fade_in_shape = new ArdourCanvas::Polygon (*group);
146 fade_in_shape->property_fill_color_rgba() = fade_color;
147 fade_in_shape->set_data ("regionview", this);
149 fade_out_shape = new ArdourCanvas::Polygon (*group);
150 fade_out_shape->property_fill_color_rgba() = fade_color;
151 fade_out_shape->set_data ("regionview", this);
154 fade_in_handle = new ArdourCanvas::SimpleRect (*group);
155 fade_in_handle->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fill_color, 0);
156 fade_in_handle->property_outline_pixels() = 0;
158 fade_in_handle->set_data ("regionview", this);
160 fade_out_handle = new ArdourCanvas::SimpleRect (*group);
161 fade_out_handle->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fill_color, 0);
162 fade_out_handle->property_outline_pixels() = 0;
164 fade_out_handle->set_data ("regionview", this);
166 fade_position_line = new ArdourCanvas::SimpleLine (*group);
167 fade_position_line->property_color_rgba() = 0xBBBBBBAA;
168 fade_position_line->property_y1() = 7;
169 fade_position_line->property_y2() = _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1;
171 fade_position_line->hide();
174 setup_fade_handle_positions ();
176 if (!trackview.session()->config.get_show_region_fades()) {
177 set_fade_visibility (false);
180 const string line_name = _region->name() + ":gain";
182 if (!Profile->get_sae()) {
183 gain_line = new AudioRegionGainLine (line_name, *this, *group, audio_region()->envelope());
186 if (Config->get_show_region_gain()) {
194 set_height (trackview.current_height());
197 region_sync_changed ();
199 region_resized (ARDOUR::bounds_change);
200 set_waveview_data_src();
202 envelope_active_changed ();
203 fade_in_active_changed ();
204 fade_out_active_changed ();
206 reset_width_dependent_items (_pixel_width);
208 fade_in_shape->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
209 if (fade_in_handle) {
210 fade_in_handle->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
213 fade_out_shape->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
215 if (fade_out_handle) {
216 fade_out_handle->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
221 /* XXX sync mark drag? */
224 AudioRegionView::~AudioRegionView ()
226 in_destructor = true;
228 RegionViewGoingAway (this); /* EMIT_SIGNAL */
230 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
231 gnome_canvas_waveview_cache_destroy (*cache);
234 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
238 for (list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator i = feature_lines.begin(); i != feature_lines.end(); ++i) {
239 delete ((*i).second);
242 /* all waveviews etc will be destroyed when the group is destroyed */
247 boost::shared_ptr<ARDOUR::AudioRegion>
248 AudioRegionView::audio_region() const
250 // "Guaranteed" to succeed...
251 return boost::dynamic_pointer_cast<AudioRegion>(_region);
255 AudioRegionView::region_changed (const PropertyChange& what_changed)
257 ENSURE_GUI_THREAD (*this, &AudioRegionView::region_changed, what_changed);
258 // cerr << "AudioRegionView::region_changed() called" << endl;
260 RegionView::region_changed (what_changed);
262 if (what_changed.contains (ARDOUR::Properties::scale_amplitude)) {
263 region_scale_amplitude_changed ();
265 if (what_changed.contains (ARDOUR::Properties::fade_in)) {
268 if (what_changed.contains (ARDOUR::Properties::fade_out)) {
271 if (what_changed.contains (ARDOUR::Properties::fade_in_active)) {
272 fade_in_active_changed ();
274 if (what_changed.contains (ARDOUR::Properties::fade_out_active)) {
275 fade_out_active_changed ();
277 if (what_changed.contains (ARDOUR::Properties::envelope_active)) {
278 envelope_active_changed ();
280 if (what_changed.contains (ARDOUR::Properties::valid_transients)) {
281 transients_changed ();
286 AudioRegionView::fade_in_changed ()
288 reset_fade_in_shape ();
292 AudioRegionView::fade_out_changed ()
294 reset_fade_out_shape ();
297 AudioRegionView::fade_in_active_changed ()
299 if (audio_region()->fade_in_active()) {
300 fade_in_shape->property_fill_color_rgba() = RGBA_TO_UINT(45,45,45,90); // FIXME make a themeable colour
301 fade_in_shape->property_width_pixels() = 1;
303 fade_in_shape->property_fill_color_rgba() = RGBA_TO_UINT(45,45,45,20); // FIXME make a themeable colour
304 fade_in_shape->property_width_pixels() = 1;
309 AudioRegionView::fade_out_active_changed ()
311 if (audio_region()->fade_out_active()) {
312 fade_out_shape->property_fill_color_rgba() = RGBA_TO_UINT(45,45,45,90); // FIXME make a themeable colour
313 fade_out_shape->property_width_pixels() = 1;
315 fade_out_shape->property_fill_color_rgba() = RGBA_TO_UINT(45,45,45,20); // FIXME make a themeable colour
316 fade_out_shape->property_width_pixels() = 1;
322 AudioRegionView::region_scale_amplitude_changed ()
324 ENSURE_GUI_THREAD (*this, &AudioRegionView::region_scale_amplitude_changed)
326 for (uint32_t n = 0; n < waves.size(); ++n) {
327 // force a reload of the cache
328 waves[n]->property_data_src() = _region.get();
333 AudioRegionView::region_renamed ()
335 std::string str = RegionView::make_name ();
337 if (audio_region()->speed_mismatch (trackview.session()->frame_rate())) {
338 str = string ("*") + str;
341 if (_region->muted()) {
342 str = string ("!") + str;
345 set_item_name (str, this);
350 AudioRegionView::region_resized (const PropertyChange& what_changed)
352 AudioGhostRegion* agr;
354 RegionView::region_resized(what_changed);
355 PropertyChange interesting_stuff;
357 interesting_stuff.add (ARDOUR::Properties::start);
358 interesting_stuff.add (ARDOUR::Properties::length);
360 if (what_changed.contains (interesting_stuff)) {
362 for (uint32_t n = 0; n < waves.size(); ++n) {
363 waves[n]->property_region_start() = _region->start();
366 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
367 if ((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
369 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
370 (*w)->property_region_start() = _region->start();
375 /* hide transient lines that extend beyond the region end */
377 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
379 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
380 if (l->first > _region->length() - 1) {
390 AudioRegionView::reset_width_dependent_items (double pixel_width)
392 RegionView::reset_width_dependent_items(pixel_width);
393 assert(_pixel_width == pixel_width);
395 if (fade_in_handle) {
396 if (pixel_width <= 6.0 || _height < 5.0 || !trackview.session()->config.get_show_region_fades()) {
397 fade_in_handle->hide();
398 fade_out_handle->hide();
401 fade_in_handle->show();
402 fade_out_handle->show();
406 AnalysisFeatureList analysis_features = _region->transients();
407 AnalysisFeatureList::const_iterator i;
409 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
411 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
413 float x_pos = trackview.editor().frame_to_pixel (*i);
415 ArdourCanvas::Points points;
416 points.push_back(Gnome::Art::Point(x_pos, 2.0)); // first x-coord needs to be a non-normal value
417 points.push_back(Gnome::Art::Point(x_pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
420 (*l).second->property_points() = points;
423 reset_fade_shapes ();
427 AudioRegionView::region_muted ()
429 RegionView::region_muted();
431 for (uint32_t n=0; n < waves.size(); ++n) {
432 if (_region->muted()) {
433 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
435 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
441 AudioRegionView::setup_fade_handle_positions()
443 /* position of fade handle offset from the top of the region view */
444 double const handle_pos = 2;
445 /* height of fade handles */
446 double const handle_height = 5;
448 if (fade_in_handle) {
449 fade_in_handle->property_y1() = handle_pos;
450 fade_in_handle->property_y2() = handle_pos + handle_height;
453 if (fade_out_handle) {
454 fade_out_handle->property_y1() = handle_pos;
455 fade_out_handle->property_y2() = handle_pos + handle_height;
460 AudioRegionView::set_height (gdouble height)
462 RegionView::set_height (height);
464 uint32_t wcnt = waves.size();
466 for (uint32_t n = 0; n < wcnt; ++n) {
469 if (height < NAME_HIGHLIGHT_THRESH) {
470 ht = ((height - 2 * wcnt) / (double) wcnt);
472 ht = (((height - 2 * wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
475 gdouble yoff = n * (ht + 1);
477 waves[n]->property_height() = ht;
478 waves[n]->property_y() = yoff + 2;
483 if ((height/wcnt) < NAME_HIGHLIGHT_THRESH) {
486 if (Config->get_show_region_gain ()) {
491 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE) - 2);
494 reset_fade_shapes ();
496 /* Update hights for any active feature lines */
497 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
499 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
501 float pos_x = trackview.editor().frame_to_pixel((*l).first);
503 ArdourCanvas::Points points;
505 points.push_back(Gnome::Art::Point(pos_x, 2.0)); // first x-coord needs to be a non-normal value
506 points.push_back(Gnome::Art::Point(pos_x, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
508 (*l).second->property_points() = points;
511 if (fade_position_line) {
513 if (height < NAME_HIGHLIGHT_THRESH) {
514 fade_position_line->property_y2() = _height - 1;
517 fade_position_line->property_y2() = _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1;
522 name_pixbuf->raise_to_top();
527 AudioRegionView::reset_fade_shapes ()
529 reset_fade_in_shape ();
530 reset_fade_out_shape ();
534 AudioRegionView::reset_fade_in_shape ()
536 reset_fade_in_shape_width ((framecnt_t) audio_region()->fade_in()->back()->when);
540 AudioRegionView::reset_fade_in_shape_width (framecnt_t width)
542 if (fade_in_handle == 0) {
546 /* smallest size for a fade is 64 frames */
548 width = std::max ((framecnt_t) 64, width);
552 /* round here to prevent little visual glitches with sub-pixel placement */
553 double const pwidth = rint (width / samples_per_unit);
554 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
558 fade_in_shape->hide();
559 fade_in_handle->hide();
563 double const handle_center = pwidth;
565 /* Put the fade in handle so that its left side is at the end-of-fade line */
566 fade_in_handle->property_x1() = handle_center;
567 fade_in_handle->property_x2() = handle_center + 6;
570 fade_in_shape->hide();
574 if (trackview.session()->config.get_show_region_fades()) {
575 fade_in_shape->show();
578 float curve[npoints];
579 audio_region()->fade_in()->curve().get_vector (0, audio_region()->fade_in()->back()->when, curve, npoints);
581 points = get_canvas_points ("fade in shape", npoints + 3);
583 if (_height >= NAME_HIGHLIGHT_THRESH) {
584 h = _height - NAME_HIGHLIGHT_SIZE - 2;
589 /* points *MUST* be in anti-clockwise order */
592 double xdelta = pwidth/npoints;
594 for (pi = 0, pc = 0; pc < npoints; ++pc) {
595 (*points)[pi].set_x(1 + (pc * xdelta));
596 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
601 (*points)[pi].set_x(pwidth);
602 (*points)[pi++].set_y(2);
604 (*points)[pi].set_x(1);
605 (*points)[pi++].set_y(2);
607 /* connect the dots ... */
609 (*points)[pi] = (*points)[0];
611 fade_in_shape->property_points() = *points;
614 /* ensure trim handle stays on top */
615 if (frame_handle_start) {
616 frame_handle_start->raise_to_top();
621 AudioRegionView::reset_fade_out_shape ()
623 reset_fade_out_shape_width ((framecnt_t) audio_region()->fade_out()->back()->when);
627 AudioRegionView::reset_fade_out_shape_width (framecnt_t width)
629 if (fade_out_handle == 0) {
633 /* smallest size for a fade is 64 frames */
635 width = std::max ((framecnt_t) 64, width);
639 /* round here to prevent little visual glitches with sub-pixel placement */
640 double const pwidth = rint (width / samples_per_unit);
641 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
645 fade_out_shape->hide();
646 fade_out_handle->hide();
650 double const handle_center = (_region->length() - width) / samples_per_unit;
652 /* Put the fade out handle so that its right side is at the end-of-fade line;
653 * it's `one out' for precise pixel accuracy.
655 fade_out_handle->property_x1() = handle_center - 5;
656 fade_out_handle->property_x2() = handle_center + 1;
658 /* don't show shape if its too small */
661 fade_out_shape->hide();
665 if (trackview.session()->config.get_show_region_fades()) {
666 fade_out_shape->show();
669 float curve[npoints];
670 audio_region()->fade_out()->curve().get_vector (0, audio_region()->fade_out()->back()->when, curve, npoints);
672 if (_height >= NAME_HIGHLIGHT_THRESH) {
673 h = _height - NAME_HIGHLIGHT_SIZE - 2;
678 /* points *MUST* be in anti-clockwise order */
680 points = get_canvas_points ("fade out shape", npoints + 3);
683 double xdelta = pwidth/npoints;
685 for (pi = 0, pc = 0; pc < npoints; ++pc) {
686 (*points)[pi].set_x(_pixel_width - pwidth + (pc * xdelta));
687 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
692 (*points)[pi].set_x(_pixel_width);
693 (*points)[pi++].set_y(h);
695 (*points)[pi].set_x(_pixel_width);
696 (*points)[pi++].set_y(2);
698 /* connect the dots ... */
700 (*points)[pi] = (*points)[0];
702 fade_out_shape->property_points() = *points;
705 /* ensure trim handle stays on top */
706 if (frame_handle_end) {
707 frame_handle_end->raise_to_top();
712 AudioRegionView::set_samples_per_unit (gdouble spu)
714 RegionView::set_samples_per_unit (spu);
716 if (_flags & WaveformVisible) {
717 for (uint32_t n=0; n < waves.size(); ++n) {
718 waves[n]->property_samples_per_unit() = spu;
726 reset_fade_shapes ();
730 AudioRegionView::set_amplitude_above_axis (gdouble spp)
732 for (uint32_t n=0; n < waves.size(); ++n) {
733 waves[n]->property_amplitude_above_axis() = spp;
738 AudioRegionView::compute_colors (Gdk::Color const & basic_color)
740 RegionView::compute_colors (basic_color);
742 /* gain color computed in envelope_active_changed() */
744 fade_color = UINT_RGBA_CHANGE_A (fill_color, 120);
748 AudioRegionView::set_colors ()
750 RegionView::set_colors();
753 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
756 for (uint32_t n=0; n < waves.size(); ++n) {
757 if (_region->muted()) {
758 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
760 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
763 waves[n]->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
764 waves[n]->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
769 AudioRegionView::set_waveform_visible (bool yn)
771 if (((_flags & WaveformVisible) != yn)) {
773 for (uint32_t n=0; n < waves.size(); ++n) {
774 /* make sure the zoom level is correct, since we don't update
775 this when waveforms are hidden.
777 waves[n]->property_samples_per_unit() = samples_per_unit;
780 _flags |= WaveformVisible;
782 for (uint32_t n=0; n < waves.size(); ++n) {
785 _flags &= ~WaveformVisible;
792 AudioRegionView::temporarily_hide_envelope ()
800 AudioRegionView::unhide_envelope ()
808 AudioRegionView::set_envelope_visible (bool yn)
820 AudioRegionView::create_waves ()
822 // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
823 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
829 ChanCount nchans = atv.track()->n_channels();
831 // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data
832 // << " and channels = " << nchans.n_audio() << endl;
834 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
835 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
836 tmp_waves.push_back (0);
839 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
843 _data_ready_connections.clear ();
845 for (uint32_t i = 0; i < nchans.n_audio(); ++i) {
846 _data_ready_connections.push_back (0);
849 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
851 if (n >= audio_region()->n_channels()) {
855 wave_caches.push_back (WaveView::create_cache ());
857 // cerr << "\tchannel " << n << endl;
860 if (audio_region()->audio_source(n)->peaks_ready (boost::bind (&AudioRegionView::peaks_ready_handler, this, n), &_data_ready_connections[n], gui_context())) {
861 // cerr << "\tData is ready\n";
862 create_one_wave (n, true);
864 // cerr << "\tdata is not ready\n";
865 // we'll get a PeaksReady signal from the source in the future
866 // and will call create_one_wave(n) then.
870 // cerr << "\tdon't delay, display today!\n";
871 create_one_wave (n, true);
878 AudioRegionView::create_one_wave (uint32_t which, bool /*direct*/)
880 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
881 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
882 uint32_t nchans = atv.track()->n_channels().n_audio();
884 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
887 if (trackview.current_height() < NAME_HIGHLIGHT_THRESH) {
888 ht = ((trackview.current_height()) / (double) nchans);
890 ht = ((trackview.current_height() - NAME_HIGHLIGHT_SIZE) / (double) nchans);
893 gdouble yoff = which * ht;
895 WaveView *wave = new WaveView(*group);
897 wave->property_data_src() = (gpointer) _region.get();
898 wave->property_cache() = wave_caches[which];
899 wave->property_cache_updater() = true;
900 wave->property_channel() = which;
901 wave->property_length_function() = (gpointer) region_length_from_c;
902 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
903 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
904 wave->property_x() = 0.0;
905 wave->property_y() = yoff;
906 wave->property_height() = (double) ht;
907 wave->property_samples_per_unit() = samples_per_unit;
908 wave->property_amplitude_above_axis() = _amplitude_above_axis;
911 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
912 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
914 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_WaveForm.get();
915 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
918 wave->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
919 wave->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
920 wave->property_zero_line() = true;
921 wave->property_region_start() = _region->start();
922 wave->property_rectified() = (bool) (_flags & WaveformRectified);
923 wave->property_logscaled() = (bool) (_flags & WaveformLogScaled);
925 if (!(_flags & WaveformVisible)) {
929 /* note: calling this function is serialized by the lock
930 held in the peak building thread that signals that
931 peaks are ready for use *or* by the fact that it is
932 called one by one from the GUI thread.
935 if (which < nchans) {
936 tmp_waves[which] = wave;
938 /* n-channel track, >n-channel source */
941 /* see if we're all ready */
943 for (n = 0; n < nchans; ++n) {
944 if (tmp_waves[n] == 0) {
949 if (n == nwaves && waves.empty()) {
950 /* all waves are ready */
951 tmp_waves.resize(nwaves);
956 /* all waves created, don't hook into peaks ready anymore */
957 delete _data_ready_connections[which];
958 _data_ready_connections[which] = 0;
963 AudioRegionView::peaks_ready_handler (uint32_t which)
965 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AudioRegionView::create_one_wave, this, which, false));
966 // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
970 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
972 if (gain_line == 0) {
978 /* don't create points that can't be seen */
980 set_envelope_visible (true);
987 framepos_t fx = trackview.editor().pixel_to_frame (x);
989 if (fx > _region->length()) {
993 /* compute vertical fractional position */
995 y = 1.0 - (y / (_height - NAME_HIGHLIGHT_SIZE));
997 /* map using gain line */
999 gain_line->view_to_model_coord (x, y);
1001 /* XXX STATEFUL: can't convert to stateful diff until we
1002 can represent automation data with it.
1005 trackview.session()->begin_reversible_command (_("add gain control point"));
1006 XMLNode &before = audio_region()->envelope()->get_state();
1008 if (!audio_region()->envelope_active()) {
1009 XMLNode ®ion_before = audio_region()->get_state();
1010 audio_region()->set_envelope_active(true);
1011 XMLNode ®ion_after = audio_region()->get_state();
1012 trackview.session()->add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
1015 audio_region()->envelope()->add (fx, y);
1017 XMLNode &after = audio_region()->envelope()->get_state();
1018 trackview.session()->add_command (new MementoCommand<AutomationList>(*audio_region()->envelope().get(), &before, &after));
1019 trackview.session()->commit_reversible_command ();
1023 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent */*ev*/)
1025 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1026 audio_region()->envelope()->erase (cp->model());
1030 AudioRegionView::store_flags()
1032 XMLNode *node = new XMLNode ("GUI");
1034 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
1035 node->add_property ("waveform-rectified", (_flags & WaveformRectified) ? "yes" : "no");
1036 node->add_property ("waveform-logscaled", (_flags & WaveformLogScaled) ? "yes" : "no");
1038 _region->add_extra_xml (*node);
1042 AudioRegionView::set_flags (XMLNode* node)
1046 if ((prop = node->property ("waveform-visible")) != 0) {
1047 if (string_is_affirmative (prop->value())) {
1048 _flags |= WaveformVisible;
1052 if ((prop = node->property ("waveform-rectified")) != 0) {
1053 if (string_is_affirmative (prop->value())) {
1054 _flags |= WaveformRectified;
1058 if ((prop = node->property ("waveform-logscaled")) != 0) {
1059 if (string_is_affirmative (prop->value())) {
1060 _flags |= WaveformLogScaled;
1066 AudioRegionView::set_waveform_shape (WaveformShape shape)
1070 /* this slightly odd approach is to leave the door open to
1071 other "shapes" such as spectral displays, etc.
1084 if (yn != (bool) (_flags & WaveformRectified)) {
1085 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1086 (*wave)->property_rectified() = yn;
1090 _flags |= WaveformRectified;
1092 _flags &= ~WaveformRectified;
1099 AudioRegionView::set_waveform_scale (WaveformScale scale)
1101 bool yn = (scale == Logarithmic);
1103 if (yn != (bool) (_flags & WaveformLogScaled)) {
1104 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1105 (*wave)->property_logscaled() = yn;
1109 _flags |= WaveformLogScaled;
1111 _flags &= ~WaveformLogScaled;
1119 AudioRegionView::add_ghost (TimeAxisView& tv)
1121 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1124 double unit_position = _region->position () / samples_per_unit;
1125 AudioGhostRegion* ghost = new AudioGhostRegion (tv, trackview, unit_position);
1128 nchans = rtv->track()->n_channels().n_audio();
1130 for (uint32_t n = 0; n < nchans; ++n) {
1132 if (n >= audio_region()->n_channels()) {
1136 WaveView *wave = new WaveView(*ghost->group);
1138 wave->property_data_src() = _region.get();
1139 wave->property_cache() = wave_caches[n];
1140 wave->property_cache_updater() = false;
1141 wave->property_channel() = n;
1142 wave->property_length_function() = (gpointer)region_length_from_c;
1143 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1144 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1145 wave->property_x() = 0.0;
1146 wave->property_samples_per_unit() = samples_per_unit;
1147 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1149 wave->property_region_start() = _region->start();
1151 ghost->waves.push_back(wave);
1154 ghost->set_height ();
1155 ghost->set_duration (_region->length() / samples_per_unit);
1156 ghost->set_colors();
1157 ghosts.push_back (ghost);
1163 AudioRegionView::entered (bool internal_editing)
1165 trackview.editor().set_current_trimmable (_region);
1166 trackview.editor().set_current_movable (_region);
1168 if (gain_line && Config->get_show_region_gain ()) {
1169 gain_line->show_all_control_points ();
1172 if (fade_in_handle && !internal_editing) {
1173 fade_in_handle->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fade_color, 255);
1174 fade_out_handle->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fade_color, 255);
1179 AudioRegionView::exited ()
1181 trackview.editor().set_current_trimmable (boost::shared_ptr<Trimmable>());
1182 trackview.editor().set_current_movable (boost::shared_ptr<Movable>());
1185 gain_line->hide_all_but_selected_control_points ();
1188 if (fade_in_handle) {
1189 fade_in_handle->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fade_color, 0);
1190 fade_out_handle->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fade_color, 0);
1195 AudioRegionView::envelope_active_changed ()
1198 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
1203 AudioRegionView::set_waveview_data_src()
1205 AudioGhostRegion* agr;
1206 double unit_length= _region->length() / samples_per_unit;
1208 for (uint32_t n = 0; n < waves.size(); ++n) {
1209 // TODO: something else to let it know the channel
1210 waves[n]->property_data_src() = _region.get();
1213 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1215 (*i)->set_duration (unit_length);
1217 if((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
1218 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
1219 (*w)->property_data_src() = _region.get();
1227 AudioRegionView::color_handler ()
1229 //case cMutedWaveForm:
1231 //case cWaveFormClip:
1235 //case cGainLineInactive:
1237 envelope_active_changed();
1242 AudioRegionView::set_frame_color ()
1248 if (_region->opaque()) {
1254 TimeAxisViewItem::set_frame_color ();
1260 if (_region->muted()) {
1261 wc = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get(), MUTED_ALPHA);
1263 wc = ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get();
1265 fc = ARDOUR_UI::config()->canvasvar_SelectedWaveFormFill.get();
1268 if (_region->muted()) {
1269 wc = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA);
1271 wc = ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
1273 fc = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
1275 if (_region->muted()) {
1276 wc = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
1278 wc = ARDOUR_UI::config()->canvasvar_WaveForm.get();
1280 fc = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
1284 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1285 if (_region->muted()) {
1286 (*w)->property_wave_color() = wc;
1288 (*w)->property_wave_color() = wc;
1289 (*w)->property_fill_color() = fc;
1295 AudioRegionView::set_fade_visibility (bool yn)
1298 if (fade_in_shape) {
1299 fade_in_shape->show();
1301 if (fade_out_shape) {
1302 fade_out_shape->show ();
1304 if (fade_in_handle) {
1305 fade_in_handle->show ();
1307 if (fade_out_handle) {
1308 fade_out_handle->show ();
1311 if (fade_in_shape) {
1312 fade_in_shape->hide();
1314 if (fade_out_shape) {
1315 fade_out_shape->hide ();
1317 if (fade_in_handle) {
1318 fade_in_handle->hide ();
1320 if (fade_out_handle) {
1321 fade_out_handle->hide ();
1327 AudioRegionView::update_coverage_frames (LayerDisplay d)
1329 RegionView::update_coverage_frames (d);
1331 if (fade_in_handle) {
1332 fade_in_handle->raise_to_top ();
1333 fade_out_handle->raise_to_top ();
1338 AudioRegionView::show_region_editor ()
1341 editor = new AudioRegionEditor (trackview.session(), audio_region());
1345 editor->set_position (Gtk::WIN_POS_MOUSE);
1351 AudioRegionView::show_fade_line (framepos_t pos)
1353 fade_position_line->property_x1() = trackview.editor().frame_to_pixel (pos);
1354 fade_position_line->property_x2() = trackview.editor().frame_to_pixel (pos);
1355 fade_position_line->show ();
1356 fade_position_line->raise_to_top ();
1360 AudioRegionView::hide_fade_line ()
1362 fade_position_line->hide ();
1367 AudioRegionView::transients_changed ()
1369 AnalysisFeatureList analysis_features = _region->transients();
1371 while (feature_lines.size() < analysis_features.size()) {
1373 ArdourCanvas::Line* canvas_item = new ArdourCanvas::Line(*group);
1375 ArdourCanvas::Points points;
1377 points.push_back(Gnome::Art::Point(-1.0, 2.0)); // first x-coord needs to be a non-normal value
1378 points.push_back(Gnome::Art::Point(1.0, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
1380 canvas_item->property_points() = points;
1381 canvas_item->property_width_pixels() = 1;
1382 canvas_item->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
1383 canvas_item->property_first_arrowhead() = TRUE;
1384 canvas_item->property_last_arrowhead() = TRUE;
1385 canvas_item->property_arrow_shape_a() = 11.0;
1386 canvas_item->property_arrow_shape_b() = 0.0;
1387 canvas_item->property_arrow_shape_c() = 4.0;
1389 canvas_item->raise_to_top ();
1390 canvas_item->show ();
1392 canvas_item->set_data ("regionview", this);
1393 canvas_item->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_feature_line_event), canvas_item, this));
1395 feature_lines.push_back (make_pair(0, canvas_item));
1398 while (feature_lines.size() > analysis_features.size()) {
1399 ArdourCanvas::Line* line = feature_lines.back().second;
1400 feature_lines.pop_back ();
1404 AnalysisFeatureList::const_iterator i;
1405 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1407 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
1409 ArdourCanvas::Points points;
1411 float *pos = new float;
1412 *pos = trackview.editor().frame_to_pixel (*i);
1414 points.push_back(Gnome::Art::Point(*pos, 2.0)); // first x-coord needs to be a non-normal value
1415 points.push_back(Gnome::Art::Point(*pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
1417 (*l).second->property_points() = points;
1418 (*l).second->set_data ("position", pos);
1425 AudioRegionView::update_transient(float /*old_pos*/, float new_pos)
1427 /* Find frame at old pos, calulate new frame then update region transients*/
1428 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1430 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1432 /* Line has been updated in drag so we compare to new_pos */
1434 float* pos = (float*) (*l).second->get_data ("position");
1436 if (rint(new_pos) == rint(*pos)) {
1438 framepos_t old_frame = (*l).first;
1439 framepos_t new_frame = trackview.editor().pixel_to_frame (new_pos);
1441 _region->update_transient (old_frame, new_frame);
1449 AudioRegionView::remove_transient(float pos)
1451 /* Find frame at old pos, calulate new frame then update region transients*/
1452 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1454 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1456 /* Line has been updated in drag so we compare to new_pos */
1457 float *line_pos = (float*) (*l).second->get_data ("position");
1459 if (rint(pos) == rint(*line_pos)) {
1460 _region->remove_transient ((*l).first);
1467 AudioRegionView::thaw_after_trim ()
1469 RegionView::thaw_after_trim ();