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.
27 #include <gtkmm2ext/gtk_ui.h>
29 #include <ardour/playlist.h>
30 #include <ardour/audioregion.h>
31 #include <ardour/audiosource.h>
32 #include <ardour/audio_diskstream.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"
54 using namespace ARDOUR;
56 using namespace Editing;
57 using namespace ArdourCanvas;
59 static const int32_t sync_mark_width = 9;
61 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
62 Gdk::Color& basic_color)
63 : RegionView (parent, tv, r, spu, basic_color)
71 , _amplitude_above_axis(1.0)
77 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
78 Gdk::Color& basic_color, TimeAxisViewItem::Visibility visibility)
79 : RegionView (parent, tv, r, spu, basic_color, visibility)
87 , _amplitude_above_axis(1.0)
94 AudioRegionView::init (Gdk::Color& basic_color, bool wfd)
96 // FIXME: Some redundancy here with RegionView::init. Need to figure out
97 // where order is important and where it isn't...
99 RegionView::init(basic_color, wfd);
103 _amplitude_above_axis = 1.0;
107 if ((node = _region->extra_xml ("GUI")) != 0) {
110 _flags = WaveformVisible;
114 if (trackview.editor.new_regionviews_display_gain()) {
115 _flags |= EnvelopeVisible;
118 compute_colors (basic_color);
122 fade_in_shape = new ArdourCanvas::Polygon (*group);
123 fade_in_shape->property_fill_color_rgba() = fade_color;
124 fade_in_shape->set_data ("regionview", this);
126 fade_out_shape = new ArdourCanvas::Polygon (*group);
127 fade_out_shape->property_fill_color_rgba() = fade_color;
128 fade_out_shape->set_data ("regionview", this);
133 UINT_TO_RGBA(fill_color,&r,&g,&b,&a);
136 fade_in_handle = new ArdourCanvas::SimpleRect (*group);
137 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
138 fade_in_handle->property_outline_pixels() = 0;
139 fade_in_handle->property_y1() = 2.0;
140 fade_in_handle->property_y2() = 7.0;
142 fade_in_handle->set_data ("regionview", this);
144 fade_out_handle = new ArdourCanvas::SimpleRect (*group);
145 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
146 fade_out_handle->property_outline_pixels() = 0;
147 fade_out_handle->property_y1() = 2.0;
148 fade_out_handle->property_y2() = 7.0;
150 fade_out_handle->set_data ("regionview", this);
153 string foo = _region->name();
157 gain_line = new AudioRegionGainLine (foo, trackview.session(), *this, *group, audio_region()->envelope());
159 if (!(_flags & EnvelopeVisible)) {
167 set_height (trackview.height);
170 region_sync_changed ();
171 region_resized (BoundsChanged);
172 set_waveview_data_src();
174 envelope_active_changed ();
175 fade_in_active_changed ();
176 fade_out_active_changed ();
178 _region->StateChanged.connect (mem_fun(*this, &AudioRegionView::region_changed));
180 fade_in_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
181 fade_in_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
182 fade_out_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
183 fade_out_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
187 /* XXX sync mark drag? */
190 AudioRegionView::~AudioRegionView ()
192 in_destructor = true;
194 RegionViewGoingAway (this); /* EMIT_SIGNAL */
196 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
197 gnome_canvas_waveview_cache_destroy (*cache);
200 /* all waveviews etc will be destroyed when the group is destroyed */
207 boost::shared_ptr<ARDOUR::AudioRegion>
208 AudioRegionView::audio_region() const
210 // "Guaranteed" to succeed...
211 return boost::dynamic_pointer_cast<AudioRegion>(_region);
215 AudioRegionView::region_changed (Change what_changed)
217 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionView::region_changed), what_changed));
219 RegionView::region_changed(what_changed);
221 if (what_changed & AudioRegion::ScaleAmplitudeChanged) {
222 region_scale_amplitude_changed ();
224 if (what_changed & AudioRegion::FadeInChanged) {
227 if (what_changed & AudioRegion::FadeOutChanged) {
230 if (what_changed & AudioRegion::FadeInActiveChanged) {
231 fade_in_active_changed ();
233 if (what_changed & AudioRegion::FadeOutActiveChanged) {
234 fade_out_active_changed ();
236 if (what_changed & AudioRegion::EnvelopeActiveChanged) {
237 envelope_active_changed ();
242 AudioRegionView::fade_in_changed ()
244 reset_fade_in_shape ();
248 AudioRegionView::fade_out_changed ()
250 reset_fade_out_shape ();
254 AudioRegionView::set_fade_in_shape (AudioRegion::FadeShape shape)
256 AutomationList& alist = audio_region()->fade_in();
257 XMLNode& before (alist.get_state());
258 trackview.session().begin_reversible_command ("fade in shape");
259 audio_region()->set_fade_in_shape (shape);
260 XMLNode& after (alist.get_state());
261 trackview.session().add_command (new MementoCommand<AutomationList>(alist, &before, &after));
262 trackview.session().commit_reversible_command ();
266 AudioRegionView::set_fade_out_shape (AudioRegion::FadeShape shape)
268 AutomationList& alist = audio_region()->fade_out();
269 XMLNode& before (alist.get_state());
270 trackview.session().begin_reversible_command ("fade out shape");
271 audio_region()->set_fade_out_shape (shape);
272 XMLNode& after (alist.get_state());
273 trackview.session().add_command (new MementoCommand<AutomationList>(alist, &before, &after));
274 trackview.session().commit_reversible_command ();
278 AudioRegionView::set_fade_in_active (bool yn)
280 AutomationList& alist = audio_region()->fade_in();
281 XMLNode& before (alist.get_state());
282 trackview.session().begin_reversible_command ("fade in shape");
283 audio_region()->set_fade_in_active (yn);
284 XMLNode& after (alist.get_state());
285 trackview.session().add_command (new MementoCommand<AutomationList>(alist, &before, &after));
286 trackview.session().commit_reversible_command ();
290 AudioRegionView::set_fade_out_active (bool yn)
292 AutomationList& alist = audio_region()->fade_out();
293 XMLNode& before (alist.get_state());
294 trackview.session().begin_reversible_command ("fade out shape");
295 audio_region()->set_fade_out_active (yn);
296 XMLNode& after (alist.get_state());
297 trackview.session().add_command (new MementoCommand<AutomationList>(alist, &before, &after));
298 trackview.session().commit_reversible_command ();
302 AudioRegionView::fade_in_active_changed ()
306 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
308 if (audio_region()->fade_in_active()) {
309 col = RGBA_TO_UINT(r,g,b,120);
310 fade_in_shape->property_fill_color_rgba() = col;
311 fade_in_shape->property_width_pixels() = 0;
312 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
314 col = RGBA_TO_UINT(r,g,b,0);
315 fade_in_shape->property_fill_color_rgba() = col;
316 fade_in_shape->property_width_pixels() = 1;
317 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
322 AudioRegionView::fade_out_active_changed ()
326 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
328 if (audio_region()->fade_out_active()) {
329 col = RGBA_TO_UINT(r,g,b,120);
330 fade_out_shape->property_fill_color_rgba() = col;
331 fade_out_shape->property_width_pixels() = 0;
332 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
334 col = RGBA_TO_UINT(r,g,b,0);
335 fade_out_shape->property_fill_color_rgba() = col;
336 fade_out_shape->property_width_pixels() = 1;
337 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
343 AudioRegionView::region_scale_amplitude_changed ()
345 ENSURE_GUI_THREAD (mem_fun(*this, &AudioRegionView::region_scale_amplitude_changed));
347 for (uint32_t n = 0; n < waves.size(); ++n) {
348 // force a reload of the cache
349 waves[n]->property_data_src() = _region.get();
354 AudioRegionView::region_resized (Change what_changed)
356 RegionView::region_resized(what_changed);
358 if (what_changed & Change (StartChanged|LengthChanged)) {
360 for (uint32_t n = 0; n < waves.size(); ++n) {
361 waves[n]->property_region_start() = _region->start();
364 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
366 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
367 (*w)->property_region_start() = _region->start();
374 AudioRegionView::reset_width_dependent_items (double pixel_width)
376 RegionView::reset_width_dependent_items(pixel_width);
377 assert(_pixel_width == pixel_width);
380 zero_line->property_x2() = pixel_width - 1.0;
383 if (fade_in_handle) {
384 if (pixel_width <= 6.0) {
385 fade_in_handle->hide();
386 fade_out_handle->hide();
389 fade_in_handle->hide();
390 fade_out_handle->hide();
392 fade_in_handle->show();
393 fade_out_handle->show();
398 reset_fade_shapes ();
402 AudioRegionView::region_muted ()
404 RegionView::region_muted();
406 for (uint32_t n=0; n < waves.size(); ++n) {
407 if (_region->muted()) {
408 waves[n]->property_wave_color() = color_map[cMutedWaveForm];
410 waves[n]->property_wave_color() = color_map[cWaveForm];
417 AudioRegionView::set_height (gdouble height)
419 uint32_t wcnt = waves.size();
422 TimeAxisViewItem::set_height (height - 2);
426 for (uint32_t n=0; n < wcnt; ++n) {
429 if ((height) <= NAME_HIGHLIGHT_THRESH) {
430 ht = ((height-2*wcnt) / (double) wcnt);
432 ht = (((height-2*wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
435 gdouble yoff = n * (ht+1);
437 waves[n]->property_height() = ht;
438 waves[n]->property_y() = yoff + 2;
442 if ((height/wcnt) < NAME_HIGHLIGHT_SIZE) {
445 if (_flags & EnvelopeVisible) {
449 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE));
453 reset_fade_shapes ();
456 name_text->raise_to_top();
461 AudioRegionView::manage_zero_line ()
467 if (_height >= 100) {
468 gdouble wave_midpoint = (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
469 zero_line->property_y1() = wave_midpoint;
470 zero_line->property_y2() = wave_midpoint;
478 AudioRegionView::reset_fade_shapes ()
480 reset_fade_in_shape ();
481 reset_fade_out_shape ();
485 AudioRegionView::reset_fade_in_shape ()
487 reset_fade_in_shape_width ((nframes_t) audio_region()->fade_in().back()->when);
491 AudioRegionView::reset_fade_in_shape_width (nframes_t width)
493 if (fade_in_handle == 0) {
497 /* smallest size for a fade is 64 frames */
499 width = std::max ((nframes_t) 64, width);
502 double pwidth = width / samples_per_unit;
503 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
507 fade_in_shape->hide();
508 fade_in_handle->hide();
512 double handle_center;
513 handle_center = pwidth;
515 if (handle_center > 7.0) {
516 handle_center -= 3.0;
521 fade_in_handle->property_x1() = handle_center - 3.0;
522 fade_in_handle->property_x2() = handle_center + 3.0;
525 fade_in_shape->hide();
529 fade_in_shape->show();
531 float curve[npoints];
532 audio_region()->fade_in().get_vector (0, audio_region()->fade_in().back()->when, curve, npoints);
534 points = get_canvas_points ("fade in shape", npoints+3);
536 if (_height > NAME_HIGHLIGHT_THRESH) {
537 h = _height - NAME_HIGHLIGHT_SIZE;
542 /* points *MUST* be in anti-clockwise order */
545 double xdelta = pwidth/npoints;
547 for (pi = 0, pc = 0; pc < npoints; ++pc) {
548 (*points)[pi].set_x(1 + (pc * xdelta));
549 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
554 (*points)[pi].set_x(pwidth);
555 (*points)[pi++].set_y(2);
557 (*points)[pi].set_x(1);
558 (*points)[pi++].set_y(2);
560 /* connect the dots ... */
562 (*points)[pi] = (*points)[0];
564 fade_in_shape->property_points() = *points;
569 AudioRegionView::reset_fade_out_shape ()
571 reset_fade_out_shape_width ((nframes_t) audio_region()->fade_out().back()->when);
575 AudioRegionView::reset_fade_out_shape_width (nframes_t width)
577 if (fade_out_handle == 0) {
581 /* smallest size for a fade is 64 frames */
583 width = std::max ((nframes_t) 64, width);
586 double pwidth = width / samples_per_unit;
587 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
591 fade_out_shape->hide();
592 fade_out_handle->hide();
596 double handle_center;
597 handle_center = (_region->length() - width) / samples_per_unit;
599 if (handle_center > 7.0) {
600 handle_center -= 3.0;
605 fade_out_handle->property_x1() = handle_center - 3.0;
606 fade_out_handle->property_x2() = handle_center + 3.0;
608 /* don't show shape if its too small */
611 fade_out_shape->hide();
615 fade_out_shape->show();
617 float curve[npoints];
618 audio_region()->fade_out().get_vector (0, audio_region()->fade_out().back()->when, curve, npoints);
620 if (_height > NAME_HIGHLIGHT_THRESH) {
621 h = _height - NAME_HIGHLIGHT_SIZE;
626 /* points *MUST* be in anti-clockwise order */
628 points = get_canvas_points ("fade out shape", npoints+3);
631 double xdelta = pwidth/npoints;
633 for (pi = 0, pc = 0; pc < npoints; ++pc) {
634 (*points)[pi].set_x(_pixel_width - 1 - pwidth + (pc*xdelta));
635 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
640 (*points)[pi].set_x(_pixel_width);
641 (*points)[pi++].set_y(h);
643 (*points)[pi].set_x(_pixel_width);
644 (*points)[pi++].set_y(2);
646 /* connect the dots ... */
648 (*points)[pi] = (*points)[0];
650 fade_out_shape->property_points() = *points;
655 AudioRegionView::set_samples_per_unit (gdouble spu)
657 RegionView::set_samples_per_unit (spu);
659 for (uint32_t n=0; n < waves.size(); ++n) {
660 waves[n]->property_samples_per_unit() = spu;
666 reset_fade_shapes ();
670 AudioRegionView::set_amplitude_above_axis (gdouble spp)
672 for (uint32_t n=0; n < waves.size(); ++n) {
673 waves[n]->property_amplitude_above_axis() = spp;
678 AudioRegionView::compute_colors (Gdk::Color& basic_color)
680 RegionView::compute_colors(basic_color);
684 /* gain color computed in envelope_active_changed() */
686 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
687 fade_color = RGBA_TO_UINT(r,g,b,120);
691 AudioRegionView::set_colors ()
693 RegionView::set_colors();
696 gain_line->set_line_color (audio_region()->envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]);
699 for (uint32_t n=0; n < waves.size(); ++n) {
700 if (_region->muted()) {
701 waves[n]->property_wave_color() = color_map[cMutedWaveForm];
703 waves[n]->property_wave_color() = color_map[cWaveForm];
709 AudioRegionView::show_region_editor ()
712 editor = new AudioRegionEditor (trackview.session(), audio_region(), *this);
713 // GTK2FIX : how to ensure float without realizing
714 // editor->realize ();
715 // trackview.editor.ensure_float (*editor);
719 editor->get_window()->raise();
723 AudioRegionView::set_waveform_visible (bool yn)
725 if (((_flags & WaveformVisible) != yn)) {
727 for (uint32_t n=0; n < waves.size(); ++n) {
730 _flags |= WaveformVisible;
732 for (uint32_t n=0; n < waves.size(); ++n) {
735 _flags &= ~WaveformVisible;
742 AudioRegionView::temporarily_hide_envelope ()
750 AudioRegionView::unhide_envelope ()
752 if (gain_line && (_flags & EnvelopeVisible)) {
758 AudioRegionView::set_envelope_visible (bool yn)
760 if (gain_line && ((_flags & EnvelopeVisible) != yn)) {
763 _flags |= EnvelopeVisible;
766 _flags &= ~EnvelopeVisible;
773 AudioRegionView::create_waves ()
775 bool create_zero_line = true;
777 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
779 if (!atv.get_diskstream()) {
783 uint32_t nchans = atv.get_diskstream()->n_channels();
785 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
786 for (uint32_t n = 0; n < nchans; ++n) {
787 tmp_waves.push_back (0);
790 for (uint32_t n = 0; n < nchans; ++n) {
792 if (n >= audio_region()->n_channels()) {
796 wave_caches.push_back (WaveView::create_cache ());
799 if (audio_region()->source(n)->peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n), data_ready_connection)) {
800 create_one_wave (n, true);
802 create_zero_line = false;
805 create_one_wave (n, true);
809 if (create_zero_line) {
813 zero_line = new ArdourCanvas::SimpleLine (*group);
814 zero_line->property_x1() = (gdouble) 1.0;
815 zero_line->property_x2() = (gdouble) (_region->length() / samples_per_unit) - 1.0;
816 zero_line->property_color_rgba() = (guint) color_map[cZeroLine];
822 AudioRegionView::create_one_wave (uint32_t which, bool direct)
824 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
825 uint32_t nchans = atv.get_diskstream()->n_channels();
827 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
830 if (trackview.height < NAME_HIGHLIGHT_SIZE) {
831 ht = ((trackview.height) / (double) nchans);
833 ht = ((trackview.height - NAME_HIGHLIGHT_SIZE) / (double) nchans);
836 gdouble yoff = which * ht;
838 WaveView *wave = new WaveView(*group);
840 wave->property_data_src() = (gpointer) _region.get();
841 wave->property_cache() = wave_caches[which];
842 wave->property_cache_updater() = true;
843 wave->property_channel() = which;
844 wave->property_length_function() = (gpointer) region_length_from_c;
845 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
846 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
847 wave->property_x() = 0.0;
848 wave->property_y() = yoff;
849 wave->property_height() = (double) ht;
850 wave->property_samples_per_unit() = samples_per_unit;
851 wave->property_amplitude_above_axis() = _amplitude_above_axis;
852 wave->property_wave_color() = _region->muted() ? color_map[cMutedWaveForm] : color_map[cWaveForm];
853 wave->property_region_start() = _region->start();
855 if (!(_flags & WaveformVisible)) {
859 /* note: calling this function is serialized by the lock
860 held in the peak building thread that signals that
861 peaks are ready for use *or* by the fact that it is
862 called one by one from the GUI thread.
865 if (which < nchans) {
866 tmp_waves[which] = wave;
868 /* n-channel track, >n-channel source */
871 /* see if we're all ready */
873 for (n = 0; n < nchans; ++n) {
874 if (tmp_waves[n] == 0) {
879 if (n == nwaves && waves.empty()) {
880 /* all waves are ready */
881 tmp_waves.resize(nwaves);
886 /* all waves created, don't hook into peaks ready anymore */
887 data_ready_connection.disconnect ();
890 zero_line = new ArdourCanvas::SimpleLine (*group);
891 zero_line->property_x1() = (gdouble) 1.0;
892 zero_line->property_x2() = (gdouble) (_region->length() / samples_per_unit) - 1.0;
893 zero_line->property_color_rgba() = (guint) color_map[cZeroLine];
900 AudioRegionView::peaks_ready_handler (uint32_t which)
902 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
906 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
908 if (gain_line == 0) {
914 /* don't create points that can't be seen */
916 set_envelope_visible (true);
923 nframes_t fx = trackview.editor.pixel_to_frame (x);
925 if (fx > _region->length()) {
929 /* compute vertical fractional position */
931 y = 1.0 - (y / (trackview.height - NAME_HIGHLIGHT_SIZE));
933 /* map using gain line */
935 gain_line->view_to_model_y (y);
937 trackview.session().begin_reversible_command (_("add gain control point"));
938 XMLNode &before = audio_region()->envelope().get_state();
940 if (!audio_region()->envelope_active()) {
941 XMLNode ®ion_before = audio_region()->get_state();
942 audio_region()->set_envelope_active(true);
943 XMLNode ®ion_after = audio_region()->get_state();
944 trackview.session().add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
947 audio_region()->envelope().add (fx, y);
949 XMLNode &after = audio_region()->envelope().get_state();
950 trackview.session().add_command (new MementoCommand<Curve>(audio_region()->envelope(), &before, &after));
951 trackview.session().commit_reversible_command ();
955 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
957 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
958 audio_region()->envelope().erase (cp->model);
962 AudioRegionView::store_flags()
964 XMLNode *node = new XMLNode ("GUI");
966 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
967 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
969 _region->add_extra_xml (*node);
973 AudioRegionView::set_flags (XMLNode* node)
977 if ((prop = node->property ("waveform-visible")) != 0) {
978 if (prop->value() == "yes") {
979 _flags |= WaveformVisible;
983 if ((prop = node->property ("envelope-visible")) != 0) {
984 if (prop->value() == "yes") {
985 _flags |= EnvelopeVisible;
991 AudioRegionView::set_waveform_shape (WaveformShape shape)
995 /* this slightly odd approach is to leave the door open to
996 other "shapes" such as spectral displays, etc.
1009 if (yn != (bool) (_flags & WaveformRectified)) {
1010 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1011 (*wave)->property_rectified() = yn;
1023 _flags |= WaveformRectified;
1025 _flags &= ~WaveformRectified;
1031 AudioRegionView::add_ghost (AutomationTimeAxisView& atv)
1033 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1036 double unit_position = _region->position () / samples_per_unit;
1037 GhostRegion* ghost = new GhostRegion (atv, unit_position);
1040 nchans = rtv->get_diskstream()->n_channels();
1042 for (uint32_t n = 0; n < nchans; ++n) {
1044 if (n >= audio_region()->n_channels()) {
1048 WaveView *wave = new WaveView(*ghost->group);
1050 wave->property_data_src() = _region.get();
1051 wave->property_cache() = wave_caches[n];
1052 wave->property_cache_updater() = false;
1053 wave->property_channel() = n;
1054 wave->property_length_function() = (gpointer)region_length_from_c;
1055 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1056 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1057 wave->property_x() = 0.0;
1058 wave->property_samples_per_unit() = samples_per_unit;
1059 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1060 wave->property_wave_color() = color_map[cGhostTrackWave];
1061 wave->property_region_start() = _region->start();
1063 ghost->waves.push_back(wave);
1066 ghost->set_height ();
1067 ghost->set_duration (_region->length() / samples_per_unit);
1068 ghosts.push_back (ghost);
1070 ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost));
1076 AudioRegionView::entered ()
1078 if (gain_line && _flags & EnvelopeVisible) {
1079 gain_line->show_all_control_points ();
1083 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1086 if (fade_in_handle) {
1087 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1088 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1093 AudioRegionView::exited ()
1096 gain_line->hide_all_but_selected_control_points ();
1100 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1103 if (fade_in_handle) {
1104 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1105 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1110 AudioRegionView::envelope_active_changed ()
1113 gain_line->set_line_color (audio_region()->envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]);
1118 AudioRegionView::set_waveview_data_src()
1121 double unit_length= _region->length() / samples_per_unit;
1123 for (uint32_t n = 0; n < waves.size(); ++n) {
1124 // TODO: something else to let it know the channel
1125 waves[n]->property_data_src() = _region.get();
1128 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1130 (*i)->set_duration (unit_length);
1132 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
1133 (*w)->property_data_src() = _region.get();
1140 AudioRegionView::color_handler (ColorID id, uint32_t val)
1143 case cMutedWaveForm:
1148 case cGainLineInactive:
1150 envelope_active_changed();
1155 zero_line->property_color_rgba() = (guint) color_map[cZeroLine];
1159 case cGhostTrackWave: