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)
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)
94 , _amplitude_above_axis(1.0)
101 AudioRegionView::AudioRegionView (const AudioRegionView& other)
102 : sigc::trackable(other)
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))
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;
158 if ((node = _region->extra_xml ("GUI")) != 0) {
161 _flags = WaveformVisible;
165 /* make envelope visible if it has anything interesting in it */
166 if (audio_region()->envelope()->size() > 2) {
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);
184 UINT_TO_RGBA(fill_color,&r,&g,&b,&a);
186 fade_in_handle = new ArdourCanvas::SimpleRect (*group);
187 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
188 fade_in_handle->property_outline_pixels() = 0;
190 fade_in_handle->set_data ("regionview", this);
192 fade_out_handle = new ArdourCanvas::SimpleRect (*group);
193 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
194 fade_out_handle->property_outline_pixels() = 0;
196 fade_out_handle->set_data ("regionview", this);
199 setup_fade_handle_positions ();
201 if (!trackview.session()->config.get_show_region_fades()) {
202 set_fade_visibility (false);
205 const string line_name = _region->name() + ":gain";
207 if (!Profile->get_sae()) {
208 gain_line = new AudioRegionGainLine (line_name, *this, *group, audio_region()->envelope());
211 if (!(_flags & EnvelopeVisible)) {
219 set_height (trackview.current_height());
222 region_sync_changed ();
224 region_resized (ARDOUR::bounds_change);
225 set_waveview_data_src();
227 envelope_active_changed ();
228 fade_in_active_changed ();
229 fade_out_active_changed ();
231 reset_width_dependent_items (_pixel_width);
233 fade_in_shape->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
234 fade_in_handle->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
235 fade_out_shape->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
236 fade_out_handle->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
240 /* XXX sync mark drag? */
243 AudioRegionView::~AudioRegionView ()
245 in_destructor = true;
247 RegionViewGoingAway (this); /* EMIT_SIGNAL */
249 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
250 gnome_canvas_waveview_cache_destroy (*cache);
253 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
257 /* all waveviews etc will be destroyed when the group is destroyed */
262 boost::shared_ptr<ARDOUR::AudioRegion>
263 AudioRegionView::audio_region() const
265 // "Guaranteed" to succeed...
266 return boost::dynamic_pointer_cast<AudioRegion>(_region);
270 AudioRegionView::region_changed (const PropertyChange& what_changed)
272 ENSURE_GUI_THREAD (*this, &AudioRegionView::region_changed, what_changed);
273 // cerr << "AudioRegionView::region_changed() called" << endl;
275 RegionView::region_changed (what_changed);
277 if (what_changed.contains (ARDOUR::Properties::scale_amplitude)) {
278 region_scale_amplitude_changed ();
280 if (what_changed.contains (ARDOUR::Properties::fade_in)) {
283 if (what_changed.contains (ARDOUR::Properties::fade_out)) {
286 if (what_changed.contains (ARDOUR::Properties::fade_in_active)) {
287 fade_in_active_changed ();
289 if (what_changed.contains (ARDOUR::Properties::fade_out_active)) {
290 fade_out_active_changed ();
292 if (what_changed.contains (ARDOUR::Properties::envelope_active)) {
293 envelope_active_changed ();
298 AudioRegionView::fade_in_changed ()
300 reset_fade_in_shape ();
304 AudioRegionView::fade_out_changed ()
306 reset_fade_out_shape ();
309 AudioRegionView::fade_in_active_changed ()
313 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
315 if (audio_region()->fade_in_active()) {
316 col = RGBA_TO_UINT(r,g,b,120);
317 fade_in_shape->property_fill_color_rgba() = col;
318 fade_in_shape->property_width_pixels() = 0;
319 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
321 col = RGBA_TO_UINT(r,g,b,0);
322 fade_in_shape->property_fill_color_rgba() = col;
323 fade_in_shape->property_width_pixels() = 1;
324 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
329 AudioRegionView::fade_out_active_changed ()
333 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
335 if (audio_region()->fade_out_active()) {
336 col = RGBA_TO_UINT(r,g,b,120);
337 fade_out_shape->property_fill_color_rgba() = col;
338 fade_out_shape->property_width_pixels() = 0;
339 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
341 col = RGBA_TO_UINT(r,g,b,0);
342 fade_out_shape->property_fill_color_rgba() = col;
343 fade_out_shape->property_width_pixels() = 1;
344 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
350 AudioRegionView::region_scale_amplitude_changed ()
352 ENSURE_GUI_THREAD (*this, &AudioRegionView::region_scale_amplitude_changed)
354 for (uint32_t n = 0; n < waves.size(); ++n) {
355 // force a reload of the cache
356 waves[n]->property_data_src() = _region.get();
361 AudioRegionView::region_renamed ()
363 Glib::ustring str = RegionView::make_name ();
365 if (audio_region()->speed_mismatch (trackview.session()->frame_rate())) {
366 str = string ("*") + str;
369 if (_region->muted()) {
370 str = string ("!") + str;
373 set_item_name (str, this);
378 AudioRegionView::region_resized (const PropertyChange& what_changed)
380 AudioGhostRegion* agr;
382 RegionView::region_resized(what_changed);
383 PropertyChange interesting_stuff;
385 interesting_stuff.add (ARDOUR::Properties::start);
386 interesting_stuff.add (ARDOUR::Properties::length);
388 if (what_changed.contains (interesting_stuff)) {
390 for (uint32_t n = 0; n < waves.size(); ++n) {
391 waves[n]->property_region_start() = _region->start();
394 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
395 if((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
397 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
398 (*w)->property_region_start() = _region->start();
406 AudioRegionView::reset_width_dependent_items (double pixel_width)
408 RegionView::reset_width_dependent_items(pixel_width);
409 assert(_pixel_width == pixel_width);
412 zero_line->property_x2() = pixel_width - 1.0;
415 if (fade_in_handle) {
416 if (pixel_width <= 6.0) {
417 fade_in_handle->hide();
418 fade_out_handle->hide();
421 fade_in_handle->hide();
422 fade_out_handle->hide();
424 if (trackview.session()->config.get_show_region_fades()) {
425 fade_in_handle->show();
426 fade_out_handle->show();
432 reset_fade_shapes ();
436 AudioRegionView::region_muted ()
438 RegionView::region_muted();
440 for (uint32_t n=0; n < waves.size(); ++n) {
441 if (_region->muted()) {
442 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
444 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
450 AudioRegionView::setup_fade_handle_positions()
452 /* position of fade handle offset from the top of the region view */
453 double const handle_pos = 2;
454 /* height of fade handles */
455 double const handle_height = 5;
457 if (fade_in_handle) {
458 fade_in_handle->property_y1() = handle_pos;
459 fade_in_handle->property_y2() = handle_pos + handle_height;
462 if (fade_out_handle) {
463 fade_out_handle->property_y1() = handle_pos;
464 fade_out_handle->property_y2() = handle_pos + handle_height;
469 AudioRegionView::set_height (gdouble height)
471 RegionView::set_height (height);
473 uint32_t wcnt = waves.size();
478 for (uint32_t n = 0; n < wcnt; ++n) {
481 if ((height) < NAME_HIGHLIGHT_THRESH) {
482 ht = ((height - 2 * wcnt) / (double) wcnt);
484 ht = (((height - 2 * wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
487 gdouble yoff = n * (ht + 1);
489 waves[n]->property_height() = ht;
490 waves[n]->property_y() = yoff + 2;
495 if ((height/wcnt) < NAME_HIGHLIGHT_THRESH) {
498 if (_flags & EnvelopeVisible) {
503 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE) - 2);
507 reset_fade_shapes ();
510 name_pixbuf->raise_to_top();
515 AudioRegionView::manage_zero_line ()
521 if (_height >= 100) {
522 double const wave_midpoint = (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
523 zero_line->property_y1() = wave_midpoint;
524 zero_line->property_y2() = wave_midpoint;
532 AudioRegionView::reset_fade_shapes ()
534 reset_fade_in_shape ();
535 reset_fade_out_shape ();
539 AudioRegionView::reset_fade_in_shape ()
541 reset_fade_in_shape_width ((nframes_t) audio_region()->fade_in()->back()->when);
545 AudioRegionView::reset_fade_in_shape_width (nframes_t width)
547 if (fade_in_handle == 0) {
551 /* smallest size for a fade is 64 frames */
553 width = std::max ((nframes_t) 64, width);
556 double pwidth = width / samples_per_unit;
557 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
561 fade_in_shape->hide();
562 fade_in_handle->hide();
566 double handle_center;
567 handle_center = pwidth;
569 if (handle_center > 7.0) {
570 handle_center -= 3.0;
575 fade_in_handle->property_x1() = handle_center - 3.0;
576 fade_in_handle->property_x2() = handle_center + 3.0;
579 fade_in_shape->hide();
583 if (trackview.session()->config.get_show_region_fades()) {
584 fade_in_shape->show();
587 float curve[npoints];
588 audio_region()->fade_in()->curve().get_vector (0, audio_region()->fade_in()->back()->when, curve, npoints);
590 points = get_canvas_points ("fade in shape", npoints+3);
592 if (_height >= NAME_HIGHLIGHT_THRESH) {
593 h = _height - NAME_HIGHLIGHT_SIZE;
598 /* points *MUST* be in anti-clockwise order */
601 double xdelta = pwidth/npoints;
603 for (pi = 0, pc = 0; pc < npoints; ++pc) {
604 (*points)[pi].set_x(1 + (pc * xdelta));
605 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
610 (*points)[pi].set_x(pwidth);
611 (*points)[pi++].set_y(2);
613 (*points)[pi].set_x(1);
614 (*points)[pi++].set_y(2);
616 /* connect the dots ... */
618 (*points)[pi] = (*points)[0];
620 fade_in_shape->property_points() = *points;
623 /* ensure trim handle stays on top */
624 frame_handle_start->raise_to_top();
628 AudioRegionView::reset_fade_out_shape ()
630 reset_fade_out_shape_width ((nframes_t) audio_region()->fade_out()->back()->when);
634 AudioRegionView::reset_fade_out_shape_width (nframes_t width)
636 if (fade_out_handle == 0) {
640 /* smallest size for a fade is 64 frames */
642 width = std::max ((nframes_t) 64, width);
645 double pwidth = width / samples_per_unit;
646 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
650 fade_out_shape->hide();
651 fade_out_handle->hide();
655 double handle_center;
656 handle_center = (_region->length() - width) / samples_per_unit;
658 if (handle_center > 7.0) {
659 handle_center -= 3.0;
664 fade_out_handle->property_x1() = handle_center - 3.0;
665 fade_out_handle->property_x2() = handle_center + 3.0;
667 /* don't show shape if its too small */
670 fade_out_shape->hide();
674 if (trackview.session()->config.get_show_region_fades()) {
675 fade_out_shape->show();
678 float curve[npoints];
679 audio_region()->fade_out()->curve().get_vector (0, audio_region()->fade_out()->back()->when, curve, npoints);
681 if (_height >= NAME_HIGHLIGHT_THRESH) {
682 h = _height - NAME_HIGHLIGHT_SIZE;
687 /* points *MUST* be in anti-clockwise order */
689 points = get_canvas_points ("fade out shape", npoints+3);
692 double xdelta = pwidth/npoints;
694 for (pi = 0, pc = 0; pc < npoints; ++pc) {
695 (*points)[pi].set_x(_pixel_width - 1 - pwidth + (pc*xdelta));
696 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
701 (*points)[pi].set_x(_pixel_width);
702 (*points)[pi++].set_y(h);
704 (*points)[pi].set_x(_pixel_width);
705 (*points)[pi++].set_y(2);
707 /* connect the dots ... */
709 (*points)[pi] = (*points)[0];
711 fade_out_shape->property_points() = *points;
714 /* ensure trim handle stays on top */
715 frame_handle_end->raise_to_top();
719 AudioRegionView::set_samples_per_unit (gdouble spu)
721 RegionView::set_samples_per_unit (spu);
723 if (_flags & WaveformVisible) {
724 for (uint32_t n=0; n < waves.size(); ++n) {
725 waves[n]->property_samples_per_unit() = spu;
733 reset_fade_shapes ();
737 AudioRegionView::set_amplitude_above_axis (gdouble spp)
739 for (uint32_t n=0; n < waves.size(); ++n) {
740 waves[n]->property_amplitude_above_axis() = spp;
745 AudioRegionView::compute_colors (Gdk::Color const & basic_color)
747 RegionView::compute_colors (basic_color);
751 /* gain color computed in envelope_active_changed() */
753 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
754 fade_color = RGBA_TO_UINT(r,g,b,120);
758 AudioRegionView::set_colors ()
760 RegionView::set_colors();
763 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
766 for (uint32_t n=0; n < waves.size(); ++n) {
767 if (_region->muted()) {
768 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
770 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
773 waves[n]->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
774 waves[n]->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
779 AudioRegionView::show_region_editor ()
782 editor = new AudioRegionEditor (trackview.session(), audio_region(), *this);
783 // GTK2FIX : how to ensure float without realizing
784 // editor->realize ();
785 // trackview.editor.ensure_float (*editor);
793 AudioRegionView::set_waveform_visible (bool yn)
795 if (((_flags & WaveformVisible) != yn)) {
797 for (uint32_t n=0; n < waves.size(); ++n) {
798 /* make sure the zoom level is correct, since we don't update
799 this when waveforms are hidden.
801 waves[n]->property_samples_per_unit() = samples_per_unit;
804 _flags |= WaveformVisible;
806 for (uint32_t n=0; n < waves.size(); ++n) {
809 _flags &= ~WaveformVisible;
816 AudioRegionView::temporarily_hide_envelope ()
824 AudioRegionView::unhide_envelope ()
826 if (gain_line && (_flags & EnvelopeVisible)) {
832 AudioRegionView::set_envelope_visible (bool yn)
834 if (gain_line && ((_flags & EnvelopeVisible) != yn)) {
837 _flags |= EnvelopeVisible;
840 _flags &= ~EnvelopeVisible;
847 AudioRegionView::create_waves ()
849 // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
850 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
856 ChanCount nchans = atv.track()->n_channels();
858 // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data
859 // << " and channels = " << nchans.n_audio() << endl;
861 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
862 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
863 tmp_waves.push_back (0);
866 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
870 _data_ready_connections.clear ();
872 for (uint32_t i = 0; i < nchans.n_audio(); ++i) {
873 _data_ready_connections.push_back (0);
876 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
878 if (n >= audio_region()->n_channels()) {
882 wave_caches.push_back (WaveView::create_cache ());
884 // cerr << "\tchannel " << n << endl;
887 if (audio_region()->audio_source(n)->peaks_ready (boost::bind (&AudioRegionView::peaks_ready_handler, this, n), &_data_ready_connections[n], gui_context())) {
888 // cerr << "\tData is ready\n";
889 create_one_wave (n, true);
891 // cerr << "\tdata is not ready\n";
892 // we'll get a PeaksReady signal from the source in the future
893 // and will call create_one_wave(n) then.
897 // cerr << "\tdon't delay, display today!\n";
898 create_one_wave (n, true);
905 AudioRegionView::create_one_wave (uint32_t which, bool /*direct*/)
907 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
908 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
909 uint32_t nchans = atv.track()->n_channels().n_audio();
911 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
914 if (trackview.current_height() < NAME_HIGHLIGHT_THRESH) {
915 ht = ((trackview.current_height()) / (double) nchans);
917 ht = ((trackview.current_height() - NAME_HIGHLIGHT_SIZE) / (double) nchans);
920 gdouble yoff = which * ht;
922 WaveView *wave = new WaveView(*group);
924 wave->property_data_src() = (gpointer) _region.get();
925 wave->property_cache() = wave_caches[which];
926 wave->property_cache_updater() = true;
927 wave->property_channel() = which;
928 wave->property_length_function() = (gpointer) region_length_from_c;
929 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
930 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
931 wave->property_x() = 0.0;
932 wave->property_y() = yoff;
933 wave->property_height() = (double) ht;
934 wave->property_samples_per_unit() = samples_per_unit;
935 wave->property_amplitude_above_axis() = _amplitude_above_axis;
938 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
939 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
941 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_WaveForm.get();
942 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
945 wave->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
946 wave->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
947 wave->property_region_start() = _region->start();
948 wave->property_rectified() = (bool) (_flags & WaveformRectified);
949 wave->property_logscaled() = (bool) (_flags & WaveformLogScaled);
951 if (!(_flags & WaveformVisible)) {
955 /* note: calling this function is serialized by the lock
956 held in the peak building thread that signals that
957 peaks are ready for use *or* by the fact that it is
958 called one by one from the GUI thread.
961 if (which < nchans) {
962 tmp_waves[which] = wave;
964 /* n-channel track, >n-channel source */
967 /* see if we're all ready */
969 for (n = 0; n < nchans; ++n) {
970 if (tmp_waves[n] == 0) {
975 if (n == nwaves && waves.empty()) {
976 /* all waves are ready */
977 tmp_waves.resize(nwaves);
982 /* all waves created, don't hook into peaks ready anymore */
983 delete _data_ready_connections[which];
984 _data_ready_connections[which] = 0;
988 zero_line = new ArdourCanvas::SimpleLine (*group);
989 zero_line->property_x1() = (gdouble) 1.0;
990 zero_line->property_x2() = (gdouble) (_region->length() / samples_per_unit) - 1.0;
991 zero_line->property_color_rgba() = (guint) ARDOUR_UI::config()->canvasvar_ZeroLine.get();
999 AudioRegionView::peaks_ready_handler (uint32_t which)
1001 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AudioRegionView::create_one_wave, this, which, false));
1002 // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
1006 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1008 if (gain_line == 0) {
1014 /* don't create points that can't be seen */
1016 set_envelope_visible (true);
1023 nframes_t fx = trackview.editor().pixel_to_frame (x);
1025 if (fx > _region->length()) {
1029 /* compute vertical fractional position */
1031 y = 1.0 - (y / (_height - NAME_HIGHLIGHT_SIZE));
1033 /* map using gain line */
1035 gain_line->view_to_model_coord (x, y);
1037 /* XXX STATEFUL: can't convert to stateful diff until we
1038 can represent automation data with it.
1041 trackview.session()->begin_reversible_command (_("add gain control point"));
1042 XMLNode &before = audio_region()->envelope()->get_state();
1044 if (!audio_region()->envelope_active()) {
1045 XMLNode ®ion_before = audio_region()->get_state();
1046 audio_region()->set_envelope_active(true);
1047 XMLNode ®ion_after = audio_region()->get_state();
1048 trackview.session()->add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
1051 audio_region()->envelope()->add (fx, y);
1053 XMLNode &after = audio_region()->envelope()->get_state();
1054 trackview.session()->add_command (new MementoCommand<AutomationList>(*audio_region()->envelope().get(), &before, &after));
1055 trackview.session()->commit_reversible_command ();
1059 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent */*ev*/)
1061 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1062 audio_region()->envelope()->erase (cp->model());
1066 AudioRegionView::store_flags()
1068 XMLNode *node = new XMLNode ("GUI");
1070 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
1071 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
1072 node->add_property ("waveform-rectified", (_flags & WaveformRectified) ? "yes" : "no");
1073 node->add_property ("waveform-logscaled", (_flags & WaveformLogScaled) ? "yes" : "no");
1075 _region->add_extra_xml (*node);
1079 AudioRegionView::set_flags (XMLNode* node)
1083 if ((prop = node->property ("waveform-visible")) != 0) {
1084 if (string_is_affirmative (prop->value())) {
1085 _flags |= WaveformVisible;
1089 if ((prop = node->property ("envelope-visible")) != 0) {
1090 if (string_is_affirmative (prop->value())) {
1091 _flags |= EnvelopeVisible;
1095 if ((prop = node->property ("waveform-rectified")) != 0) {
1096 if (string_is_affirmative (prop->value())) {
1097 _flags |= WaveformRectified;
1101 if ((prop = node->property ("waveform-logscaled")) != 0) {
1102 if (string_is_affirmative (prop->value())) {
1103 _flags |= WaveformLogScaled;
1109 AudioRegionView::set_waveform_shape (WaveformShape shape)
1113 /* this slightly odd approach is to leave the door open to
1114 other "shapes" such as spectral displays, etc.
1127 if (yn != (bool) (_flags & WaveformRectified)) {
1128 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1129 (*wave)->property_rectified() = yn;
1141 _flags |= WaveformRectified;
1143 _flags &= ~WaveformRectified;
1150 AudioRegionView::set_waveform_scale (WaveformScale scale)
1152 bool yn = (scale == Logarithmic);
1154 if (yn != (bool) (_flags & WaveformLogScaled)) {
1155 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1156 (*wave)->property_logscaled() = yn;
1160 _flags |= WaveformLogScaled;
1162 _flags &= ~WaveformLogScaled;
1170 AudioRegionView::add_ghost (TimeAxisView& tv)
1172 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1175 double unit_position = _region->position () / samples_per_unit;
1176 AudioGhostRegion* ghost = new AudioGhostRegion (tv, trackview, unit_position);
1179 nchans = rtv->track()->n_channels().n_audio();
1181 for (uint32_t n = 0; n < nchans; ++n) {
1183 if (n >= audio_region()->n_channels()) {
1187 WaveView *wave = new WaveView(*ghost->group);
1189 wave->property_data_src() = _region.get();
1190 wave->property_cache() = wave_caches[n];
1191 wave->property_cache_updater() = false;
1192 wave->property_channel() = n;
1193 wave->property_length_function() = (gpointer)region_length_from_c;
1194 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1195 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1196 wave->property_x() = 0.0;
1197 wave->property_samples_per_unit() = samples_per_unit;
1198 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1200 wave->property_region_start() = _region->start();
1202 ghost->waves.push_back(wave);
1205 ghost->set_height ();
1206 ghost->set_duration (_region->length() / samples_per_unit);
1207 ghost->set_colors();
1208 ghosts.push_back (ghost);
1214 AudioRegionView::entered ()
1216 if (gain_line && _flags & EnvelopeVisible) {
1217 gain_line->show_all_control_points ();
1221 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1224 if (fade_in_handle) {
1225 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1226 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1231 AudioRegionView::exited ()
1234 gain_line->hide_all_but_selected_control_points ();
1238 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1241 if (fade_in_handle) {
1242 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1243 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1248 AudioRegionView::envelope_active_changed ()
1251 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
1256 AudioRegionView::set_waveview_data_src()
1258 AudioGhostRegion* agr;
1259 double unit_length= _region->length() / samples_per_unit;
1261 for (uint32_t n = 0; n < waves.size(); ++n) {
1262 // TODO: something else to let it know the channel
1263 waves[n]->property_data_src() = _region.get();
1266 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1268 (*i)->set_duration (unit_length);
1270 if((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
1271 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
1272 (*w)->property_data_src() = _region.get();
1280 AudioRegionView::color_handler ()
1282 //case cMutedWaveForm:
1284 //case cWaveFormClip:
1288 //case cGainLineInactive:
1290 envelope_active_changed();
1295 AudioRegionView::set_frame_color ()
1301 if (_region->opaque()) {
1309 if (_selected && should_show_selection) {
1310 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_SelectedFrameBase.get(), &r, &g, &b, &a);
1311 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
1313 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1314 if (_region->muted()) {
1315 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get(), MUTED_ALPHA);
1317 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get();
1318 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveFormFill.get();
1323 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_RecordingRect.get(), &r, &g, &b, &a);
1324 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, a);
1326 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1327 if (_region->muted()) {
1328 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA);
1330 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
1331 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
1335 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_FrameBase.get(), &r, &g, &b, &a);
1336 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
1338 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1339 if (_region->muted()) {
1340 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
1342 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
1343 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
1351 AudioRegionView::set_fade_visibility (bool yn)
1354 if (fade_in_shape) {
1355 fade_in_shape->show();
1357 if (fade_out_shape) {
1358 fade_out_shape->show ();
1360 if (fade_in_handle) {
1361 fade_in_handle->show ();
1363 if (fade_out_handle) {
1364 fade_out_handle->show ();
1367 if (fade_in_shape) {
1368 fade_in_shape->hide();
1370 if (fade_out_shape) {
1371 fade_out_shape->hide ();
1373 if (fade_in_handle) {
1374 fade_in_handle->hide ();
1376 if (fade_out_handle) {
1377 fade_out_handle->hide ();
1383 AudioRegionView::update_coverage_frames (LayerDisplay d)
1385 RegionView::update_coverage_frames (d);
1387 fade_in_handle->raise_to_top ();
1388 fade_out_handle->raise_to_top ();