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"
51 #define MUTED_ALPHA 0x50
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::AudioRegionView (const AudioRegionView& other)
102 , _amplitude_above_axis(1.0)
110 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
111 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
117 AudioRegionView::init (Gdk::Color& basic_color, bool wfd)
119 // FIXME: Some redundancy here with RegionView::init. Need to figure out
120 // where order is important and where it isn't...
122 RegionView::init(basic_color, false);
126 _amplitude_above_axis = 1.0;
130 if ((node = _region->extra_xml ("GUI")) != 0) {
133 _flags = WaveformVisible;
137 if (trackview.editor.new_regionviews_display_gain()) {
138 _flags |= EnvelopeVisible;
141 compute_colors (basic_color);
145 fade_in_shape = new ArdourCanvas::Polygon (*group);
146 fade_in_shape->property_fill_color_rgba() = fade_color;
147 fade_in_shape->set_data ("regionview", this);
149 fade_out_shape = new ArdourCanvas::Polygon (*group);
150 fade_out_shape->property_fill_color_rgba() = fade_color;
151 fade_out_shape->set_data ("regionview", this);
156 UINT_TO_RGBA(fill_color,&r,&g,&b,&a);
159 fade_in_handle = new ArdourCanvas::SimpleRect (*group);
160 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
161 fade_in_handle->property_outline_pixels() = 0;
163 fade_in_handle->set_data ("regionview", this);
165 fade_out_handle = new ArdourCanvas::SimpleRect (*group);
166 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
167 fade_out_handle->property_outline_pixels() = 0;
169 fade_out_handle->set_data ("regionview", this);
172 setup_fade_handle_positions ();
174 string foo = _region->name();
178 gain_line = new AudioRegionGainLine (foo, trackview.session(), *this, *group, audio_region()->envelope());
180 if (!(_flags & EnvelopeVisible)) {
188 set_y_position_and_height (0, trackview.height);
191 region_sync_changed ();
192 region_resized (BoundsChanged);
193 set_waveview_data_src();
195 envelope_active_changed ();
196 fade_in_active_changed ();
197 fade_out_active_changed ();
199 fade_in_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
200 fade_in_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
201 fade_out_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
202 fade_out_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
206 /* XXX sync mark drag? */
209 AudioRegionView::~AudioRegionView ()
211 in_destructor = true;
213 RegionViewGoingAway (this); /* EMIT_SIGNAL */
215 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
216 gnome_canvas_waveview_cache_destroy (*cache);
219 /* all waveviews etc will be destroyed when the group is destroyed */
226 boost::shared_ptr<ARDOUR::AudioRegion>
227 AudioRegionView::audio_region() const
229 // "Guaranteed" to succeed...
230 return boost::dynamic_pointer_cast<AudioRegion>(_region);
234 AudioRegionView::region_changed (Change what_changed)
236 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionView::region_changed), what_changed));
238 RegionView::region_changed(what_changed);
240 if (what_changed & AudioRegion::ScaleAmplitudeChanged) {
241 region_scale_amplitude_changed ();
243 if (what_changed & AudioRegion::FadeInChanged) {
246 if (what_changed & AudioRegion::FadeOutChanged) {
249 if (what_changed & AudioRegion::FadeInActiveChanged) {
250 fade_in_active_changed ();
252 if (what_changed & AudioRegion::FadeOutActiveChanged) {
253 fade_out_active_changed ();
255 if (what_changed & AudioRegion::EnvelopeActiveChanged) {
256 envelope_active_changed ();
261 AudioRegionView::fade_in_changed ()
263 reset_fade_in_shape ();
267 AudioRegionView::fade_out_changed ()
269 reset_fade_out_shape ();
272 AudioRegionView::fade_in_active_changed ()
276 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
278 if (audio_region()->fade_in_active()) {
279 col = RGBA_TO_UINT(r,g,b,120);
280 fade_in_shape->property_fill_color_rgba() = col;
281 fade_in_shape->property_width_pixels() = 0;
282 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
284 col = RGBA_TO_UINT(r,g,b,0);
285 fade_in_shape->property_fill_color_rgba() = col;
286 fade_in_shape->property_width_pixels() = 1;
287 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
292 AudioRegionView::fade_out_active_changed ()
296 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
298 if (audio_region()->fade_out_active()) {
299 col = RGBA_TO_UINT(r,g,b,120);
300 fade_out_shape->property_fill_color_rgba() = col;
301 fade_out_shape->property_width_pixels() = 0;
302 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
304 col = RGBA_TO_UINT(r,g,b,0);
305 fade_out_shape->property_fill_color_rgba() = col;
306 fade_out_shape->property_width_pixels() = 1;
307 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
313 AudioRegionView::region_scale_amplitude_changed ()
315 ENSURE_GUI_THREAD (mem_fun(*this, &AudioRegionView::region_scale_amplitude_changed));
317 for (uint32_t n = 0; n < waves.size(); ++n) {
318 // force a reload of the cache
319 waves[n]->property_data_src() = _region.get();
324 AudioRegionView::region_renamed ()
326 Glib::ustring str = RegionView::make_name ();
328 if (audio_region()->speed_mismatch (trackview.session().frame_rate())) {
329 str = string ("*") + str;
332 if (_region->muted()) {
333 str = string ("!") + str;
336 set_item_name (str, this);
341 AudioRegionView::region_resized (Change what_changed)
343 RegionView::region_resized(what_changed);
345 if (what_changed & Change (StartChanged|LengthChanged)) {
347 for (uint32_t n = 0; n < waves.size(); ++n) {
348 waves[n]->property_region_start() = _region->start();
351 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
353 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
354 (*w)->property_region_start() = _region->start();
361 AudioRegionView::reset_width_dependent_items (double pixel_width)
363 RegionView::reset_width_dependent_items(pixel_width);
364 assert(_pixel_width == pixel_width);
367 zero_line->property_x2() = pixel_width - 1.0;
370 if (fade_in_handle) {
371 if (pixel_width <= 6.0) {
372 fade_in_handle->hide();
373 fade_out_handle->hide();
376 fade_in_handle->hide();
377 fade_out_handle->hide();
379 fade_in_handle->show();
380 fade_out_handle->show();
385 reset_fade_shapes ();
389 AudioRegionView::region_muted ()
391 RegionView::region_muted();
393 for (uint32_t n=0; n < waves.size(); ++n) {
394 if (_region->muted()) {
395 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(Config->canvasvar_WaveForm.get(), MUTED_ALPHA);
397 waves[n]->property_wave_color() = Config->canvasvar_WaveForm.get();
403 AudioRegionView::set_y_position_and_height (double y, double h)
405 RegionView::set_y_position_and_height(y, h - 1);
410 uint32_t const wcnt = waves.size();
411 for (uint32_t n = 0; n < wcnt; ++n) {
414 if (h <= NAME_HIGHLIGHT_THRESH) {
415 ht = ((_height - 2 * wcnt) / (double) wcnt);
417 ht = (((_height - 2 * wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
420 double const yoff = n * (ht + 1);
422 waves[n]->property_height() = ht;
423 waves[n]->property_y() = _y_position + yoff + 2;
427 if ((_height / wcnt) < NAME_HIGHLIGHT_SIZE) {
430 if (_flags & EnvelopeVisible) {
434 gain_line->set_y_position_and_height ((uint32_t) _y_position, (uint32_t) rint (_height - NAME_HIGHLIGHT_SIZE));
437 setup_fade_handle_positions ();
439 reset_fade_shapes ();
442 name_text->raise_to_top();
447 AudioRegionView::setup_fade_handle_positions()
449 /* position of fade handle offset from the top of the region view */
450 double const handle_pos = 2;
451 /* height of fade handles */
452 double const handle_height = 5;
454 if (fade_in_handle) {
455 fade_in_handle->property_y1() = _y_position + handle_pos;
456 fade_in_handle->property_y2() = _y_position + handle_pos + handle_height;
459 if (fade_out_handle) {
460 fade_out_handle->property_y1() = _y_position + handle_pos;
461 fade_out_handle->property_y2() = _y_position + handle_pos + handle_height;
466 AudioRegionView::manage_zero_line ()
472 if (_height >= 100) {
473 double const wave_midpoint = _y_position + (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
474 zero_line->property_y1() = wave_midpoint;
475 zero_line->property_y2() = wave_midpoint;
483 AudioRegionView::reset_fade_shapes ()
485 reset_fade_in_shape ();
486 reset_fade_out_shape ();
490 AudioRegionView::reset_fade_in_shape ()
492 reset_fade_in_shape_width ((nframes_t) audio_region()->fade_in().back()->when);
496 AudioRegionView::reset_fade_in_shape_width (nframes_t width)
498 if (fade_in_handle == 0) {
502 /* smallest size for a fade is 64 frames */
504 width = std::max ((nframes_t) 64, width);
507 double pwidth = width / samples_per_unit;
508 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
512 fade_in_shape->hide();
513 fade_in_handle->hide();
517 double handle_center;
518 handle_center = pwidth;
520 if (handle_center > 7.0) {
521 handle_center -= 3.0;
526 fade_in_handle->property_x1() = handle_center - 3.0;
527 fade_in_handle->property_x2() = handle_center + 3.0;
530 fade_in_shape->hide();
534 fade_in_shape->show();
536 float curve[npoints];
537 audio_region()->fade_in().get_vector (0, audio_region()->fade_in().back()->when, curve, npoints);
539 points = get_canvas_points ("fade in shape", npoints+3);
541 if (_height > NAME_HIGHLIGHT_THRESH) {
542 h = _height - NAME_HIGHLIGHT_SIZE;
547 /* points *MUST* be in anti-clockwise order */
550 double xdelta = pwidth/npoints;
552 for (pi = 0, pc = 0; pc < npoints; ++pc) {
553 (*points)[pi].set_x(1 + (pc * xdelta));
554 (*points)[pi++].set_y(_y_position + 2 + (h - (curve[pc] * h)));
559 (*points)[pi].set_x(pwidth);
560 (*points)[pi++].set_y(_y_position + 2);
562 (*points)[pi].set_x(1);
563 (*points)[pi++].set_y(_y_position + 2);
565 /* connect the dots ... */
567 (*points)[pi] = (*points)[0];
569 fade_in_shape->property_points() = *points;
574 AudioRegionView::reset_fade_out_shape ()
576 reset_fade_out_shape_width ((nframes_t) audio_region()->fade_out().back()->when);
580 AudioRegionView::reset_fade_out_shape_width (nframes_t width)
582 if (fade_out_handle == 0) {
586 /* smallest size for a fade is 64 frames */
588 width = std::max ((nframes_t) 64, width);
591 double pwidth = width / samples_per_unit;
592 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
596 fade_out_shape->hide();
597 fade_out_handle->hide();
601 double handle_center;
602 handle_center = (_region->length() - width) / samples_per_unit;
604 if (handle_center > 7.0) {
605 handle_center -= 3.0;
610 fade_out_handle->property_x1() = handle_center - 3.0;
611 fade_out_handle->property_x2() = handle_center + 3.0;
613 /* don't show shape if its too small */
616 fade_out_shape->hide();
620 fade_out_shape->show();
622 float curve[npoints];
623 audio_region()->fade_out().get_vector (0, audio_region()->fade_out().back()->when, curve, npoints);
625 if (_height > NAME_HIGHLIGHT_THRESH) {
626 h = _height - NAME_HIGHLIGHT_SIZE;
631 /* points *MUST* be in anti-clockwise order */
633 points = get_canvas_points ("fade out shape", npoints+3);
636 double xdelta = pwidth/npoints;
638 for (pi = 0, pc = 0; pc < npoints; ++pc) {
639 (*points)[pi].set_x(_pixel_width - 1 - pwidth + (pc*xdelta));
640 (*points)[pi++].set_y(_y_position + 2 + (h - (curve[pc] * h)));
645 (*points)[pi].set_x(_pixel_width);
646 (*points)[pi++].set_y(_y_position + h);
648 (*points)[pi].set_x(_pixel_width);
649 (*points)[pi++].set_y(_y_position + 2);
651 /* connect the dots ... */
653 (*points)[pi] = (*points)[0];
655 fade_out_shape->property_points() = *points;
660 AudioRegionView::set_samples_per_unit (gdouble spu)
662 RegionView::set_samples_per_unit (spu);
664 if (_flags & WaveformVisible) {
665 for (uint32_t n=0; n < waves.size(); ++n) {
666 waves[n]->property_samples_per_unit() = spu;
674 reset_fade_shapes ();
678 AudioRegionView::set_amplitude_above_axis (gdouble spp)
680 for (uint32_t n=0; n < waves.size(); ++n) {
681 waves[n]->property_amplitude_above_axis() = spp;
686 AudioRegionView::compute_colors (Gdk::Color& basic_color)
688 RegionView::compute_colors(basic_color);
692 /* gain color computed in envelope_active_changed() */
694 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
695 fade_color = RGBA_TO_UINT(r,g,b,120);
699 AudioRegionView::set_colors ()
701 RegionView::set_colors();
704 gain_line->set_line_color (audio_region()->envelope_active() ? Config->canvasvar_GainLine.get() : Config->canvasvar_GainLineInactive.get());
707 for (uint32_t n=0; n < waves.size(); ++n) {
708 if (_region->muted()) {
709 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(Config->canvasvar_WaveForm.get(), MUTED_ALPHA);
711 waves[n]->property_wave_color() = Config->canvasvar_WaveForm.get();
714 waves[n]->property_clip_color() = Config->canvasvar_WaveFormClip.get();
715 waves[n]->property_zero_color() = Config->canvasvar_ZeroLine.get();
720 AudioRegionView::show_region_editor ()
723 editor = new AudioRegionEditor (trackview.session(), audio_region(), *this);
724 // GTK2FIX : how to ensure float without realizing
725 // editor->realize ();
726 // trackview.editor.ensure_float (*editor);
734 AudioRegionView::set_waveform_visible (bool yn)
736 if (((_flags & WaveformVisible) != yn)) {
738 for (uint32_t n=0; n < waves.size(); ++n) {
739 /* make sure the zoom level is correct, since we don't update
740 this when waveforms are hidden.
742 waves[n]->property_samples_per_unit() = samples_per_unit;
745 _flags |= WaveformVisible;
747 for (uint32_t n=0; n < waves.size(); ++n) {
750 _flags &= ~WaveformVisible;
757 AudioRegionView::temporarily_hide_envelope ()
765 AudioRegionView::unhide_envelope ()
767 if (gain_line && (_flags & EnvelopeVisible)) {
773 AudioRegionView::set_envelope_visible (bool yn)
775 if (gain_line && ((_flags & EnvelopeVisible) != yn)) {
778 _flags |= EnvelopeVisible;
781 _flags &= ~EnvelopeVisible;
788 AudioRegionView::create_waves ()
790 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
792 if (!atv.get_diskstream()) {
796 uint32_t nchans = atv.get_diskstream()->n_channels().n_audio();
798 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
799 for (uint32_t n = 0; n < nchans; ++n) {
800 tmp_waves.push_back (0);
803 for (uint32_t n = 0; n < nchans; ++n) {
805 if (n >= audio_region()->n_channels()) {
809 wave_caches.push_back (WaveView::create_cache ());
812 if (audio_region()->audio_source(n)->peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n), data_ready_connection)) {
813 create_one_wave (n, true);
817 create_one_wave (n, true);
823 AudioRegionView::create_one_wave (uint32_t which, bool direct)
825 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
826 uint32_t nchans = atv.get_diskstream()->n_channels().n_audio();
828 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
831 if (trackview.height < NAME_HIGHLIGHT_SIZE) {
832 ht = ((trackview.height) / (double) nchans);
834 ht = ((trackview.height - NAME_HIGHLIGHT_SIZE) / (double) nchans);
837 gdouble yoff = which * ht;
839 WaveView *wave = new WaveView(*group);
841 wave->property_data_src() = (gpointer) _region.get();
842 wave->property_cache() = wave_caches[which];
843 wave->property_cache_updater() = true;
844 wave->property_channel() = which;
845 wave->property_length_function() = (gpointer) region_length_from_c;
846 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
847 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
848 wave->property_x() = 0.0;
849 wave->property_y() = yoff;
850 wave->property_height() = (double) ht;
851 wave->property_samples_per_unit() = samples_per_unit;
852 wave->property_amplitude_above_axis() = _amplitude_above_axis;
853 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(Config->canvasvar_WaveForm.get(), MUTED_ALPHA) : Config->canvasvar_WaveForm.get();
854 wave->property_clip_color() = Config->canvasvar_WaveFormClip.get();
855 wave->property_zero_color() = Config->canvasvar_ZeroLine.get();
856 wave->property_region_start() = _region->start();
857 wave->property_rectified() = (bool) (_flags & WaveformRectified);
858 wave->property_logscaled() = (bool) (_flags & WaveformLogScaled);
860 if (!(_flags & WaveformVisible)) {
864 /* note: calling this function is serialized by the lock
865 held in the peak building thread that signals that
866 peaks are ready for use *or* by the fact that it is
867 called one by one from the GUI thread.
870 if (which < nchans) {
871 tmp_waves[which] = wave;
873 /* n-channel track, >n-channel source */
876 /* see if we're all ready */
878 for (n = 0; n < nchans; ++n) {
879 if (tmp_waves[n] == 0) {
884 if (n == nwaves && waves.empty()) {
885 /* all waves are ready */
886 tmp_waves.resize(nwaves);
891 /* all waves created, don't hook into peaks ready anymore */
892 data_ready_connection.disconnect ();
896 zero_line = new ArdourCanvas::SimpleLine (*group);
897 zero_line->property_x1() = (gdouble) 1.0;
898 zero_line->property_x2() = (gdouble) (_region->length() / samples_per_unit) - 1.0;
899 zero_line->property_color_rgba() = (guint) Config->canvasvar_ZeroLine.get();
906 AudioRegionView::peaks_ready_handler (uint32_t which)
908 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
912 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
914 if (gain_line == 0) {
920 /* don't create points that can't be seen */
922 set_envelope_visible (true);
929 nframes_t fx = trackview.editor.pixel_to_frame (x);
931 if (fx > _region->length()) {
935 /* compute vertical fractional position */
937 y = 1.0 - ((y - _y_position) / (_height - NAME_HIGHLIGHT_SIZE));
939 /* map using gain line */
941 gain_line->view_to_model_y (y);
943 trackview.session().begin_reversible_command (_("add gain control point"));
944 XMLNode &before = audio_region()->envelope().get_state();
946 if (!audio_region()->envelope_active()) {
947 XMLNode ®ion_before = audio_region()->get_state();
948 audio_region()->set_envelope_active(true);
949 XMLNode ®ion_after = audio_region()->get_state();
950 trackview.session().add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
953 audio_region()->envelope().add (fx, y);
955 XMLNode &after = audio_region()->envelope().get_state();
956 trackview.session().add_command (new MementoCommand<Curve>(audio_region()->envelope(), &before, &after));
957 trackview.session().commit_reversible_command ();
961 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
963 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
964 audio_region()->envelope().erase (cp->model);
968 AudioRegionView::store_flags()
970 XMLNode *node = new XMLNode ("GUI");
972 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
973 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
974 node->add_property ("waveform-rectified", (_flags & WaveformRectified) ? "yes" : "no");
975 node->add_property ("waveform-logscaled", (_flags & WaveformLogScaled) ? "yes" : "no");
977 _region->add_extra_xml (*node);
981 AudioRegionView::set_flags (XMLNode* node)
985 if ((prop = node->property ("waveform-visible")) != 0) {
986 if (prop->value() == "yes") {
987 _flags |= WaveformVisible;
991 if ((prop = node->property ("envelope-visible")) != 0) {
992 if (prop->value() == "yes") {
993 _flags |= EnvelopeVisible;
997 if ((prop = node->property ("waveform-rectified")) != 0) {
998 if (prop->value() == "yes") {
999 _flags |= WaveformRectified;
1003 if ((prop = node->property ("waveform-logscaled")) != 0) {
1004 if (prop->value() == "yes") {
1005 _flags |= WaveformLogScaled;
1011 AudioRegionView::set_waveform_shape (WaveformShape shape)
1015 /* this slightly odd approach is to leave the door open to
1016 other "shapes" such as spectral displays, etc.
1029 if (yn != (bool) (_flags & WaveformRectified)) {
1030 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1031 (*wave)->property_rectified() = yn;
1043 _flags |= WaveformRectified;
1045 _flags &= ~WaveformRectified;
1052 AudioRegionView::set_waveform_scale (WaveformScale scale)
1054 bool yn = (scale == LogWaveform);
1056 if (yn != (bool) (_flags & WaveformLogScaled)) {
1057 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1058 (*wave)->property_logscaled() = yn;
1062 _flags |= WaveformLogScaled;
1064 _flags &= ~WaveformLogScaled;
1072 AudioRegionView::add_ghost (AutomationTimeAxisView& atv)
1074 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1077 double unit_position = _region->position () / samples_per_unit;
1078 GhostRegion* ghost = new GhostRegion (atv, unit_position);
1081 nchans = rtv->get_diskstream()->n_channels().n_audio();
1083 for (uint32_t n = 0; n < nchans; ++n) {
1085 if (n >= audio_region()->n_channels()) {
1089 WaveView *wave = new WaveView(*ghost->group);
1091 wave->property_data_src() = _region.get();
1092 wave->property_cache() = wave_caches[n];
1093 wave->property_cache_updater() = false;
1094 wave->property_channel() = n;
1095 wave->property_length_function() = (gpointer)region_length_from_c;
1096 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1097 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1098 wave->property_x() = 0.0;
1099 wave->property_samples_per_unit() = samples_per_unit;
1100 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1101 wave->property_wave_color() = Config->canvasvar_GhostTrackWave.get();
1102 wave->property_clip_color() = Config->canvasvar_GhostTrackWaveClip.get();
1103 wave->property_zero_color() = Config->canvasvar_GhostTrackZeroLine.get();
1104 wave->property_region_start() = _region->start();
1106 ghost->waves.push_back(wave);
1109 ghost->set_height ();
1110 ghost->set_duration (_region->length() / samples_per_unit);
1111 ghosts.push_back (ghost);
1113 ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost));
1119 AudioRegionView::entered ()
1121 if (gain_line && _flags & EnvelopeVisible) {
1122 gain_line->show_all_control_points ();
1126 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1129 if (fade_in_handle) {
1130 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1131 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1136 AudioRegionView::exited ()
1139 gain_line->hide_all_but_selected_control_points ();
1143 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1146 if (fade_in_handle) {
1147 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1148 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1153 AudioRegionView::envelope_active_changed ()
1156 gain_line->set_line_color (audio_region()->envelope_active() ? Config->canvasvar_GainLine.get() : Config->canvasvar_GainLineInactive.get());
1161 AudioRegionView::set_waveview_data_src()
1164 double unit_length= _region->length() / samples_per_unit;
1166 for (uint32_t n = 0; n < waves.size(); ++n) {
1167 // TODO: something else to let it know the channel
1168 waves[n]->property_data_src() = _region.get();
1171 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1173 (*i)->set_duration (unit_length);
1175 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
1176 (*w)->property_data_src() = _region.get();
1183 AudioRegionView::color_handler ()
1185 //case cMutedWaveForm:
1187 //case cWaveFormClip:
1191 //case cGainLineInactive:
1193 envelope_active_changed();