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);
121 AudioRegionView::init (Gdk::Color& basic_color, bool wfd)
123 // FIXME: Some redundancy here with RegionView::init. Need to figure out
124 // where order is important and where it isn't...
126 RegionView::init (basic_color, wfd);
130 _amplitude_above_axis = 1.0;
134 if ((node = _region->extra_xml ("GUI")) != 0) {
137 _flags = WaveformVisible;
141 if (trackview.editor.new_regionviews_display_gain()) {
142 _flags |= EnvelopeVisible;
145 compute_colors (basic_color);
149 fade_in_shape = new ArdourCanvas::Polygon (*group);
150 fade_in_shape->property_fill_color_rgba() = fade_color;
151 fade_in_shape->set_data ("regionview", this);
153 fade_out_shape = new ArdourCanvas::Polygon (*group);
154 fade_out_shape->property_fill_color_rgba() = fade_color;
155 fade_out_shape->set_data ("regionview", this);
160 UINT_TO_RGBA(fill_color,&r,&g,&b,&a);
163 fade_in_handle = new ArdourCanvas::SimpleRect (*group);
164 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
165 fade_in_handle->property_outline_pixels() = 0;
167 fade_in_handle->set_data ("regionview", this);
169 fade_out_handle = new ArdourCanvas::SimpleRect (*group);
170 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
171 fade_out_handle->property_outline_pixels() = 0;
173 fade_out_handle->set_data ("regionview", this);
176 setup_fade_handle_positions ();
178 string line_name = _region->name();
182 if (!Profile->get_sae()) {
183 gain_line = new AudioRegionGainLine (line_name, trackview.session(), *this, *group, audio_region()->envelope());
186 if (!(_flags & EnvelopeVisible)) {
194 set_y_position_and_height (0, trackview.height);
197 region_sync_changed ();
198 region_resized (BoundsChanged);
199 set_waveview_data_src();
201 envelope_active_changed ();
202 fade_in_active_changed ();
203 fade_out_active_changed ();
205 reset_width_dependent_items (_pixel_width);
207 fade_in_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
208 fade_in_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
209 fade_out_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
210 fade_out_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
214 /* XXX sync mark drag? */
217 AudioRegionView::~AudioRegionView ()
219 in_destructor = true;
221 RegionViewGoingAway (this); /* EMIT_SIGNAL */
223 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
224 gnome_canvas_waveview_cache_destroy (*cache);
227 /* all waveviews etc will be destroyed when the group is destroyed */
234 boost::shared_ptr<ARDOUR::AudioRegion>
235 AudioRegionView::audio_region() const
237 // "Guaranteed" to succeed...
238 return boost::dynamic_pointer_cast<AudioRegion>(_region);
242 AudioRegionView::region_changed (Change what_changed)
244 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionView::region_changed), what_changed));
246 RegionView::region_changed(what_changed);
248 if (what_changed & AudioRegion::ScaleAmplitudeChanged) {
249 region_scale_amplitude_changed ();
251 if (what_changed & AudioRegion::FadeInChanged) {
254 if (what_changed & AudioRegion::FadeOutChanged) {
257 if (what_changed & AudioRegion::FadeInActiveChanged) {
258 fade_in_active_changed ();
260 if (what_changed & AudioRegion::FadeOutActiveChanged) {
261 fade_out_active_changed ();
263 if (what_changed & AudioRegion::EnvelopeActiveChanged) {
264 envelope_active_changed ();
269 AudioRegionView::fade_in_changed ()
271 reset_fade_in_shape ();
275 AudioRegionView::fade_out_changed ()
277 reset_fade_out_shape ();
280 AudioRegionView::fade_in_active_changed ()
284 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
286 if (audio_region()->fade_in_active()) {
287 col = RGBA_TO_UINT(r,g,b,120);
288 fade_in_shape->property_fill_color_rgba() = col;
289 fade_in_shape->property_width_pixels() = 0;
290 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
292 col = RGBA_TO_UINT(r,g,b,0);
293 fade_in_shape->property_fill_color_rgba() = col;
294 fade_in_shape->property_width_pixels() = 1;
295 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
300 AudioRegionView::fade_out_active_changed ()
304 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
306 if (audio_region()->fade_out_active()) {
307 col = RGBA_TO_UINT(r,g,b,120);
308 fade_out_shape->property_fill_color_rgba() = col;
309 fade_out_shape->property_width_pixels() = 0;
310 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
312 col = RGBA_TO_UINT(r,g,b,0);
313 fade_out_shape->property_fill_color_rgba() = col;
314 fade_out_shape->property_width_pixels() = 1;
315 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
321 AudioRegionView::region_scale_amplitude_changed ()
323 ENSURE_GUI_THREAD (mem_fun(*this, &AudioRegionView::region_scale_amplitude_changed));
325 for (uint32_t n = 0; n < waves.size(); ++n) {
326 // force a reload of the cache
327 waves[n]->property_data_src() = _region.get();
332 AudioRegionView::region_renamed ()
334 Glib::ustring str = RegionView::make_name ();
336 if (audio_region()->speed_mismatch (trackview.session().frame_rate())) {
337 str = string ("*") + str;
340 if (_region->muted()) {
341 str = string ("!") + str;
344 set_item_name (str, this);
349 AudioRegionView::region_resized (Change what_changed)
351 AudioGhostRegion* agr;
353 RegionView::region_resized(what_changed);
355 if (what_changed & Change (StartChanged|LengthChanged)) {
357 for (uint32_t n = 0; n < waves.size(); ++n) {
358 waves[n]->property_region_start() = _region->start();
361 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
362 if((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
364 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
365 (*w)->property_region_start() = _region->start();
373 AudioRegionView::reset_width_dependent_items (double pixel_width)
375 RegionView::reset_width_dependent_items(pixel_width);
376 assert(_pixel_width == pixel_width);
379 zero_line->property_x2() = pixel_width - 1.0;
382 if (fade_in_handle) {
383 if (pixel_width <= 6.0) {
384 fade_in_handle->hide();
385 fade_out_handle->hide();
388 fade_in_handle->hide();
389 fade_out_handle->hide();
391 fade_in_handle->show();
392 fade_out_handle->show();
397 reset_fade_shapes ();
401 AudioRegionView::region_muted ()
403 RegionView::region_muted();
405 for (uint32_t n=0; n < waves.size(); ++n) {
406 if (_region->muted()) {
407 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
409 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
415 AudioRegionView::set_y_position_and_height (double y, double h)
417 RegionView::set_y_position_and_height(y, h - 1);
419 const uint32_t wcnt = waves.size();
424 for (uint32_t n = 0; n < wcnt; ++n) {
427 if (h <= NAME_HIGHLIGHT_THRESH) {
428 ht = ((_height - 2 * wcnt) / (double) wcnt);
430 ht = (((_height - 2 * wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
433 double const yoff = n * (ht + 1);
435 waves[n]->property_height() = ht;
436 waves[n]->property_y() = _y_position + yoff + 2;
440 if ((_height / wcnt) < NAME_HIGHLIGHT_SIZE) {
443 if (_flags & EnvelopeVisible) {
447 gain_line->set_y_position_and_height ((uint32_t) _y_position, (uint32_t) rint (_height - NAME_HIGHLIGHT_SIZE));
450 setup_fade_handle_positions ();
452 reset_fade_shapes ();
455 name_text->raise_to_top();
460 AudioRegionView::setup_fade_handle_positions()
462 /* position of fade handle offset from the top of the region view */
463 double const handle_pos = 2;
464 /* height of fade handles */
465 double const handle_height = 5;
467 if (fade_in_handle) {
468 fade_in_handle->property_y1() = _y_position + handle_pos;
469 fade_in_handle->property_y2() = _y_position + handle_pos + handle_height;
472 if (fade_out_handle) {
473 fade_out_handle->property_y1() = _y_position + handle_pos;
474 fade_out_handle->property_y2() = _y_position + handle_pos + handle_height;
479 AudioRegionView::manage_zero_line ()
485 if (_height >= 100) {
486 double const wave_midpoint = _y_position + (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
487 zero_line->property_y1() = wave_midpoint;
488 zero_line->property_y2() = wave_midpoint;
496 AudioRegionView::reset_fade_shapes ()
498 reset_fade_in_shape ();
499 reset_fade_out_shape ();
503 AudioRegionView::reset_fade_in_shape ()
505 reset_fade_in_shape_width ((nframes_t) audio_region()->fade_in()->back()->when);
509 AudioRegionView::reset_fade_in_shape_width (nframes_t width)
511 if (fade_in_handle == 0) {
515 /* smallest size for a fade is 64 frames */
517 width = std::max ((nframes_t) 64, width);
520 double pwidth = width / samples_per_unit;
521 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
525 fade_in_shape->hide();
526 fade_in_handle->hide();
530 double handle_center;
531 handle_center = pwidth;
533 if (handle_center > 7.0) {
534 handle_center -= 3.0;
539 fade_in_handle->property_x1() = handle_center - 3.0;
540 fade_in_handle->property_x2() = handle_center + 3.0;
543 fade_in_shape->hide();
547 fade_in_shape->show();
549 float curve[npoints];
550 audio_region()->fade_in()->curve().get_vector (0, audio_region()->fade_in()->back()->when, curve, npoints);
552 points = get_canvas_points ("fade in shape", npoints+3);
554 if (_height > NAME_HIGHLIGHT_THRESH) {
555 h = _height - NAME_HIGHLIGHT_SIZE;
560 /* points *MUST* be in anti-clockwise order */
563 double xdelta = pwidth/npoints;
565 for (pi = 0, pc = 0; pc < npoints; ++pc) {
566 (*points)[pi].set_x(1 + (pc * xdelta));
567 (*points)[pi++].set_y(_y_position + 2 + (h - (curve[pc] * h)));
572 (*points)[pi].set_x(pwidth);
573 (*points)[pi++].set_y(_y_position + 2);
575 (*points)[pi].set_x(1);
576 (*points)[pi++].set_y(_y_position + 2);
578 /* connect the dots ... */
580 (*points)[pi] = (*points)[0];
582 fade_in_shape->property_points() = *points;
587 AudioRegionView::reset_fade_out_shape ()
589 reset_fade_out_shape_width ((nframes_t) audio_region()->fade_out()->back()->when);
593 AudioRegionView::reset_fade_out_shape_width (nframes_t width)
595 if (fade_out_handle == 0) {
599 /* smallest size for a fade is 64 frames */
601 width = std::max ((nframes_t) 64, width);
604 double pwidth = width / samples_per_unit;
605 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
609 fade_out_shape->hide();
610 fade_out_handle->hide();
614 double handle_center;
615 handle_center = (_region->length() - width) / samples_per_unit;
617 if (handle_center > 7.0) {
618 handle_center -= 3.0;
623 fade_out_handle->property_x1() = handle_center - 3.0;
624 fade_out_handle->property_x2() = handle_center + 3.0;
626 /* don't show shape if its too small */
629 fade_out_shape->hide();
633 fade_out_shape->show();
635 float curve[npoints];
636 audio_region()->fade_out()->curve().get_vector (0, audio_region()->fade_out()->back()->when, curve, npoints);
638 if (_height > NAME_HIGHLIGHT_THRESH) {
639 h = _height - NAME_HIGHLIGHT_SIZE;
644 /* points *MUST* be in anti-clockwise order */
646 points = get_canvas_points ("fade out shape", npoints+3);
649 double xdelta = pwidth/npoints;
651 for (pi = 0, pc = 0; pc < npoints; ++pc) {
652 (*points)[pi].set_x(_pixel_width - 1 - pwidth + (pc*xdelta));
653 (*points)[pi++].set_y(_y_position + 2 + (h - (curve[pc] * h)));
658 (*points)[pi].set_x(_pixel_width);
659 (*points)[pi++].set_y(_y_position + h);
661 (*points)[pi].set_x(_pixel_width);
662 (*points)[pi++].set_y(_y_position + 2);
664 /* connect the dots ... */
666 (*points)[pi] = (*points)[0];
668 fade_out_shape->property_points() = *points;
673 AudioRegionView::set_samples_per_unit (gdouble spu)
675 RegionView::set_samples_per_unit (spu);
677 if (_flags & WaveformVisible) {
678 for (uint32_t n=0; n < waves.size(); ++n) {
679 waves[n]->property_samples_per_unit() = spu;
687 reset_fade_shapes ();
691 AudioRegionView::set_amplitude_above_axis (gdouble spp)
693 for (uint32_t n=0; n < waves.size(); ++n) {
694 waves[n]->property_amplitude_above_axis() = spp;
699 AudioRegionView::compute_colors (Gdk::Color& basic_color)
701 RegionView::compute_colors(basic_color);
705 /* gain color computed in envelope_active_changed() */
707 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
708 fade_color = RGBA_TO_UINT(r,g,b,120);
712 AudioRegionView::set_colors ()
714 RegionView::set_colors();
717 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
720 for (uint32_t n=0; n < waves.size(); ++n) {
721 if (_region->muted()) {
722 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
724 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
727 waves[n]->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
728 waves[n]->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
733 AudioRegionView::show_region_editor ()
736 editor = new AudioRegionEditor (trackview.session(), audio_region(), *this);
737 // GTK2FIX : how to ensure float without realizing
738 // editor->realize ();
739 // trackview.editor.ensure_float (*editor);
747 AudioRegionView::set_waveform_visible (bool yn)
749 if (((_flags & WaveformVisible) != yn)) {
751 for (uint32_t n=0; n < waves.size(); ++n) {
752 /* make sure the zoom level is correct, since we don't update
753 this when waveforms are hidden.
755 waves[n]->property_samples_per_unit() = samples_per_unit;
758 _flags |= WaveformVisible;
760 for (uint32_t n=0; n < waves.size(); ++n) {
763 _flags &= ~WaveformVisible;
770 AudioRegionView::temporarily_hide_envelope ()
778 AudioRegionView::unhide_envelope ()
780 if (gain_line && (_flags & EnvelopeVisible)) {
786 AudioRegionView::set_envelope_visible (bool yn)
788 if (gain_line && ((_flags & EnvelopeVisible) != yn)) {
791 _flags |= EnvelopeVisible;
794 _flags &= ~EnvelopeVisible;
801 AudioRegionView::create_waves ()
803 //cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
804 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
806 if (!atv.get_diskstream()) {
810 ChanCount nchans = atv.get_diskstream()->n_channels();
812 cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data << " and channels = " << nchans << endl;
814 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
815 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
816 tmp_waves.push_back (0);
819 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
821 if (n >= audio_region()->n_channels()) {
825 wave_caches.push_back (WaveView::create_cache ());
827 cerr << "\tchannel " << n << endl;
830 if (audio_region()->audio_source(n)->peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n), data_ready_connection)) {
831 cerr << "\tData is ready\n";
832 create_one_wave (n, true);
834 cerr << "\tdata is not ready\n";
835 // we'll get a PeaksReady signal from the source in the future
836 // and will call create_one_wave(n) then.
840 cerr << "\tdon't delay, display today!\n";
841 create_one_wave (n, true);
848 AudioRegionView::create_one_wave (uint32_t which, bool direct)
850 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
851 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
852 uint32_t nchans = atv.get_diskstream()->n_channels().n_audio();
854 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
857 if (trackview.height < NAME_HIGHLIGHT_SIZE) {
858 ht = ((trackview.height) / (double) nchans);
860 ht = ((trackview.height - NAME_HIGHLIGHT_SIZE) / (double) nchans);
863 gdouble yoff = which * ht;
865 WaveView *wave = new WaveView(*group);
867 wave->property_data_src() = (gpointer) _region.get();
868 wave->property_cache() = wave_caches[which];
869 wave->property_cache_updater() = true;
870 wave->property_channel() = which;
871 wave->property_length_function() = (gpointer) region_length_from_c;
872 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
873 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
874 wave->property_x() = 0.0;
875 wave->property_y() = yoff;
876 wave->property_height() = (double) ht;
877 wave->property_samples_per_unit() = samples_per_unit;
878 wave->property_amplitude_above_axis() = _amplitude_above_axis;
879 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_WaveForm.get();
880 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
881 wave->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
882 wave->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
883 wave->property_region_start() = _region->start();
884 wave->property_rectified() = (bool) (_flags & WaveformRectified);
885 wave->property_logscaled() = (bool) (_flags & WaveformLogScaled);
887 if (!(_flags & WaveformVisible)) {
891 /* note: calling this function is serialized by the lock
892 held in the peak building thread that signals that
893 peaks are ready for use *or* by the fact that it is
894 called one by one from the GUI thread.
897 if (which < nchans) {
898 tmp_waves[which] = wave;
900 /* n-channel track, >n-channel source */
903 /* see if we're all ready */
905 for (n = 0; n < nchans; ++n) {
906 if (tmp_waves[n] == 0) {
911 if (n == nwaves && waves.empty()) {
912 /* all waves are ready */
913 tmp_waves.resize(nwaves);
918 /* all waves created, don't hook into peaks ready anymore */
919 data_ready_connection.disconnect ();
923 zero_line = new ArdourCanvas::SimpleLine (*group);
924 zero_line->property_x1() = (gdouble) 1.0;
925 zero_line->property_x2() = (gdouble) (_region->length() / samples_per_unit) - 1.0;
926 zero_line->property_color_rgba() = (guint) ARDOUR_UI::config()->canvasvar_ZeroLine.get();
933 AudioRegionView::peaks_ready_handler (uint32_t which)
935 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
936 // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
940 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
942 if (gain_line == 0) {
948 /* don't create points that can't be seen */
950 set_envelope_visible (true);
957 nframes_t fx = trackview.editor.pixel_to_frame (x);
959 if (fx > _region->length()) {
963 /* compute vertical fractional position */
965 y = 1.0 - ((y - _y_position) / (_height - NAME_HIGHLIGHT_SIZE));
967 /* map using gain line */
969 gain_line->view_to_model_y (y);
971 trackview.session().begin_reversible_command (_("add gain control point"));
972 XMLNode &before = audio_region()->envelope()->get_state();
974 if (!audio_region()->envelope_active()) {
975 XMLNode ®ion_before = audio_region()->get_state();
976 audio_region()->set_envelope_active(true);
977 XMLNode ®ion_after = audio_region()->get_state();
978 trackview.session().add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
981 audio_region()->envelope()->add (fx, y);
983 XMLNode &after = audio_region()->envelope()->get_state();
984 trackview.session().add_command (new MementoCommand<AutomationList>(*audio_region()->envelope().get(), &before, &after));
985 trackview.session().commit_reversible_command ();
989 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
991 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
992 audio_region()->envelope()->erase (cp->model());
996 AudioRegionView::store_flags()
998 XMLNode *node = new XMLNode ("GUI");
1000 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
1001 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
1002 node->add_property ("waveform-rectified", (_flags & WaveformRectified) ? "yes" : "no");
1003 node->add_property ("waveform-logscaled", (_flags & WaveformLogScaled) ? "yes" : "no");
1005 _region->add_extra_xml (*node);
1009 AudioRegionView::set_flags (XMLNode* node)
1013 if ((prop = node->property ("waveform-visible")) != 0) {
1014 if (prop->value() == "yes") {
1015 _flags |= WaveformVisible;
1019 if ((prop = node->property ("envelope-visible")) != 0) {
1020 if (prop->value() == "yes") {
1021 _flags |= EnvelopeVisible;
1025 if ((prop = node->property ("waveform-rectified")) != 0) {
1026 if (prop->value() == "yes") {
1027 _flags |= WaveformRectified;
1031 if ((prop = node->property ("waveform-logscaled")) != 0) {
1032 if (prop->value() == "yes") {
1033 _flags |= WaveformLogScaled;
1039 AudioRegionView::set_waveform_shape (WaveformShape shape)
1043 /* this slightly odd approach is to leave the door open to
1044 other "shapes" such as spectral displays, etc.
1057 if (yn != (bool) (_flags & WaveformRectified)) {
1058 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1059 (*wave)->property_rectified() = yn;
1071 _flags |= WaveformRectified;
1073 _flags &= ~WaveformRectified;
1080 AudioRegionView::set_waveform_scale (WaveformScale scale)
1082 bool yn = (scale == LogWaveform);
1084 if (yn != (bool) (_flags & WaveformLogScaled)) {
1085 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1086 (*wave)->property_logscaled() = yn;
1090 _flags |= WaveformLogScaled;
1092 _flags &= ~WaveformLogScaled;
1100 AudioRegionView::add_ghost (TimeAxisView& tv)
1102 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1105 double unit_position = _region->position () / samples_per_unit;
1106 AudioGhostRegion* ghost = new AudioGhostRegion (tv, trackview, unit_position);
1109 nchans = rtv->get_diskstream()->n_channels().n_audio();
1111 for (uint32_t n = 0; n < nchans; ++n) {
1113 if (n >= audio_region()->n_channels()) {
1117 WaveView *wave = new WaveView(*ghost->group);
1119 wave->property_data_src() = _region.get();
1120 wave->property_cache() = wave_caches[n];
1121 wave->property_cache_updater() = false;
1122 wave->property_channel() = n;
1123 wave->property_length_function() = (gpointer)region_length_from_c;
1124 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1125 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1126 wave->property_x() = 0.0;
1127 wave->property_samples_per_unit() = samples_per_unit;
1128 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1130 wave->property_region_start() = _region->start();
1132 ghost->waves.push_back(wave);
1135 ghost->set_height ();
1136 ghost->set_duration (_region->length() / samples_per_unit);
1137 ghost->set_colors();
1138 ghosts.push_back (ghost);
1140 ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost));
1146 AudioRegionView::entered ()
1148 if (gain_line && _flags & EnvelopeVisible) {
1149 gain_line->show_all_control_points ();
1153 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1156 if (fade_in_handle) {
1157 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1158 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1163 AudioRegionView::exited ()
1166 gain_line->hide_all_but_selected_control_points ();
1170 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1173 if (fade_in_handle) {
1174 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1175 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1180 AudioRegionView::envelope_active_changed ()
1183 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
1188 AudioRegionView::set_waveview_data_src()
1190 AudioGhostRegion* agr;
1191 double unit_length= _region->length() / samples_per_unit;
1193 for (uint32_t n = 0; n < waves.size(); ++n) {
1194 // TODO: something else to let it know the channel
1195 waves[n]->property_data_src() = _region.get();
1198 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1200 (*i)->set_duration (unit_length);
1202 if((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
1203 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
1204 (*w)->property_data_src() = _region.get();
1212 AudioRegionView::color_handler ()
1214 //case cMutedWaveForm:
1216 //case cWaveFormClip:
1220 //case cGainLineInactive:
1222 envelope_active_changed();
1227 AudioRegionView::set_frame_color ()
1233 if (_region->opaque()) {
1241 if (_selected && should_show_selection) {
1242 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_SelectedFrameBase.get(), &r, &g, &b, &a);
1243 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
1245 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1246 if (_region->muted()) {
1247 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get(), MUTED_ALPHA);
1249 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get();
1250 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveFormFill.get();
1254 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_FrameBase.get(), &r, &g, &b, &a);
1255 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
1257 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1258 if (_region->muted()) {
1259 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
1261 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
1262 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();