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 string line_name = _region->name();
203 if (!Profile->get_sae()) {
204 gain_line = new AudioRegionGainLine (line_name, trackview.session(), *this, *group, audio_region()->envelope());
207 if (!(_flags & EnvelopeVisible)) {
215 set_height (trackview.current_height());
218 region_sync_changed ();
219 region_resized (BoundsChanged);
220 set_waveview_data_src();
222 envelope_active_changed ();
223 fade_in_active_changed ();
224 fade_out_active_changed ();
226 reset_width_dependent_items (_pixel_width);
228 fade_in_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
229 fade_in_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
230 fade_out_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
231 fade_out_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
235 /* XXX sync mark drag? */
238 AudioRegionView::~AudioRegionView ()
240 in_destructor = true;
242 RegionViewGoingAway (this); /* EMIT_SIGNAL */
244 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
245 gnome_canvas_waveview_cache_destroy (*cache);
248 /* all waveviews etc will be destroyed when the group is destroyed */
255 boost::shared_ptr<ARDOUR::AudioRegion>
256 AudioRegionView::audio_region() const
258 // "Guaranteed" to succeed...
259 return boost::dynamic_pointer_cast<AudioRegion>(_region);
263 AudioRegionView::region_changed (Change what_changed)
265 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionView::region_changed), what_changed));
266 //cerr << "AudioRegionView::region_changed() called" << endl;
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::setup_fade_handle_positions()
439 /* position of fade handle offset from the top of the region view */
440 double const handle_pos = 2;
441 /* height of fade handles */
442 double const handle_height = 5;
444 if (fade_in_handle) {
445 fade_in_handle->property_y1() = handle_pos;
446 fade_in_handle->property_y2() = handle_pos + handle_height;
449 if (fade_out_handle) {
450 fade_out_handle->property_y1() = handle_pos;
451 fade_out_handle->property_y2() = handle_pos + handle_height;
456 AudioRegionView::set_height (gdouble height)
458 RegionView::set_height (height);
460 uint32_t wcnt = waves.size();
467 for (uint32_t n=0; n < wcnt; ++n) {
470 if ((height) < NAME_HIGHLIGHT_THRESH) {
471 ht = ((height-2*wcnt) / (double) wcnt);
473 ht = (((height-2*wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
476 gdouble yoff = n * (ht+1);
478 waves[n]->property_height() = ht;
479 waves[n]->property_y() = yoff + 2;
483 if ((height/wcnt) < NAME_HIGHLIGHT_THRESH) {
486 if (_flags & EnvelopeVisible) {
490 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE));
494 reset_fade_shapes ();
497 name_text->raise_to_top();
502 AudioRegionView::manage_zero_line ()
508 if (_height >= 100) {
509 double const wave_midpoint = (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
510 zero_line->property_y1() = wave_midpoint;
511 zero_line->property_y2() = wave_midpoint;
519 AudioRegionView::reset_fade_shapes ()
521 reset_fade_in_shape ();
522 reset_fade_out_shape ();
526 AudioRegionView::reset_fade_in_shape ()
528 reset_fade_in_shape_width ((nframes_t) audio_region()->fade_in()->back()->when);
532 AudioRegionView::reset_fade_in_shape_width (nframes_t width)
534 if (fade_in_handle == 0) {
538 /* smallest size for a fade is 64 frames */
540 width = std::max ((nframes_t) 64, width);
543 double pwidth = width / samples_per_unit;
544 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
548 fade_in_shape->hide();
549 fade_in_handle->hide();
553 double handle_center;
554 handle_center = pwidth;
556 if (handle_center > 7.0) {
557 handle_center -= 3.0;
562 fade_in_handle->property_x1() = handle_center - 3.0;
563 fade_in_handle->property_x2() = handle_center + 3.0;
566 fade_in_shape->hide();
570 fade_in_shape->show();
572 float curve[npoints];
573 audio_region()->fade_in()->curve().get_vector (0, audio_region()->fade_in()->back()->when, curve, npoints);
575 points = get_canvas_points ("fade in shape", npoints+3);
577 if (_height >= NAME_HIGHLIGHT_THRESH) {
578 h = _height - NAME_HIGHLIGHT_SIZE;
583 /* points *MUST* be in anti-clockwise order */
586 double xdelta = pwidth/npoints;
588 for (pi = 0, pc = 0; pc < npoints; ++pc) {
589 (*points)[pi].set_x(1 + (pc * xdelta));
590 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
595 (*points)[pi].set_x(pwidth);
596 (*points)[pi++].set_y(2);
598 (*points)[pi].set_x(1);
599 (*points)[pi++].set_y(2);
601 /* connect the dots ... */
603 (*points)[pi] = (*points)[0];
605 fade_in_shape->property_points() = *points;
610 AudioRegionView::reset_fade_out_shape ()
612 reset_fade_out_shape_width ((nframes_t) audio_region()->fade_out()->back()->when);
616 AudioRegionView::reset_fade_out_shape_width (nframes_t width)
618 if (fade_out_handle == 0) {
622 /* smallest size for a fade is 64 frames */
624 width = std::max ((nframes_t) 64, width);
627 double pwidth = width / samples_per_unit;
628 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
632 fade_out_shape->hide();
633 fade_out_handle->hide();
637 double handle_center;
638 handle_center = (_region->length() - width) / samples_per_unit;
640 if (handle_center > 7.0) {
641 handle_center -= 3.0;
646 fade_out_handle->property_x1() = handle_center - 3.0;
647 fade_out_handle->property_x2() = handle_center + 3.0;
649 /* don't show shape if its too small */
652 fade_out_shape->hide();
656 fade_out_shape->show();
658 float curve[npoints];
659 audio_region()->fade_out()->curve().get_vector (0, audio_region()->fade_out()->back()->when, curve, npoints);
661 if (_height >= NAME_HIGHLIGHT_THRESH) {
662 h = _height - NAME_HIGHLIGHT_SIZE;
667 /* points *MUST* be in anti-clockwise order */
669 points = get_canvas_points ("fade out shape", npoints+3);
672 double xdelta = pwidth/npoints;
674 for (pi = 0, pc = 0; pc < npoints; ++pc) {
675 (*points)[pi].set_x(_pixel_width - 1 - pwidth + (pc*xdelta));
676 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
681 (*points)[pi].set_x(_pixel_width);
682 (*points)[pi++].set_y(h);
684 (*points)[pi].set_x(_pixel_width);
685 (*points)[pi++].set_y(2);
687 /* connect the dots ... */
689 (*points)[pi] = (*points)[0];
691 fade_out_shape->property_points() = *points;
696 AudioRegionView::set_samples_per_unit (gdouble spu)
698 RegionView::set_samples_per_unit (spu);
700 if (_flags & WaveformVisible) {
701 for (uint32_t n=0; n < waves.size(); ++n) {
702 waves[n]->property_samples_per_unit() = spu;
710 reset_fade_shapes ();
714 AudioRegionView::set_amplitude_above_axis (gdouble spp)
716 for (uint32_t n=0; n < waves.size(); ++n) {
717 waves[n]->property_amplitude_above_axis() = spp;
722 AudioRegionView::compute_colors (Gdk::Color& basic_color)
724 RegionView::compute_colors(basic_color);
728 /* gain color computed in envelope_active_changed() */
730 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
731 fade_color = RGBA_TO_UINT(r,g,b,120);
735 AudioRegionView::set_colors ()
737 RegionView::set_colors();
740 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
743 for (uint32_t n=0; n < waves.size(); ++n) {
744 if (_region->muted()) {
745 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
747 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
750 waves[n]->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
751 waves[n]->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
756 AudioRegionView::show_region_editor ()
759 editor = new AudioRegionEditor (trackview.session(), audio_region(), *this);
760 // GTK2FIX : how to ensure float without realizing
761 // editor->realize ();
762 // trackview.editor.ensure_float (*editor);
770 AudioRegionView::set_waveform_visible (bool yn)
772 if (((_flags & WaveformVisible) != yn)) {
774 for (uint32_t n=0; n < waves.size(); ++n) {
775 /* make sure the zoom level is correct, since we don't update
776 this when waveforms are hidden.
778 waves[n]->property_samples_per_unit() = samples_per_unit;
781 _flags |= WaveformVisible;
783 for (uint32_t n=0; n < waves.size(); ++n) {
786 _flags &= ~WaveformVisible;
793 AudioRegionView::temporarily_hide_envelope ()
801 AudioRegionView::unhide_envelope ()
803 if (gain_line && (_flags & EnvelopeVisible)) {
809 AudioRegionView::set_envelope_visible (bool yn)
811 if (gain_line && ((_flags & EnvelopeVisible) != yn)) {
814 _flags |= EnvelopeVisible;
817 _flags &= ~EnvelopeVisible;
824 AudioRegionView::create_waves ()
826 // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
827 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
829 if (!atv.get_diskstream()) {
833 ChanCount nchans = atv.get_diskstream()->n_channels();
835 // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data
836 // << " and channels = " << nchans.n_audio() << endl;
838 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
839 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
840 tmp_waves.push_back (0);
843 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
845 if (n >= audio_region()->n_channels()) {
849 wave_caches.push_back (WaveView::create_cache ());
851 // cerr << "\tchannel " << n << endl;
854 if (audio_region()->audio_source(n)->peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n), data_ready_connection)) {
855 // cerr << "\tData is ready\n";
856 cerr << "\tData is ready\n";
857 // cerr << "\tData is ready\n";
858 create_one_wave (n, true);
860 // cerr << "\tdata is not ready\n";
861 // we'll get a PeaksReady signal from the source in the future
862 // and will call create_one_wave(n) then.
866 // cerr << "\tdon't delay, display today!\n";
867 create_one_wave (n, true);
874 AudioRegionView::create_one_wave (uint32_t which, bool direct)
876 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
877 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
878 uint32_t nchans = atv.get_diskstream()->n_channels().n_audio();
880 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
883 if (trackview.current_height() < NAME_HIGHLIGHT_THRESH) {
884 ht = ((trackview.current_height()) / (double) nchans);
886 ht = ((trackview.current_height() - NAME_HIGHLIGHT_SIZE) / (double) nchans);
889 gdouble yoff = which * ht;
891 WaveView *wave = new WaveView(*group);
893 wave->property_data_src() = (gpointer) _region.get();
894 wave->property_cache() = wave_caches[which];
895 wave->property_cache_updater() = true;
896 wave->property_channel() = which;
897 wave->property_length_function() = (gpointer) region_length_from_c;
898 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
899 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
900 wave->property_x() = 0.0;
901 wave->property_y() = yoff;
902 wave->property_height() = (double) ht;
903 wave->property_samples_per_unit() = samples_per_unit;
904 wave->property_amplitude_above_axis() = _amplitude_above_axis;
907 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
908 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
910 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_WaveForm.get();
911 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
914 wave->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
915 wave->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
916 wave->property_region_start() = _region->start();
917 wave->property_rectified() = (bool) (_flags & WaveformRectified);
918 wave->property_logscaled() = (bool) (_flags & WaveformLogScaled);
920 if (!(_flags & WaveformVisible)) {
924 /* note: calling this function is serialized by the lock
925 held in the peak building thread that signals that
926 peaks are ready for use *or* by the fact that it is
927 called one by one from the GUI thread.
930 if (which < nchans) {
931 tmp_waves[which] = wave;
933 /* n-channel track, >n-channel source */
936 /* see if we're all ready */
938 for (n = 0; n < nchans; ++n) {
939 if (tmp_waves[n] == 0) {
944 if (n == nwaves && waves.empty()) {
945 /* all waves are ready */
946 tmp_waves.resize(nwaves);
951 /* all waves created, don't hook into peaks ready anymore */
952 data_ready_connection.disconnect ();
956 zero_line = new ArdourCanvas::SimpleLine (*group);
957 zero_line->property_x1() = (gdouble) 1.0;
958 zero_line->property_x2() = (gdouble) (_region->length() / samples_per_unit) - 1.0;
959 zero_line->property_color_rgba() = (guint) ARDOUR_UI::config()->canvasvar_ZeroLine.get();
967 AudioRegionView::peaks_ready_handler (uint32_t which)
969 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
970 // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
974 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
976 if (gain_line == 0) {
982 /* don't create points that can't be seen */
984 set_envelope_visible (true);
991 nframes_t fx = trackview.editor.pixel_to_frame (x);
993 if (fx > _region->length()) {
997 /* compute vertical fractional position */
999 y = 1.0 - (y / (trackview.current_height() - NAME_HIGHLIGHT_SIZE));
1001 /* map using gain line */
1003 gain_line->view_to_model_y (y);
1005 trackview.session().begin_reversible_command (_("add gain control point"));
1006 XMLNode &before = audio_region()->envelope()->get_state();
1008 if (!audio_region()->envelope_active()) {
1009 XMLNode ®ion_before = audio_region()->get_state();
1010 audio_region()->set_envelope_active(true);
1011 XMLNode ®ion_after = audio_region()->get_state();
1012 trackview.session().add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
1015 audio_region()->envelope()->add (fx, y);
1017 XMLNode &after = audio_region()->envelope()->get_state();
1018 trackview.session().add_command (new MementoCommand<AutomationList>(*audio_region()->envelope().get(), &before, &after));
1019 trackview.session().commit_reversible_command ();
1023 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1025 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1026 audio_region()->envelope()->erase (cp->model());
1030 AudioRegionView::store_flags()
1032 XMLNode *node = new XMLNode ("GUI");
1034 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
1035 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
1036 node->add_property ("waveform-rectified", (_flags & WaveformRectified) ? "yes" : "no");
1037 node->add_property ("waveform-logscaled", (_flags & WaveformLogScaled) ? "yes" : "no");
1039 _region->add_extra_xml (*node);
1043 AudioRegionView::set_flags (XMLNode* node)
1047 if ((prop = node->property ("waveform-visible")) != 0) {
1048 if (prop->value() == "yes") {
1049 _flags |= WaveformVisible;
1053 if ((prop = node->property ("envelope-visible")) != 0) {
1054 if (prop->value() == "yes") {
1055 _flags |= EnvelopeVisible;
1059 if ((prop = node->property ("waveform-rectified")) != 0) {
1060 if (prop->value() == "yes") {
1061 _flags |= WaveformRectified;
1065 if ((prop = node->property ("waveform-logscaled")) != 0) {
1066 if (prop->value() == "yes") {
1067 _flags |= WaveformLogScaled;
1073 AudioRegionView::set_waveform_shape (WaveformShape shape)
1077 /* this slightly odd approach is to leave the door open to
1078 other "shapes" such as spectral displays, etc.
1091 if (yn != (bool) (_flags & WaveformRectified)) {
1092 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1093 (*wave)->property_rectified() = yn;
1105 _flags |= WaveformRectified;
1107 _flags &= ~WaveformRectified;
1114 AudioRegionView::set_waveform_scale (WaveformScale scale)
1116 bool yn = (scale == LogWaveform);
1118 if (yn != (bool) (_flags & WaveformLogScaled)) {
1119 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1120 (*wave)->property_logscaled() = yn;
1124 _flags |= WaveformLogScaled;
1126 _flags &= ~WaveformLogScaled;
1134 AudioRegionView::add_ghost (TimeAxisView& tv)
1136 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1139 double unit_position = _region->position () / samples_per_unit;
1140 AudioGhostRegion* ghost = new AudioGhostRegion (tv, trackview, unit_position);
1143 nchans = rtv->get_diskstream()->n_channels().n_audio();
1145 for (uint32_t n = 0; n < nchans; ++n) {
1147 if (n >= audio_region()->n_channels()) {
1151 WaveView *wave = new WaveView(*ghost->group);
1153 wave->property_data_src() = _region.get();
1154 wave->property_cache() = wave_caches[n];
1155 wave->property_cache_updater() = false;
1156 wave->property_channel() = n;
1157 wave->property_length_function() = (gpointer)region_length_from_c;
1158 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1159 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1160 wave->property_x() = 0.0;
1161 wave->property_samples_per_unit() = samples_per_unit;
1162 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1164 wave->property_region_start() = _region->start();
1166 ghost->waves.push_back(wave);
1169 ghost->set_height ();
1170 ghost->set_duration (_region->length() / samples_per_unit);
1171 ghost->set_colors();
1172 ghosts.push_back (ghost);
1174 ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost));
1180 AudioRegionView::entered ()
1182 if (gain_line && _flags & EnvelopeVisible) {
1183 gain_line->show_all_control_points ();
1187 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1190 if (fade_in_handle) {
1191 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1192 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1197 AudioRegionView::exited ()
1200 gain_line->hide_all_but_selected_control_points ();
1204 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1207 if (fade_in_handle) {
1208 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1209 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1214 AudioRegionView::envelope_active_changed ()
1217 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
1222 AudioRegionView::set_waveview_data_src()
1224 AudioGhostRegion* agr;
1225 double unit_length= _region->length() / samples_per_unit;
1227 for (uint32_t n = 0; n < waves.size(); ++n) {
1228 // TODO: something else to let it know the channel
1229 waves[n]->property_data_src() = _region.get();
1232 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1234 (*i)->set_duration (unit_length);
1236 if((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
1237 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
1238 (*w)->property_data_src() = _region.get();
1246 AudioRegionView::color_handler ()
1248 //case cMutedWaveForm:
1250 //case cWaveFormClip:
1254 //case cGainLineInactive:
1256 envelope_active_changed();
1261 AudioRegionView::set_frame_color ()
1267 if (_region->opaque()) {
1275 if (_selected && should_show_selection) {
1276 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_SelectedFrameBase.get(), &r, &g, &b, &a);
1277 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
1279 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1280 if (_region->muted()) {
1281 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get(), MUTED_ALPHA);
1283 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get();
1284 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveFormFill.get();
1289 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_RecordingRect.get(), &r, &g, &b, &a);
1290 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, a);
1292 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1293 if (_region->muted()) {
1294 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA);
1296 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
1297 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
1301 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_FrameBase.get(), &r, &g, &b, &a);
1302 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
1304 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1305 if (_region->muted()) {
1306 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
1308 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
1309 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();