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)
101 AudioRegionView::AudioRegionView (const AudioRegionView& other)
102 : sigc::trackable(other)
108 , fade_position_line(0)
110 , _amplitude_above_axis(1.0)
117 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
118 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
123 AudioRegionView::AudioRegionView (const AudioRegionView& other, boost::shared_ptr<AudioRegion> other_region)
124 : RegionView (other, boost::shared_ptr<Region> (other_region))
129 , fade_position_line(0)
131 , _amplitude_above_axis(1.0)
138 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
139 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
145 AudioRegionView::init (Gdk::Color const & basic_color, bool wfd)
147 // FIXME: Some redundancy here with RegionView::init. Need to figure out
148 // where order is important and where it isn't...
150 RegionView::init (basic_color, wfd);
154 _amplitude_above_axis = 1.0;
157 if ((node = _region->extra_xml ("GUI")) != 0) {
160 _flags = WaveformVisible;
164 /* make envelope visible if it has anything interesting in it */
165 boost::shared_ptr<AutomationList> env = audio_region()->envelope ();
166 if (env->size() > 2 || (env->size() == 2 && env->front()->value != env->back()->value)) {
167 _flags |= EnvelopeVisible;
170 compute_colors (basic_color);
174 fade_in_shape = new ArdourCanvas::Polygon (*group);
175 fade_in_shape->property_fill_color_rgba() = fade_color;
176 fade_in_shape->set_data ("regionview", this);
178 fade_out_shape = new ArdourCanvas::Polygon (*group);
179 fade_out_shape->property_fill_color_rgba() = fade_color;
180 fade_out_shape->set_data ("regionview", this);
183 fade_in_handle = new ArdourCanvas::SimpleRect (*group);
184 fade_in_handle->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fill_color, 0);
185 fade_in_handle->property_outline_pixels() = 0;
187 fade_in_handle->set_data ("regionview", this);
189 fade_out_handle = new ArdourCanvas::SimpleRect (*group);
190 fade_out_handle->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fill_color, 0);
191 fade_out_handle->property_outline_pixels() = 0;
193 fade_out_handle->set_data ("regionview", this);
195 fade_position_line = new ArdourCanvas::SimpleLine (*group);
196 fade_position_line->property_color_rgba() = 0xBBBBBBAA;
197 fade_position_line->property_y1() = 7;
198 fade_position_line->property_y2() = _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1;
200 fade_position_line->hide();
203 setup_fade_handle_positions ();
205 if (!trackview.session()->config.get_show_region_fades()) {
206 set_fade_visibility (false);
209 const string line_name = _region->name() + ":gain";
211 if (!Profile->get_sae()) {
212 gain_line = new AudioRegionGainLine (line_name, *this, *group, audio_region()->envelope());
215 if (!(_flags & EnvelopeVisible)) {
223 set_height (trackview.current_height());
226 region_sync_changed ();
228 region_resized (ARDOUR::bounds_change);
229 set_waveview_data_src();
231 envelope_active_changed ();
232 fade_in_active_changed ();
233 fade_out_active_changed ();
235 reset_width_dependent_items (_pixel_width);
237 fade_in_shape->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
238 if (fade_in_handle) {
239 fade_in_handle->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
242 fade_out_shape->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
244 if (fade_out_handle) {
245 fade_out_handle->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
250 /* XXX sync mark drag? */
253 AudioRegionView::~AudioRegionView ()
255 in_destructor = true;
257 RegionViewGoingAway (this); /* EMIT_SIGNAL */
259 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
260 gnome_canvas_waveview_cache_destroy (*cache);
263 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
267 for (list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator i = feature_lines.begin(); i != feature_lines.end(); ++i) {
268 delete ((*i).second);
271 /* all waveviews etc will be destroyed when the group is destroyed */
276 boost::shared_ptr<ARDOUR::AudioRegion>
277 AudioRegionView::audio_region() const
279 // "Guaranteed" to succeed...
280 return boost::dynamic_pointer_cast<AudioRegion>(_region);
284 AudioRegionView::region_changed (const PropertyChange& what_changed)
286 ENSURE_GUI_THREAD (*this, &AudioRegionView::region_changed, what_changed);
287 // cerr << "AudioRegionView::region_changed() called" << endl;
289 RegionView::region_changed (what_changed);
291 if (what_changed.contains (ARDOUR::Properties::scale_amplitude)) {
292 region_scale_amplitude_changed ();
294 if (what_changed.contains (ARDOUR::Properties::fade_in)) {
297 if (what_changed.contains (ARDOUR::Properties::fade_out)) {
300 if (what_changed.contains (ARDOUR::Properties::fade_in_active)) {
301 fade_in_active_changed ();
303 if (what_changed.contains (ARDOUR::Properties::fade_out_active)) {
304 fade_out_active_changed ();
306 if (what_changed.contains (ARDOUR::Properties::envelope_active)) {
307 envelope_active_changed ();
309 if (what_changed.contains (ARDOUR::Properties::valid_transients)) {
310 transients_changed ();
315 AudioRegionView::fade_in_changed ()
317 reset_fade_in_shape ();
321 AudioRegionView::fade_out_changed ()
323 reset_fade_out_shape ();
326 AudioRegionView::fade_in_active_changed ()
328 if (audio_region()->fade_in_active()) {
329 fade_in_shape->property_fill_color_rgba() = RGBA_TO_UINT(45,45,45,90); // FIXME make a themeable colour
330 fade_in_shape->property_width_pixels() = 1;
332 fade_in_shape->property_fill_color_rgba() = RGBA_TO_UINT(45,45,45,20); // FIXME make a themeable colour
333 fade_in_shape->property_width_pixels() = 1;
338 AudioRegionView::fade_out_active_changed ()
340 if (audio_region()->fade_out_active()) {
341 fade_out_shape->property_fill_color_rgba() = RGBA_TO_UINT(45,45,45,90); // FIXME make a themeable colour
342 fade_out_shape->property_width_pixels() = 1;
344 fade_out_shape->property_fill_color_rgba() = RGBA_TO_UINT(45,45,45,20); // FIXME make a themeable colour
345 fade_out_shape->property_width_pixels() = 1;
351 AudioRegionView::region_scale_amplitude_changed ()
353 ENSURE_GUI_THREAD (*this, &AudioRegionView::region_scale_amplitude_changed)
355 for (uint32_t n = 0; n < waves.size(); ++n) {
356 // force a reload of the cache
357 waves[n]->property_data_src() = _region.get();
362 AudioRegionView::region_renamed ()
364 std::string str = RegionView::make_name ();
366 if (audio_region()->speed_mismatch (trackview.session()->frame_rate())) {
367 str = string ("*") + str;
370 if (_region->muted()) {
371 str = string ("!") + str;
374 set_item_name (str, this);
379 AudioRegionView::region_resized (const PropertyChange& what_changed)
381 AudioGhostRegion* agr;
383 RegionView::region_resized(what_changed);
384 PropertyChange interesting_stuff;
386 interesting_stuff.add (ARDOUR::Properties::start);
387 interesting_stuff.add (ARDOUR::Properties::length);
389 if (what_changed.contains (interesting_stuff)) {
391 for (uint32_t n = 0; n < waves.size(); ++n) {
392 waves[n]->property_region_start() = _region->start();
395 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
396 if ((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
398 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
399 (*w)->property_region_start() = _region->start();
404 /* hide transient lines that extend beyond the region end */
406 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
408 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
409 if (l->first > _region->length() - 1) {
419 AudioRegionView::reset_width_dependent_items (double pixel_width)
421 RegionView::reset_width_dependent_items(pixel_width);
422 assert(_pixel_width == pixel_width);
424 if (fade_in_handle) {
425 if (pixel_width <= 6.0 || _height < 5.0 || !trackview.session()->config.get_show_region_fades()) {
426 fade_in_handle->hide();
427 fade_out_handle->hide();
430 fade_in_handle->show();
431 fade_out_handle->show();
435 AnalysisFeatureList analysis_features = _region->transients();
436 AnalysisFeatureList::const_iterator i;
438 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
440 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
442 float x_pos = trackview.editor().frame_to_pixel (*i);
444 ArdourCanvas::Points points;
445 points.push_back(Gnome::Art::Point(x_pos, 2.0)); // first x-coord needs to be a non-normal value
446 points.push_back(Gnome::Art::Point(x_pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
449 (*l).second->property_points() = points;
452 reset_fade_shapes ();
456 AudioRegionView::region_muted ()
458 RegionView::region_muted();
460 for (uint32_t n=0; n < waves.size(); ++n) {
461 if (_region->muted()) {
462 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
464 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
470 AudioRegionView::setup_fade_handle_positions()
472 /* position of fade handle offset from the top of the region view */
473 double const handle_pos = 2;
474 /* height of fade handles */
475 double const handle_height = 5;
477 if (fade_in_handle) {
478 fade_in_handle->property_y1() = handle_pos;
479 fade_in_handle->property_y2() = handle_pos + handle_height;
482 if (fade_out_handle) {
483 fade_out_handle->property_y1() = handle_pos;
484 fade_out_handle->property_y2() = handle_pos + handle_height;
489 AudioRegionView::set_height (gdouble height)
491 RegionView::set_height (height);
493 uint32_t wcnt = waves.size();
495 for (uint32_t n = 0; n < wcnt; ++n) {
498 if (height < NAME_HIGHLIGHT_THRESH) {
499 ht = ((height - 2 * wcnt) / (double) wcnt);
501 ht = (((height - 2 * wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
504 gdouble yoff = n * (ht + 1);
506 waves[n]->property_height() = ht;
507 waves[n]->property_y() = yoff + 2;
512 if ((height/wcnt) < NAME_HIGHLIGHT_THRESH) {
515 if (_flags & EnvelopeVisible) {
520 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE) - 2);
523 reset_fade_shapes ();
525 /* Update hights for any active feature lines */
526 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
528 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
530 float pos_x = trackview.editor().frame_to_pixel((*l).first);
532 ArdourCanvas::Points points;
534 points.push_back(Gnome::Art::Point(pos_x, 2.0)); // first x-coord needs to be a non-normal value
535 points.push_back(Gnome::Art::Point(pos_x, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
537 (*l).second->property_points() = points;
540 if (fade_position_line) {
542 if (height < NAME_HIGHLIGHT_THRESH) {
543 fade_position_line->property_y2() = _height - 1;
546 fade_position_line->property_y2() = _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1;
551 name_pixbuf->raise_to_top();
556 AudioRegionView::reset_fade_shapes ()
558 reset_fade_in_shape ();
559 reset_fade_out_shape ();
563 AudioRegionView::reset_fade_in_shape ()
565 reset_fade_in_shape_width ((framecnt_t) audio_region()->fade_in()->back()->when);
569 AudioRegionView::reset_fade_in_shape_width (framecnt_t width)
571 if (fade_in_handle == 0) {
575 /* smallest size for a fade is 64 frames */
577 width = std::max ((framecnt_t) 64, width);
581 /* round here to prevent little visual glitches with sub-pixel placement */
582 double const pwidth = rint (width / samples_per_unit);
583 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
587 fade_in_shape->hide();
588 fade_in_handle->hide();
592 double const handle_center = pwidth;
594 /* Put the fade in handle so that its left side is at the end-of-fade line */
595 fade_in_handle->property_x1() = handle_center;
596 fade_in_handle->property_x2() = handle_center + 6;
599 fade_in_shape->hide();
603 if (trackview.session()->config.get_show_region_fades()) {
604 fade_in_shape->show();
607 float curve[npoints];
608 audio_region()->fade_in()->curve().get_vector (0, audio_region()->fade_in()->back()->when, curve, npoints);
610 points = get_canvas_points ("fade in shape", npoints + 3);
612 if (_height >= NAME_HIGHLIGHT_THRESH) {
613 h = _height - NAME_HIGHLIGHT_SIZE - 2;
618 /* points *MUST* be in anti-clockwise order */
621 double xdelta = pwidth/npoints;
623 for (pi = 0, pc = 0; pc < npoints; ++pc) {
624 (*points)[pi].set_x(1 + (pc * xdelta));
625 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
630 (*points)[pi].set_x(pwidth);
631 (*points)[pi++].set_y(2);
633 (*points)[pi].set_x(1);
634 (*points)[pi++].set_y(2);
636 /* connect the dots ... */
638 (*points)[pi] = (*points)[0];
640 fade_in_shape->property_points() = *points;
643 /* ensure trim handle stays on top */
644 if (frame_handle_start) {
645 frame_handle_start->raise_to_top();
650 AudioRegionView::reset_fade_out_shape ()
652 reset_fade_out_shape_width ((framecnt_t) audio_region()->fade_out()->back()->when);
656 AudioRegionView::reset_fade_out_shape_width (framecnt_t width)
658 if (fade_out_handle == 0) {
662 /* smallest size for a fade is 64 frames */
664 width = std::max ((framecnt_t) 64, width);
668 /* round here to prevent little visual glitches with sub-pixel placement */
669 double const pwidth = rint (width / samples_per_unit);
670 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
674 fade_out_shape->hide();
675 fade_out_handle->hide();
679 double const handle_center = (_region->length() - width) / samples_per_unit;
681 /* Put the fade out handle so that its right side is at the end-of-fade line;
682 * it's `one out' for precise pixel accuracy.
684 fade_out_handle->property_x1() = handle_center - 5;
685 fade_out_handle->property_x2() = handle_center + 1;
687 /* don't show shape if its too small */
690 fade_out_shape->hide();
694 if (trackview.session()->config.get_show_region_fades()) {
695 fade_out_shape->show();
698 float curve[npoints];
699 audio_region()->fade_out()->curve().get_vector (0, audio_region()->fade_out()->back()->when, curve, npoints);
701 if (_height >= NAME_HIGHLIGHT_THRESH) {
702 h = _height - NAME_HIGHLIGHT_SIZE - 2;
707 /* points *MUST* be in anti-clockwise order */
709 points = get_canvas_points ("fade out shape", npoints + 3);
712 double xdelta = pwidth/npoints;
714 for (pi = 0, pc = 0; pc < npoints; ++pc) {
715 (*points)[pi].set_x(_pixel_width - pwidth + (pc * xdelta));
716 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
721 (*points)[pi].set_x(_pixel_width);
722 (*points)[pi++].set_y(h);
724 (*points)[pi].set_x(_pixel_width);
725 (*points)[pi++].set_y(2);
727 /* connect the dots ... */
729 (*points)[pi] = (*points)[0];
731 fade_out_shape->property_points() = *points;
734 /* ensure trim handle stays on top */
735 if (frame_handle_end) {
736 frame_handle_end->raise_to_top();
741 AudioRegionView::set_samples_per_unit (gdouble spu)
743 RegionView::set_samples_per_unit (spu);
745 if (_flags & WaveformVisible) {
746 for (uint32_t n=0; n < waves.size(); ++n) {
747 waves[n]->property_samples_per_unit() = spu;
755 reset_fade_shapes ();
759 AudioRegionView::set_amplitude_above_axis (gdouble spp)
761 for (uint32_t n=0; n < waves.size(); ++n) {
762 waves[n]->property_amplitude_above_axis() = spp;
767 AudioRegionView::compute_colors (Gdk::Color const & basic_color)
769 RegionView::compute_colors (basic_color);
771 /* gain color computed in envelope_active_changed() */
773 fade_color = UINT_RGBA_CHANGE_A (fill_color, 120);
777 AudioRegionView::set_colors ()
779 RegionView::set_colors();
782 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
785 for (uint32_t n=0; n < waves.size(); ++n) {
786 if (_region->muted()) {
787 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
789 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
792 waves[n]->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
793 waves[n]->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
798 AudioRegionView::set_waveform_visible (bool yn)
800 if (((_flags & WaveformVisible) != yn)) {
802 for (uint32_t n=0; n < waves.size(); ++n) {
803 /* make sure the zoom level is correct, since we don't update
804 this when waveforms are hidden.
806 waves[n]->property_samples_per_unit() = samples_per_unit;
809 _flags |= WaveformVisible;
811 for (uint32_t n=0; n < waves.size(); ++n) {
814 _flags &= ~WaveformVisible;
821 AudioRegionView::temporarily_hide_envelope ()
829 AudioRegionView::unhide_envelope ()
831 if (gain_line && (_flags & EnvelopeVisible)) {
837 AudioRegionView::set_envelope_visible (bool yn)
839 if (gain_line && ((_flags & EnvelopeVisible) != yn)) {
842 _flags |= EnvelopeVisible;
845 _flags &= ~EnvelopeVisible;
852 AudioRegionView::create_waves ()
854 // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
855 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
861 ChanCount nchans = atv.track()->n_channels();
863 // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data
864 // << " and channels = " << nchans.n_audio() << endl;
866 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
867 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
868 tmp_waves.push_back (0);
871 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
875 _data_ready_connections.clear ();
877 for (uint32_t i = 0; i < nchans.n_audio(); ++i) {
878 _data_ready_connections.push_back (0);
881 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
883 if (n >= audio_region()->n_channels()) {
887 wave_caches.push_back (WaveView::create_cache ());
889 // cerr << "\tchannel " << n << endl;
892 if (audio_region()->audio_source(n)->peaks_ready (boost::bind (&AudioRegionView::peaks_ready_handler, this, n), &_data_ready_connections[n], gui_context())) {
893 // cerr << "\tData is ready\n";
894 create_one_wave (n, true);
896 // cerr << "\tdata is not ready\n";
897 // we'll get a PeaksReady signal from the source in the future
898 // and will call create_one_wave(n) then.
902 // cerr << "\tdon't delay, display today!\n";
903 create_one_wave (n, true);
910 AudioRegionView::create_one_wave (uint32_t which, bool /*direct*/)
912 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
913 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
914 uint32_t nchans = atv.track()->n_channels().n_audio();
916 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
919 if (trackview.current_height() < NAME_HIGHLIGHT_THRESH) {
920 ht = ((trackview.current_height()) / (double) nchans);
922 ht = ((trackview.current_height() - NAME_HIGHLIGHT_SIZE) / (double) nchans);
925 gdouble yoff = which * ht;
927 WaveView *wave = new WaveView(*group);
929 wave->property_data_src() = (gpointer) _region.get();
930 wave->property_cache() = wave_caches[which];
931 wave->property_cache_updater() = true;
932 wave->property_channel() = which;
933 wave->property_length_function() = (gpointer) region_length_from_c;
934 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
935 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
936 wave->property_x() = 0.0;
937 wave->property_y() = yoff;
938 wave->property_height() = (double) ht;
939 wave->property_samples_per_unit() = samples_per_unit;
940 wave->property_amplitude_above_axis() = _amplitude_above_axis;
943 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
944 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
946 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_WaveForm.get();
947 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
950 wave->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
951 wave->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
952 wave->property_zero_line() = true;
953 wave->property_region_start() = _region->start();
954 wave->property_rectified() = (bool) (_flags & WaveformRectified);
955 wave->property_logscaled() = (bool) (_flags & WaveformLogScaled);
957 if (!(_flags & WaveformVisible)) {
961 /* note: calling this function is serialized by the lock
962 held in the peak building thread that signals that
963 peaks are ready for use *or* by the fact that it is
964 called one by one from the GUI thread.
967 if (which < nchans) {
968 tmp_waves[which] = wave;
970 /* n-channel track, >n-channel source */
973 /* see if we're all ready */
975 for (n = 0; n < nchans; ++n) {
976 if (tmp_waves[n] == 0) {
981 if (n == nwaves && waves.empty()) {
982 /* all waves are ready */
983 tmp_waves.resize(nwaves);
988 /* all waves created, don't hook into peaks ready anymore */
989 delete _data_ready_connections[which];
990 _data_ready_connections[which] = 0;
995 AudioRegionView::peaks_ready_handler (uint32_t which)
997 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AudioRegionView::create_one_wave, this, which, false));
998 // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
1002 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1004 if (gain_line == 0) {
1010 /* don't create points that can't be seen */
1012 set_envelope_visible (true);
1019 framepos_t fx = trackview.editor().pixel_to_frame (x);
1021 if (fx > _region->length()) {
1025 /* compute vertical fractional position */
1027 y = 1.0 - (y / (_height - NAME_HIGHLIGHT_SIZE));
1029 /* map using gain line */
1031 gain_line->view_to_model_coord (x, y);
1033 /* XXX STATEFUL: can't convert to stateful diff until we
1034 can represent automation data with it.
1037 trackview.session()->begin_reversible_command (_("add gain control point"));
1038 XMLNode &before = audio_region()->envelope()->get_state();
1040 if (!audio_region()->envelope_active()) {
1041 XMLNode ®ion_before = audio_region()->get_state();
1042 audio_region()->set_envelope_active(true);
1043 XMLNode ®ion_after = audio_region()->get_state();
1044 trackview.session()->add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
1047 audio_region()->envelope()->add (fx, y);
1049 XMLNode &after = audio_region()->envelope()->get_state();
1050 trackview.session()->add_command (new MementoCommand<AutomationList>(*audio_region()->envelope().get(), &before, &after));
1051 trackview.session()->commit_reversible_command ();
1055 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent */*ev*/)
1057 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1058 audio_region()->envelope()->erase (cp->model());
1062 AudioRegionView::store_flags()
1064 XMLNode *node = new XMLNode ("GUI");
1066 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
1067 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
1068 node->add_property ("waveform-rectified", (_flags & WaveformRectified) ? "yes" : "no");
1069 node->add_property ("waveform-logscaled", (_flags & WaveformLogScaled) ? "yes" : "no");
1071 _region->add_extra_xml (*node);
1075 AudioRegionView::set_flags (XMLNode* node)
1079 if ((prop = node->property ("waveform-visible")) != 0) {
1080 if (string_is_affirmative (prop->value())) {
1081 _flags |= WaveformVisible;
1085 if ((prop = node->property ("envelope-visible")) != 0) {
1086 if (string_is_affirmative (prop->value())) {
1087 _flags |= EnvelopeVisible;
1091 if ((prop = node->property ("waveform-rectified")) != 0) {
1092 if (string_is_affirmative (prop->value())) {
1093 _flags |= WaveformRectified;
1097 if ((prop = node->property ("waveform-logscaled")) != 0) {
1098 if (string_is_affirmative (prop->value())) {
1099 _flags |= WaveformLogScaled;
1105 AudioRegionView::set_waveform_shape (WaveformShape shape)
1109 /* this slightly odd approach is to leave the door open to
1110 other "shapes" such as spectral displays, etc.
1123 if (yn != (bool) (_flags & WaveformRectified)) {
1124 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1125 (*wave)->property_rectified() = yn;
1129 _flags |= WaveformRectified;
1131 _flags &= ~WaveformRectified;
1138 AudioRegionView::set_waveform_scale (WaveformScale scale)
1140 bool yn = (scale == Logarithmic);
1142 if (yn != (bool) (_flags & WaveformLogScaled)) {
1143 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1144 (*wave)->property_logscaled() = yn;
1148 _flags |= WaveformLogScaled;
1150 _flags &= ~WaveformLogScaled;
1158 AudioRegionView::add_ghost (TimeAxisView& tv)
1160 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1163 double unit_position = _region->position () / samples_per_unit;
1164 AudioGhostRegion* ghost = new AudioGhostRegion (tv, trackview, unit_position);
1167 nchans = rtv->track()->n_channels().n_audio();
1169 for (uint32_t n = 0; n < nchans; ++n) {
1171 if (n >= audio_region()->n_channels()) {
1175 WaveView *wave = new WaveView(*ghost->group);
1177 wave->property_data_src() = _region.get();
1178 wave->property_cache() = wave_caches[n];
1179 wave->property_cache_updater() = false;
1180 wave->property_channel() = n;
1181 wave->property_length_function() = (gpointer)region_length_from_c;
1182 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1183 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1184 wave->property_x() = 0.0;
1185 wave->property_samples_per_unit() = samples_per_unit;
1186 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1188 wave->property_region_start() = _region->start();
1190 ghost->waves.push_back(wave);
1193 ghost->set_height ();
1194 ghost->set_duration (_region->length() / samples_per_unit);
1195 ghost->set_colors();
1196 ghosts.push_back (ghost);
1202 AudioRegionView::entered (bool internal_editing)
1204 trackview.editor().set_current_trimmable (_region);
1205 trackview.editor().set_current_movable (_region);
1207 if (gain_line && _flags & EnvelopeVisible) {
1208 gain_line->show_all_control_points ();
1211 if (fade_in_handle && !internal_editing) {
1212 fade_in_handle->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fade_color, 255);
1213 fade_out_handle->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fade_color, 255);
1218 AudioRegionView::exited ()
1220 trackview.editor().set_current_trimmable (boost::shared_ptr<Trimmable>());
1221 trackview.editor().set_current_movable (boost::shared_ptr<Movable>());
1224 gain_line->hide_all_but_selected_control_points ();
1227 if (fade_in_handle) {
1228 fade_in_handle->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fade_color, 0);
1229 fade_out_handle->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fade_color, 0);
1234 AudioRegionView::envelope_active_changed ()
1237 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
1242 AudioRegionView::set_waveview_data_src()
1244 AudioGhostRegion* agr;
1245 double unit_length= _region->length() / samples_per_unit;
1247 for (uint32_t n = 0; n < waves.size(); ++n) {
1248 // TODO: something else to let it know the channel
1249 waves[n]->property_data_src() = _region.get();
1252 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1254 (*i)->set_duration (unit_length);
1256 if((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
1257 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
1258 (*w)->property_data_src() = _region.get();
1266 AudioRegionView::color_handler ()
1268 //case cMutedWaveForm:
1270 //case cWaveFormClip:
1274 //case cGainLineInactive:
1276 envelope_active_changed();
1281 AudioRegionView::set_frame_color ()
1287 if (_region->opaque()) {
1293 TimeAxisViewItem::set_frame_color ();
1299 if (_region->muted()) {
1300 wc = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get(), MUTED_ALPHA);
1302 wc = ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get();
1304 fc = ARDOUR_UI::config()->canvasvar_SelectedWaveFormFill.get();
1307 if (_region->muted()) {
1308 wc = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA);
1310 wc = ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
1312 fc = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
1314 if (_region->muted()) {
1315 wc = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
1317 wc = ARDOUR_UI::config()->canvasvar_WaveForm.get();
1319 fc = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
1323 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1324 if (_region->muted()) {
1325 (*w)->property_wave_color() = wc;
1327 (*w)->property_wave_color() = wc;
1328 (*w)->property_fill_color() = fc;
1334 AudioRegionView::set_fade_visibility (bool yn)
1337 if (fade_in_shape) {
1338 fade_in_shape->show();
1340 if (fade_out_shape) {
1341 fade_out_shape->show ();
1343 if (fade_in_handle) {
1344 fade_in_handle->show ();
1346 if (fade_out_handle) {
1347 fade_out_handle->show ();
1350 if (fade_in_shape) {
1351 fade_in_shape->hide();
1353 if (fade_out_shape) {
1354 fade_out_shape->hide ();
1356 if (fade_in_handle) {
1357 fade_in_handle->hide ();
1359 if (fade_out_handle) {
1360 fade_out_handle->hide ();
1366 AudioRegionView::update_coverage_frames (LayerDisplay d)
1368 RegionView::update_coverage_frames (d);
1370 if (fade_in_handle) {
1371 fade_in_handle->raise_to_top ();
1372 fade_out_handle->raise_to_top ();
1377 AudioRegionView::show_region_editor ()
1380 editor = new AudioRegionEditor (trackview.session(), audio_region());
1384 editor->set_position (Gtk::WIN_POS_MOUSE);
1390 AudioRegionView::show_fade_line (framepos_t pos)
1392 fade_position_line->property_x1() = trackview.editor().frame_to_pixel (pos);
1393 fade_position_line->property_x2() = trackview.editor().frame_to_pixel (pos);
1394 fade_position_line->show ();
1395 fade_position_line->raise_to_top ();
1399 AudioRegionView::hide_fade_line ()
1401 fade_position_line->hide ();
1406 AudioRegionView::transients_changed ()
1408 AnalysisFeatureList analysis_features = _region->transients();
1410 while (feature_lines.size() < analysis_features.size()) {
1412 ArdourCanvas::Line* canvas_item = new ArdourCanvas::Line(*group);
1414 ArdourCanvas::Points points;
1416 points.push_back(Gnome::Art::Point(-1.0, 2.0)); // first x-coord needs to be a non-normal value
1417 points.push_back(Gnome::Art::Point(1.0, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
1419 canvas_item->property_points() = points;
1420 canvas_item->property_width_pixels() = 1;
1421 canvas_item->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
1422 canvas_item->property_first_arrowhead() = TRUE;
1423 canvas_item->property_last_arrowhead() = TRUE;
1424 canvas_item->property_arrow_shape_a() = 11.0;
1425 canvas_item->property_arrow_shape_b() = 0.0;
1426 canvas_item->property_arrow_shape_c() = 4.0;
1428 canvas_item->raise_to_top ();
1429 canvas_item->show ();
1431 canvas_item->set_data ("regionview", this);
1432 canvas_item->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_feature_line_event), canvas_item, this));
1434 feature_lines.push_back (make_pair(0, canvas_item));
1437 while (feature_lines.size() > analysis_features.size()) {
1438 ArdourCanvas::Line* line = feature_lines.back().second;
1439 feature_lines.pop_back ();
1443 AnalysisFeatureList::const_iterator i;
1444 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1446 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
1448 ArdourCanvas::Points points;
1450 float *pos = new float;
1451 *pos = trackview.editor().frame_to_pixel (*i);
1453 points.push_back(Gnome::Art::Point(*pos, 2.0)); // first x-coord needs to be a non-normal value
1454 points.push_back(Gnome::Art::Point(*pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
1456 (*l).second->property_points() = points;
1457 (*l).second->set_data ("position", pos);
1464 AudioRegionView::update_transient(float /*old_pos*/, float new_pos)
1466 /* Find frame at old pos, calulate new frame then update region transients*/
1467 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1469 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1471 /* Line has been updated in drag so we compare to new_pos */
1473 float* pos = (float*) (*l).second->get_data ("position");
1475 if (rint(new_pos) == rint(*pos)) {
1477 framepos_t old_frame = (*l).first;
1478 framepos_t new_frame = trackview.editor().pixel_to_frame (new_pos);
1480 _region->update_transient (old_frame, new_frame);
1488 AudioRegionView::remove_transient(float pos)
1490 /* Find frame at old pos, calulate new frame then update region transients*/
1491 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1493 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1495 /* Line has been updated in drag so we compare to new_pos */
1496 float *line_pos = (float*) (*l).second->get_data ("position");
1498 if (rint(pos) == rint(*line_pos)) {
1499 _region->remove_transient ((*l).first);
1506 AudioRegionView::thaw_after_trim ()
1508 RegionView::thaw_after_trim ();