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"
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
61 using namespace ARDOUR;
63 using namespace Editing;
64 using namespace ArdourCanvas;
66 static const int32_t sync_mark_width = 9;
68 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
69 Gdk::Color const & basic_color)
70 : RegionView (parent, tv, r, spu, basic_color)
78 , _amplitude_above_axis(1.0)
85 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
86 Gdk::Color const & basic_color, bool recording, TimeAxisViewItem::Visibility visibility)
87 : RegionView (parent, tv, r, spu, basic_color, recording, visibility)
95 , _amplitude_above_axis(1.0)
102 AudioRegionView::AudioRegionView (const AudioRegionView& other)
103 : sigc::trackable(other)
111 , _amplitude_above_axis(1.0)
119 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
120 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
125 AudioRegionView::AudioRegionView (const AudioRegionView& other, boost::shared_ptr<AudioRegion> other_region)
126 : RegionView (other, boost::shared_ptr<Region> (other_region))
133 , _amplitude_above_axis(1.0)
141 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
142 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
148 AudioRegionView::init (Gdk::Color const & basic_color, bool wfd)
150 // FIXME: Some redundancy here with RegionView::init. Need to figure out
151 // where order is important and where it isn't...
153 RegionView::init (basic_color, wfd);
157 _amplitude_above_axis = 1.0;
161 if ((node = _region->extra_xml ("GUI")) != 0) {
164 _flags = WaveformVisible;
168 if (trackview.editor().new_regionviews_display_gain()) {
169 _flags |= EnvelopeVisible;
172 compute_colors (basic_color);
176 fade_in_shape = new ArdourCanvas::Polygon (*group);
177 fade_in_shape->property_fill_color_rgba() = fade_color;
178 fade_in_shape->set_data ("regionview", this);
180 fade_out_shape = new ArdourCanvas::Polygon (*group);
181 fade_out_shape->property_fill_color_rgba() = fade_color;
182 fade_out_shape->set_data ("regionview", this);
186 UINT_TO_RGBA(fill_color,&r,&g,&b,&a);
188 fade_in_handle = new ArdourCanvas::SimpleRect (*group);
189 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
190 fade_in_handle->property_outline_pixels() = 0;
192 fade_in_handle->set_data ("regionview", this);
194 fade_out_handle = new ArdourCanvas::SimpleRect (*group);
195 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
196 fade_out_handle->property_outline_pixels() = 0;
198 fade_out_handle->set_data ("regionview", this);
201 setup_fade_handle_positions ();
203 if (!trackview.session().config.get_show_region_fades()) {
204 set_fade_visibility (false);
207 const string line_name = _region->name() + ":gain";
209 if (!Profile->get_sae()) {
210 gain_line = new AudioRegionGainLine (line_name, trackview.session(), *this, *group,
211 audio_region()->envelope());
214 if (!(_flags & EnvelopeVisible)) {
222 set_height (trackview.current_height());
225 region_sync_changed ();
226 region_resized (BoundsChanged);
227 set_waveview_data_src();
229 envelope_active_changed ();
230 fade_in_active_changed ();
231 fade_out_active_changed ();
233 reset_width_dependent_items (_pixel_width);
235 fade_in_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
236 fade_in_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
237 fade_out_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
238 fade_out_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
242 /* XXX sync mark drag? */
245 AudioRegionView::~AudioRegionView ()
247 in_destructor = true;
249 RegionViewGoingAway (this); /* EMIT_SIGNAL */
251 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
252 gnome_canvas_waveview_cache_destroy (*cache);
255 /* all waveviews etc will be destroyed when the group is destroyed */
260 boost::shared_ptr<ARDOUR::AudioRegion>
261 AudioRegionView::audio_region() const
263 // "Guaranteed" to succeed...
264 return boost::dynamic_pointer_cast<AudioRegion>(_region);
268 AudioRegionView::region_changed (Change what_changed)
270 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionView::region_changed), what_changed));
271 //cerr << "AudioRegionView::region_changed() called" << endl;
273 RegionView::region_changed(what_changed);
275 if (what_changed & AudioRegion::ScaleAmplitudeChanged) {
276 region_scale_amplitude_changed ();
278 if (what_changed & AudioRegion::FadeInChanged) {
281 if (what_changed & AudioRegion::FadeOutChanged) {
284 if (what_changed & AudioRegion::FadeInActiveChanged) {
285 fade_in_active_changed ();
287 if (what_changed & AudioRegion::FadeOutActiveChanged) {
288 fade_out_active_changed ();
290 if (what_changed & AudioRegion::EnvelopeActiveChanged) {
291 envelope_active_changed ();
296 AudioRegionView::fade_in_changed ()
298 reset_fade_in_shape ();
302 AudioRegionView::fade_out_changed ()
304 reset_fade_out_shape ();
307 AudioRegionView::fade_in_active_changed ()
311 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
313 if (audio_region()->fade_in_active()) {
314 col = RGBA_TO_UINT(r,g,b,120);
315 fade_in_shape->property_fill_color_rgba() = col;
316 fade_in_shape->property_width_pixels() = 0;
317 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
319 col = RGBA_TO_UINT(r,g,b,0);
320 fade_in_shape->property_fill_color_rgba() = col;
321 fade_in_shape->property_width_pixels() = 1;
322 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
327 AudioRegionView::fade_out_active_changed ()
331 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
333 if (audio_region()->fade_out_active()) {
334 col = RGBA_TO_UINT(r,g,b,120);
335 fade_out_shape->property_fill_color_rgba() = col;
336 fade_out_shape->property_width_pixels() = 0;
337 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
339 col = RGBA_TO_UINT(r,g,b,0);
340 fade_out_shape->property_fill_color_rgba() = col;
341 fade_out_shape->property_width_pixels() = 1;
342 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
348 AudioRegionView::region_scale_amplitude_changed ()
350 ENSURE_GUI_THREAD (mem_fun(*this, &AudioRegionView::region_scale_amplitude_changed));
352 for (uint32_t n = 0; n < waves.size(); ++n) {
353 // force a reload of the cache
354 waves[n]->property_data_src() = _region.get();
359 AudioRegionView::region_renamed ()
361 Glib::ustring str = RegionView::make_name ();
363 if (audio_region()->speed_mismatch (trackview.session().frame_rate())) {
364 str = string ("*") + str;
367 if (_region->muted()) {
368 str = string ("!") + str;
371 set_item_name (str, this);
376 AudioRegionView::region_resized (Change what_changed)
378 AudioGhostRegion* agr;
380 RegionView::region_resized(what_changed);
382 if (what_changed & Change (StartChanged|LengthChanged)) {
384 for (uint32_t n = 0; n < waves.size(); ++n) {
385 waves[n]->property_region_start() = _region->start();
388 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
389 if((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
391 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
392 (*w)->property_region_start() = _region->start();
400 AudioRegionView::reset_width_dependent_items (double pixel_width)
402 RegionView::reset_width_dependent_items(pixel_width);
403 assert(_pixel_width == pixel_width);
406 zero_line->property_x2() = pixel_width - 1.0;
409 if (fade_in_handle) {
410 if (pixel_width <= 6.0) {
411 fade_in_handle->hide();
412 fade_out_handle->hide();
415 fade_in_handle->hide();
416 fade_out_handle->hide();
418 if (trackview.session().config.get_show_region_fades()) {
419 fade_in_handle->show();
420 fade_out_handle->show();
426 reset_fade_shapes ();
430 AudioRegionView::region_muted ()
432 RegionView::region_muted();
434 for (uint32_t n=0; n < waves.size(); ++n) {
435 if (_region->muted()) {
436 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
438 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
444 AudioRegionView::setup_fade_handle_positions()
446 /* position of fade handle offset from the top of the region view */
447 double const handle_pos = 2;
448 /* height of fade handles */
449 double const handle_height = 5;
451 if (fade_in_handle) {
452 fade_in_handle->property_y1() = handle_pos;
453 fade_in_handle->property_y2() = handle_pos + handle_height;
456 if (fade_out_handle) {
457 fade_out_handle->property_y1() = handle_pos;
458 fade_out_handle->property_y2() = handle_pos + handle_height;
463 AudioRegionView::set_height (gdouble height)
465 RegionView::set_height (height);
467 uint32_t wcnt = waves.size();
474 for (uint32_t n=0; n < wcnt; ++n) {
477 if ((height) < NAME_HIGHLIGHT_THRESH) {
478 ht = ((height-2*wcnt) / (double) wcnt);
480 ht = (((height-2*wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
483 gdouble yoff = n * (ht+1);
485 waves[n]->property_height() = ht;
486 waves[n]->property_y() = yoff + 2;
490 if ((height/wcnt) < NAME_HIGHLIGHT_THRESH) {
493 if (_flags & EnvelopeVisible) {
497 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE));
501 reset_fade_shapes ();
504 name_pixbuf->raise_to_top();
510 AudioRegionView::manage_zero_line ()
516 if (_height >= 100) {
517 double const wave_midpoint = (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
518 zero_line->property_y1() = wave_midpoint;
519 zero_line->property_y2() = wave_midpoint;
527 AudioRegionView::reset_fade_shapes ()
529 reset_fade_in_shape ();
530 reset_fade_out_shape ();
534 AudioRegionView::reset_fade_in_shape ()
536 reset_fade_in_shape_width ((nframes_t) audio_region()->fade_in()->back()->when);
540 AudioRegionView::reset_fade_in_shape_width (nframes_t width)
542 if (fade_in_handle == 0) {
546 /* smallest size for a fade is 64 frames */
548 width = std::max ((nframes_t) 64, width);
551 double pwidth = width / samples_per_unit;
552 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
556 fade_in_shape->hide();
557 fade_in_handle->hide();
561 double handle_center;
562 handle_center = pwidth;
564 if (handle_center > 7.0) {
565 handle_center -= 3.0;
570 fade_in_handle->property_x1() = handle_center - 3.0;
571 fade_in_handle->property_x2() = handle_center + 3.0;
574 fade_in_shape->hide();
578 if (trackview.session().config.get_show_region_fades()) {
579 fade_in_shape->show();
582 float curve[npoints];
583 audio_region()->fade_in()->curve().get_vector (0, audio_region()->fade_in()->back()->when, curve, npoints);
585 points = get_canvas_points ("fade in shape", npoints+3);
587 if (_height >= NAME_HIGHLIGHT_THRESH) {
588 h = _height - NAME_HIGHLIGHT_SIZE;
593 /* points *MUST* be in anti-clockwise order */
596 double xdelta = pwidth/npoints;
598 for (pi = 0, pc = 0; pc < npoints; ++pc) {
599 (*points)[pi].set_x(1 + (pc * xdelta));
600 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
605 (*points)[pi].set_x(pwidth);
606 (*points)[pi++].set_y(2);
608 (*points)[pi].set_x(1);
609 (*points)[pi++].set_y(2);
611 /* connect the dots ... */
613 (*points)[pi] = (*points)[0];
615 fade_in_shape->property_points() = *points;
620 AudioRegionView::reset_fade_out_shape ()
622 reset_fade_out_shape_width ((nframes_t) audio_region()->fade_out()->back()->when);
626 AudioRegionView::reset_fade_out_shape_width (nframes_t width)
628 if (fade_out_handle == 0) {
632 /* smallest size for a fade is 64 frames */
634 width = std::max ((nframes_t) 64, width);
637 double pwidth = width / samples_per_unit;
638 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
642 fade_out_shape->hide();
643 fade_out_handle->hide();
647 double handle_center;
648 handle_center = (_region->length() - width) / samples_per_unit;
650 if (handle_center > 7.0) {
651 handle_center -= 3.0;
656 fade_out_handle->property_x1() = handle_center - 3.0;
657 fade_out_handle->property_x2() = handle_center + 3.0;
659 /* don't show shape if its too small */
662 fade_out_shape->hide();
666 if (trackview.session().config.get_show_region_fades()) {
667 fade_out_shape->show();
670 float curve[npoints];
671 audio_region()->fade_out()->curve().get_vector (0, audio_region()->fade_out()->back()->when, curve, npoints);
673 if (_height >= NAME_HIGHLIGHT_THRESH) {
674 h = _height - NAME_HIGHLIGHT_SIZE;
679 /* points *MUST* be in anti-clockwise order */
681 points = get_canvas_points ("fade out shape", npoints+3);
684 double xdelta = pwidth/npoints;
686 for (pi = 0, pc = 0; pc < npoints; ++pc) {
687 (*points)[pi].set_x(_pixel_width - 1 - pwidth + (pc*xdelta));
688 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
693 (*points)[pi].set_x(_pixel_width);
694 (*points)[pi++].set_y(h);
696 (*points)[pi].set_x(_pixel_width);
697 (*points)[pi++].set_y(2);
699 /* connect the dots ... */
701 (*points)[pi] = (*points)[0];
703 fade_out_shape->property_points() = *points;
708 AudioRegionView::set_samples_per_unit (gdouble spu)
710 RegionView::set_samples_per_unit (spu);
712 if (_flags & WaveformVisible) {
713 for (uint32_t n=0; n < waves.size(); ++n) {
714 waves[n]->property_samples_per_unit() = spu;
722 reset_fade_shapes ();
726 AudioRegionView::set_amplitude_above_axis (gdouble spp)
728 for (uint32_t n=0; n < waves.size(); ++n) {
729 waves[n]->property_amplitude_above_axis() = spp;
734 AudioRegionView::compute_colors (Gdk::Color const & basic_color)
736 RegionView::compute_colors (basic_color);
740 /* gain color computed in envelope_active_changed() */
742 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
743 fade_color = RGBA_TO_UINT(r,g,b,120);
747 AudioRegionView::set_colors ()
749 RegionView::set_colors();
752 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
755 for (uint32_t n=0; n < waves.size(); ++n) {
756 if (_region->muted()) {
757 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
759 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
762 waves[n]->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
763 waves[n]->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
768 AudioRegionView::show_region_editor ()
771 editor = new AudioRegionEditor (trackview.session(), audio_region(), *this);
772 // GTK2FIX : how to ensure float without realizing
773 // editor->realize ();
774 // trackview.editor.ensure_float (*editor);
782 AudioRegionView::set_waveform_visible (bool yn)
784 if (((_flags & WaveformVisible) != yn)) {
786 for (uint32_t n=0; n < waves.size(); ++n) {
787 /* make sure the zoom level is correct, since we don't update
788 this when waveforms are hidden.
790 waves[n]->property_samples_per_unit() = samples_per_unit;
793 _flags |= WaveformVisible;
795 for (uint32_t n=0; n < waves.size(); ++n) {
798 _flags &= ~WaveformVisible;
805 AudioRegionView::temporarily_hide_envelope ()
813 AudioRegionView::unhide_envelope ()
815 if (gain_line && (_flags & EnvelopeVisible)) {
821 AudioRegionView::set_envelope_visible (bool yn)
823 if (gain_line && ((_flags & EnvelopeVisible) != yn)) {
826 _flags |= EnvelopeVisible;
829 _flags &= ~EnvelopeVisible;
836 AudioRegionView::create_waves ()
838 // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
839 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
841 if (!atv.get_diskstream()) {
845 ChanCount nchans = atv.get_diskstream()->n_channels();
847 // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data
848 // << " and channels = " << nchans.n_audio() << endl;
850 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
851 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
852 tmp_waves.push_back (0);
855 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
857 if (n >= audio_region()->n_channels()) {
861 wave_caches.push_back (WaveView::create_cache ());
863 // cerr << "\tchannel " << n << endl;
866 if (audio_region()->audio_source(n)->peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n), data_ready_connection)) {
867 // cerr << "\tData is ready\n";
868 create_one_wave (n, true);
870 // cerr << "\tdata is not ready\n";
871 // we'll get a PeaksReady signal from the source in the future
872 // and will call create_one_wave(n) then.
876 // cerr << "\tdon't delay, display today!\n";
877 create_one_wave (n, true);
884 AudioRegionView::create_one_wave (uint32_t which, bool direct)
886 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
887 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
888 uint32_t nchans = atv.get_diskstream()->n_channels().n_audio();
890 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
893 if (trackview.current_height() < NAME_HIGHLIGHT_THRESH) {
894 ht = ((trackview.current_height()) / (double) nchans);
896 ht = ((trackview.current_height() - NAME_HIGHLIGHT_SIZE) / (double) nchans);
899 gdouble yoff = which * ht;
901 WaveView *wave = new WaveView(*group);
903 wave->property_data_src() = (gpointer) _region.get();
904 wave->property_cache() = wave_caches[which];
905 wave->property_cache_updater() = true;
906 wave->property_channel() = which;
907 wave->property_length_function() = (gpointer) region_length_from_c;
908 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
909 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
910 wave->property_x() = 0.0;
911 wave->property_y() = yoff;
912 wave->property_height() = (double) ht;
913 wave->property_samples_per_unit() = samples_per_unit;
914 wave->property_amplitude_above_axis() = _amplitude_above_axis;
917 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
918 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
920 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_WaveForm.get();
921 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
924 wave->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
925 wave->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
926 wave->property_region_start() = _region->start();
927 wave->property_rectified() = (bool) (_flags & WaveformRectified);
928 wave->property_logscaled() = (bool) (_flags & WaveformLogScaled);
930 if (!(_flags & WaveformVisible)) {
934 /* note: calling this function is serialized by the lock
935 held in the peak building thread that signals that
936 peaks are ready for use *or* by the fact that it is
937 called one by one from the GUI thread.
940 if (which < nchans) {
941 tmp_waves[which] = wave;
943 /* n-channel track, >n-channel source */
946 /* see if we're all ready */
948 for (n = 0; n < nchans; ++n) {
949 if (tmp_waves[n] == 0) {
954 if (n == nwaves && waves.empty()) {
955 /* all waves are ready */
956 tmp_waves.resize(nwaves);
961 /* all waves created, don't hook into peaks ready anymore */
962 data_ready_connection.disconnect ();
966 zero_line = new ArdourCanvas::SimpleLine (*group);
967 zero_line->property_x1() = (gdouble) 1.0;
968 zero_line->property_x2() = (gdouble) (_region->length() / samples_per_unit) - 1.0;
969 zero_line->property_color_rgba() = (guint) ARDOUR_UI::config()->canvasvar_ZeroLine.get();
977 AudioRegionView::peaks_ready_handler (uint32_t which)
979 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
980 // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
984 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
986 if (gain_line == 0) {
992 /* don't create points that can't be seen */
994 set_envelope_visible (true);
1001 nframes_t fx = trackview.editor().pixel_to_frame (x);
1003 if (fx > _region->length()) {
1007 /* compute vertical fractional position */
1009 y = 1.0 - (y / (_height - NAME_HIGHLIGHT_SIZE));
1011 /* map using gain line */
1013 gain_line->view_to_model_coord (x, y);
1015 trackview.session().begin_reversible_command (_("add gain control point"));
1016 XMLNode &before = audio_region()->envelope()->get_state();
1018 if (!audio_region()->envelope_active()) {
1019 XMLNode ®ion_before = audio_region()->get_state();
1020 audio_region()->set_envelope_active(true);
1021 XMLNode ®ion_after = audio_region()->get_state();
1022 trackview.session().add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
1025 audio_region()->envelope()->add (fx, y);
1027 XMLNode &after = audio_region()->envelope()->get_state();
1028 trackview.session().add_command (new MementoCommand<AutomationList>(*audio_region()->envelope().get(), &before, &after));
1029 trackview.session().commit_reversible_command ();
1033 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1035 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1036 audio_region()->envelope()->erase (cp->model());
1040 AudioRegionView::store_flags()
1042 XMLNode *node = new XMLNode ("GUI");
1044 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
1045 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
1046 node->add_property ("waveform-rectified", (_flags & WaveformRectified) ? "yes" : "no");
1047 node->add_property ("waveform-logscaled", (_flags & WaveformLogScaled) ? "yes" : "no");
1049 _region->add_extra_xml (*node);
1053 AudioRegionView::set_flags (XMLNode* node)
1057 if ((prop = node->property ("waveform-visible")) != 0) {
1058 if (prop->value() == "yes") {
1059 _flags |= WaveformVisible;
1063 if ((prop = node->property ("envelope-visible")) != 0) {
1064 if (prop->value() == "yes") {
1065 _flags |= EnvelopeVisible;
1069 if ((prop = node->property ("waveform-rectified")) != 0) {
1070 if (prop->value() == "yes") {
1071 _flags |= WaveformRectified;
1075 if ((prop = node->property ("waveform-logscaled")) != 0) {
1076 if (prop->value() == "yes") {
1077 _flags |= WaveformLogScaled;
1083 AudioRegionView::set_waveform_shape (WaveformShape shape)
1087 /* this slightly odd approach is to leave the door open to
1088 other "shapes" such as spectral displays, etc.
1101 if (yn != (bool) (_flags & WaveformRectified)) {
1102 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1103 (*wave)->property_rectified() = yn;
1115 _flags |= WaveformRectified;
1117 _flags &= ~WaveformRectified;
1124 AudioRegionView::set_waveform_scale (WaveformScale scale)
1126 bool yn = (scale == Logarithmic);
1128 if (yn != (bool) (_flags & WaveformLogScaled)) {
1129 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1130 (*wave)->property_logscaled() = yn;
1134 _flags |= WaveformLogScaled;
1136 _flags &= ~WaveformLogScaled;
1144 AudioRegionView::add_ghost (TimeAxisView& tv)
1146 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1149 double unit_position = _region->position () / samples_per_unit;
1150 AudioGhostRegion* ghost = new AudioGhostRegion (tv, trackview, unit_position);
1153 nchans = rtv->get_diskstream()->n_channels().n_audio();
1155 for (uint32_t n = 0; n < nchans; ++n) {
1157 if (n >= audio_region()->n_channels()) {
1161 WaveView *wave = new WaveView(*ghost->group);
1163 wave->property_data_src() = _region.get();
1164 wave->property_cache() = wave_caches[n];
1165 wave->property_cache_updater() = false;
1166 wave->property_channel() = n;
1167 wave->property_length_function() = (gpointer)region_length_from_c;
1168 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1169 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1170 wave->property_x() = 0.0;
1171 wave->property_samples_per_unit() = samples_per_unit;
1172 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1174 wave->property_region_start() = _region->start();
1176 ghost->waves.push_back(wave);
1179 ghost->set_height ();
1180 ghost->set_duration (_region->length() / samples_per_unit);
1181 ghost->set_colors();
1182 ghosts.push_back (ghost);
1184 ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost));
1190 AudioRegionView::entered ()
1192 if (gain_line && _flags & EnvelopeVisible) {
1193 gain_line->show_all_control_points ();
1197 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1200 if (fade_in_handle) {
1201 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1202 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1207 AudioRegionView::exited ()
1210 gain_line->hide_all_but_selected_control_points ();
1214 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1217 if (fade_in_handle) {
1218 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1219 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1224 AudioRegionView::envelope_active_changed ()
1227 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
1232 AudioRegionView::set_waveview_data_src()
1234 AudioGhostRegion* agr;
1235 double unit_length= _region->length() / samples_per_unit;
1237 for (uint32_t n = 0; n < waves.size(); ++n) {
1238 // TODO: something else to let it know the channel
1239 waves[n]->property_data_src() = _region.get();
1242 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1244 (*i)->set_duration (unit_length);
1246 if((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
1247 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
1248 (*w)->property_data_src() = _region.get();
1256 AudioRegionView::color_handler ()
1258 //case cMutedWaveForm:
1260 //case cWaveFormClip:
1264 //case cGainLineInactive:
1266 envelope_active_changed();
1271 AudioRegionView::set_frame_color ()
1277 if (_region->opaque()) {
1285 if (_selected && should_show_selection) {
1286 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_SelectedFrameBase.get(), &r, &g, &b, &a);
1287 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
1289 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1290 if (_region->muted()) {
1291 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get(), MUTED_ALPHA);
1293 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get();
1294 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveFormFill.get();
1299 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_RecordingRect.get(), &r, &g, &b, &a);
1300 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, a);
1302 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1303 if (_region->muted()) {
1304 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA);
1306 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
1307 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
1311 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_FrameBase.get(), &r, &g, &b, &a);
1312 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
1314 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1315 if (_region->muted()) {
1316 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
1318 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
1319 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
1327 AudioRegionView::set_fade_visibility (bool yn)
1330 if (fade_in_shape) {
1331 fade_in_shape->show();
1333 if (fade_out_shape) {
1334 fade_out_shape->show ();
1336 if (fade_in_handle) {
1337 fade_in_handle->show ();
1339 if (fade_out_handle) {
1340 fade_out_handle->show ();
1343 if (fade_in_shape) {
1344 fade_in_shape->hide();
1346 if (fade_out_shape) {
1347 fade_out_shape->hide ();
1349 if (fade_in_handle) {
1350 fade_in_handle->hide ();
1352 if (fade_out_handle) {
1353 fade_out_handle->hide ();