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
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& 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& 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)
109 , _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)
139 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
140 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
146 AudioRegionView::init (Gdk::Color& basic_color, bool wfd)
148 // FIXME: Some redundancy here with RegionView::init. Need to figure out
149 // where order is important and where it isn't...
151 RegionView::init (basic_color, wfd);
155 _amplitude_above_axis = 1.0;
159 if ((node = _region->extra_xml ("GUI")) != 0) {
162 _flags = WaveformVisible;
166 if (trackview.editor().new_regionviews_display_gain()) {
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 (!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, trackview.session(), *this, *group,
209 audio_region()->envelope());
212 if (!(_flags & EnvelopeVisible)) {
220 set_height (trackview.current_height());
223 region_sync_changed ();
224 region_resized (BoundsChanged);
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 (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
234 fade_in_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
235 fade_out_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
236 fade_out_handle->signal_event().connect (bind (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 /* all waveviews etc will be destroyed when the group is destroyed */
258 boost::shared_ptr<ARDOUR::AudioRegion>
259 AudioRegionView::audio_region() const
261 // "Guaranteed" to succeed...
262 return boost::dynamic_pointer_cast<AudioRegion>(_region);
266 AudioRegionView::region_changed (Change what_changed)
268 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionView::region_changed), what_changed));
269 //cerr << "AudioRegionView::region_changed() called" << endl;
271 RegionView::region_changed(what_changed);
273 if (what_changed & AudioRegion::ScaleAmplitudeChanged) {
274 region_scale_amplitude_changed ();
276 if (what_changed & AudioRegion::FadeInChanged) {
279 if (what_changed & AudioRegion::FadeOutChanged) {
282 if (what_changed & AudioRegion::FadeInActiveChanged) {
283 fade_in_active_changed ();
285 if (what_changed & AudioRegion::FadeOutActiveChanged) {
286 fade_out_active_changed ();
288 if (what_changed & AudioRegion::EnvelopeActiveChanged) {
289 envelope_active_changed ();
294 AudioRegionView::fade_in_changed ()
296 reset_fade_in_shape ();
300 AudioRegionView::fade_out_changed ()
302 reset_fade_out_shape ();
305 AudioRegionView::fade_in_active_changed ()
309 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
311 if (audio_region()->fade_in_active()) {
312 col = RGBA_TO_UINT(r,g,b,120);
313 fade_in_shape->property_fill_color_rgba() = col;
314 fade_in_shape->property_width_pixels() = 0;
315 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
317 col = RGBA_TO_UINT(r,g,b,0);
318 fade_in_shape->property_fill_color_rgba() = col;
319 fade_in_shape->property_width_pixels() = 1;
320 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
325 AudioRegionView::fade_out_active_changed ()
329 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
331 if (audio_region()->fade_out_active()) {
332 col = RGBA_TO_UINT(r,g,b,120);
333 fade_out_shape->property_fill_color_rgba() = col;
334 fade_out_shape->property_width_pixels() = 0;
335 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
337 col = RGBA_TO_UINT(r,g,b,0);
338 fade_out_shape->property_fill_color_rgba() = col;
339 fade_out_shape->property_width_pixels() = 1;
340 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
346 AudioRegionView::region_scale_amplitude_changed ()
348 ENSURE_GUI_THREAD (mem_fun(*this, &AudioRegionView::region_scale_amplitude_changed));
350 for (uint32_t n = 0; n < waves.size(); ++n) {
351 // force a reload of the cache
352 waves[n]->property_data_src() = _region.get();
357 AudioRegionView::region_renamed ()
359 Glib::ustring str = RegionView::make_name ();
361 if (audio_region()->speed_mismatch (trackview.session().frame_rate())) {
362 str = string ("*") + str;
365 if (_region->muted()) {
366 str = string ("!") + str;
369 set_item_name (str, this);
374 AudioRegionView::region_resized (Change what_changed)
376 AudioGhostRegion* agr;
378 RegionView::region_resized(what_changed);
380 if (what_changed & Change (StartChanged|LengthChanged)) {
382 for (uint32_t n = 0; n < waves.size(); ++n) {
383 waves[n]->property_region_start() = _region->start();
386 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
387 if((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
389 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
390 (*w)->property_region_start() = _region->start();
398 AudioRegionView::reset_width_dependent_items (double pixel_width)
400 RegionView::reset_width_dependent_items(pixel_width);
401 assert(_pixel_width == pixel_width);
404 zero_line->property_x2() = pixel_width - 1.0;
407 if (fade_in_handle) {
408 if (pixel_width <= 6.0) {
409 fade_in_handle->hide();
410 fade_out_handle->hide();
413 fade_in_handle->hide();
414 fade_out_handle->hide();
416 if (Config->get_show_region_fades()) {
417 fade_in_handle->show();
418 fade_out_handle->show();
424 reset_fade_shapes ();
428 AudioRegionView::region_muted ()
430 RegionView::region_muted();
432 for (uint32_t n=0; n < waves.size(); ++n) {
433 if (_region->muted()) {
434 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
436 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
442 AudioRegionView::setup_fade_handle_positions()
444 /* position of fade handle offset from the top of the region view */
445 double const handle_pos = 2;
446 /* height of fade handles */
447 double const handle_height = 5;
449 if (fade_in_handle) {
450 fade_in_handle->property_y1() = handle_pos;
451 fade_in_handle->property_y2() = handle_pos + handle_height;
454 if (fade_out_handle) {
455 fade_out_handle->property_y1() = handle_pos;
456 fade_out_handle->property_y2() = handle_pos + handle_height;
461 AudioRegionView::set_height (gdouble height)
463 RegionView::set_height (height);
465 uint32_t wcnt = waves.size();
472 for (uint32_t n=0; n < wcnt; ++n) {
475 if ((height) < NAME_HIGHLIGHT_THRESH) {
476 ht = ((height-2*wcnt) / (double) wcnt);
478 ht = (((height-2*wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
481 gdouble yoff = n * (ht+1);
483 waves[n]->property_height() = ht;
484 waves[n]->property_y() = yoff + 2;
488 if ((height/wcnt) < NAME_HIGHLIGHT_THRESH) {
491 if (_flags & EnvelopeVisible) {
495 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE));
499 reset_fade_shapes ();
502 name_text->raise_to_top();
507 AudioRegionView::manage_zero_line ()
513 if (_height >= 100) {
514 double const wave_midpoint = (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
515 zero_line->property_y1() = wave_midpoint;
516 zero_line->property_y2() = wave_midpoint;
524 AudioRegionView::reset_fade_shapes ()
526 reset_fade_in_shape ();
527 reset_fade_out_shape ();
531 AudioRegionView::reset_fade_in_shape ()
533 reset_fade_in_shape_width ((nframes_t) audio_region()->fade_in()->back()->when);
537 AudioRegionView::reset_fade_in_shape_width (nframes_t width)
539 if (fade_in_handle == 0) {
543 /* smallest size for a fade is 64 frames */
545 width = std::max ((nframes_t) 64, width);
548 double pwidth = width / samples_per_unit;
549 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
553 fade_in_shape->hide();
554 fade_in_handle->hide();
558 double handle_center;
559 handle_center = pwidth;
561 if (handle_center > 7.0) {
562 handle_center -= 3.0;
567 fade_in_handle->property_x1() = handle_center - 3.0;
568 fade_in_handle->property_x2() = handle_center + 3.0;
571 fade_in_shape->hide();
575 if (Config->get_show_region_fades()) {
576 fade_in_shape->show();
579 float curve[npoints];
580 audio_region()->fade_in()->curve().get_vector (0, audio_region()->fade_in()->back()->when, curve, npoints);
582 points = get_canvas_points ("fade in shape", npoints+3);
584 if (_height >= NAME_HIGHLIGHT_THRESH) {
585 h = _height - NAME_HIGHLIGHT_SIZE;
590 /* points *MUST* be in anti-clockwise order */
593 double xdelta = pwidth/npoints;
595 for (pi = 0, pc = 0; pc < npoints; ++pc) {
596 (*points)[pi].set_x(1 + (pc * xdelta));
597 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
602 (*points)[pi].set_x(pwidth);
603 (*points)[pi++].set_y(2);
605 (*points)[pi].set_x(1);
606 (*points)[pi++].set_y(2);
608 /* connect the dots ... */
610 (*points)[pi] = (*points)[0];
612 fade_in_shape->property_points() = *points;
617 AudioRegionView::reset_fade_out_shape ()
619 reset_fade_out_shape_width ((nframes_t) audio_region()->fade_out()->back()->when);
623 AudioRegionView::reset_fade_out_shape_width (nframes_t width)
625 if (fade_out_handle == 0) {
629 /* smallest size for a fade is 64 frames */
631 width = std::max ((nframes_t) 64, width);
634 double pwidth = width / samples_per_unit;
635 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
639 fade_out_shape->hide();
640 fade_out_handle->hide();
644 double handle_center;
645 handle_center = (_region->length() - width) / samples_per_unit;
647 if (handle_center > 7.0) {
648 handle_center -= 3.0;
653 fade_out_handle->property_x1() = handle_center - 3.0;
654 fade_out_handle->property_x2() = handle_center + 3.0;
656 /* don't show shape if its too small */
659 fade_out_shape->hide();
663 if (Config->get_show_region_fades()) {
664 fade_out_shape->show();
667 float curve[npoints];
668 audio_region()->fade_out()->curve().get_vector (0, audio_region()->fade_out()->back()->when, curve, npoints);
670 if (_height >= NAME_HIGHLIGHT_THRESH) {
671 h = _height - NAME_HIGHLIGHT_SIZE;
676 /* points *MUST* be in anti-clockwise order */
678 points = get_canvas_points ("fade out shape", npoints+3);
681 double xdelta = pwidth/npoints;
683 for (pi = 0, pc = 0; pc < npoints; ++pc) {
684 (*points)[pi].set_x(_pixel_width - 1 - pwidth + (pc*xdelta));
685 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
690 (*points)[pi].set_x(_pixel_width);
691 (*points)[pi++].set_y(h);
693 (*points)[pi].set_x(_pixel_width);
694 (*points)[pi++].set_y(2);
696 /* connect the dots ... */
698 (*points)[pi] = (*points)[0];
700 fade_out_shape->property_points() = *points;
705 AudioRegionView::set_samples_per_unit (gdouble spu)
707 RegionView::set_samples_per_unit (spu);
709 if (_flags & WaveformVisible) {
710 for (uint32_t n=0; n < waves.size(); ++n) {
711 waves[n]->property_samples_per_unit() = spu;
719 reset_fade_shapes ();
723 AudioRegionView::set_amplitude_above_axis (gdouble spp)
725 for (uint32_t n=0; n < waves.size(); ++n) {
726 waves[n]->property_amplitude_above_axis() = spp;
731 AudioRegionView::compute_colors (Gdk::Color& basic_color)
733 RegionView::compute_colors(basic_color);
737 /* gain color computed in envelope_active_changed() */
739 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
740 fade_color = RGBA_TO_UINT(r,g,b,120);
744 AudioRegionView::set_colors ()
746 RegionView::set_colors();
749 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
752 for (uint32_t n=0; n < waves.size(); ++n) {
753 if (_region->muted()) {
754 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
756 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
759 waves[n]->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
760 waves[n]->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
765 AudioRegionView::show_region_editor ()
768 editor = new AudioRegionEditor (trackview.session(), audio_region(), *this);
769 // GTK2FIX : how to ensure float without realizing
770 // editor->realize ();
771 // trackview.editor.ensure_float (*editor);
779 AudioRegionView::set_waveform_visible (bool yn)
781 if (((_flags & WaveformVisible) != yn)) {
783 for (uint32_t n=0; n < waves.size(); ++n) {
784 /* make sure the zoom level is correct, since we don't update
785 this when waveforms are hidden.
787 waves[n]->property_samples_per_unit() = samples_per_unit;
790 _flags |= WaveformVisible;
792 for (uint32_t n=0; n < waves.size(); ++n) {
795 _flags &= ~WaveformVisible;
802 AudioRegionView::temporarily_hide_envelope ()
810 AudioRegionView::unhide_envelope ()
812 if (gain_line && (_flags & EnvelopeVisible)) {
818 AudioRegionView::set_envelope_visible (bool yn)
820 if (gain_line && ((_flags & EnvelopeVisible) != yn)) {
823 _flags |= EnvelopeVisible;
826 _flags &= ~EnvelopeVisible;
833 AudioRegionView::create_waves ()
835 // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
836 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
838 if (!atv.get_diskstream()) {
842 ChanCount nchans = atv.get_diskstream()->n_channels();
844 // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data
845 // << " and channels = " << nchans.n_audio() << endl;
847 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
848 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
849 tmp_waves.push_back (0);
852 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
854 if (n >= audio_region()->n_channels()) {
858 wave_caches.push_back (WaveView::create_cache ());
860 // cerr << "\tchannel " << n << endl;
863 if (audio_region()->audio_source(n)->peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n), data_ready_connection)) {
864 // cerr << "\tData is ready\n";
865 cerr << "\tData is ready\n";
866 // cerr << "\tData is ready\n";
867 create_one_wave (n, true);
869 // cerr << "\tdata is not ready\n";
870 // we'll get a PeaksReady signal from the source in the future
871 // and will call create_one_wave(n) then.
875 // cerr << "\tdon't delay, display today!\n";
876 create_one_wave (n, true);
883 AudioRegionView::create_one_wave (uint32_t which, bool direct)
885 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
886 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
887 uint32_t nchans = atv.get_diskstream()->n_channels().n_audio();
889 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
892 if (trackview.current_height() < NAME_HIGHLIGHT_THRESH) {
893 ht = ((trackview.current_height()) / (double) nchans);
895 ht = ((trackview.current_height() - NAME_HIGHLIGHT_SIZE) / (double) nchans);
898 gdouble yoff = which * ht;
900 WaveView *wave = new WaveView(*group);
902 wave->property_data_src() = (gpointer) _region.get();
903 wave->property_cache() = wave_caches[which];
904 wave->property_cache_updater() = true;
905 wave->property_channel() = which;
906 wave->property_length_function() = (gpointer) region_length_from_c;
907 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
908 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
909 wave->property_x() = 0.0;
910 wave->property_y() = yoff;
911 wave->property_height() = (double) ht;
912 wave->property_samples_per_unit() = samples_per_unit;
913 wave->property_amplitude_above_axis() = _amplitude_above_axis;
916 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
917 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
919 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_WaveForm.get();
920 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
923 wave->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
924 wave->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
925 wave->property_region_start() = _region->start();
926 wave->property_rectified() = (bool) (_flags & WaveformRectified);
927 wave->property_logscaled() = (bool) (_flags & WaveformLogScaled);
929 if (!(_flags & WaveformVisible)) {
933 /* note: calling this function is serialized by the lock
934 held in the peak building thread that signals that
935 peaks are ready for use *or* by the fact that it is
936 called one by one from the GUI thread.
939 if (which < nchans) {
940 tmp_waves[which] = wave;
942 /* n-channel track, >n-channel source */
945 /* see if we're all ready */
947 for (n = 0; n < nchans; ++n) {
948 if (tmp_waves[n] == 0) {
953 if (n == nwaves && waves.empty()) {
954 /* all waves are ready */
955 tmp_waves.resize(nwaves);
960 /* all waves created, don't hook into peaks ready anymore */
961 data_ready_connection.disconnect ();
965 zero_line = new ArdourCanvas::SimpleLine (*group);
966 zero_line->property_x1() = (gdouble) 1.0;
967 zero_line->property_x2() = (gdouble) (_region->length() / samples_per_unit) - 1.0;
968 zero_line->property_color_rgba() = (guint) ARDOUR_UI::config()->canvasvar_ZeroLine.get();
976 AudioRegionView::peaks_ready_handler (uint32_t which)
978 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
979 // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
983 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
985 if (gain_line == 0) {
991 /* don't create points that can't be seen */
993 set_envelope_visible (true);
1000 nframes_t fx = trackview.editor().pixel_to_frame (x);
1002 if (fx > _region->length()) {
1006 /* compute vertical fractional position */
1008 y = 1.0 - (y / (_height - NAME_HIGHLIGHT_SIZE));
1010 /* map using gain line */
1012 gain_line->view_to_model_coord (x, y);
1014 trackview.session().begin_reversible_command (_("add gain control point"));
1015 XMLNode &before = audio_region()->envelope()->get_state();
1017 if (!audio_region()->envelope_active()) {
1018 XMLNode ®ion_before = audio_region()->get_state();
1019 audio_region()->set_envelope_active(true);
1020 XMLNode ®ion_after = audio_region()->get_state();
1021 trackview.session().add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
1024 audio_region()->envelope()->add (fx, y);
1026 XMLNode &after = audio_region()->envelope()->get_state();
1027 trackview.session().add_command (new MementoCommand<AutomationList>(*audio_region()->envelope().get(), &before, &after));
1028 trackview.session().commit_reversible_command ();
1032 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1034 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1035 audio_region()->envelope()->erase (cp->model());
1039 AudioRegionView::store_flags()
1041 XMLNode *node = new XMLNode ("GUI");
1043 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
1044 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
1045 node->add_property ("waveform-rectified", (_flags & WaveformRectified) ? "yes" : "no");
1046 node->add_property ("waveform-logscaled", (_flags & WaveformLogScaled) ? "yes" : "no");
1048 _region->add_extra_xml (*node);
1052 AudioRegionView::set_flags (XMLNode* node)
1056 if ((prop = node->property ("waveform-visible")) != 0) {
1057 if (prop->value() == "yes") {
1058 _flags |= WaveformVisible;
1062 if ((prop = node->property ("envelope-visible")) != 0) {
1063 if (prop->value() == "yes") {
1064 _flags |= EnvelopeVisible;
1068 if ((prop = node->property ("waveform-rectified")) != 0) {
1069 if (prop->value() == "yes") {
1070 _flags |= WaveformRectified;
1074 if ((prop = node->property ("waveform-logscaled")) != 0) {
1075 if (prop->value() == "yes") {
1076 _flags |= WaveformLogScaled;
1082 AudioRegionView::set_waveform_shape (WaveformShape shape)
1086 /* this slightly odd approach is to leave the door open to
1087 other "shapes" such as spectral displays, etc.
1100 if (yn != (bool) (_flags & WaveformRectified)) {
1101 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1102 (*wave)->property_rectified() = yn;
1114 _flags |= WaveformRectified;
1116 _flags &= ~WaveformRectified;
1123 AudioRegionView::set_waveform_scale (WaveformScale scale)
1125 bool yn = (scale == LogWaveform);
1127 if (yn != (bool) (_flags & WaveformLogScaled)) {
1128 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1129 (*wave)->property_logscaled() = yn;
1133 _flags |= WaveformLogScaled;
1135 _flags &= ~WaveformLogScaled;
1143 AudioRegionView::add_ghost (TimeAxisView& tv)
1145 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1148 double unit_position = _region->position () / samples_per_unit;
1149 AudioGhostRegion* ghost = new AudioGhostRegion (tv, trackview, unit_position);
1152 nchans = rtv->get_diskstream()->n_channels().n_audio();
1154 for (uint32_t n = 0; n < nchans; ++n) {
1156 if (n >= audio_region()->n_channels()) {
1160 WaveView *wave = new WaveView(*ghost->group);
1162 wave->property_data_src() = _region.get();
1163 wave->property_cache() = wave_caches[n];
1164 wave->property_cache_updater() = false;
1165 wave->property_channel() = n;
1166 wave->property_length_function() = (gpointer)region_length_from_c;
1167 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1168 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1169 wave->property_x() = 0.0;
1170 wave->property_samples_per_unit() = samples_per_unit;
1171 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1173 wave->property_region_start() = _region->start();
1175 ghost->waves.push_back(wave);
1178 ghost->set_height ();
1179 ghost->set_duration (_region->length() / samples_per_unit);
1180 ghost->set_colors();
1181 ghosts.push_back (ghost);
1183 ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost));
1189 AudioRegionView::entered ()
1191 if (gain_line && _flags & EnvelopeVisible) {
1192 gain_line->show_all_control_points ();
1196 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1199 if (fade_in_handle) {
1200 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1201 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1206 AudioRegionView::exited ()
1209 gain_line->hide_all_but_selected_control_points ();
1213 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1216 if (fade_in_handle) {
1217 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1218 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1223 AudioRegionView::envelope_active_changed ()
1226 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
1231 AudioRegionView::set_waveview_data_src()
1233 AudioGhostRegion* agr;
1234 double unit_length= _region->length() / samples_per_unit;
1236 for (uint32_t n = 0; n < waves.size(); ++n) {
1237 // TODO: something else to let it know the channel
1238 waves[n]->property_data_src() = _region.get();
1241 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1243 (*i)->set_duration (unit_length);
1245 if((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
1246 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
1247 (*w)->property_data_src() = _region.get();
1255 AudioRegionView::color_handler ()
1257 //case cMutedWaveForm:
1259 //case cWaveFormClip:
1263 //case cGainLineInactive:
1265 envelope_active_changed();
1270 AudioRegionView::set_frame_color ()
1276 if (_region->opaque()) {
1284 if (_selected && should_show_selection) {
1285 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_SelectedFrameBase.get(), &r, &g, &b, &a);
1286 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
1288 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1289 if (_region->muted()) {
1290 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get(), MUTED_ALPHA);
1292 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get();
1293 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveFormFill.get();
1298 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_RecordingRect.get(), &r, &g, &b, &a);
1299 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, a);
1301 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1302 if (_region->muted()) {
1303 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA);
1305 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
1306 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
1310 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_FrameBase.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_WaveForm.get(), MUTED_ALPHA);
1317 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
1318 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
1326 AudioRegionView::set_fade_visibility (bool yn)
1329 if (fade_in_shape) {
1330 fade_in_shape->show();
1332 if (fade_out_shape) {
1333 fade_out_shape->show ();
1335 if (fade_in_handle) {
1336 fade_in_handle->show ();
1338 if (fade_out_handle) {
1339 fade_out_handle->show ();
1342 if (fade_in_shape) {
1343 fade_in_shape->hide();
1345 if (fade_out_shape) {
1346 fade_out_shape->hide ();
1348 if (fade_in_handle) {
1349 fade_in_handle->hide ();
1351 if (fade_out_handle) {
1352 fade_out_handle->hide ();