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.
26 #include <gtkmm2ext/gtk_ui.h>
28 #include <ardour/playlist.h>
29 #include <ardour/audioregion.h>
30 #include <ardour/audiosource.h>
31 #include <ardour/audio_diskstream.h>
32 #include <ardour/profile.h>
33 #include <pbd/memento_command.h>
34 #include <pbd/stacktrace.h>
36 #include "streamview.h"
37 #include "audio_region_view.h"
38 #include "audio_time_axis.h"
39 #include "simplerect.h"
40 #include "simpleline.h"
42 #include "public_editor.h"
43 #include "audio_region_editor.h"
44 #include "region_gain_line.h"
45 #include "ghostregion.h"
46 #include "audio_time_axis.h"
48 #include "rgb_macros.h"
49 #include "gui_thread.h"
50 #include "ardour_ui.h"
54 #define MUTED_ALPHA 10
57 using namespace ARDOUR;
59 using namespace Editing;
60 using namespace ArdourCanvas;
62 static const int32_t sync_mark_width = 9;
64 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
65 Gdk::Color& basic_color)
66 : RegionView (parent, tv, r, spu, basic_color)
74 , _amplitude_above_axis(1.0)
80 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
81 Gdk::Color& basic_color, TimeAxisViewItem::Visibility visibility)
82 : RegionView (parent, tv, r, spu, basic_color, visibility)
90 , _amplitude_above_axis(1.0)
97 AudioRegionView::AudioRegionView (const AudioRegionView& other)
105 , _amplitude_above_axis(1.0)
113 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
114 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
119 AudioRegionView::AudioRegionView (const AudioRegionView& other, boost::shared_ptr<AudioRegion> other_region)
120 : RegionView (other, boost::shared_ptr<Region> (other_region))
127 , _amplitude_above_axis(1.0)
135 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
136 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
142 AudioRegionView::init (Gdk::Color& basic_color, bool wfd)
144 // FIXME: Some redundancy here with RegionView::init. Need to figure out
145 // where order is important and where it isn't...
147 RegionView::init (basic_color, wfd);
151 _amplitude_above_axis = 1.0;
155 if ((node = _region->extra_xml ("GUI")) != 0) {
158 _flags = WaveformVisible;
162 if (trackview.editor.new_regionviews_display_gain()) {
163 _flags |= EnvelopeVisible;
166 compute_colors (basic_color);
170 fade_in_shape = new ArdourCanvas::Polygon (*group);
171 fade_in_shape->property_fill_color_rgba() = fade_color;
172 fade_in_shape->set_data ("regionview", this);
174 fade_out_shape = new ArdourCanvas::Polygon (*group);
175 fade_out_shape->property_fill_color_rgba() = fade_color;
176 fade_out_shape->set_data ("regionview", this);
181 UINT_TO_RGBA(fill_color,&r,&g,&b,&a);
184 fade_in_handle = new ArdourCanvas::SimpleRect (*group);
185 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
186 fade_in_handle->property_outline_pixels() = 0;
187 fade_in_handle->property_y1() = 2.0;
188 fade_in_handle->property_y2() = 7.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;
195 fade_out_handle->property_y1() = 2.0;
196 fade_out_handle->property_y2() = 7.0;
198 fade_out_handle->set_data ("regionview", this);
201 string foo = _region->name();
205 if (!Profile->get_sae()) {
206 gain_line = new AudioRegionGainLine (foo, trackview.session(), *this, *group, audio_region()->envelope());
208 if (!(_flags & EnvelopeVisible)) {
217 set_height (trackview.height);
220 region_sync_changed ();
221 region_resized (BoundsChanged);
222 set_waveview_data_src();
224 envelope_active_changed ();
225 fade_in_active_changed ();
226 fade_out_active_changed ();
228 _region->StateChanged.connect (mem_fun(*this, &AudioRegionView::region_changed));
230 fade_in_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
231 fade_in_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
232 fade_out_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
233 fade_out_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
237 /* XXX sync mark drag? */
240 AudioRegionView::~AudioRegionView ()
242 in_destructor = true;
244 RegionViewGoingAway (this); /* EMIT_SIGNAL */
246 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
247 gnome_canvas_waveview_cache_destroy (*cache);
250 /* all waveviews etc will be destroyed when the group is destroyed */
257 boost::shared_ptr<ARDOUR::AudioRegion>
258 AudioRegionView::audio_region() const
260 // "Guaranteed" to succeed...
261 return boost::dynamic_pointer_cast<AudioRegion>(_region);
265 AudioRegionView::region_changed (Change what_changed)
267 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionView::region_changed), what_changed));
269 RegionView::region_changed(what_changed);
271 if (what_changed & AudioRegion::ScaleAmplitudeChanged) {
272 region_scale_amplitude_changed ();
274 if (what_changed & AudioRegion::FadeInChanged) {
277 if (what_changed & AudioRegion::FadeOutChanged) {
280 if (what_changed & AudioRegion::FadeInActiveChanged) {
281 fade_in_active_changed ();
283 if (what_changed & AudioRegion::FadeOutActiveChanged) {
284 fade_out_active_changed ();
286 if (what_changed & AudioRegion::EnvelopeActiveChanged) {
287 envelope_active_changed ();
292 AudioRegionView::fade_in_changed ()
294 reset_fade_in_shape ();
298 AudioRegionView::fade_out_changed ()
300 reset_fade_out_shape ();
303 AudioRegionView::fade_in_active_changed ()
307 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
309 if (audio_region()->fade_in_active()) {
310 col = RGBA_TO_UINT(r,g,b,120);
311 fade_in_shape->property_fill_color_rgba() = col;
312 fade_in_shape->property_width_pixels() = 0;
313 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
315 col = RGBA_TO_UINT(r,g,b,0);
316 fade_in_shape->property_fill_color_rgba() = col;
317 fade_in_shape->property_width_pixels() = 1;
318 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
323 AudioRegionView::fade_out_active_changed ()
327 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
329 if (audio_region()->fade_out_active()) {
330 col = RGBA_TO_UINT(r,g,b,120);
331 fade_out_shape->property_fill_color_rgba() = col;
332 fade_out_shape->property_width_pixels() = 0;
333 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
335 col = RGBA_TO_UINT(r,g,b,0);
336 fade_out_shape->property_fill_color_rgba() = col;
337 fade_out_shape->property_width_pixels() = 1;
338 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
344 AudioRegionView::region_scale_amplitude_changed ()
346 ENSURE_GUI_THREAD (mem_fun(*this, &AudioRegionView::region_scale_amplitude_changed));
348 for (uint32_t n = 0; n < waves.size(); ++n) {
349 // force a reload of the cache
350 waves[n]->property_data_src() = _region.get();
355 AudioRegionView::region_resized (Change what_changed)
357 RegionView::region_resized(what_changed);
359 if (what_changed & Change (StartChanged|LengthChanged)) {
361 for (uint32_t n = 0; n < waves.size(); ++n) {
362 waves[n]->property_region_start() = _region->start();
365 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
367 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
368 (*w)->property_region_start() = _region->start();
375 AudioRegionView::reset_width_dependent_items (double pixel_width)
377 RegionView::reset_width_dependent_items(pixel_width);
378 assert(_pixel_width == pixel_width);
381 zero_line->property_x2() = pixel_width - 1.0;
384 if (fade_in_handle) {
385 if (pixel_width <= 6.0) {
386 fade_in_handle->hide();
387 fade_out_handle->hide();
390 fade_in_handle->hide();
391 fade_out_handle->hide();
393 fade_in_handle->show();
394 fade_out_handle->show();
399 reset_fade_shapes ();
403 AudioRegionView::region_muted ()
405 RegionView::region_muted();
407 for (uint32_t n=0; n < waves.size(); ++n) {
408 if (_region->muted()) {
409 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
411 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
418 AudioRegionView::set_height (gdouble height)
420 RegionView::set_height (height);
422 uint32_t wcnt = waves.size();
425 TimeAxisViewItem::set_height (height - 2);
429 for (uint32_t n=0; n < wcnt; ++n) {
432 if ((height) <= NAME_HIGHLIGHT_THRESH) {
433 ht = ((height-2*wcnt) / (double) wcnt);
435 ht = (((height-2*wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
438 gdouble yoff = n * (ht+1);
440 waves[n]->property_height() = ht;
441 waves[n]->property_y() = yoff + 2;
445 if ((height/wcnt) < NAME_HIGHLIGHT_SIZE) {
448 if (_flags & EnvelopeVisible) {
452 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE));
456 reset_fade_shapes ();
459 name_text->raise_to_top();
464 AudioRegionView::manage_zero_line ()
470 if (_height >= 100) {
471 gdouble wave_midpoint = (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
472 zero_line->property_y1() = wave_midpoint;
473 zero_line->property_y2() = wave_midpoint;
481 AudioRegionView::reset_fade_shapes ()
483 reset_fade_in_shape ();
484 reset_fade_out_shape ();
488 AudioRegionView::reset_fade_in_shape ()
490 reset_fade_in_shape_width ((nframes_t) audio_region()->fade_in().back()->when);
494 AudioRegionView::reset_fade_in_shape_width (nframes_t width)
496 if (fade_in_handle == 0) {
500 /* smallest size for a fade is 64 frames */
502 width = std::max ((nframes_t) 64, width);
505 double pwidth = width / samples_per_unit;
506 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
510 fade_in_shape->hide();
511 fade_in_handle->hide();
515 double handle_center;
516 handle_center = pwidth;
518 if (handle_center > 7.0) {
519 handle_center -= 3.0;
524 fade_in_handle->property_x1() = handle_center - 3.0;
525 fade_in_handle->property_x2() = handle_center + 3.0;
528 fade_in_shape->hide();
532 fade_in_shape->show();
534 float curve[npoints];
535 audio_region()->fade_in().get_vector (0, audio_region()->fade_in().back()->when, curve, npoints);
537 points = get_canvas_points ("fade in shape", npoints+3);
539 if (_height > NAME_HIGHLIGHT_THRESH) {
540 h = _height - NAME_HIGHLIGHT_SIZE;
545 /* points *MUST* be in anti-clockwise order */
548 double xdelta = pwidth/npoints;
550 for (pi = 0, pc = 0; pc < npoints; ++pc) {
551 (*points)[pi].set_x(1 + (pc * xdelta));
552 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
557 (*points)[pi].set_x(pwidth);
558 (*points)[pi++].set_y(2);
560 (*points)[pi].set_x(1);
561 (*points)[pi++].set_y(2);
563 /* connect the dots ... */
565 (*points)[pi] = (*points)[0];
567 fade_in_shape->property_points() = *points;
572 AudioRegionView::reset_fade_out_shape ()
574 reset_fade_out_shape_width ((nframes_t) audio_region()->fade_out().back()->when);
578 AudioRegionView::reset_fade_out_shape_width (nframes_t width)
580 if (fade_out_handle == 0) {
584 /* smallest size for a fade is 64 frames */
586 width = std::max ((nframes_t) 64, width);
589 double pwidth = width / samples_per_unit;
590 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
594 fade_out_shape->hide();
595 fade_out_handle->hide();
599 double handle_center;
600 handle_center = (_region->length() - width) / samples_per_unit;
602 if (handle_center > 7.0) {
603 handle_center -= 3.0;
608 fade_out_handle->property_x1() = handle_center - 3.0;
609 fade_out_handle->property_x2() = handle_center + 3.0;
611 /* don't show shape if its too small */
614 fade_out_shape->hide();
618 fade_out_shape->show();
620 float curve[npoints];
621 audio_region()->fade_out().get_vector (0, audio_region()->fade_out().back()->when, curve, npoints);
623 if (_height > NAME_HIGHLIGHT_THRESH) {
624 h = _height - NAME_HIGHLIGHT_SIZE;
629 /* points *MUST* be in anti-clockwise order */
631 points = get_canvas_points ("fade out shape", npoints+3);
634 double xdelta = pwidth/npoints;
636 for (pi = 0, pc = 0; pc < npoints; ++pc) {
637 (*points)[pi].set_x(_pixel_width - 1 - pwidth + (pc*xdelta));
638 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
643 (*points)[pi].set_x(_pixel_width);
644 (*points)[pi++].set_y(h);
646 (*points)[pi].set_x(_pixel_width);
647 (*points)[pi++].set_y(2);
649 /* connect the dots ... */
651 (*points)[pi] = (*points)[0];
653 fade_out_shape->property_points() = *points;
658 AudioRegionView::set_samples_per_unit (gdouble spu)
660 RegionView::set_samples_per_unit (spu);
662 if (_flags & WaveformVisible) {
663 for (uint32_t n=0; n < waves.size(); ++n) {
664 waves[n]->property_samples_per_unit() = spu;
672 reset_fade_shapes ();
676 AudioRegionView::set_amplitude_above_axis (gdouble spp)
678 for (uint32_t n=0; n < waves.size(); ++n) {
679 waves[n]->property_amplitude_above_axis() = spp;
684 AudioRegionView::compute_colors (Gdk::Color& basic_color)
686 RegionView::compute_colors(basic_color);
690 /* gain color computed in envelope_active_changed() */
692 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
693 fade_color = RGBA_TO_UINT(r,g,b,120);
697 AudioRegionView::set_colors ()
699 RegionView::set_colors();
702 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
705 for (uint32_t n=0; n < waves.size(); ++n) {
706 if (_region->muted()) {
707 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
709 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
712 waves[n]->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
713 waves[n]->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
718 AudioRegionView::show_region_editor ()
721 editor = new AudioRegionEditor (trackview.session(), audio_region(), *this);
722 // GTK2FIX : how to ensure float without realizing
723 // editor->realize ();
724 // trackview.editor.ensure_float (*editor);
732 AudioRegionView::set_waveform_visible (bool yn)
734 if (((_flags & WaveformVisible) != yn)) {
736 for (uint32_t n=0; n < waves.size(); ++n) {
737 /* make sure the zoom level is correct, since we don't update
738 this when waveforms are hidden.
740 waves[n]->property_samples_per_unit() = samples_per_unit;
743 _flags |= WaveformVisible;
745 for (uint32_t n=0; n < waves.size(); ++n) {
748 _flags &= ~WaveformVisible;
755 AudioRegionView::temporarily_hide_envelope ()
763 AudioRegionView::unhide_envelope ()
765 if (gain_line && (_flags & EnvelopeVisible)) {
771 AudioRegionView::set_envelope_visible (bool yn)
773 if (gain_line && ((_flags & EnvelopeVisible) != yn)) {
776 _flags |= EnvelopeVisible;
779 _flags &= ~EnvelopeVisible;
786 AudioRegionView::create_waves ()
788 // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
789 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
791 if (!atv.get_diskstream()) {
795 uint32_t nchans = atv.get_diskstream()->n_channels();
797 // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data << " and channels = " << nchans << endl;
799 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
800 for (uint32_t n = 0; n < nchans; ++n) {
801 tmp_waves.push_back (0);
804 for (uint32_t n = 0; n < nchans; ++n) {
806 if (n >= audio_region()->n_channels()) {
810 wave_caches.push_back (WaveView::create_cache ());
812 // cerr << "\tchannel " << n << endl;
815 if (audio_region()->source(n)->peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n), data_ready_connection)) {
816 // cerr << "\tData is ready\n";
817 create_one_wave (n, true);
819 // cerr << "\tdata is not ready\n";
820 // we'll get a PeaksReady signal from the source in the future
821 // and will call create_one_wave(n) then.
825 // cerr << "\tdon't delay, display today!\n";
826 create_one_wave (n, true);
833 AudioRegionView::create_one_wave (uint32_t which, bool direct)
835 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
836 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
837 uint32_t nchans = atv.get_diskstream()->n_channels();
839 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
842 if (trackview.height < NAME_HIGHLIGHT_SIZE) {
843 ht = ((trackview.height) / (double) nchans);
845 ht = ((trackview.height - NAME_HIGHLIGHT_SIZE) / (double) nchans);
848 gdouble yoff = which * ht;
850 WaveView *wave = new WaveView(*group);
852 wave->property_data_src() = (gpointer) _region.get();
853 wave->property_cache() = wave_caches[which];
854 wave->property_cache_updater() = true;
855 wave->property_channel() = which;
856 wave->property_length_function() = (gpointer) region_length_from_c;
857 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
858 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
859 wave->property_x() = 0.0;
860 wave->property_y() = yoff;
861 wave->property_height() = (double) ht;
862 wave->property_samples_per_unit() = samples_per_unit;
863 wave->property_amplitude_above_axis() = _amplitude_above_axis;
864 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_WaveForm.get();
865 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
866 wave->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
867 wave->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
868 wave->property_region_start() = _region->start();
869 wave->property_rectified() = (bool) (_flags & WaveformRectified);
870 wave->property_logscaled() = (bool) (_flags & WaveformLogScaled);
872 if (!(_flags & WaveformVisible)) {
876 /* note: calling this function is serialized by the lock
877 held in the peak building thread that signals that
878 peaks are ready for use *or* by the fact that it is
879 called one by one from the GUI thread.
882 if (which < nchans) {
883 tmp_waves[which] = wave;
885 /* n-channel track, >n-channel source */
888 /* see if we're all ready */
890 for (n = 0; n < nchans; ++n) {
891 if (tmp_waves[n] == 0) {
896 if (n == nwaves && waves.empty()) {
897 /* all waves are ready */
898 tmp_waves.resize(nwaves);
903 /* all waves created, don't hook into peaks ready anymore */
904 data_ready_connection.disconnect ();
907 zero_line = new ArdourCanvas::SimpleLine (*group);
908 zero_line->property_x1() = (gdouble) 1.0;
909 zero_line->property_x2() = (gdouble) (_region->length() / samples_per_unit) - 1.0;
910 zero_line->property_color_rgba() = (guint) ARDOUR_UI::config()->canvasvar_ZeroLine.get();
917 AudioRegionView::peaks_ready_handler (uint32_t which)
919 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
920 // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
924 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
926 if (gain_line == 0) {
932 /* don't create points that can't be seen */
934 set_envelope_visible (true);
941 nframes_t fx = trackview.editor.pixel_to_frame (x);
943 if (fx > _region->length()) {
947 /* compute vertical fractional position */
949 y = 1.0 - (y / (trackview.height - NAME_HIGHLIGHT_SIZE));
951 /* map using gain line */
953 gain_line->view_to_model_y (y);
955 trackview.session().begin_reversible_command (_("add gain control point"));
956 XMLNode &before = audio_region()->envelope().get_state();
958 if (!audio_region()->envelope_active()) {
959 XMLNode ®ion_before = audio_region()->get_state();
960 audio_region()->set_envelope_active(true);
961 XMLNode ®ion_after = audio_region()->get_state();
962 trackview.session().add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
965 audio_region()->envelope().add (fx, y);
967 XMLNode &after = audio_region()->envelope().get_state();
968 trackview.session().add_command (new MementoCommand<Curve>(audio_region()->envelope(), &before, &after));
969 trackview.session().commit_reversible_command ();
973 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
975 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
976 audio_region()->envelope().erase (cp->model);
980 AudioRegionView::store_flags()
982 XMLNode *node = new XMLNode ("GUI");
984 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
985 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
986 node->add_property ("waveform-rectified", (_flags & WaveformRectified) ? "yes" : "no");
987 node->add_property ("waveform-logscaled", (_flags & WaveformLogScaled) ? "yes" : "no");
989 _region->add_extra_xml (*node);
993 AudioRegionView::set_flags (XMLNode* node)
997 if ((prop = node->property ("waveform-visible")) != 0) {
998 if (prop->value() == "yes") {
999 _flags |= WaveformVisible;
1003 if ((prop = node->property ("envelope-visible")) != 0) {
1004 if (prop->value() == "yes") {
1005 _flags |= EnvelopeVisible;
1009 if ((prop = node->property ("waveform-rectified")) != 0) {
1010 if (prop->value() == "yes") {
1011 _flags |= WaveformRectified;
1015 if ((prop = node->property ("waveform-logscaled")) != 0) {
1016 if (prop->value() == "yes") {
1017 _flags |= WaveformLogScaled;
1023 AudioRegionView::set_waveform_shape (WaveformShape shape)
1027 /* this slightly odd approach is to leave the door open to
1028 other "shapes" such as spectral displays, etc.
1041 if (yn != (bool) (_flags & WaveformRectified)) {
1042 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1043 (*wave)->property_rectified() = yn;
1055 _flags |= WaveformRectified;
1057 _flags &= ~WaveformRectified;
1064 AudioRegionView::set_waveform_scale (WaveformScale scale)
1066 bool yn = (scale == LogWaveform);
1068 if (yn != (bool) (_flags & WaveformLogScaled)) {
1069 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1070 (*wave)->property_logscaled() = yn;
1074 _flags |= WaveformLogScaled;
1076 _flags &= ~WaveformLogScaled;
1084 AudioRegionView::add_ghost (AutomationTimeAxisView& atv)
1086 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1089 double unit_position = _region->position () / samples_per_unit;
1090 GhostRegion* ghost = new GhostRegion (atv, unit_position);
1093 nchans = rtv->get_diskstream()->n_channels();
1095 for (uint32_t n = 0; n < nchans; ++n) {
1097 if (n >= audio_region()->n_channels()) {
1101 WaveView *wave = new WaveView(*ghost->group);
1103 wave->property_data_src() = _region.get();
1104 wave->property_cache() = wave_caches[n];
1105 wave->property_cache_updater() = false;
1106 wave->property_channel() = n;
1107 wave->property_length_function() = (gpointer)region_length_from_c;
1108 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1109 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1110 wave->property_x() = 0.0;
1111 wave->property_samples_per_unit() = samples_per_unit;
1112 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1113 wave->property_wave_color() = ARDOUR_UI::config()->canvasvar_GhostTrackWave.get();
1114 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_GhostTrackWave.get();
1115 wave->property_clip_color() = ARDOUR_UI::config()->canvasvar_GhostTrackWaveClip.get();
1116 wave->property_zero_color() = ARDOUR_UI::config()->canvasvar_GhostTrackZeroLine.get();
1117 wave->property_region_start() = _region->start();
1119 ghost->waves.push_back(wave);
1122 ghost->set_height ();
1123 ghost->set_duration (_region->length() / samples_per_unit);
1124 ghosts.push_back (ghost);
1126 ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost));
1132 AudioRegionView::entered ()
1134 if (gain_line && _flags & EnvelopeVisible) {
1135 gain_line->show_all_control_points ();
1139 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1142 if (fade_in_handle) {
1143 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1144 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1149 AudioRegionView::exited ()
1152 gain_line->hide_all_but_selected_control_points ();
1156 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1159 if (fade_in_handle) {
1160 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1161 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1166 AudioRegionView::envelope_active_changed ()
1169 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
1174 AudioRegionView::set_waveview_data_src()
1177 double unit_length= _region->length() / samples_per_unit;
1179 for (uint32_t n = 0; n < waves.size(); ++n) {
1180 // TODO: something else to let it know the channel
1181 waves[n]->property_data_src() = _region.get();
1184 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1186 (*i)->set_duration (unit_length);
1188 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
1189 (*w)->property_data_src() = _region.get();
1196 AudioRegionView::color_handler ()
1199 envelope_active_changed();
1203 AudioRegionView::set_frame_color ()
1209 if (_region->opaque()) {
1217 if (_selected && should_show_selection) {
1218 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_SelectedFrameBase.get(), &r, &g, &b, &a);
1219 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
1221 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1222 if (_region->muted()) {
1223 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get(), MUTED_ALPHA);
1225 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get();
1226 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveFormFill.get();
1230 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_FrameBase.get(), &r, &g, &b, &a);
1231 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
1233 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1234 if (_region->muted()) {
1235 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
1237 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
1238 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();