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);
120 AudioRegionView::init (Gdk::Color& basic_color, bool wfd)
122 // FIXME: Some redundancy here with RegionView::init. Need to figure out
123 // where order is important and where it isn't...
125 RegionView::init (basic_color, true);
129 _amplitude_above_axis = 1.0;
133 if ((node = _region->extra_xml ("GUI")) != 0) {
136 _flags = WaveformVisible;
140 if (trackview.editor.new_regionviews_display_gain()) {
141 _flags |= EnvelopeVisible;
144 compute_colors (basic_color);
148 fade_in_shape = new ArdourCanvas::Polygon (*group);
149 fade_in_shape->property_fill_color_rgba() = fade_color;
150 fade_in_shape->set_data ("regionview", this);
152 fade_out_shape = new ArdourCanvas::Polygon (*group);
153 fade_out_shape->property_fill_color_rgba() = fade_color;
154 fade_out_shape->set_data ("regionview", this);
159 UINT_TO_RGBA(fill_color,&r,&g,&b,&a);
162 fade_in_handle = new ArdourCanvas::SimpleRect (*group);
163 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
164 fade_in_handle->property_outline_pixels() = 0;
165 fade_in_handle->property_y1() = 2.0;
166 fade_in_handle->property_y2() = 7.0;
168 fade_in_handle->set_data ("regionview", this);
170 fade_out_handle = new ArdourCanvas::SimpleRect (*group);
171 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
172 fade_out_handle->property_outline_pixels() = 0;
173 fade_out_handle->property_y1() = 2.0;
174 fade_out_handle->property_y2() = 7.0;
176 fade_out_handle->set_data ("regionview", this);
179 string foo = _region->name();
183 if (!Profile->get_sae()) {
184 gain_line = new AudioRegionGainLine (foo, trackview.session(), *this, *group, audio_region()->envelope());
186 if (!(_flags & EnvelopeVisible)) {
195 set_height (trackview.height);
198 region_sync_changed ();
199 region_resized (BoundsChanged);
200 set_waveview_data_src();
202 envelope_active_changed ();
203 fade_in_active_changed ();
204 fade_out_active_changed ();
206 _region->StateChanged.connect (mem_fun(*this, &AudioRegionView::region_changed));
208 fade_in_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
209 fade_in_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
210 fade_out_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
211 fade_out_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
215 /* XXX sync mark drag? */
218 AudioRegionView::~AudioRegionView ()
220 in_destructor = true;
222 RegionViewGoingAway (this); /* EMIT_SIGNAL */
224 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
225 gnome_canvas_waveview_cache_destroy (*cache);
228 /* all waveviews etc will be destroyed when the group is destroyed */
235 boost::shared_ptr<ARDOUR::AudioRegion>
236 AudioRegionView::audio_region() const
238 // "Guaranteed" to succeed...
239 return boost::dynamic_pointer_cast<AudioRegion>(_region);
243 AudioRegionView::region_changed (Change what_changed)
245 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionView::region_changed), what_changed));
247 RegionView::region_changed(what_changed);
249 if (what_changed & AudioRegion::ScaleAmplitudeChanged) {
250 region_scale_amplitude_changed ();
252 if (what_changed & AudioRegion::FadeInChanged) {
255 if (what_changed & AudioRegion::FadeOutChanged) {
258 if (what_changed & AudioRegion::FadeInActiveChanged) {
259 fade_in_active_changed ();
261 if (what_changed & AudioRegion::FadeOutActiveChanged) {
262 fade_out_active_changed ();
264 if (what_changed & AudioRegion::EnvelopeActiveChanged) {
265 envelope_active_changed ();
270 AudioRegionView::fade_in_changed ()
272 reset_fade_in_shape ();
276 AudioRegionView::fade_out_changed ()
278 reset_fade_out_shape ();
281 AudioRegionView::fade_in_active_changed ()
285 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
287 if (audio_region()->fade_in_active()) {
288 col = RGBA_TO_UINT(r,g,b,120);
289 fade_in_shape->property_fill_color_rgba() = col;
290 fade_in_shape->property_width_pixels() = 0;
291 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
293 col = RGBA_TO_UINT(r,g,b,0);
294 fade_in_shape->property_fill_color_rgba() = col;
295 fade_in_shape->property_width_pixels() = 1;
296 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
301 AudioRegionView::fade_out_active_changed ()
305 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
307 if (audio_region()->fade_out_active()) {
308 col = RGBA_TO_UINT(r,g,b,120);
309 fade_out_shape->property_fill_color_rgba() = col;
310 fade_out_shape->property_width_pixels() = 0;
311 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
313 col = RGBA_TO_UINT(r,g,b,0);
314 fade_out_shape->property_fill_color_rgba() = col;
315 fade_out_shape->property_width_pixels() = 1;
316 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
322 AudioRegionView::region_scale_amplitude_changed ()
324 ENSURE_GUI_THREAD (mem_fun(*this, &AudioRegionView::region_scale_amplitude_changed));
326 for (uint32_t n = 0; n < waves.size(); ++n) {
327 // force a reload of the cache
328 waves[n]->property_data_src() = _region.get();
333 AudioRegionView::region_resized (Change what_changed)
335 RegionView::region_resized(what_changed);
337 if (what_changed & Change (StartChanged|LengthChanged)) {
339 for (uint32_t n = 0; n < waves.size(); ++n) {
340 waves[n]->property_region_start() = _region->start();
343 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
345 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
346 (*w)->property_region_start() = _region->start();
353 AudioRegionView::reset_width_dependent_items (double pixel_width)
355 RegionView::reset_width_dependent_items(pixel_width);
356 assert(_pixel_width == pixel_width);
359 zero_line->property_x2() = pixel_width - 1.0;
362 if (fade_in_handle) {
363 if (pixel_width <= 6.0) {
364 fade_in_handle->hide();
365 fade_out_handle->hide();
368 fade_in_handle->hide();
369 fade_out_handle->hide();
371 fade_in_handle->show();
372 fade_out_handle->show();
377 reset_fade_shapes ();
381 AudioRegionView::region_muted ()
383 RegionView::region_muted();
385 for (uint32_t n=0; n < waves.size(); ++n) {
386 if (_region->muted()) {
387 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
389 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
396 AudioRegionView::set_height (gdouble height)
398 RegionView::set_height (height);
400 uint32_t wcnt = waves.size();
403 TimeAxisViewItem::set_height (height - 2);
407 for (uint32_t n=0; n < wcnt; ++n) {
410 if ((height) <= NAME_HIGHLIGHT_THRESH) {
411 ht = ((height-2*wcnt) / (double) wcnt);
413 ht = (((height-2*wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
416 gdouble yoff = n * (ht+1);
418 waves[n]->property_height() = ht;
419 waves[n]->property_y() = yoff + 2;
423 if ((height/wcnt) < NAME_HIGHLIGHT_SIZE) {
426 if (_flags & EnvelopeVisible) {
430 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE));
434 reset_fade_shapes ();
437 name_text->raise_to_top();
442 AudioRegionView::manage_zero_line ()
448 if (_height >= 100) {
449 gdouble wave_midpoint = (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
450 zero_line->property_y1() = wave_midpoint;
451 zero_line->property_y2() = wave_midpoint;
459 AudioRegionView::reset_fade_shapes ()
461 reset_fade_in_shape ();
462 reset_fade_out_shape ();
466 AudioRegionView::reset_fade_in_shape ()
468 reset_fade_in_shape_width ((nframes_t) audio_region()->fade_in().back()->when);
472 AudioRegionView::reset_fade_in_shape_width (nframes_t width)
474 if (fade_in_handle == 0) {
478 /* smallest size for a fade is 64 frames */
480 width = std::max ((nframes_t) 64, width);
483 double pwidth = width / samples_per_unit;
484 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
488 fade_in_shape->hide();
489 fade_in_handle->hide();
493 double handle_center;
494 handle_center = pwidth;
496 if (handle_center > 7.0) {
497 handle_center -= 3.0;
502 fade_in_handle->property_x1() = handle_center - 3.0;
503 fade_in_handle->property_x2() = handle_center + 3.0;
506 fade_in_shape->hide();
510 fade_in_shape->show();
512 float curve[npoints];
513 audio_region()->fade_in().get_vector (0, audio_region()->fade_in().back()->when, curve, npoints);
515 points = get_canvas_points ("fade in shape", npoints+3);
517 if (_height > NAME_HIGHLIGHT_THRESH) {
518 h = _height - NAME_HIGHLIGHT_SIZE;
523 /* points *MUST* be in anti-clockwise order */
526 double xdelta = pwidth/npoints;
528 for (pi = 0, pc = 0; pc < npoints; ++pc) {
529 (*points)[pi].set_x(1 + (pc * xdelta));
530 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
535 (*points)[pi].set_x(pwidth);
536 (*points)[pi++].set_y(2);
538 (*points)[pi].set_x(1);
539 (*points)[pi++].set_y(2);
541 /* connect the dots ... */
543 (*points)[pi] = (*points)[0];
545 fade_in_shape->property_points() = *points;
550 AudioRegionView::reset_fade_out_shape ()
552 reset_fade_out_shape_width ((nframes_t) audio_region()->fade_out().back()->when);
556 AudioRegionView::reset_fade_out_shape_width (nframes_t width)
558 if (fade_out_handle == 0) {
562 /* smallest size for a fade is 64 frames */
564 width = std::max ((nframes_t) 64, width);
567 double pwidth = width / samples_per_unit;
568 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
572 fade_out_shape->hide();
573 fade_out_handle->hide();
577 double handle_center;
578 handle_center = (_region->length() - width) / samples_per_unit;
580 if (handle_center > 7.0) {
581 handle_center -= 3.0;
586 fade_out_handle->property_x1() = handle_center - 3.0;
587 fade_out_handle->property_x2() = handle_center + 3.0;
589 /* don't show shape if its too small */
592 fade_out_shape->hide();
596 fade_out_shape->show();
598 float curve[npoints];
599 audio_region()->fade_out().get_vector (0, audio_region()->fade_out().back()->when, curve, npoints);
601 if (_height > NAME_HIGHLIGHT_THRESH) {
602 h = _height - NAME_HIGHLIGHT_SIZE;
607 /* points *MUST* be in anti-clockwise order */
609 points = get_canvas_points ("fade out shape", npoints+3);
612 double xdelta = pwidth/npoints;
614 for (pi = 0, pc = 0; pc < npoints; ++pc) {
615 (*points)[pi].set_x(_pixel_width - 1 - pwidth + (pc*xdelta));
616 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
621 (*points)[pi].set_x(_pixel_width);
622 (*points)[pi++].set_y(h);
624 (*points)[pi].set_x(_pixel_width);
625 (*points)[pi++].set_y(2);
627 /* connect the dots ... */
629 (*points)[pi] = (*points)[0];
631 fade_out_shape->property_points() = *points;
636 AudioRegionView::set_samples_per_unit (gdouble spu)
638 RegionView::set_samples_per_unit (spu);
640 if (_flags & WaveformVisible) {
641 for (uint32_t n=0; n < waves.size(); ++n) {
642 waves[n]->property_samples_per_unit() = spu;
650 reset_fade_shapes ();
654 AudioRegionView::set_amplitude_above_axis (gdouble spp)
656 for (uint32_t n=0; n < waves.size(); ++n) {
657 waves[n]->property_amplitude_above_axis() = spp;
662 AudioRegionView::compute_colors (Gdk::Color& basic_color)
664 RegionView::compute_colors(basic_color);
668 /* gain color computed in envelope_active_changed() */
670 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
671 fade_color = RGBA_TO_UINT(r,g,b,120);
675 AudioRegionView::set_colors ()
677 RegionView::set_colors();
680 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
683 for (uint32_t n=0; n < waves.size(); ++n) {
684 if (_region->muted()) {
685 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
687 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
690 waves[n]->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
691 waves[n]->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
696 AudioRegionView::show_region_editor ()
699 editor = new AudioRegionEditor (trackview.session(), audio_region(), *this);
700 // GTK2FIX : how to ensure float without realizing
701 // editor->realize ();
702 // trackview.editor.ensure_float (*editor);
710 AudioRegionView::set_waveform_visible (bool yn)
712 if (((_flags & WaveformVisible) != yn)) {
714 for (uint32_t n=0; n < waves.size(); ++n) {
715 /* make sure the zoom level is correct, since we don't update
716 this when waveforms are hidden.
718 waves[n]->property_samples_per_unit() = samples_per_unit;
721 _flags |= WaveformVisible;
723 for (uint32_t n=0; n < waves.size(); ++n) {
726 _flags &= ~WaveformVisible;
733 AudioRegionView::temporarily_hide_envelope ()
741 AudioRegionView::unhide_envelope ()
743 if (gain_line && (_flags & EnvelopeVisible)) {
749 AudioRegionView::set_envelope_visible (bool yn)
751 if (gain_line && ((_flags & EnvelopeVisible) != yn)) {
754 _flags |= EnvelopeVisible;
757 _flags &= ~EnvelopeVisible;
764 AudioRegionView::create_waves ()
766 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
768 if (!atv.get_diskstream()) {
772 uint32_t nchans = atv.get_diskstream()->n_channels();
774 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
775 for (uint32_t n = 0; n < nchans; ++n) {
776 tmp_waves.push_back (0);
779 for (uint32_t n = 0; n < nchans; ++n) {
781 if (n >= audio_region()->n_channels()) {
785 wave_caches.push_back (WaveView::create_cache ());
789 if (audio_region()->source(n)->peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n), data_ready_connection)) {
790 create_one_wave (n, true);
792 // we'll get a PeaksReady signal from the source in the future
793 // and will call create_one_wave(n) then.
797 create_one_wave (n, true);
803 AudioRegionView::create_one_wave (uint32_t which, bool direct)
805 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
806 uint32_t nchans = atv.get_diskstream()->n_channels();
808 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
811 if (trackview.height < NAME_HIGHLIGHT_SIZE) {
812 ht = ((trackview.height) / (double) nchans);
814 ht = ((trackview.height - NAME_HIGHLIGHT_SIZE) / (double) nchans);
817 gdouble yoff = which * ht;
819 WaveView *wave = new WaveView(*group);
821 wave->property_data_src() = (gpointer) _region.get();
822 wave->property_cache() = wave_caches[which];
823 wave->property_cache_updater() = true;
824 wave->property_channel() = which;
825 wave->property_length_function() = (gpointer) region_length_from_c;
826 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
827 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
828 wave->property_x() = 0.0;
829 wave->property_y() = yoff;
830 wave->property_height() = (double) ht;
831 wave->property_samples_per_unit() = samples_per_unit;
832 wave->property_amplitude_above_axis() = _amplitude_above_axis;
833 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_WaveForm.get();
834 wave->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
835 wave->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
836 wave->property_region_start() = _region->start();
837 wave->property_rectified() = (bool) (_flags & WaveformRectified);
838 wave->property_logscaled() = (bool) (_flags & WaveformLogScaled);
840 if (!(_flags & WaveformVisible)) {
844 /* note: calling this function is serialized by the lock
845 held in the peak building thread that signals that
846 peaks are ready for use *or* by the fact that it is
847 called one by one from the GUI thread.
850 if (which < nchans) {
851 tmp_waves[which] = wave;
853 /* n-channel track, >n-channel source */
856 /* see if we're all ready */
858 for (n = 0; n < nchans; ++n) {
859 if (tmp_waves[n] == 0) {
864 if (n == nwaves && waves.empty()) {
865 /* all waves are ready */
866 tmp_waves.resize(nwaves);
871 /* all waves created, don't hook into peaks ready anymore */
872 data_ready_connection.disconnect ();
875 zero_line = new ArdourCanvas::SimpleLine (*group);
876 zero_line->property_x1() = (gdouble) 1.0;
877 zero_line->property_x2() = (gdouble) (_region->length() / samples_per_unit) - 1.0;
878 zero_line->property_color_rgba() = (guint) ARDOUR_UI::config()->canvasvar_ZeroLine.get();
885 AudioRegionView::peaks_ready_handler (uint32_t which)
887 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
891 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
893 if (gain_line == 0) {
899 /* don't create points that can't be seen */
901 set_envelope_visible (true);
908 nframes_t fx = trackview.editor.pixel_to_frame (x);
910 if (fx > _region->length()) {
914 /* compute vertical fractional position */
916 y = 1.0 - (y / (trackview.height - NAME_HIGHLIGHT_SIZE));
918 /* map using gain line */
920 gain_line->view_to_model_y (y);
922 trackview.session().begin_reversible_command (_("add gain control point"));
923 XMLNode &before = audio_region()->envelope().get_state();
925 if (!audio_region()->envelope_active()) {
926 XMLNode ®ion_before = audio_region()->get_state();
927 audio_region()->set_envelope_active(true);
928 XMLNode ®ion_after = audio_region()->get_state();
929 trackview.session().add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
932 audio_region()->envelope().add (fx, y);
934 XMLNode &after = audio_region()->envelope().get_state();
935 trackview.session().add_command (new MementoCommand<Curve>(audio_region()->envelope(), &before, &after));
936 trackview.session().commit_reversible_command ();
940 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
942 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
943 audio_region()->envelope().erase (cp->model);
947 AudioRegionView::store_flags()
949 XMLNode *node = new XMLNode ("GUI");
951 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
952 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
953 node->add_property ("waveform-rectified", (_flags & WaveformRectified) ? "yes" : "no");
954 node->add_property ("waveform-logscaled", (_flags & WaveformLogScaled) ? "yes" : "no");
956 _region->add_extra_xml (*node);
960 AudioRegionView::set_flags (XMLNode* node)
964 if ((prop = node->property ("waveform-visible")) != 0) {
965 if (prop->value() == "yes") {
966 _flags |= WaveformVisible;
970 if ((prop = node->property ("envelope-visible")) != 0) {
971 if (prop->value() == "yes") {
972 _flags |= EnvelopeVisible;
976 if ((prop = node->property ("waveform-rectified")) != 0) {
977 if (prop->value() == "yes") {
978 _flags |= WaveformRectified;
982 if ((prop = node->property ("waveform-logscaled")) != 0) {
983 if (prop->value() == "yes") {
984 _flags |= WaveformLogScaled;
990 AudioRegionView::set_waveform_shape (WaveformShape shape)
994 /* this slightly odd approach is to leave the door open to
995 other "shapes" such as spectral displays, etc.
1008 if (yn != (bool) (_flags & WaveformRectified)) {
1009 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1010 (*wave)->property_rectified() = yn;
1022 _flags |= WaveformRectified;
1024 _flags &= ~WaveformRectified;
1031 AudioRegionView::set_waveform_scale (WaveformScale scale)
1033 bool yn = (scale == LogWaveform);
1035 if (yn != (bool) (_flags & WaveformLogScaled)) {
1036 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1037 (*wave)->property_logscaled() = yn;
1041 _flags |= WaveformLogScaled;
1043 _flags &= ~WaveformLogScaled;
1051 AudioRegionView::add_ghost (AutomationTimeAxisView& atv)
1053 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1056 double unit_position = _region->position () / samples_per_unit;
1057 GhostRegion* ghost = new GhostRegion (atv, unit_position);
1060 nchans = rtv->get_diskstream()->n_channels();
1062 for (uint32_t n = 0; n < nchans; ++n) {
1064 if (n >= audio_region()->n_channels()) {
1068 WaveView *wave = new WaveView(*ghost->group);
1070 wave->property_data_src() = _region.get();
1071 wave->property_cache() = wave_caches[n];
1072 wave->property_cache_updater() = false;
1073 wave->property_channel() = n;
1074 wave->property_length_function() = (gpointer)region_length_from_c;
1075 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1076 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1077 wave->property_x() = 0.0;
1078 wave->property_samples_per_unit() = samples_per_unit;
1079 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1080 wave->property_wave_color() = ARDOUR_UI::config()->canvasvar_GhostTrackWave.get();
1081 wave->property_clip_color() = ARDOUR_UI::config()->canvasvar_GhostTrackWaveClip.get();
1082 wave->property_zero_color() = ARDOUR_UI::config()->canvasvar_GhostTrackZeroLine.get();
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() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
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 ()
1165 envelope_active_changed();
1169 AudioRegionView::set_frame_color ()
1175 if (_region->opaque()) {
1183 if (_selected && should_show_selection) {
1184 frame->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
1186 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_FrameBase.get(), &r, &g, &b, &a);
1187 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1188 if (_region->muted()) {
1189 (*w)->property_wave_color() = RGBA_TO_UINT(r, g, b, MUTED_ALPHA);
1191 (*w)->property_wave_color() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);// Lets still use the theme's opacity value if Opaque is not set
1195 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_FrameBase.get(), &r, &g, &b, &a);
1196 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
1198 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1199 if (_region->muted()) {
1200 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
1202 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();