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/audio_diskstream.h"
31 #include "ardour/profile.h"
32 #include "ardour/session.h"
34 #include "pbd/memento_command.h"
35 #include "pbd/stacktrace.h"
37 #include "evoral/Curve.hpp"
39 #include "streamview.h"
40 #include "audio_region_view.h"
41 #include "audio_time_axis.h"
42 #include "simplerect.h"
43 #include "simpleline.h"
45 #include "public_editor.h"
46 #include "audio_region_editor.h"
47 #include "region_gain_line.h"
48 #include "control_point.h"
49 #include "ghostregion.h"
50 #include "audio_time_axis.h"
52 #include "rgb_macros.h"
53 #include "gui_thread.h"
54 #include "ardour_ui.h"
58 #define MUTED_ALPHA 10
62 using namespace ARDOUR;
64 using namespace Editing;
65 using namespace ArdourCanvas;
67 static const int32_t sync_mark_width = 9;
69 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
70 Gdk::Color const & basic_color)
71 : RegionView (parent, tv, r, spu, basic_color)
79 , _amplitude_above_axis(1.0)
86 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
87 Gdk::Color const & basic_color, bool recording, TimeAxisViewItem::Visibility visibility)
88 : RegionView (parent, tv, r, spu, basic_color, recording, visibility)
96 , _amplitude_above_axis(1.0)
103 AudioRegionView::AudioRegionView (const AudioRegionView& other)
104 : sigc::trackable(other)
112 , _amplitude_above_axis(1.0)
120 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
121 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
126 AudioRegionView::AudioRegionView (const AudioRegionView& other, boost::shared_ptr<AudioRegion> other_region)
127 : RegionView (other, boost::shared_ptr<Region> (other_region))
134 , _amplitude_above_axis(1.0)
142 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
143 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
149 AudioRegionView::init (Gdk::Color const & basic_color, bool wfd)
151 // FIXME: Some redundancy here with RegionView::init. Need to figure out
152 // where order is important and where it isn't...
154 RegionView::init (basic_color, wfd);
158 _amplitude_above_axis = 1.0;
162 if ((node = _region->extra_xml ("GUI")) != 0) {
165 _flags = WaveformVisible;
169 if (trackview.editor().new_regionviews_display_gain()) {
170 _flags |= EnvelopeVisible;
173 compute_colors (basic_color);
177 fade_in_shape = new ArdourCanvas::Polygon (*group);
178 fade_in_shape->property_fill_color_rgba() = fade_color;
179 fade_in_shape->set_data ("regionview", this);
181 fade_out_shape = new ArdourCanvas::Polygon (*group);
182 fade_out_shape->property_fill_color_rgba() = fade_color;
183 fade_out_shape->set_data ("regionview", this);
187 UINT_TO_RGBA(fill_color,&r,&g,&b,&a);
189 fade_in_handle = new ArdourCanvas::SimpleRect (*group);
190 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
191 fade_in_handle->property_outline_pixels() = 0;
193 fade_in_handle->set_data ("regionview", this);
195 fade_out_handle = new ArdourCanvas::SimpleRect (*group);
196 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
197 fade_out_handle->property_outline_pixels() = 0;
199 fade_out_handle->set_data ("regionview", this);
202 setup_fade_handle_positions ();
204 if (!trackview.session().config.get_show_region_fades()) {
205 set_fade_visibility (false);
208 const string line_name = _region->name() + ":gain";
210 if (!Profile->get_sae()) {
211 gain_line = new AudioRegionGainLine (line_name, trackview.session(), *this, *group,
212 audio_region()->envelope());
215 if (!(_flags & EnvelopeVisible)) {
223 set_height (trackview.current_height());
226 region_sync_changed ();
227 region_resized (BoundsChanged);
228 set_waveview_data_src();
230 envelope_active_changed ();
231 fade_in_active_changed ();
232 fade_out_active_changed ();
234 reset_width_dependent_items (_pixel_width);
236 fade_in_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
237 fade_in_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
238 fade_out_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
239 fade_out_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
243 /* XXX sync mark drag? */
246 AudioRegionView::~AudioRegionView ()
248 in_destructor = true;
250 RegionViewGoingAway (this); /* EMIT_SIGNAL */
252 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
253 gnome_canvas_waveview_cache_destroy (*cache);
256 /* all waveviews etc will be destroyed when the group is destroyed */
261 boost::shared_ptr<ARDOUR::AudioRegion>
262 AudioRegionView::audio_region() const
264 // "Guaranteed" to succeed...
265 return boost::dynamic_pointer_cast<AudioRegion>(_region);
269 AudioRegionView::region_changed (Change what_changed)
271 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionView::region_changed), what_changed));
272 //cerr << "AudioRegionView::region_changed() called" << endl;
274 RegionView::region_changed(what_changed);
276 if (what_changed & AudioRegion::ScaleAmplitudeChanged) {
277 region_scale_amplitude_changed ();
279 if (what_changed & AudioRegion::FadeInChanged) {
282 if (what_changed & AudioRegion::FadeOutChanged) {
285 if (what_changed & AudioRegion::FadeInActiveChanged) {
286 fade_in_active_changed ();
288 if (what_changed & AudioRegion::FadeOutActiveChanged) {
289 fade_out_active_changed ();
291 if (what_changed & AudioRegion::EnvelopeActiveChanged) {
292 envelope_active_changed ();
297 AudioRegionView::fade_in_changed ()
299 reset_fade_in_shape ();
303 AudioRegionView::fade_out_changed ()
305 reset_fade_out_shape ();
308 AudioRegionView::fade_in_active_changed ()
312 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
314 if (audio_region()->fade_in_active()) {
315 col = RGBA_TO_UINT(r,g,b,120);
316 fade_in_shape->property_fill_color_rgba() = col;
317 fade_in_shape->property_width_pixels() = 0;
318 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
320 col = RGBA_TO_UINT(r,g,b,0);
321 fade_in_shape->property_fill_color_rgba() = col;
322 fade_in_shape->property_width_pixels() = 1;
323 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
328 AudioRegionView::fade_out_active_changed ()
332 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
334 if (audio_region()->fade_out_active()) {
335 col = RGBA_TO_UINT(r,g,b,120);
336 fade_out_shape->property_fill_color_rgba() = col;
337 fade_out_shape->property_width_pixels() = 0;
338 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
340 col = RGBA_TO_UINT(r,g,b,0);
341 fade_out_shape->property_fill_color_rgba() = col;
342 fade_out_shape->property_width_pixels() = 1;
343 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
349 AudioRegionView::region_scale_amplitude_changed ()
351 ENSURE_GUI_THREAD (mem_fun(*this, &AudioRegionView::region_scale_amplitude_changed));
353 for (uint32_t n = 0; n < waves.size(); ++n) {
354 // force a reload of the cache
355 waves[n]->property_data_src() = _region.get();
360 AudioRegionView::region_renamed ()
362 Glib::ustring str = RegionView::make_name ();
364 if (audio_region()->speed_mismatch (trackview.session().frame_rate())) {
365 str = string ("*") + str;
368 if (_region->muted()) {
369 str = string ("!") + str;
372 set_item_name (str, this);
377 AudioRegionView::region_resized (Change what_changed)
379 AudioGhostRegion* agr;
381 RegionView::region_resized(what_changed);
383 if (what_changed & Change (StartChanged|LengthChanged)) {
385 for (uint32_t n = 0; n < waves.size(); ++n) {
386 waves[n]->property_region_start() = _region->start();
389 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
390 if((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
392 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
393 (*w)->property_region_start() = _region->start();
401 AudioRegionView::reset_width_dependent_items (double pixel_width)
403 RegionView::reset_width_dependent_items(pixel_width);
404 assert(_pixel_width == pixel_width);
407 zero_line->property_x2() = pixel_width - 1.0;
410 if (fade_in_handle) {
411 if (pixel_width <= 6.0) {
412 fade_in_handle->hide();
413 fade_out_handle->hide();
416 fade_in_handle->hide();
417 fade_out_handle->hide();
419 if (trackview.session().config.get_show_region_fades()) {
420 fade_in_handle->show();
421 fade_out_handle->show();
427 reset_fade_shapes ();
431 AudioRegionView::region_muted ()
433 RegionView::region_muted();
435 for (uint32_t n=0; n < waves.size(); ++n) {
436 if (_region->muted()) {
437 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
439 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
445 AudioRegionView::setup_fade_handle_positions()
447 /* position of fade handle offset from the top of the region view */
448 double const handle_pos = 2;
449 /* height of fade handles */
450 double const handle_height = 5;
452 if (fade_in_handle) {
453 fade_in_handle->property_y1() = handle_pos;
454 fade_in_handle->property_y2() = handle_pos + handle_height;
457 if (fade_out_handle) {
458 fade_out_handle->property_y1() = handle_pos;
459 fade_out_handle->property_y2() = handle_pos + handle_height;
464 AudioRegionView::set_height (gdouble height)
466 RegionView::set_height (height);
468 uint32_t wcnt = waves.size();
475 for (uint32_t n=0; n < wcnt; ++n) {
478 if ((height) < NAME_HIGHLIGHT_THRESH) {
479 ht = ((height-2*wcnt) / (double) wcnt);
481 ht = (((height-2*wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
484 gdouble yoff = n * (ht+1);
486 waves[n]->property_height() = ht;
487 waves[n]->property_y() = yoff + 2;
491 if ((height/wcnt) < NAME_HIGHLIGHT_THRESH) {
494 if (_flags & EnvelopeVisible) {
498 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE - 2));
502 reset_fade_shapes ();
505 name_pixbuf->raise_to_top();
511 AudioRegionView::manage_zero_line ()
517 if (_height >= 100) {
518 double const wave_midpoint = (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
519 zero_line->property_y1() = wave_midpoint;
520 zero_line->property_y2() = wave_midpoint;
528 AudioRegionView::reset_fade_shapes ()
530 reset_fade_in_shape ();
531 reset_fade_out_shape ();
535 AudioRegionView::reset_fade_in_shape ()
537 reset_fade_in_shape_width ((nframes_t) audio_region()->fade_in()->back()->when);
541 AudioRegionView::reset_fade_in_shape_width (nframes_t width)
543 if (fade_in_handle == 0) {
547 /* smallest size for a fade is 64 frames */
549 width = std::max ((nframes_t) 64, width);
552 double pwidth = width / samples_per_unit;
553 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
557 fade_in_shape->hide();
558 fade_in_handle->hide();
562 double handle_center;
563 handle_center = pwidth;
565 if (handle_center > 7.0) {
566 handle_center -= 3.0;
571 fade_in_handle->property_x1() = handle_center - 3.0;
572 fade_in_handle->property_x2() = handle_center + 3.0;
575 fade_in_shape->hide();
579 if (trackview.session().config.get_show_region_fades()) {
580 fade_in_shape->show();
583 float curve[npoints];
584 audio_region()->fade_in()->curve().get_vector (0, audio_region()->fade_in()->back()->when, curve, npoints);
586 points = get_canvas_points ("fade in shape", npoints+3);
588 if (_height >= NAME_HIGHLIGHT_THRESH) {
589 h = _height - NAME_HIGHLIGHT_SIZE;
594 /* points *MUST* be in anti-clockwise order */
597 double xdelta = pwidth/npoints;
599 for (pi = 0, pc = 0; pc < npoints; ++pc) {
600 (*points)[pi].set_x(1 + (pc * xdelta));
601 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
606 (*points)[pi].set_x(pwidth);
607 (*points)[pi++].set_y(2);
609 (*points)[pi].set_x(1);
610 (*points)[pi++].set_y(2);
612 /* connect the dots ... */
614 (*points)[pi] = (*points)[0];
616 fade_in_shape->property_points() = *points;
619 /* ensure trim handle stays on top */
620 frame_handle_start->raise_to_top();
624 AudioRegionView::reset_fade_out_shape ()
626 reset_fade_out_shape_width ((nframes_t) audio_region()->fade_out()->back()->when);
630 AudioRegionView::reset_fade_out_shape_width (nframes_t width)
632 if (fade_out_handle == 0) {
636 /* smallest size for a fade is 64 frames */
638 width = std::max ((nframes_t) 64, width);
641 double pwidth = width / samples_per_unit;
642 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
646 fade_out_shape->hide();
647 fade_out_handle->hide();
651 double handle_center;
652 handle_center = (_region->length() - width) / samples_per_unit;
654 if (handle_center > 7.0) {
655 handle_center -= 3.0;
660 fade_out_handle->property_x1() = handle_center - 3.0;
661 fade_out_handle->property_x2() = handle_center + 3.0;
663 /* don't show shape if its too small */
666 fade_out_shape->hide();
670 if (trackview.session().config.get_show_region_fades()) {
671 fade_out_shape->show();
674 float curve[npoints];
675 audio_region()->fade_out()->curve().get_vector (0, audio_region()->fade_out()->back()->when, curve, npoints);
677 if (_height >= NAME_HIGHLIGHT_THRESH) {
678 h = _height - NAME_HIGHLIGHT_SIZE;
683 /* points *MUST* be in anti-clockwise order */
685 points = get_canvas_points ("fade out shape", npoints+3);
688 double xdelta = pwidth/npoints;
690 for (pi = 0, pc = 0; pc < npoints; ++pc) {
691 (*points)[pi].set_x(_pixel_width - 1 - pwidth + (pc*xdelta));
692 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
697 (*points)[pi].set_x(_pixel_width);
698 (*points)[pi++].set_y(h);
700 (*points)[pi].set_x(_pixel_width);
701 (*points)[pi++].set_y(2);
703 /* connect the dots ... */
705 (*points)[pi] = (*points)[0];
707 fade_out_shape->property_points() = *points;
710 /* ensure trim handle stays on top */
711 frame_handle_end->raise_to_top();
715 AudioRegionView::set_samples_per_unit (gdouble spu)
717 RegionView::set_samples_per_unit (spu);
719 if (_flags & WaveformVisible) {
720 for (uint32_t n=0; n < waves.size(); ++n) {
721 waves[n]->property_samples_per_unit() = spu;
729 reset_fade_shapes ();
733 AudioRegionView::set_amplitude_above_axis (gdouble spp)
735 for (uint32_t n=0; n < waves.size(); ++n) {
736 waves[n]->property_amplitude_above_axis() = spp;
741 AudioRegionView::compute_colors (Gdk::Color const & basic_color)
743 RegionView::compute_colors (basic_color);
747 /* gain color computed in envelope_active_changed() */
749 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
750 fade_color = RGBA_TO_UINT(r,g,b,120);
754 AudioRegionView::set_colors ()
756 RegionView::set_colors();
759 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
762 for (uint32_t n=0; n < waves.size(); ++n) {
763 if (_region->muted()) {
764 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
766 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
769 waves[n]->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
770 waves[n]->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
775 AudioRegionView::show_region_editor ()
778 editor = new AudioRegionEditor (trackview.session(), audio_region(), *this);
779 // GTK2FIX : how to ensure float without realizing
780 // editor->realize ();
781 // trackview.editor.ensure_float (*editor);
789 AudioRegionView::set_waveform_visible (bool yn)
791 if (((_flags & WaveformVisible) != yn)) {
793 for (uint32_t n=0; n < waves.size(); ++n) {
794 /* make sure the zoom level is correct, since we don't update
795 this when waveforms are hidden.
797 waves[n]->property_samples_per_unit() = samples_per_unit;
800 _flags |= WaveformVisible;
802 for (uint32_t n=0; n < waves.size(); ++n) {
805 _flags &= ~WaveformVisible;
812 AudioRegionView::temporarily_hide_envelope ()
820 AudioRegionView::unhide_envelope ()
822 if (gain_line && (_flags & EnvelopeVisible)) {
828 AudioRegionView::set_envelope_visible (bool yn)
830 if (gain_line && ((_flags & EnvelopeVisible) != yn)) {
833 _flags |= EnvelopeVisible;
836 _flags &= ~EnvelopeVisible;
843 AudioRegionView::create_waves ()
845 // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
846 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
848 if (!atv.get_diskstream()) {
852 ChanCount nchans = atv.get_diskstream()->n_channels();
854 // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data
855 // << " and channels = " << nchans.n_audio() << endl;
857 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
858 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
859 tmp_waves.push_back (0);
862 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
864 if (n >= audio_region()->n_channels()) {
868 wave_caches.push_back (WaveView::create_cache ());
870 // cerr << "\tchannel " << n << endl;
873 if (audio_region()->audio_source(n)->peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n), data_ready_connection)) {
874 // cerr << "\tData is ready\n";
875 create_one_wave (n, true);
877 // cerr << "\tdata is not ready\n";
878 // we'll get a PeaksReady signal from the source in the future
879 // and will call create_one_wave(n) then.
883 // cerr << "\tdon't delay, display today!\n";
884 create_one_wave (n, true);
891 AudioRegionView::create_one_wave (uint32_t which, bool /*direct*/)
893 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
894 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
895 uint32_t nchans = atv.get_diskstream()->n_channels().n_audio();
897 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
900 if (trackview.current_height() < NAME_HIGHLIGHT_THRESH) {
901 ht = ((trackview.current_height()) / (double) nchans);
903 ht = ((trackview.current_height() - NAME_HIGHLIGHT_SIZE) / (double) nchans);
906 gdouble yoff = which * ht;
908 WaveView *wave = new WaveView(*group);
910 wave->property_data_src() = (gpointer) _region.get();
911 wave->property_cache() = wave_caches[which];
912 wave->property_cache_updater() = true;
913 wave->property_channel() = which;
914 wave->property_length_function() = (gpointer) region_length_from_c;
915 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
916 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
917 wave->property_x() = 0.0;
918 wave->property_y() = yoff;
919 wave->property_height() = (double) ht;
920 wave->property_samples_per_unit() = samples_per_unit;
921 wave->property_amplitude_above_axis() = _amplitude_above_axis;
924 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
925 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
927 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_WaveForm.get();
928 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
931 wave->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
932 wave->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
933 wave->property_region_start() = _region->start();
934 wave->property_rectified() = (bool) (_flags & WaveformRectified);
935 wave->property_logscaled() = (bool) (_flags & WaveformLogScaled);
937 if (!(_flags & WaveformVisible)) {
941 /* note: calling this function is serialized by the lock
942 held in the peak building thread that signals that
943 peaks are ready for use *or* by the fact that it is
944 called one by one from the GUI thread.
947 if (which < nchans) {
948 tmp_waves[which] = wave;
950 /* n-channel track, >n-channel source */
953 /* see if we're all ready */
955 for (n = 0; n < nchans; ++n) {
956 if (tmp_waves[n] == 0) {
961 if (n == nwaves && waves.empty()) {
962 /* all waves are ready */
963 tmp_waves.resize(nwaves);
968 /* all waves created, don't hook into peaks ready anymore */
969 data_ready_connection.disconnect ();
973 zero_line = new ArdourCanvas::SimpleLine (*group);
974 zero_line->property_x1() = (gdouble) 1.0;
975 zero_line->property_x2() = (gdouble) (_region->length() / samples_per_unit) - 1.0;
976 zero_line->property_color_rgba() = (guint) ARDOUR_UI::config()->canvasvar_ZeroLine.get();
984 AudioRegionView::peaks_ready_handler (uint32_t which)
986 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
987 // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
991 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
993 if (gain_line == 0) {
999 /* don't create points that can't be seen */
1001 set_envelope_visible (true);
1008 nframes_t fx = trackview.editor().pixel_to_frame (x);
1010 if (fx > _region->length()) {
1014 /* compute vertical fractional position */
1016 y = 1.0 - (y / (_height - NAME_HIGHLIGHT_SIZE));
1018 /* map using gain line */
1020 gain_line->view_to_model_coord (x, y);
1022 trackview.session().begin_reversible_command (_("add gain control point"));
1023 XMLNode &before = audio_region()->envelope()->get_state();
1025 if (!audio_region()->envelope_active()) {
1026 XMLNode ®ion_before = audio_region()->get_state();
1027 audio_region()->set_envelope_active(true);
1028 XMLNode ®ion_after = audio_region()->get_state();
1029 trackview.session().add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
1032 audio_region()->envelope()->add (fx, y);
1034 XMLNode &after = audio_region()->envelope()->get_state();
1035 trackview.session().add_command (new MementoCommand<AutomationList>(*audio_region()->envelope().get(), &before, &after));
1036 trackview.session().commit_reversible_command ();
1040 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent */*ev*/)
1042 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1043 audio_region()->envelope()->erase (cp->model());
1047 AudioRegionView::store_flags()
1049 XMLNode *node = new XMLNode ("GUI");
1051 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
1052 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
1053 node->add_property ("waveform-rectified", (_flags & WaveformRectified) ? "yes" : "no");
1054 node->add_property ("waveform-logscaled", (_flags & WaveformLogScaled) ? "yes" : "no");
1056 _region->add_extra_xml (*node);
1060 AudioRegionView::set_flags (XMLNode* node)
1064 if ((prop = node->property ("waveform-visible")) != 0) {
1065 if (string_is_affirmative (prop->value())) {
1066 _flags |= WaveformVisible;
1070 if ((prop = node->property ("envelope-visible")) != 0) {
1071 if (string_is_affirmative (prop->value())) {
1072 _flags |= EnvelopeVisible;
1076 if ((prop = node->property ("waveform-rectified")) != 0) {
1077 if (string_is_affirmative (prop->value())) {
1078 _flags |= WaveformRectified;
1082 if ((prop = node->property ("waveform-logscaled")) != 0) {
1083 if (string_is_affirmative (prop->value())) {
1084 _flags |= WaveformLogScaled;
1090 AudioRegionView::set_waveform_shape (WaveformShape shape)
1094 /* this slightly odd approach is to leave the door open to
1095 other "shapes" such as spectral displays, etc.
1108 if (yn != (bool) (_flags & WaveformRectified)) {
1109 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1110 (*wave)->property_rectified() = yn;
1122 _flags |= WaveformRectified;
1124 _flags &= ~WaveformRectified;
1131 AudioRegionView::set_waveform_scale (WaveformScale scale)
1133 bool yn = (scale == Logarithmic);
1135 if (yn != (bool) (_flags & WaveformLogScaled)) {
1136 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1137 (*wave)->property_logscaled() = yn;
1141 _flags |= WaveformLogScaled;
1143 _flags &= ~WaveformLogScaled;
1151 AudioRegionView::add_ghost (TimeAxisView& tv)
1153 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1156 double unit_position = _region->position () / samples_per_unit;
1157 AudioGhostRegion* ghost = new AudioGhostRegion (tv, trackview, unit_position);
1160 nchans = rtv->get_diskstream()->n_channels().n_audio();
1162 for (uint32_t n = 0; n < nchans; ++n) {
1164 if (n >= audio_region()->n_channels()) {
1168 WaveView *wave = new WaveView(*ghost->group);
1170 wave->property_data_src() = _region.get();
1171 wave->property_cache() = wave_caches[n];
1172 wave->property_cache_updater() = false;
1173 wave->property_channel() = n;
1174 wave->property_length_function() = (gpointer)region_length_from_c;
1175 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1176 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1177 wave->property_x() = 0.0;
1178 wave->property_samples_per_unit() = samples_per_unit;
1179 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1181 wave->property_region_start() = _region->start();
1183 ghost->waves.push_back(wave);
1186 ghost->set_height ();
1187 ghost->set_duration (_region->length() / samples_per_unit);
1188 ghost->set_colors();
1189 ghosts.push_back (ghost);
1191 ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost));
1197 AudioRegionView::entered ()
1199 if (gain_line && _flags & EnvelopeVisible) {
1200 gain_line->show_all_control_points ();
1204 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1207 if (fade_in_handle) {
1208 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1209 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1214 AudioRegionView::exited ()
1217 gain_line->hide_all_but_selected_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::envelope_active_changed ()
1234 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
1239 AudioRegionView::set_waveview_data_src()
1241 AudioGhostRegion* agr;
1242 double unit_length= _region->length() / samples_per_unit;
1244 for (uint32_t n = 0; n < waves.size(); ++n) {
1245 // TODO: something else to let it know the channel
1246 waves[n]->property_data_src() = _region.get();
1249 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1251 (*i)->set_duration (unit_length);
1253 if((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
1254 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
1255 (*w)->property_data_src() = _region.get();
1263 AudioRegionView::color_handler ()
1265 //case cMutedWaveForm:
1267 //case cWaveFormClip:
1271 //case cGainLineInactive:
1273 envelope_active_changed();
1278 AudioRegionView::set_frame_color ()
1284 if (_region->opaque()) {
1292 if (_selected && should_show_selection) {
1293 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_SelectedFrameBase.get(), &r, &g, &b, &a);
1294 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
1296 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1297 if (_region->muted()) {
1298 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get(), MUTED_ALPHA);
1300 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get();
1301 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveFormFill.get();
1306 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_RecordingRect.get(), &r, &g, &b, &a);
1307 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, a);
1309 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1310 if (_region->muted()) {
1311 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA);
1313 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
1314 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
1318 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_FrameBase.get(), &r, &g, &b, &a);
1319 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
1321 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1322 if (_region->muted()) {
1323 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
1325 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
1326 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
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 fade_in_handle->raise_to_top ();
1371 fade_out_handle->raise_to_top ();