2 Copyright (C) 2001-2006 Paul Davis
4 This program is free software; you can redistribute 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 <pbd/memento_command.h>
32 #include <pbd/stacktrace.h>
34 #include "streamview.h"
35 #include "audio_region_view.h"
36 #include "audio_time_axis.h"
37 #include "simplerect.h"
38 #include "simpleline.h"
40 #include "public_editor.h"
41 #include "audio_region_editor.h"
42 #include "region_gain_line.h"
43 #include "ghostregion.h"
44 #include "audio_time_axis.h"
46 #include "rgb_macros.h"
47 #include "gui_thread.h"
52 using namespace ARDOUR;
54 using namespace Editing;
55 using namespace ArdourCanvas;
57 static const int32_t sync_mark_width = 9;
59 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
60 Gdk::Color& basic_color)
61 : RegionView (parent, tv, r, spu, basic_color)
69 , _amplitude_above_axis(1.0)
75 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
76 Gdk::Color& basic_color, TimeAxisViewItem::Visibility visibility)
77 : RegionView (parent, tv, r, spu, basic_color, visibility)
85 , _amplitude_above_axis(1.0)
92 AudioRegionView::init (Gdk::Color& basic_color, bool wfd)
94 // FIXME: Some redundancy here with RegionView::init. Need to figure out
95 // where order is important and where it isn't...
97 RegionView::init(basic_color, wfd);
101 _amplitude_above_axis = 1.0;
105 if ((node = _region->extra_xml ("GUI")) != 0) {
108 _flags = WaveformVisible;
112 if (trackview.editor.new_regionviews_display_gain()) {
113 _flags |= EnvelopeVisible;
116 compute_colors (basic_color);
120 fade_in_shape = new ArdourCanvas::Polygon (*group);
121 fade_in_shape->property_fill_color_rgba() = fade_color;
122 fade_in_shape->set_data ("regionview", this);
124 fade_out_shape = new ArdourCanvas::Polygon (*group);
125 fade_out_shape->property_fill_color_rgba() = fade_color;
126 fade_out_shape->set_data ("regionview", this);
131 UINT_TO_RGBA(fill_color,&r,&g,&b,&a);
134 fade_in_handle = new ArdourCanvas::SimpleRect (*group);
135 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
136 fade_in_handle->property_outline_pixels() = 0;
137 fade_in_handle->property_y1() = 2.0;
138 fade_in_handle->property_y2() = 7.0;
140 fade_in_handle->set_data ("regionview", this);
142 fade_out_handle = new ArdourCanvas::SimpleRect (*group);
143 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
144 fade_out_handle->property_outline_pixels() = 0;
145 fade_out_handle->property_y1() = 2.0;
146 fade_out_handle->property_y2() = 7.0;
148 fade_out_handle->set_data ("regionview", this);
151 string foo = _region->name();
155 gain_line = new AudioRegionGainLine (foo, trackview.session(), *this, *group, audio_region()->envelope());
157 if (!(_flags & EnvelopeVisible)) {
165 set_height (trackview.height);
168 region_sync_changed ();
169 region_resized (BoundsChanged);
170 set_waveview_data_src();
172 envelope_active_changed ();
173 fade_in_active_changed ();
174 fade_out_active_changed ();
176 _region->StateChanged.connect (mem_fun(*this, &AudioRegionView::region_changed));
178 fade_in_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
179 fade_in_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
180 fade_out_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
181 fade_out_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
185 /* XXX sync mark drag? */
188 AudioRegionView::~AudioRegionView ()
190 in_destructor = true;
192 RegionViewGoingAway (this); /* EMIT_SIGNAL */
194 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
195 gnome_canvas_waveview_cache_destroy (*cache);
198 /* all waveviews etc will be destroyed when the group is destroyed */
205 boost::shared_ptr<ARDOUR::AudioRegion>
206 AudioRegionView::audio_region() const
208 // "Guaranteed" to succeed...
209 return boost::dynamic_pointer_cast<AudioRegion>(_region);
213 AudioRegionView::region_changed (Change what_changed)
215 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionView::region_changed), what_changed));
217 RegionView::region_changed(what_changed);
219 if (what_changed & AudioRegion::ScaleAmplitudeChanged) {
220 region_scale_amplitude_changed ();
222 if (what_changed & AudioRegion::FadeInChanged) {
225 if (what_changed & AudioRegion::FadeOutChanged) {
228 if (what_changed & AudioRegion::FadeInActiveChanged) {
229 fade_in_active_changed ();
231 if (what_changed & AudioRegion::FadeOutActiveChanged) {
232 fade_out_active_changed ();
234 if (what_changed & AudioRegion::EnvelopeActiveChanged) {
235 envelope_active_changed ();
240 AudioRegionView::fade_in_changed ()
242 reset_fade_in_shape ();
246 AudioRegionView::fade_out_changed ()
248 reset_fade_out_shape ();
252 AudioRegionView::set_fade_in_shape (AudioRegion::FadeShape shape)
254 AutomationList& alist = audio_region()->fade_in();
255 XMLNode& before (alist.get_state());
256 trackview.session().begin_reversible_command ("fade in shape");
257 audio_region()->set_fade_in_shape (shape);
258 XMLNode& after (alist.get_state());
259 trackview.session().add_command (new MementoCommand<AutomationList>(alist, &before, &after));
260 trackview.session().commit_reversible_command ();
264 AudioRegionView::set_fade_out_shape (AudioRegion::FadeShape shape)
266 AutomationList& alist = audio_region()->fade_out();
267 XMLNode& before (alist.get_state());
268 trackview.session().begin_reversible_command ("fade out shape");
269 audio_region()->set_fade_out_shape (shape);
270 XMLNode& after (alist.get_state());
271 trackview.session().add_command (new MementoCommand<AutomationList>(alist, &before, &after));
272 trackview.session().commit_reversible_command ();
276 AudioRegionView::set_fade_in_active (bool yn)
278 AutomationList& alist = audio_region()->fade_in();
279 XMLNode& before (alist.get_state());
280 trackview.session().begin_reversible_command ("fade in shape");
281 audio_region()->set_fade_in_active (yn);
282 XMLNode& after (alist.get_state());
283 trackview.session().add_command (new MementoCommand<AutomationList>(alist, &before, &after));
284 trackview.session().commit_reversible_command ();
288 AudioRegionView::set_fade_out_active (bool yn)
290 AutomationList& alist = audio_region()->fade_out();
291 XMLNode& before (alist.get_state());
292 trackview.session().begin_reversible_command ("fade out shape");
293 audio_region()->set_fade_out_active (yn);
294 XMLNode& after (alist.get_state());
295 trackview.session().add_command (new MementoCommand<AutomationList>(alist, &before, &after));
296 trackview.session().commit_reversible_command ();
300 AudioRegionView::fade_in_active_changed ()
304 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
306 if (audio_region()->fade_in_active()) {
307 col = RGBA_TO_UINT(r,g,b,120);
308 fade_in_shape->property_fill_color_rgba() = col;
309 fade_in_shape->property_width_pixels() = 0;
310 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
312 col = RGBA_TO_UINT(r,g,b,0);
313 fade_in_shape->property_fill_color_rgba() = col;
314 fade_in_shape->property_width_pixels() = 1;
315 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
320 AudioRegionView::fade_out_active_changed ()
324 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
326 if (audio_region()->fade_out_active()) {
327 col = RGBA_TO_UINT(r,g,b,120);
328 fade_out_shape->property_fill_color_rgba() = col;
329 fade_out_shape->property_width_pixels() = 0;
330 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
332 col = RGBA_TO_UINT(r,g,b,0);
333 fade_out_shape->property_fill_color_rgba() = col;
334 fade_out_shape->property_width_pixels() = 1;
335 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
341 AudioRegionView::region_scale_amplitude_changed ()
343 ENSURE_GUI_THREAD (mem_fun(*this, &AudioRegionView::region_scale_amplitude_changed));
345 for (uint32_t n = 0; n < waves.size(); ++n) {
346 // force a reload of the cache
347 waves[n]->property_data_src() = _region.get();
352 AudioRegionView::region_renamed ()
354 // FIXME: ugly duplication with RegionView...
358 if (_region->locked()) {
360 str += _region->name();
363 str = _region->name();
366 // ... because of this
367 if (audio_region()->speed_mismatch (trackview.session().frame_rate())) {
368 str = string ("*") + str;
371 if (_region->muted()) {
372 str = string ("!") + str;
375 set_item_name (str, this);
380 AudioRegionView::region_resized (Change what_changed)
382 RegionView::region_resized(what_changed);
384 if (what_changed & Change (StartChanged|LengthChanged)) {
386 for (uint32_t n = 0; n < waves.size(); ++n) {
387 waves[n]->property_region_start() = _region->start();
390 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
392 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
393 (*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 fade_in_handle->show();
419 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() = color_map[cMutedWaveForm];
436 waves[n]->property_wave_color() = color_map[cWaveForm];
442 AudioRegionView::set_height (gdouble height)
444 RegionView::set_height(height);
446 uint32_t wcnt = waves.size();
448 for (uint32_t n=0; n < wcnt; ++n) {
451 if ((height) <= NAME_HIGHLIGHT_THRESH) {
452 ht = ((height-2*wcnt) / (double) wcnt);
454 ht = (((height-2*wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
457 gdouble yoff = n * (ht+1);
459 waves[n]->property_height() = ht;
460 waves[n]->property_y() = yoff + 2;
464 if ((height/wcnt) < NAME_HIGHLIGHT_SIZE) {
467 if (_flags & EnvelopeVisible) {
471 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE));
475 reset_fade_shapes ();
478 name_text->raise_to_top();
483 AudioRegionView::manage_zero_line ()
489 if (_height >= 100) {
490 gdouble wave_midpoint = (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
491 zero_line->property_y1() = wave_midpoint;
492 zero_line->property_y2() = wave_midpoint;
500 AudioRegionView::reset_fade_shapes ()
502 reset_fade_in_shape ();
503 reset_fade_out_shape ();
507 AudioRegionView::reset_fade_in_shape ()
509 reset_fade_in_shape_width ((nframes_t) audio_region()->fade_in().back()->when);
513 AudioRegionView::reset_fade_in_shape_width (nframes_t width)
515 if (fade_in_handle == 0) {
519 /* smallest size for a fade is 64 frames */
521 width = std::max ((nframes_t) 64, width);
524 double pwidth = width / samples_per_unit;
525 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
529 fade_in_shape->hide();
530 fade_in_handle->hide();
534 double handle_center;
535 handle_center = pwidth;
537 if (handle_center > 7.0) {
538 handle_center -= 3.0;
543 fade_in_handle->property_x1() = handle_center - 3.0;
544 fade_in_handle->property_x2() = handle_center + 3.0;
547 fade_in_shape->hide();
551 fade_in_shape->show();
553 float curve[npoints];
554 audio_region()->fade_in().get_vector (0, audio_region()->fade_in().back()->when, curve, npoints);
556 points = get_canvas_points ("fade in shape", npoints+3);
558 if (_height > NAME_HIGHLIGHT_THRESH) {
559 h = _height - NAME_HIGHLIGHT_SIZE;
564 /* points *MUST* be in anti-clockwise order */
567 double xdelta = pwidth/npoints;
569 for (pi = 0, pc = 0; pc < npoints; ++pc) {
570 (*points)[pi].set_x(1 + (pc * xdelta));
571 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
576 (*points)[pi].set_x(pwidth);
577 (*points)[pi++].set_y(2);
579 (*points)[pi].set_x(1);
580 (*points)[pi++].set_y(2);
582 /* connect the dots ... */
584 (*points)[pi] = (*points)[0];
586 fade_in_shape->property_points() = *points;
591 AudioRegionView::reset_fade_out_shape ()
593 reset_fade_out_shape_width ((nframes_t) audio_region()->fade_out().back()->when);
597 AudioRegionView::reset_fade_out_shape_width (nframes_t width)
599 if (fade_out_handle == 0) {
603 /* smallest size for a fade is 64 frames */
605 width = std::max ((nframes_t) 64, width);
608 double pwidth = width / samples_per_unit;
609 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
613 fade_out_shape->hide();
614 fade_out_handle->hide();
618 double handle_center;
619 handle_center = (_region->length() - width) / samples_per_unit;
621 if (handle_center > 7.0) {
622 handle_center -= 3.0;
627 fade_out_handle->property_x1() = handle_center - 3.0;
628 fade_out_handle->property_x2() = handle_center + 3.0;
630 /* don't show shape if its too small */
633 fade_out_shape->hide();
637 fade_out_shape->show();
639 float curve[npoints];
640 audio_region()->fade_out().get_vector (0, audio_region()->fade_out().back()->when, curve, npoints);
642 if (_height > NAME_HIGHLIGHT_THRESH) {
643 h = _height - NAME_HIGHLIGHT_SIZE;
648 /* points *MUST* be in anti-clockwise order */
650 points = get_canvas_points ("fade out shape", npoints+3);
653 double xdelta = pwidth/npoints;
655 for (pi = 0, pc = 0; pc < npoints; ++pc) {
656 (*points)[pi].set_x(_pixel_width - 1 - pwidth + (pc*xdelta));
657 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
662 (*points)[pi].set_x(_pixel_width);
663 (*points)[pi++].set_y(h);
665 (*points)[pi].set_x(_pixel_width);
666 (*points)[pi++].set_y(2);
668 /* connect the dots ... */
670 (*points)[pi] = (*points)[0];
672 fade_out_shape->property_points() = *points;
677 AudioRegionView::set_samples_per_unit (gdouble spu)
679 RegionView::set_samples_per_unit (spu);
681 for (uint32_t n=0; n < waves.size(); ++n) {
682 waves[n]->property_samples_per_unit() = spu;
688 reset_fade_shapes ();
692 AudioRegionView::set_amplitude_above_axis (gdouble spp)
694 for (uint32_t n=0; n < waves.size(); ++n) {
695 waves[n]->property_amplitude_above_axis() = spp;
700 AudioRegionView::compute_colors (Gdk::Color& basic_color)
702 RegionView::compute_colors(basic_color);
706 /* gain color computed in envelope_active_changed() */
708 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
709 fade_color = RGBA_TO_UINT(r,g,b,120);
713 AudioRegionView::set_colors ()
715 RegionView::set_colors();
718 gain_line->set_line_color (audio_region()->envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]);
721 for (uint32_t n=0; n < waves.size(); ++n) {
722 if (_region->muted()) {
723 waves[n]->property_wave_color() = color_map[cMutedWaveForm];
725 waves[n]->property_wave_color() = color_map[cWaveForm];
731 AudioRegionView::show_region_editor ()
734 editor = new AudioRegionEditor (trackview.session(), audio_region(), *this);
735 // GTK2FIX : how to ensure float without realizing
736 // editor->realize ();
737 // trackview.editor.ensure_float (*editor);
741 editor->get_window()->raise();
745 AudioRegionView::set_waveform_visible (bool yn)
747 if (((_flags & WaveformVisible) != yn)) {
749 for (uint32_t n=0; n < waves.size(); ++n) {
752 _flags |= WaveformVisible;
754 for (uint32_t n=0; n < waves.size(); ++n) {
757 _flags &= ~WaveformVisible;
764 AudioRegionView::temporarily_hide_envelope ()
772 AudioRegionView::unhide_envelope ()
774 if (gain_line && (_flags & EnvelopeVisible)) {
780 AudioRegionView::set_envelope_visible (bool yn)
782 if (gain_line && ((_flags & EnvelopeVisible) != yn)) {
785 _flags |= EnvelopeVisible;
788 _flags &= ~EnvelopeVisible;
795 AudioRegionView::create_waves ()
797 bool create_zero_line = true;
799 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
801 if (!atv.get_diskstream()) {
805 uint32_t nchans = atv.get_diskstream()->n_channels().get(DataType::AUDIO);
807 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
808 for (uint32_t n = 0; n < nchans; ++n) {
809 tmp_waves.push_back (0);
812 for (uint32_t n = 0; n < nchans; ++n) {
814 if (n >= audio_region()->n_channels()) {
818 wave_caches.push_back (WaveView::create_cache ());
821 if (audio_region()->audio_source(n)->peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n), data_ready_connection)) {
822 create_one_wave (n, true);
824 create_zero_line = false;
827 create_one_wave (n, true);
831 if (create_zero_line) {
835 zero_line = new ArdourCanvas::SimpleLine (*group);
836 zero_line->property_x1() = (gdouble) 1.0;
837 zero_line->property_x2() = (gdouble) (_region->length() / samples_per_unit) - 1.0;
838 zero_line->property_color_rgba() = (guint) color_map[cZeroLine];
844 AudioRegionView::create_one_wave (uint32_t which, bool direct)
846 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
847 uint32_t nchans = atv.get_diskstream()->n_channels().get(DataType::AUDIO);
849 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
852 if (trackview.height < NAME_HIGHLIGHT_SIZE) {
853 ht = ((trackview.height) / (double) nchans);
855 ht = ((trackview.height - NAME_HIGHLIGHT_SIZE) / (double) nchans);
858 gdouble yoff = which * ht;
860 WaveView *wave = new WaveView(*group);
862 wave->property_data_src() = (gpointer) _region.get();
863 wave->property_cache() = wave_caches[which];
864 wave->property_cache_updater() = true;
865 wave->property_channel() = which;
866 wave->property_length_function() = (gpointer) region_length_from_c;
867 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
868 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
869 wave->property_x() = 0.0;
870 wave->property_y() = yoff;
871 wave->property_height() = (double) ht;
872 wave->property_samples_per_unit() = samples_per_unit;
873 wave->property_amplitude_above_axis() = _amplitude_above_axis;
874 wave->property_wave_color() = _region->muted() ? color_map[cMutedWaveForm] : color_map[cWaveForm];
875 wave->property_region_start() = _region->start();
877 if (!(_flags & WaveformVisible)) {
881 /* note: calling this function is serialized by the lock
882 held in the peak building thread that signals that
883 peaks are ready for use *or* by the fact that it is
884 called one by one from the GUI thread.
887 if (which < nchans) {
888 tmp_waves[which] = wave;
890 /* n-channel track, >n-channel source */
893 /* see if we're all ready */
895 for (n = 0; n < nchans; ++n) {
896 if (tmp_waves[n] == 0) {
901 if (n == nwaves && waves.empty()) {
902 /* all waves are ready */
903 tmp_waves.resize(nwaves);
908 /* all waves created, don't hook into peaks ready anymore */
909 data_ready_connection.disconnect ();
912 zero_line = new ArdourCanvas::SimpleLine (*group);
913 zero_line->property_x1() = (gdouble) 1.0;
914 zero_line->property_x2() = (gdouble) (_region->length() / samples_per_unit) - 1.0;
915 zero_line->property_color_rgba() = (guint) color_map[cZeroLine];
922 AudioRegionView::peaks_ready_handler (uint32_t which)
924 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
928 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
930 if (gain_line == 0) {
936 /* don't create points that can't be seen */
938 set_envelope_visible (true);
945 nframes_t fx = trackview.editor.pixel_to_frame (x);
947 if (fx > _region->length()) {
951 /* compute vertical fractional position */
953 y = 1.0 - (y / (trackview.height - NAME_HIGHLIGHT_SIZE));
955 /* map using gain line */
957 gain_line->view_to_model_y (y);
959 trackview.session().begin_reversible_command (_("add gain control point"));
960 XMLNode &before = audio_region()->envelope().get_state();
962 if (!audio_region()->envelope_active()) {
963 XMLNode ®ion_before = audio_region()->get_state();
964 audio_region()->set_envelope_active(true);
965 XMLNode ®ion_after = audio_region()->get_state();
966 trackview.session().add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
969 audio_region()->envelope().add (fx, y);
971 XMLNode &after = audio_region()->envelope().get_state();
972 trackview.session().add_command (new MementoCommand<Curve>(audio_region()->envelope(), &before, &after));
973 trackview.session().commit_reversible_command ();
977 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
979 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
980 audio_region()->envelope().erase (cp->model);
984 AudioRegionView::store_flags()
986 XMLNode *node = new XMLNode ("GUI");
988 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
989 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
991 _region->add_extra_xml (*node);
995 AudioRegionView::set_flags (XMLNode* node)
999 if ((prop = node->property ("waveform-visible")) != 0) {
1000 if (prop->value() == "yes") {
1001 _flags |= WaveformVisible;
1005 if ((prop = node->property ("envelope-visible")) != 0) {
1006 if (prop->value() == "yes") {
1007 _flags |= EnvelopeVisible;
1013 AudioRegionView::set_waveform_shape (WaveformShape shape)
1017 /* this slightly odd approach is to leave the door open to
1018 other "shapes" such as spectral displays, etc.
1031 if (yn != (bool) (_flags & WaveformRectified)) {
1032 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1033 (*wave)->property_rectified() = yn;
1045 _flags |= WaveformRectified;
1047 _flags &= ~WaveformRectified;
1053 AudioRegionView::add_ghost (AutomationTimeAxisView& atv)
1055 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1058 double unit_position = _region->position () / samples_per_unit;
1059 GhostRegion* ghost = new GhostRegion (atv, unit_position);
1062 nchans = rtv->get_diskstream()->n_channels().get(DataType::AUDIO);
1064 for (uint32_t n = 0; n < nchans; ++n) {
1066 if (n >= audio_region()->n_channels()) {
1070 WaveView *wave = new WaveView(*ghost->group);
1072 wave->property_data_src() = _region.get();
1073 wave->property_cache() = wave_caches[n];
1074 wave->property_cache_updater() = false;
1075 wave->property_channel() = n;
1076 wave->property_length_function() = (gpointer)region_length_from_c;
1077 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1078 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1079 wave->property_x() = 0.0;
1080 wave->property_samples_per_unit() = samples_per_unit;
1081 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1082 wave->property_wave_color() = color_map[cGhostTrackWave];
1083 wave->property_region_start() = _region->start();
1085 ghost->waves.push_back(wave);
1088 ghost->set_height ();
1089 ghost->set_duration (_region->length() / samples_per_unit);
1090 ghosts.push_back (ghost);
1092 ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost));
1098 AudioRegionView::entered ()
1100 if (gain_line && _flags & EnvelopeVisible) {
1101 gain_line->show_all_control_points ();
1105 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1108 if (fade_in_handle) {
1109 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1110 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1115 AudioRegionView::exited ()
1118 gain_line->hide_all_but_selected_control_points ();
1122 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1125 if (fade_in_handle) {
1126 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1127 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1132 AudioRegionView::envelope_active_changed ()
1135 gain_line->set_line_color (audio_region()->envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]);
1140 AudioRegionView::set_waveview_data_src()
1143 double unit_length= _region->length() / samples_per_unit;
1145 for (uint32_t n = 0; n < waves.size(); ++n) {
1146 // TODO: something else to let it know the channel
1147 waves[n]->property_data_src() = _region.get();
1150 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1152 (*i)->set_duration (unit_length);
1154 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
1155 (*w)->property_data_src() = _region.get();
1162 AudioRegionView::color_handler (ColorID id, uint32_t val)
1165 case cMutedWaveForm:
1170 case cGainLineInactive:
1172 envelope_active_changed();
1177 zero_line->property_color_rgba() = (guint) color_map[cZeroLine];
1181 case cGhostTrackWave: