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.
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 <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 "control_point.h"
46 #include "ghostregion.h"
47 #include "audio_time_axis.h"
49 #include "rgb_macros.h"
50 #include "gui_thread.h"
51 #include "ardour_ui.h"
55 #define MUTED_ALPHA 10
58 using namespace ARDOUR;
60 using namespace Editing;
61 using namespace ArdourCanvas;
63 static const int32_t sync_mark_width = 9;
65 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
66 Gdk::Color& basic_color)
67 : RegionView (parent, tv, r, spu, basic_color)
75 , _amplitude_above_axis(1.0)
81 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
82 Gdk::Color& basic_color, TimeAxisViewItem::Visibility visibility)
83 : RegionView (parent, tv, r, spu, basic_color, visibility)
91 , _amplitude_above_axis(1.0)
98 AudioRegionView::AudioRegionView (const AudioRegionView& other)
106 , _amplitude_above_axis(1.0)
114 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
115 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
120 AudioRegionView::AudioRegionView (const AudioRegionView& other, boost::shared_ptr<AudioRegion> other_region)
121 : RegionView (other, boost::shared_ptr<Region> (other_region))
128 , _amplitude_above_axis(1.0)
136 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
137 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
143 AudioRegionView::init (Gdk::Color& basic_color, bool wfd)
145 // FIXME: Some redundancy here with RegionView::init. Need to figure out
146 // where order is important and where it isn't...
148 RegionView::init (basic_color, wfd);
152 _amplitude_above_axis = 1.0;
156 if ((node = _region->extra_xml ("GUI")) != 0) {
159 _flags = WaveformVisible;
163 if (trackview.editor.new_regionviews_display_gain()) {
164 _flags |= EnvelopeVisible;
167 compute_colors (basic_color);
171 fade_in_shape = new ArdourCanvas::Polygon (*group);
172 fade_in_shape->property_fill_color_rgba() = fade_color;
173 fade_in_shape->set_data ("regionview", this);
175 fade_out_shape = new ArdourCanvas::Polygon (*group);
176 fade_out_shape->property_fill_color_rgba() = fade_color;
177 fade_out_shape->set_data ("regionview", this);
182 UINT_TO_RGBA(fill_color,&r,&g,&b,&a);
185 fade_in_handle = new ArdourCanvas::SimpleRect (*group);
186 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
187 fade_in_handle->property_outline_pixels() = 0;
189 fade_in_handle->set_data ("regionview", this);
191 fade_out_handle = new ArdourCanvas::SimpleRect (*group);
192 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
193 fade_out_handle->property_outline_pixels() = 0;
195 fade_out_handle->set_data ("regionview", this);
198 setup_fade_handle_positions ();
200 string line_name = _region->name();
204 if (!Profile->get_sae()) {
205 gain_line = new AudioRegionGainLine (line_name, trackview.session(), *this, *group, audio_region()->envelope());
208 if (!(_flags & EnvelopeVisible)) {
216 set_y_position_and_height (0, trackview.height);
219 region_sync_changed ();
220 region_resized (BoundsChanged);
221 set_waveview_data_src();
223 envelope_active_changed ();
224 fade_in_active_changed ();
225 fade_out_active_changed ();
227 reset_width_dependent_items (_pixel_width);
229 fade_in_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
230 fade_in_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
231 fade_out_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
232 fade_out_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
236 /* XXX sync mark drag? */
239 AudioRegionView::~AudioRegionView ()
241 in_destructor = true;
243 RegionViewGoingAway (this); /* EMIT_SIGNAL */
245 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
246 gnome_canvas_waveview_cache_destroy (*cache);
249 /* all waveviews etc will be destroyed when the group is destroyed */
256 boost::shared_ptr<ARDOUR::AudioRegion>
257 AudioRegionView::audio_region() const
259 // "Guaranteed" to succeed...
260 return boost::dynamic_pointer_cast<AudioRegion>(_region);
264 AudioRegionView::region_changed (Change what_changed)
266 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionView::region_changed), what_changed));
268 RegionView::region_changed(what_changed);
270 if (what_changed & AudioRegion::ScaleAmplitudeChanged) {
271 region_scale_amplitude_changed ();
273 if (what_changed & AudioRegion::FadeInChanged) {
276 if (what_changed & AudioRegion::FadeOutChanged) {
279 if (what_changed & AudioRegion::FadeInActiveChanged) {
280 fade_in_active_changed ();
282 if (what_changed & AudioRegion::FadeOutActiveChanged) {
283 fade_out_active_changed ();
285 if (what_changed & AudioRegion::EnvelopeActiveChanged) {
286 envelope_active_changed ();
291 AudioRegionView::fade_in_changed ()
293 reset_fade_in_shape ();
297 AudioRegionView::fade_out_changed ()
299 reset_fade_out_shape ();
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_renamed ()
356 Glib::ustring str = RegionView::make_name ();
358 if (audio_region()->speed_mismatch (trackview.session().frame_rate())) {
359 str = string ("*") + str;
362 if (_region->muted()) {
363 str = string ("!") + str;
366 set_item_name (str, this);
371 AudioRegionView::region_resized (Change what_changed)
373 AudioGhostRegion* agr;
375 RegionView::region_resized(what_changed);
377 if (what_changed & Change (StartChanged|LengthChanged)) {
379 for (uint32_t n = 0; n < waves.size(); ++n) {
380 waves[n]->property_region_start() = _region->start();
383 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
384 if((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
386 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
387 (*w)->property_region_start() = _region->start();
395 AudioRegionView::reset_width_dependent_items (double pixel_width)
397 RegionView::reset_width_dependent_items(pixel_width);
398 assert(_pixel_width == pixel_width);
401 zero_line->property_x2() = pixel_width - 1.0;
404 if (fade_in_handle) {
405 if (pixel_width <= 6.0) {
406 fade_in_handle->hide();
407 fade_out_handle->hide();
410 fade_in_handle->hide();
411 fade_out_handle->hide();
413 fade_in_handle->show();
414 fade_out_handle->show();
419 reset_fade_shapes ();
423 AudioRegionView::region_muted ()
425 RegionView::region_muted();
427 for (uint32_t n=0; n < waves.size(); ++n) {
428 if (_region->muted()) {
429 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
431 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
437 AudioRegionView::set_y_position_and_height (double y, double h)
439 RegionView::set_y_position_and_height(y, h - 1);
441 const uint32_t wcnt = waves.size();
446 for (uint32_t n = 0; n < wcnt; ++n) {
449 if (h <= NAME_HIGHLIGHT_THRESH) {
450 ht = ((_height - 2 * wcnt) / (double) wcnt);
452 ht = (((_height - 2 * wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
455 double const yoff = n * (ht + 1);
457 waves[n]->property_height() = ht;
458 waves[n]->property_y() = _y_position + yoff + 2;
462 if ((_height / wcnt) < NAME_HIGHLIGHT_SIZE) {
465 if (_flags & EnvelopeVisible) {
469 gain_line->set_y_position_and_height ((uint32_t) _y_position, (uint32_t) rint (_height - NAME_HIGHLIGHT_SIZE));
472 setup_fade_handle_positions ();
474 reset_fade_shapes ();
477 name_text->raise_to_top();
482 AudioRegionView::setup_fade_handle_positions()
484 /* position of fade handle offset from the top of the region view */
485 double const handle_pos = 2;
486 /* height of fade handles */
487 double const handle_height = 5;
489 if (fade_in_handle) {
490 fade_in_handle->property_y1() = _y_position + handle_pos;
491 fade_in_handle->property_y2() = _y_position + handle_pos + handle_height;
494 if (fade_out_handle) {
495 fade_out_handle->property_y1() = _y_position + handle_pos;
496 fade_out_handle->property_y2() = _y_position + handle_pos + handle_height;
501 AudioRegionView::manage_zero_line ()
507 if (_height >= 100) {
508 double const wave_midpoint = _y_position + (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
509 zero_line->property_y1() = wave_midpoint;
510 zero_line->property_y2() = wave_midpoint;
518 AudioRegionView::reset_fade_shapes ()
520 reset_fade_in_shape ();
521 reset_fade_out_shape ();
525 AudioRegionView::reset_fade_in_shape ()
527 reset_fade_in_shape_width ((nframes_t) audio_region()->fade_in()->back()->when);
531 AudioRegionView::reset_fade_in_shape_width (nframes_t width)
533 if (fade_in_handle == 0) {
537 /* smallest size for a fade is 64 frames */
539 width = std::max ((nframes_t) 64, width);
542 double pwidth = width / samples_per_unit;
543 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
547 fade_in_shape->hide();
548 fade_in_handle->hide();
552 double handle_center;
553 handle_center = pwidth;
555 if (handle_center > 7.0) {
556 handle_center -= 3.0;
561 fade_in_handle->property_x1() = handle_center - 3.0;
562 fade_in_handle->property_x2() = handle_center + 3.0;
565 fade_in_shape->hide();
569 fade_in_shape->show();
571 float curve[npoints];
572 audio_region()->fade_in()->curve().get_vector (0, audio_region()->fade_in()->back()->when, curve, npoints);
574 points = get_canvas_points ("fade in shape", npoints+3);
576 if (_height > NAME_HIGHLIGHT_THRESH) {
577 h = _height - NAME_HIGHLIGHT_SIZE;
582 /* points *MUST* be in anti-clockwise order */
585 double xdelta = pwidth/npoints;
587 for (pi = 0, pc = 0; pc < npoints; ++pc) {
588 (*points)[pi].set_x(1 + (pc * xdelta));
589 (*points)[pi++].set_y(_y_position + 2 + (h - (curve[pc] * h)));
594 (*points)[pi].set_x(pwidth);
595 (*points)[pi++].set_y(_y_position + 2);
597 (*points)[pi].set_x(1);
598 (*points)[pi++].set_y(_y_position + 2);
600 /* connect the dots ... */
602 (*points)[pi] = (*points)[0];
604 fade_in_shape->property_points() = *points;
609 AudioRegionView::reset_fade_out_shape ()
611 reset_fade_out_shape_width ((nframes_t) audio_region()->fade_out()->back()->when);
615 AudioRegionView::reset_fade_out_shape_width (nframes_t width)
617 if (fade_out_handle == 0) {
621 /* smallest size for a fade is 64 frames */
623 width = std::max ((nframes_t) 64, width);
626 double pwidth = width / samples_per_unit;
627 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
631 fade_out_shape->hide();
632 fade_out_handle->hide();
636 double handle_center;
637 handle_center = (_region->length() - width) / samples_per_unit;
639 if (handle_center > 7.0) {
640 handle_center -= 3.0;
645 fade_out_handle->property_x1() = handle_center - 3.0;
646 fade_out_handle->property_x2() = handle_center + 3.0;
648 /* don't show shape if its too small */
651 fade_out_shape->hide();
655 fade_out_shape->show();
657 float curve[npoints];
658 audio_region()->fade_out()->curve().get_vector (0, audio_region()->fade_out()->back()->when, curve, npoints);
660 if (_height > NAME_HIGHLIGHT_THRESH) {
661 h = _height - NAME_HIGHLIGHT_SIZE;
666 /* points *MUST* be in anti-clockwise order */
668 points = get_canvas_points ("fade out shape", npoints+3);
671 double xdelta = pwidth/npoints;
673 for (pi = 0, pc = 0; pc < npoints; ++pc) {
674 (*points)[pi].set_x(_pixel_width - 1 - pwidth + (pc*xdelta));
675 (*points)[pi++].set_y(_y_position + 2 + (h - (curve[pc] * h)));
680 (*points)[pi].set_x(_pixel_width);
681 (*points)[pi++].set_y(_y_position + h);
683 (*points)[pi].set_x(_pixel_width);
684 (*points)[pi++].set_y(_y_position + 2);
686 /* connect the dots ... */
688 (*points)[pi] = (*points)[0];
690 fade_out_shape->property_points() = *points;
695 AudioRegionView::set_samples_per_unit (gdouble spu)
697 RegionView::set_samples_per_unit (spu);
699 if (_flags & WaveformVisible) {
700 for (uint32_t n=0; n < waves.size(); ++n) {
701 waves[n]->property_samples_per_unit() = spu;
709 reset_fade_shapes ();
713 AudioRegionView::set_amplitude_above_axis (gdouble spp)
715 for (uint32_t n=0; n < waves.size(); ++n) {
716 waves[n]->property_amplitude_above_axis() = spp;
721 AudioRegionView::compute_colors (Gdk::Color& basic_color)
723 RegionView::compute_colors(basic_color);
727 /* gain color computed in envelope_active_changed() */
729 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
730 fade_color = RGBA_TO_UINT(r,g,b,120);
734 AudioRegionView::set_colors ()
736 RegionView::set_colors();
739 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
742 for (uint32_t n=0; n < waves.size(); ++n) {
743 if (_region->muted()) {
744 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
746 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
749 waves[n]->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
750 waves[n]->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
755 AudioRegionView::show_region_editor ()
758 editor = new AudioRegionEditor (trackview.session(), audio_region(), *this);
759 // GTK2FIX : how to ensure float without realizing
760 // editor->realize ();
761 // trackview.editor.ensure_float (*editor);
769 AudioRegionView::set_waveform_visible (bool yn)
771 if (((_flags & WaveformVisible) != yn)) {
773 for (uint32_t n=0; n < waves.size(); ++n) {
774 /* make sure the zoom level is correct, since we don't update
775 this when waveforms are hidden.
777 waves[n]->property_samples_per_unit() = samples_per_unit;
780 _flags |= WaveformVisible;
782 for (uint32_t n=0; n < waves.size(); ++n) {
785 _flags &= ~WaveformVisible;
792 AudioRegionView::temporarily_hide_envelope ()
800 AudioRegionView::unhide_envelope ()
802 if (gain_line && (_flags & EnvelopeVisible)) {
808 AudioRegionView::set_envelope_visible (bool yn)
810 if (gain_line && ((_flags & EnvelopeVisible) != yn)) {
813 _flags |= EnvelopeVisible;
816 _flags &= ~EnvelopeVisible;
823 AudioRegionView::create_waves ()
825 // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
826 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
828 if (!atv.get_diskstream()) {
832 ChanCount nchans = atv.get_diskstream()->n_channels();
834 // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data
835 // << " and channels = " << nchans.n_audio() << endl;
837 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
838 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
839 tmp_waves.push_back (0);
842 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
844 if (n >= audio_region()->n_channels()) {
848 wave_caches.push_back (WaveView::create_cache ());
850 // cerr << "\tchannel " << n << endl;
853 if (audio_region()->audio_source(n)->peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n), data_ready_connection)) {
854 // cerr << "\tData is ready\n";
855 cerr << "\tData is ready\n";
856 create_one_wave (n, true);
858 // cerr << "\tdata is not ready\n";
859 // we'll get a PeaksReady signal from the source in the future
860 // and will call create_one_wave(n) then.
864 // cerr << "\tdon't delay, display today!\n";
865 create_one_wave (n, true);
872 AudioRegionView::create_one_wave (uint32_t which, bool direct)
874 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
875 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
876 uint32_t nchans = atv.get_diskstream()->n_channels().n_audio();
878 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
881 if (trackview.height < NAME_HIGHLIGHT_SIZE) {
882 ht = ((trackview.height) / (double) nchans);
884 ht = ((trackview.height - NAME_HIGHLIGHT_SIZE) / (double) nchans);
887 gdouble yoff = which * ht;
889 WaveView *wave = new WaveView(*group);
891 wave->property_data_src() = (gpointer) _region.get();
892 wave->property_cache() = wave_caches[which];
893 wave->property_cache_updater() = true;
894 wave->property_channel() = which;
895 wave->property_length_function() = (gpointer) region_length_from_c;
896 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
897 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
898 wave->property_x() = 0.0;
899 wave->property_y() = yoff;
900 wave->property_height() = (double) ht;
901 wave->property_samples_per_unit() = samples_per_unit;
902 wave->property_amplitude_above_axis() = _amplitude_above_axis;
903 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_WaveForm.get();
904 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
905 wave->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
906 wave->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
907 wave->property_region_start() = _region->start();
908 wave->property_rectified() = (bool) (_flags & WaveformRectified);
909 wave->property_logscaled() = (bool) (_flags & WaveformLogScaled);
911 if (!(_flags & WaveformVisible)) {
915 /* note: calling this function is serialized by the lock
916 held in the peak building thread that signals that
917 peaks are ready for use *or* by the fact that it is
918 called one by one from the GUI thread.
921 if (which < nchans) {
922 tmp_waves[which] = wave;
924 /* n-channel track, >n-channel source */
927 /* see if we're all ready */
929 for (n = 0; n < nchans; ++n) {
930 if (tmp_waves[n] == 0) {
935 if (n == nwaves && waves.empty()) {
936 /* all waves are ready */
937 tmp_waves.resize(nwaves);
942 /* all waves created, don't hook into peaks ready anymore */
943 data_ready_connection.disconnect ();
947 zero_line = new ArdourCanvas::SimpleLine (*group);
948 zero_line->property_x1() = (gdouble) 1.0;
949 zero_line->property_x2() = (gdouble) (_region->length() / samples_per_unit) - 1.0;
950 zero_line->property_color_rgba() = (guint) ARDOUR_UI::config()->canvasvar_ZeroLine.get();
957 AudioRegionView::peaks_ready_handler (uint32_t which)
959 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
960 // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
964 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
966 if (gain_line == 0) {
972 /* don't create points that can't be seen */
974 set_envelope_visible (true);
981 nframes_t fx = trackview.editor.pixel_to_frame (x);
983 if (fx > _region->length()) {
987 /* compute vertical fractional position */
989 y = 1.0 - ((y - _y_position) / (_height - NAME_HIGHLIGHT_SIZE));
991 /* map using gain line */
993 gain_line->view_to_model_y (y);
995 trackview.session().begin_reversible_command (_("add gain control point"));
996 XMLNode &before = audio_region()->envelope()->get_state();
998 if (!audio_region()->envelope_active()) {
999 XMLNode ®ion_before = audio_region()->get_state();
1000 audio_region()->set_envelope_active(true);
1001 XMLNode ®ion_after = audio_region()->get_state();
1002 trackview.session().add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
1005 audio_region()->envelope()->add (fx, y);
1007 XMLNode &after = audio_region()->envelope()->get_state();
1008 trackview.session().add_command (new MementoCommand<AutomationList>(*audio_region()->envelope().get(), &before, &after));
1009 trackview.session().commit_reversible_command ();
1013 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1015 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1016 audio_region()->envelope()->erase (cp->model());
1020 AudioRegionView::store_flags()
1022 XMLNode *node = new XMLNode ("GUI");
1024 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
1025 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
1026 node->add_property ("waveform-rectified", (_flags & WaveformRectified) ? "yes" : "no");
1027 node->add_property ("waveform-logscaled", (_flags & WaveformLogScaled) ? "yes" : "no");
1029 _region->add_extra_xml (*node);
1033 AudioRegionView::set_flags (XMLNode* node)
1037 if ((prop = node->property ("waveform-visible")) != 0) {
1038 if (prop->value() == "yes") {
1039 _flags |= WaveformVisible;
1043 if ((prop = node->property ("envelope-visible")) != 0) {
1044 if (prop->value() == "yes") {
1045 _flags |= EnvelopeVisible;
1049 if ((prop = node->property ("waveform-rectified")) != 0) {
1050 if (prop->value() == "yes") {
1051 _flags |= WaveformRectified;
1055 if ((prop = node->property ("waveform-logscaled")) != 0) {
1056 if (prop->value() == "yes") {
1057 _flags |= WaveformLogScaled;
1063 AudioRegionView::set_waveform_shape (WaveformShape shape)
1067 /* this slightly odd approach is to leave the door open to
1068 other "shapes" such as spectral displays, etc.
1081 if (yn != (bool) (_flags & WaveformRectified)) {
1082 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1083 (*wave)->property_rectified() = yn;
1095 _flags |= WaveformRectified;
1097 _flags &= ~WaveformRectified;
1104 AudioRegionView::set_waveform_scale (WaveformScale scale)
1106 bool yn = (scale == LogWaveform);
1108 if (yn != (bool) (_flags & WaveformLogScaled)) {
1109 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1110 (*wave)->property_logscaled() = yn;
1114 _flags |= WaveformLogScaled;
1116 _flags &= ~WaveformLogScaled;
1124 AudioRegionView::add_ghost (TimeAxisView& tv)
1126 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1129 double unit_position = _region->position () / samples_per_unit;
1130 AudioGhostRegion* ghost = new AudioGhostRegion (tv, trackview, unit_position);
1133 nchans = rtv->get_diskstream()->n_channels().n_audio();
1135 for (uint32_t n = 0; n < nchans; ++n) {
1137 if (n >= audio_region()->n_channels()) {
1141 WaveView *wave = new WaveView(*ghost->group);
1143 wave->property_data_src() = _region.get();
1144 wave->property_cache() = wave_caches[n];
1145 wave->property_cache_updater() = false;
1146 wave->property_channel() = n;
1147 wave->property_length_function() = (gpointer)region_length_from_c;
1148 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1149 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1150 wave->property_x() = 0.0;
1151 wave->property_samples_per_unit() = samples_per_unit;
1152 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1154 wave->property_region_start() = _region->start();
1156 ghost->waves.push_back(wave);
1159 ghost->set_height ();
1160 ghost->set_duration (_region->length() / samples_per_unit);
1161 ghost->set_colors();
1162 ghosts.push_back (ghost);
1164 ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost));
1170 AudioRegionView::entered ()
1172 if (gain_line && _flags & EnvelopeVisible) {
1173 gain_line->show_all_control_points ();
1177 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1180 if (fade_in_handle) {
1181 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1182 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1187 AudioRegionView::exited ()
1190 gain_line->hide_all_but_selected_control_points ();
1194 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1197 if (fade_in_handle) {
1198 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1199 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1204 AudioRegionView::envelope_active_changed ()
1207 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
1212 AudioRegionView::set_waveview_data_src()
1214 AudioGhostRegion* agr;
1215 double unit_length= _region->length() / samples_per_unit;
1217 for (uint32_t n = 0; n < waves.size(); ++n) {
1218 // TODO: something else to let it know the channel
1219 waves[n]->property_data_src() = _region.get();
1222 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1224 (*i)->set_duration (unit_length);
1226 if((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
1227 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
1228 (*w)->property_data_src() = _region.get();
1236 AudioRegionView::color_handler ()
1238 //case cMutedWaveForm:
1240 //case cWaveFormClip:
1244 //case cGainLineInactive:
1246 envelope_active_changed();
1251 AudioRegionView::set_frame_color ()
1257 if (_region->opaque()) {
1265 if (_selected && should_show_selection) {
1266 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_SelectedFrameBase.get(), &r, &g, &b, &a);
1267 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
1269 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1270 if (_region->muted()) {
1271 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get(), MUTED_ALPHA);
1273 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get();
1274 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveFormFill.get();
1278 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_FrameBase.get(), &r, &g, &b, &a);
1279 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
1281 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1282 if (_region->muted()) {
1283 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
1285 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
1286 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();