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)
82 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
83 Gdk::Color& basic_color, bool recording, TimeAxisViewItem::Visibility visibility)
84 : RegionView (parent, tv, r, spu, basic_color, recording, visibility)
92 , _amplitude_above_axis(1.0)
99 AudioRegionView::AudioRegionView (const AudioRegionView& other)
107 , _amplitude_above_axis(1.0)
115 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
116 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
121 AudioRegionView::AudioRegionView (const AudioRegionView& other, boost::shared_ptr<AudioRegion> other_region)
122 : RegionView (other, boost::shared_ptr<Region> (other_region))
129 , _amplitude_above_axis(1.0)
137 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
138 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
144 AudioRegionView::init (Gdk::Color& basic_color, bool wfd)
146 // FIXME: Some redundancy here with RegionView::init. Need to figure out
147 // where order is important and where it isn't...
149 RegionView::init (basic_color, wfd);
153 _amplitude_above_axis = 1.0;
157 if ((node = _region->extra_xml ("GUI")) != 0) {
160 _flags = WaveformVisible;
164 if (trackview.editor().new_regionviews_display_gain()) {
165 _flags |= EnvelopeVisible;
168 compute_colors (basic_color);
172 fade_in_shape = new ArdourCanvas::Polygon (*group);
173 fade_in_shape->property_fill_color_rgba() = fade_color;
174 fade_in_shape->set_data ("regionview", this);
176 fade_out_shape = new ArdourCanvas::Polygon (*group);
177 fade_out_shape->property_fill_color_rgba() = fade_color;
178 fade_out_shape->set_data ("regionview", this);
182 UINT_TO_RGBA(fill_color,&r,&g,&b,&a);
184 fade_in_handle = new ArdourCanvas::SimpleRect (*group);
185 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
186 fade_in_handle->property_outline_pixels() = 0;
188 fade_in_handle->set_data ("regionview", this);
190 fade_out_handle = new ArdourCanvas::SimpleRect (*group);
191 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
192 fade_out_handle->property_outline_pixels() = 0;
194 fade_out_handle->set_data ("regionview", this);
197 setup_fade_handle_positions ();
199 if (!Config->get_show_region_fades()) {
200 set_fade_visibility (false);
203 const string line_name = _region->name() + ":gain";
205 if (!Profile->get_sae()) {
206 gain_line = new AudioRegionGainLine (line_name, trackview.session(), *this, *group,
207 audio_region()->envelope());
210 if (!(_flags & EnvelopeVisible)) {
218 set_height (trackview.current_height());
221 region_sync_changed ();
222 region_resized (BoundsChanged);
223 set_waveview_data_src();
225 envelope_active_changed ();
226 fade_in_active_changed ();
227 fade_out_active_changed ();
229 reset_width_dependent_items (_pixel_width);
231 fade_in_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
232 fade_in_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
233 fade_out_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
234 fade_out_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
238 /* XXX sync mark drag? */
241 AudioRegionView::~AudioRegionView ()
243 in_destructor = true;
245 RegionViewGoingAway (this); /* EMIT_SIGNAL */
247 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
248 gnome_canvas_waveview_cache_destroy (*cache);
251 /* 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));
267 //cerr << "AudioRegionView::region_changed() called" << endl;
269 RegionView::region_changed(what_changed);
271 if (what_changed & AudioRegion::ScaleAmplitudeChanged) {
272 region_scale_amplitude_changed ();
274 if (what_changed & AudioRegion::FadeInChanged) {
277 if (what_changed & AudioRegion::FadeOutChanged) {
280 if (what_changed & AudioRegion::FadeInActiveChanged) {
281 fade_in_active_changed ();
283 if (what_changed & AudioRegion::FadeOutActiveChanged) {
284 fade_out_active_changed ();
286 if (what_changed & AudioRegion::EnvelopeActiveChanged) {
287 envelope_active_changed ();
292 AudioRegionView::fade_in_changed ()
294 reset_fade_in_shape ();
298 AudioRegionView::fade_out_changed ()
300 reset_fade_out_shape ();
303 AudioRegionView::fade_in_active_changed ()
307 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
309 if (audio_region()->fade_in_active()) {
310 col = RGBA_TO_UINT(r,g,b,120);
311 fade_in_shape->property_fill_color_rgba() = col;
312 fade_in_shape->property_width_pixels() = 0;
313 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
315 col = RGBA_TO_UINT(r,g,b,0);
316 fade_in_shape->property_fill_color_rgba() = col;
317 fade_in_shape->property_width_pixels() = 1;
318 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
323 AudioRegionView::fade_out_active_changed ()
327 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
329 if (audio_region()->fade_out_active()) {
330 col = RGBA_TO_UINT(r,g,b,120);
331 fade_out_shape->property_fill_color_rgba() = col;
332 fade_out_shape->property_width_pixels() = 0;
333 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
335 col = RGBA_TO_UINT(r,g,b,0);
336 fade_out_shape->property_fill_color_rgba() = col;
337 fade_out_shape->property_width_pixels() = 1;
338 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
344 AudioRegionView::region_scale_amplitude_changed ()
346 ENSURE_GUI_THREAD (mem_fun(*this, &AudioRegionView::region_scale_amplitude_changed));
348 for (uint32_t n = 0; n < waves.size(); ++n) {
349 // force a reload of the cache
350 waves[n]->property_data_src() = _region.get();
355 AudioRegionView::region_renamed ()
357 Glib::ustring str = RegionView::make_name ();
359 if (audio_region()->speed_mismatch (trackview.session().frame_rate())) {
360 str = string ("*") + str;
363 if (_region->muted()) {
364 str = string ("!") + str;
367 set_item_name (str, this);
372 AudioRegionView::region_resized (Change what_changed)
374 AudioGhostRegion* agr;
376 RegionView::region_resized(what_changed);
378 if (what_changed & Change (StartChanged|LengthChanged)) {
380 for (uint32_t n = 0; n < waves.size(); ++n) {
381 waves[n]->property_region_start() = _region->start();
384 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
385 if((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
387 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
388 (*w)->property_region_start() = _region->start();
396 AudioRegionView::reset_width_dependent_items (double pixel_width)
398 RegionView::reset_width_dependent_items(pixel_width);
399 assert(_pixel_width == pixel_width);
402 zero_line->property_x2() = pixel_width - 1.0;
405 if (fade_in_handle) {
406 if (pixel_width <= 6.0) {
407 fade_in_handle->hide();
408 fade_out_handle->hide();
411 fade_in_handle->hide();
412 fade_out_handle->hide();
414 if (Config->get_show_region_fades()) {
415 fade_in_handle->show();
416 fade_out_handle->show();
422 reset_fade_shapes ();
426 AudioRegionView::region_muted ()
428 RegionView::region_muted();
430 for (uint32_t n=0; n < waves.size(); ++n) {
431 if (_region->muted()) {
432 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
434 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
440 AudioRegionView::setup_fade_handle_positions()
442 /* position of fade handle offset from the top of the region view */
443 double const handle_pos = 2;
444 /* height of fade handles */
445 double const handle_height = 5;
447 if (fade_in_handle) {
448 fade_in_handle->property_y1() = handle_pos;
449 fade_in_handle->property_y2() = handle_pos + handle_height;
452 if (fade_out_handle) {
453 fade_out_handle->property_y1() = handle_pos;
454 fade_out_handle->property_y2() = handle_pos + handle_height;
459 AudioRegionView::set_height (gdouble height)
461 RegionView::set_height (height);
463 uint32_t wcnt = waves.size();
470 for (uint32_t n=0; n < wcnt; ++n) {
473 if ((height) < NAME_HIGHLIGHT_THRESH) {
474 ht = ((height-2*wcnt) / (double) wcnt);
476 ht = (((height-2*wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
479 gdouble yoff = n * (ht+1);
481 waves[n]->property_height() = ht;
482 waves[n]->property_y() = yoff + 2;
486 if ((height/wcnt) < NAME_HIGHLIGHT_THRESH) {
489 if (_flags & EnvelopeVisible) {
493 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE));
497 reset_fade_shapes ();
500 name_text->raise_to_top();
505 AudioRegionView::manage_zero_line ()
511 if (_height >= 100) {
512 double const wave_midpoint = (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
513 zero_line->property_y1() = wave_midpoint;
514 zero_line->property_y2() = wave_midpoint;
522 AudioRegionView::reset_fade_shapes ()
524 reset_fade_in_shape ();
525 reset_fade_out_shape ();
529 AudioRegionView::reset_fade_in_shape ()
531 reset_fade_in_shape_width ((nframes_t) audio_region()->fade_in()->back()->when);
535 AudioRegionView::reset_fade_in_shape_width (nframes_t width)
537 if (fade_in_handle == 0) {
541 /* smallest size for a fade is 64 frames */
543 width = std::max ((nframes_t) 64, width);
546 double pwidth = width / samples_per_unit;
547 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
551 fade_in_shape->hide();
552 fade_in_handle->hide();
556 double handle_center;
557 handle_center = pwidth;
559 if (handle_center > 7.0) {
560 handle_center -= 3.0;
565 fade_in_handle->property_x1() = handle_center - 3.0;
566 fade_in_handle->property_x2() = handle_center + 3.0;
569 fade_in_shape->hide();
573 if (Config->get_show_region_fades()) {
574 fade_in_shape->show();
577 float curve[npoints];
578 audio_region()->fade_in()->curve().get_vector (0, audio_region()->fade_in()->back()->when, curve, npoints);
580 points = get_canvas_points ("fade in shape", npoints+3);
582 if (_height >= NAME_HIGHLIGHT_THRESH) {
583 h = _height - NAME_HIGHLIGHT_SIZE;
588 /* points *MUST* be in anti-clockwise order */
591 double xdelta = pwidth/npoints;
593 for (pi = 0, pc = 0; pc < npoints; ++pc) {
594 (*points)[pi].set_x(1 + (pc * xdelta));
595 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
600 (*points)[pi].set_x(pwidth);
601 (*points)[pi++].set_y(2);
603 (*points)[pi].set_x(1);
604 (*points)[pi++].set_y(2);
606 /* connect the dots ... */
608 (*points)[pi] = (*points)[0];
610 fade_in_shape->property_points() = *points;
615 AudioRegionView::reset_fade_out_shape ()
617 reset_fade_out_shape_width ((nframes_t) audio_region()->fade_out()->back()->when);
621 AudioRegionView::reset_fade_out_shape_width (nframes_t width)
623 if (fade_out_handle == 0) {
627 /* smallest size for a fade is 64 frames */
629 width = std::max ((nframes_t) 64, width);
632 double pwidth = width / samples_per_unit;
633 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
637 fade_out_shape->hide();
638 fade_out_handle->hide();
642 double handle_center;
643 handle_center = (_region->length() - width) / samples_per_unit;
645 if (handle_center > 7.0) {
646 handle_center -= 3.0;
651 fade_out_handle->property_x1() = handle_center - 3.0;
652 fade_out_handle->property_x2() = handle_center + 3.0;
654 /* don't show shape if its too small */
657 fade_out_shape->hide();
661 if (Config->get_show_region_fades()) {
662 fade_out_shape->show();
665 float curve[npoints];
666 audio_region()->fade_out()->curve().get_vector (0, audio_region()->fade_out()->back()->when, curve, npoints);
668 if (_height >= NAME_HIGHLIGHT_THRESH) {
669 h = _height - NAME_HIGHLIGHT_SIZE;
674 /* points *MUST* be in anti-clockwise order */
676 points = get_canvas_points ("fade out shape", npoints+3);
679 double xdelta = pwidth/npoints;
681 for (pi = 0, pc = 0; pc < npoints; ++pc) {
682 (*points)[pi].set_x(_pixel_width - 1 - pwidth + (pc*xdelta));
683 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
688 (*points)[pi].set_x(_pixel_width);
689 (*points)[pi++].set_y(h);
691 (*points)[pi].set_x(_pixel_width);
692 (*points)[pi++].set_y(2);
694 /* connect the dots ... */
696 (*points)[pi] = (*points)[0];
698 fade_out_shape->property_points() = *points;
703 AudioRegionView::set_samples_per_unit (gdouble spu)
705 RegionView::set_samples_per_unit (spu);
707 if (_flags & WaveformVisible) {
708 for (uint32_t n=0; n < waves.size(); ++n) {
709 waves[n]->property_samples_per_unit() = spu;
717 reset_fade_shapes ();
721 AudioRegionView::set_amplitude_above_axis (gdouble spp)
723 for (uint32_t n=0; n < waves.size(); ++n) {
724 waves[n]->property_amplitude_above_axis() = spp;
729 AudioRegionView::compute_colors (Gdk::Color& basic_color)
731 RegionView::compute_colors(basic_color);
735 /* gain color computed in envelope_active_changed() */
737 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
738 fade_color = RGBA_TO_UINT(r,g,b,120);
742 AudioRegionView::set_colors ()
744 RegionView::set_colors();
747 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
750 for (uint32_t n=0; n < waves.size(); ++n) {
751 if (_region->muted()) {
752 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
754 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
757 waves[n]->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
758 waves[n]->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
763 AudioRegionView::show_region_editor ()
766 editor = new AudioRegionEditor (trackview.session(), audio_region(), *this);
767 // GTK2FIX : how to ensure float without realizing
768 // editor->realize ();
769 // trackview.editor.ensure_float (*editor);
777 AudioRegionView::set_waveform_visible (bool yn)
779 if (((_flags & WaveformVisible) != yn)) {
781 for (uint32_t n=0; n < waves.size(); ++n) {
782 /* make sure the zoom level is correct, since we don't update
783 this when waveforms are hidden.
785 waves[n]->property_samples_per_unit() = samples_per_unit;
788 _flags |= WaveformVisible;
790 for (uint32_t n=0; n < waves.size(); ++n) {
793 _flags &= ~WaveformVisible;
800 AudioRegionView::temporarily_hide_envelope ()
808 AudioRegionView::unhide_envelope ()
810 if (gain_line && (_flags & EnvelopeVisible)) {
816 AudioRegionView::set_envelope_visible (bool yn)
818 if (gain_line && ((_flags & EnvelopeVisible) != yn)) {
821 _flags |= EnvelopeVisible;
824 _flags &= ~EnvelopeVisible;
831 AudioRegionView::create_waves ()
833 // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
834 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
836 if (!atv.get_diskstream()) {
840 ChanCount nchans = atv.get_diskstream()->n_channels();
842 // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data
843 // << " and channels = " << nchans.n_audio() << endl;
845 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
846 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
847 tmp_waves.push_back (0);
850 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
852 if (n >= audio_region()->n_channels()) {
856 wave_caches.push_back (WaveView::create_cache ());
858 // cerr << "\tchannel " << n << endl;
861 if (audio_region()->audio_source(n)->peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n), data_ready_connection)) {
862 // cerr << "\tData is ready\n";
863 cerr << "\tData is ready\n";
864 // cerr << "\tData is ready\n";
865 create_one_wave (n, true);
867 // cerr << "\tdata is not ready\n";
868 // we'll get a PeaksReady signal from the source in the future
869 // and will call create_one_wave(n) then.
873 // cerr << "\tdon't delay, display today!\n";
874 create_one_wave (n, true);
881 AudioRegionView::create_one_wave (uint32_t which, bool direct)
883 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
884 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
885 uint32_t nchans = atv.get_diskstream()->n_channels().n_audio();
887 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
890 if (trackview.current_height() < NAME_HIGHLIGHT_THRESH) {
891 ht = ((trackview.current_height()) / (double) nchans);
893 ht = ((trackview.current_height() - NAME_HIGHLIGHT_SIZE) / (double) nchans);
896 gdouble yoff = which * ht;
898 WaveView *wave = new WaveView(*group);
900 wave->property_data_src() = (gpointer) _region.get();
901 wave->property_cache() = wave_caches[which];
902 wave->property_cache_updater() = true;
903 wave->property_channel() = which;
904 wave->property_length_function() = (gpointer) region_length_from_c;
905 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
906 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
907 wave->property_x() = 0.0;
908 wave->property_y() = yoff;
909 wave->property_height() = (double) ht;
910 wave->property_samples_per_unit() = samples_per_unit;
911 wave->property_amplitude_above_axis() = _amplitude_above_axis;
914 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
915 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
917 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_WaveForm.get();
918 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
921 wave->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
922 wave->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
923 wave->property_region_start() = _region->start();
924 wave->property_rectified() = (bool) (_flags & WaveformRectified);
925 wave->property_logscaled() = (bool) (_flags & WaveformLogScaled);
927 if (!(_flags & WaveformVisible)) {
931 /* note: calling this function is serialized by the lock
932 held in the peak building thread that signals that
933 peaks are ready for use *or* by the fact that it is
934 called one by one from the GUI thread.
937 if (which < nchans) {
938 tmp_waves[which] = wave;
940 /* n-channel track, >n-channel source */
943 /* see if we're all ready */
945 for (n = 0; n < nchans; ++n) {
946 if (tmp_waves[n] == 0) {
951 if (n == nwaves && waves.empty()) {
952 /* all waves are ready */
953 tmp_waves.resize(nwaves);
958 /* all waves created, don't hook into peaks ready anymore */
959 data_ready_connection.disconnect ();
963 zero_line = new ArdourCanvas::SimpleLine (*group);
964 zero_line->property_x1() = (gdouble) 1.0;
965 zero_line->property_x2() = (gdouble) (_region->length() / samples_per_unit) - 1.0;
966 zero_line->property_color_rgba() = (guint) ARDOUR_UI::config()->canvasvar_ZeroLine.get();
974 AudioRegionView::peaks_ready_handler (uint32_t which)
976 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
977 // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
981 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
983 if (gain_line == 0) {
989 /* don't create points that can't be seen */
991 set_envelope_visible (true);
998 nframes_t fx = trackview.editor().pixel_to_frame (x);
1000 if (fx > _region->length()) {
1004 /* compute vertical fractional position */
1006 y = 1.0 - (y / (_height - NAME_HIGHLIGHT_SIZE));
1008 /* map using gain line */
1010 gain_line->view_to_model_coord (x, y);
1012 trackview.session().begin_reversible_command (_("add gain control point"));
1013 XMLNode &before = audio_region()->envelope()->get_state();
1015 if (!audio_region()->envelope_active()) {
1016 XMLNode ®ion_before = audio_region()->get_state();
1017 audio_region()->set_envelope_active(true);
1018 XMLNode ®ion_after = audio_region()->get_state();
1019 trackview.session().add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
1022 audio_region()->envelope()->add (fx, y);
1024 XMLNode &after = audio_region()->envelope()->get_state();
1025 trackview.session().add_command (new MementoCommand<AutomationList>(*audio_region()->envelope().get(), &before, &after));
1026 trackview.session().commit_reversible_command ();
1030 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1032 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1033 audio_region()->envelope()->erase (cp->model());
1037 AudioRegionView::store_flags()
1039 XMLNode *node = new XMLNode ("GUI");
1041 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
1042 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
1043 node->add_property ("waveform-rectified", (_flags & WaveformRectified) ? "yes" : "no");
1044 node->add_property ("waveform-logscaled", (_flags & WaveformLogScaled) ? "yes" : "no");
1046 _region->add_extra_xml (*node);
1050 AudioRegionView::set_flags (XMLNode* node)
1054 if ((prop = node->property ("waveform-visible")) != 0) {
1055 if (prop->value() == "yes") {
1056 _flags |= WaveformVisible;
1060 if ((prop = node->property ("envelope-visible")) != 0) {
1061 if (prop->value() == "yes") {
1062 _flags |= EnvelopeVisible;
1066 if ((prop = node->property ("waveform-rectified")) != 0) {
1067 if (prop->value() == "yes") {
1068 _flags |= WaveformRectified;
1072 if ((prop = node->property ("waveform-logscaled")) != 0) {
1073 if (prop->value() == "yes") {
1074 _flags |= WaveformLogScaled;
1080 AudioRegionView::set_waveform_shape (WaveformShape shape)
1084 /* this slightly odd approach is to leave the door open to
1085 other "shapes" such as spectral displays, etc.
1098 if (yn != (bool) (_flags & WaveformRectified)) {
1099 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1100 (*wave)->property_rectified() = yn;
1112 _flags |= WaveformRectified;
1114 _flags &= ~WaveformRectified;
1121 AudioRegionView::set_waveform_scale (WaveformScale scale)
1123 bool yn = (scale == LogWaveform);
1125 if (yn != (bool) (_flags & WaveformLogScaled)) {
1126 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1127 (*wave)->property_logscaled() = yn;
1131 _flags |= WaveformLogScaled;
1133 _flags &= ~WaveformLogScaled;
1141 AudioRegionView::add_ghost (TimeAxisView& tv)
1143 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1146 double unit_position = _region->position () / samples_per_unit;
1147 AudioGhostRegion* ghost = new AudioGhostRegion (tv, trackview, unit_position);
1150 nchans = rtv->get_diskstream()->n_channels().n_audio();
1152 for (uint32_t n = 0; n < nchans; ++n) {
1154 if (n >= audio_region()->n_channels()) {
1158 WaveView *wave = new WaveView(*ghost->group);
1160 wave->property_data_src() = _region.get();
1161 wave->property_cache() = wave_caches[n];
1162 wave->property_cache_updater() = false;
1163 wave->property_channel() = n;
1164 wave->property_length_function() = (gpointer)region_length_from_c;
1165 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1166 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1167 wave->property_x() = 0.0;
1168 wave->property_samples_per_unit() = samples_per_unit;
1169 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1171 wave->property_region_start() = _region->start();
1173 ghost->waves.push_back(wave);
1176 ghost->set_height ();
1177 ghost->set_duration (_region->length() / samples_per_unit);
1178 ghost->set_colors();
1179 ghosts.push_back (ghost);
1181 ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost));
1187 AudioRegionView::entered ()
1189 if (gain_line && _flags & EnvelopeVisible) {
1190 gain_line->show_all_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::exited ()
1207 gain_line->hide_all_but_selected_control_points ();
1211 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1214 if (fade_in_handle) {
1215 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1216 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1221 AudioRegionView::envelope_active_changed ()
1224 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
1229 AudioRegionView::set_waveview_data_src()
1231 AudioGhostRegion* agr;
1232 double unit_length= _region->length() / samples_per_unit;
1234 for (uint32_t n = 0; n < waves.size(); ++n) {
1235 // TODO: something else to let it know the channel
1236 waves[n]->property_data_src() = _region.get();
1239 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1241 (*i)->set_duration (unit_length);
1243 if((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
1244 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
1245 (*w)->property_data_src() = _region.get();
1253 AudioRegionView::color_handler ()
1255 //case cMutedWaveForm:
1257 //case cWaveFormClip:
1261 //case cGainLineInactive:
1263 envelope_active_changed();
1268 AudioRegionView::set_frame_color ()
1274 if (_region->opaque()) {
1282 if (_selected && should_show_selection) {
1283 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_SelectedFrameBase.get(), &r, &g, &b, &a);
1284 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
1286 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1287 if (_region->muted()) {
1288 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get(), MUTED_ALPHA);
1290 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get();
1291 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveFormFill.get();
1296 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_RecordingRect.get(), &r, &g, &b, &a);
1297 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, a);
1299 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1300 if (_region->muted()) {
1301 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA);
1303 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
1304 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
1308 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_FrameBase.get(), &r, &g, &b, &a);
1309 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
1311 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1312 if (_region->muted()) {
1313 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
1315 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
1316 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
1324 AudioRegionView::set_fade_visibility (bool yn)
1327 if (fade_in_shape) {
1328 fade_in_shape->show();
1330 if (fade_out_shape) {
1331 fade_out_shape->show ();
1333 if (fade_in_handle) {
1334 fade_in_handle->show ();
1336 if (fade_out_handle) {
1337 fade_out_handle->show ();
1340 if (fade_in_shape) {
1341 fade_in_shape->hide();
1343 if (fade_out_shape) {
1344 fade_out_shape->hide ();
1346 if (fade_in_handle) {
1347 fade_in_handle->hide ();
1349 if (fade_out_handle) {
1350 fade_out_handle->hide ();