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.
26 #include <gtkmm2ext/gtk_ui.h>
28 #include <ardour/playlist.h>
29 #include <ardour/audioregion.h>
30 #include <ardour/audiosource.h>
31 #include <ardour/audio_diskstream.h>
32 #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 "ghostregion.h"
46 #include "audio_time_axis.h"
48 #include "rgb_macros.h"
49 #include "gui_thread.h"
50 #include "ardour_ui.h"
54 #define MUTED_ALPHA 10
57 using namespace ARDOUR;
59 using namespace Editing;
60 using namespace ArdourCanvas;
62 static const int32_t sync_mark_width = 9;
64 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
65 Gdk::Color& basic_color)
66 : RegionView (parent, tv, r, spu, basic_color)
74 , _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, bool recording, TimeAxisViewItem::Visibility visibility)
83 : RegionView (parent, tv, r, spu, basic_color, recording, 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;
188 fade_in_handle->property_y1() = 2.0;
189 fade_in_handle->property_y2() = 7.0;
191 fade_in_handle->set_data ("regionview", this);
193 fade_out_handle = new ArdourCanvas::SimpleRect (*group);
194 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
195 fade_out_handle->property_outline_pixels() = 0;
196 fade_out_handle->property_y1() = 2.0;
197 fade_out_handle->property_y2() = 7.0;
199 fade_out_handle->set_data ("regionview", this);
202 string foo = _region->name();
206 if (!Profile->get_sae()) {
207 gain_line = new AudioRegionGainLine (foo, trackview.session(), *this, *group, audio_region()->envelope());
209 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 _region->StateChanged.connect (mem_fun(*this, &AudioRegionView::region_changed));
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 */
258 boost::shared_ptr<ARDOUR::AudioRegion>
259 AudioRegionView::audio_region() const
261 // "Guaranteed" to succeed...
262 return boost::dynamic_pointer_cast<AudioRegion>(_region);
266 AudioRegionView::region_changed (Change what_changed)
268 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionView::region_changed), what_changed));
269 //cerr << "AudioRegionView::region_changed() called" << endl;
271 RegionView::region_changed(what_changed);
273 if (what_changed & AudioRegion::ScaleAmplitudeChanged) {
274 region_scale_amplitude_changed ();
276 if (what_changed & AudioRegion::FadeInChanged) {
279 if (what_changed & AudioRegion::FadeOutChanged) {
282 if (what_changed & AudioRegion::FadeInActiveChanged) {
283 fade_in_active_changed ();
285 if (what_changed & AudioRegion::FadeOutActiveChanged) {
286 fade_out_active_changed ();
288 if (what_changed & AudioRegion::EnvelopeActiveChanged) {
289 envelope_active_changed ();
294 AudioRegionView::fade_in_changed ()
296 reset_fade_in_shape ();
300 AudioRegionView::fade_out_changed ()
302 reset_fade_out_shape ();
305 AudioRegionView::fade_in_active_changed ()
309 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
311 if (audio_region()->fade_in_active()) {
312 col = RGBA_TO_UINT(r,g,b,120);
313 fade_in_shape->property_fill_color_rgba() = col;
314 fade_in_shape->property_width_pixels() = 0;
315 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
317 col = RGBA_TO_UINT(r,g,b,0);
318 fade_in_shape->property_fill_color_rgba() = col;
319 fade_in_shape->property_width_pixels() = 1;
320 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
325 AudioRegionView::fade_out_active_changed ()
329 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
331 if (audio_region()->fade_out_active()) {
332 col = RGBA_TO_UINT(r,g,b,120);
333 fade_out_shape->property_fill_color_rgba() = col;
334 fade_out_shape->property_width_pixels() = 0;
335 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
337 col = RGBA_TO_UINT(r,g,b,0);
338 fade_out_shape->property_fill_color_rgba() = col;
339 fade_out_shape->property_width_pixels() = 1;
340 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
346 AudioRegionView::region_scale_amplitude_changed ()
348 ENSURE_GUI_THREAD (mem_fun(*this, &AudioRegionView::region_scale_amplitude_changed));
350 for (uint32_t n = 0; n < waves.size(); ++n) {
351 // force a reload of the cache
352 waves[n]->property_data_src() = _region.get();
357 AudioRegionView::region_resized (Change what_changed)
359 RegionView::region_resized(what_changed);
361 if (what_changed & Change (StartChanged|LengthChanged)) {
363 for (uint32_t n = 0; n < waves.size(); ++n) {
364 waves[n]->property_region_start() = _region->start();
367 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
369 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
370 (*w)->property_region_start() = _region->start();
377 AudioRegionView::reset_width_dependent_items (double pixel_width)
379 RegionView::reset_width_dependent_items(pixel_width);
380 assert(_pixel_width == pixel_width);
383 zero_line->property_x2() = pixel_width - 1.0;
386 if (fade_in_handle) {
387 if (pixel_width <= 6.0) {
388 fade_in_handle->hide();
389 fade_out_handle->hide();
392 fade_in_handle->hide();
393 fade_out_handle->hide();
395 fade_in_handle->show();
396 fade_out_handle->show();
401 reset_fade_shapes ();
405 AudioRegionView::region_muted ()
407 RegionView::region_muted();
409 for (uint32_t n=0; n < waves.size(); ++n) {
410 if (_region->muted()) {
411 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
413 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
420 AudioRegionView::set_height (gdouble height)
422 RegionView::set_height (height);
424 uint32_t wcnt = waves.size();
428 TimeAxisViewItem::set_height (height);
433 for (uint32_t n=0; n < wcnt; ++n) {
436 if ((height) < NAME_HIGHLIGHT_THRESH) {
437 ht = ((height-2*wcnt) / (double) wcnt);
439 ht = (((height-2*wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
442 gdouble yoff = n * (ht+1);
444 waves[n]->property_height() = ht;
445 waves[n]->property_y() = yoff + 2;
449 if ((height/wcnt) < NAME_HIGHLIGHT_THRESH) {
452 if (_flags & EnvelopeVisible) {
456 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE));
460 reset_fade_shapes ();
463 name_text->raise_to_top();
468 AudioRegionView::manage_zero_line ()
474 if (_height >= 100) {
475 gdouble wave_midpoint = (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
476 zero_line->property_y1() = wave_midpoint;
477 zero_line->property_y2() = wave_midpoint;
485 AudioRegionView::reset_fade_shapes ()
487 reset_fade_in_shape ();
488 reset_fade_out_shape ();
492 AudioRegionView::reset_fade_in_shape ()
494 reset_fade_in_shape_width ((nframes_t) audio_region()->fade_in().back()->when);
498 AudioRegionView::reset_fade_in_shape_width (nframes_t width)
500 if (fade_in_handle == 0) {
504 /* smallest size for a fade is 64 frames */
506 width = std::max ((nframes_t) 64, width);
509 double pwidth = width / samples_per_unit;
510 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
514 fade_in_shape->hide();
515 fade_in_handle->hide();
519 double handle_center;
520 handle_center = pwidth;
522 if (handle_center > 7.0) {
523 handle_center -= 3.0;
528 fade_in_handle->property_x1() = handle_center - 3.0;
529 fade_in_handle->property_x2() = handle_center + 3.0;
532 fade_in_shape->hide();
536 fade_in_shape->show();
538 float curve[npoints];
539 audio_region()->fade_in().get_vector (0, audio_region()->fade_in().back()->when, curve, npoints);
541 points = get_canvas_points ("fade in shape", npoints+3);
543 if (_height >= NAME_HIGHLIGHT_THRESH) {
544 h = _height - NAME_HIGHLIGHT_SIZE;
549 /* points *MUST* be in anti-clockwise order */
552 double xdelta = pwidth/npoints;
554 for (pi = 0, pc = 0; pc < npoints; ++pc) {
555 (*points)[pi].set_x(1 + (pc * xdelta));
556 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
561 (*points)[pi].set_x(pwidth);
562 (*points)[pi++].set_y(2);
564 (*points)[pi].set_x(1);
565 (*points)[pi++].set_y(2);
567 /* connect the dots ... */
569 (*points)[pi] = (*points)[0];
571 fade_in_shape->property_points() = *points;
576 AudioRegionView::reset_fade_out_shape ()
578 reset_fade_out_shape_width ((nframes_t) audio_region()->fade_out().back()->when);
582 AudioRegionView::reset_fade_out_shape_width (nframes_t width)
584 if (fade_out_handle == 0) {
588 /* smallest size for a fade is 64 frames */
590 width = std::max ((nframes_t) 64, width);
593 double pwidth = width / samples_per_unit;
594 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
598 fade_out_shape->hide();
599 fade_out_handle->hide();
603 double handle_center;
604 handle_center = (_region->length() - width) / samples_per_unit;
606 if (handle_center > 7.0) {
607 handle_center -= 3.0;
612 fade_out_handle->property_x1() = handle_center - 3.0;
613 fade_out_handle->property_x2() = handle_center + 3.0;
615 /* don't show shape if its too small */
618 fade_out_shape->hide();
622 fade_out_shape->show();
624 float curve[npoints];
625 audio_region()->fade_out().get_vector (0, audio_region()->fade_out().back()->when, curve, npoints);
627 if (_height >= NAME_HIGHLIGHT_THRESH) {
628 h = _height - NAME_HIGHLIGHT_SIZE;
633 /* points *MUST* be in anti-clockwise order */
635 points = get_canvas_points ("fade out shape", npoints+3);
638 double xdelta = pwidth/npoints;
640 for (pi = 0, pc = 0; pc < npoints; ++pc) {
641 (*points)[pi].set_x(_pixel_width - 1 - pwidth + (pc*xdelta));
642 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
647 (*points)[pi].set_x(_pixel_width);
648 (*points)[pi++].set_y(h);
650 (*points)[pi].set_x(_pixel_width);
651 (*points)[pi++].set_y(2);
653 /* connect the dots ... */
655 (*points)[pi] = (*points)[0];
657 fade_out_shape->property_points() = *points;
662 AudioRegionView::set_samples_per_unit (gdouble spu)
664 RegionView::set_samples_per_unit (spu);
666 if (_flags & WaveformVisible) {
667 for (uint32_t n=0; n < waves.size(); ++n) {
668 waves[n]->property_samples_per_unit() = spu;
676 reset_fade_shapes ();
680 AudioRegionView::set_amplitude_above_axis (gdouble spp)
682 for (uint32_t n=0; n < waves.size(); ++n) {
683 waves[n]->property_amplitude_above_axis() = spp;
688 AudioRegionView::compute_colors (Gdk::Color& basic_color)
690 RegionView::compute_colors(basic_color);
694 /* gain color computed in envelope_active_changed() */
696 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
697 fade_color = RGBA_TO_UINT(r,g,b,120);
701 AudioRegionView::set_colors ()
703 RegionView::set_colors();
706 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
709 for (uint32_t n=0; n < waves.size(); ++n) {
710 if (_region->muted()) {
711 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
713 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
716 waves[n]->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
717 waves[n]->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
722 AudioRegionView::show_region_editor ()
725 editor = new AudioRegionEditor (trackview.session(), audio_region(), *this);
726 // GTK2FIX : how to ensure float without realizing
727 // editor->realize ();
728 // trackview.editor.ensure_float (*editor);
736 AudioRegionView::set_waveform_visible (bool yn)
738 if (((_flags & WaveformVisible) != yn)) {
740 for (uint32_t n=0; n < waves.size(); ++n) {
741 /* make sure the zoom level is correct, since we don't update
742 this when waveforms are hidden.
744 waves[n]->property_samples_per_unit() = samples_per_unit;
747 _flags |= WaveformVisible;
749 for (uint32_t n=0; n < waves.size(); ++n) {
752 _flags &= ~WaveformVisible;
759 AudioRegionView::temporarily_hide_envelope ()
767 AudioRegionView::unhide_envelope ()
769 if (gain_line && (_flags & EnvelopeVisible)) {
775 AudioRegionView::set_envelope_visible (bool yn)
777 if (gain_line && ((_flags & EnvelopeVisible) != yn)) {
780 _flags |= EnvelopeVisible;
783 _flags &= ~EnvelopeVisible;
790 AudioRegionView::create_waves ()
792 // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
793 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
795 if (!atv.get_diskstream()) {
799 uint32_t nchans = atv.get_diskstream()->n_channels();
801 // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data << " and channels = " << nchans << endl;
803 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
804 for (uint32_t n = 0; n < nchans; ++n) {
805 tmp_waves.push_back (0);
808 for (uint32_t n = 0; n < nchans; ++n) {
810 if (n >= audio_region()->n_channels()) {
814 wave_caches.push_back (WaveView::create_cache ());
816 // cerr << "\tchannel " << n << endl;
819 if (audio_region()->source(n)->peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n), data_ready_connection)) {
820 // cerr << "\tData is ready\n";
821 create_one_wave (n, true);
823 // cerr << "\tdata is not ready\n";
824 // we'll get a PeaksReady signal from the source in the future
825 // and will call create_one_wave(n) then.
829 // cerr << "\tdon't delay, display today!\n";
830 create_one_wave (n, true);
837 AudioRegionView::create_one_wave (uint32_t which, bool direct)
839 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
840 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
841 uint32_t nchans = atv.get_diskstream()->n_channels();
843 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
846 if (trackview.current_height() < NAME_HIGHLIGHT_THRESH) {
847 ht = ((trackview.current_height()) / (double) nchans);
849 ht = ((trackview.current_height() - NAME_HIGHLIGHT_SIZE) / (double) nchans);
852 gdouble yoff = which * ht;
854 WaveView *wave = new WaveView(*group);
856 wave->property_data_src() = (gpointer) _region.get();
857 wave->property_cache() = wave_caches[which];
858 wave->property_cache_updater() = true;
859 wave->property_channel() = which;
860 wave->property_length_function() = (gpointer) region_length_from_c;
861 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
862 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
863 wave->property_x() = 0.0;
864 wave->property_y() = yoff;
865 wave->property_height() = (double) ht;
866 wave->property_samples_per_unit() = samples_per_unit;
867 wave->property_amplitude_above_axis() = _amplitude_above_axis;
870 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
871 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
873 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_WaveForm.get();
874 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
877 wave->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
878 wave->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
879 wave->property_region_start() = _region->start();
880 wave->property_rectified() = (bool) (_flags & WaveformRectified);
881 wave->property_logscaled() = (bool) (_flags & WaveformLogScaled);
883 if (!(_flags & WaveformVisible)) {
887 /* note: calling this function is serialized by the lock
888 held in the peak building thread that signals that
889 peaks are ready for use *or* by the fact that it is
890 called one by one from the GUI thread.
893 if (which < nchans) {
894 tmp_waves[which] = wave;
896 /* n-channel track, >n-channel source */
899 /* see if we're all ready */
901 for (n = 0; n < nchans; ++n) {
902 if (tmp_waves[n] == 0) {
907 if (n == nwaves && waves.empty()) {
908 /* all waves are ready */
909 tmp_waves.resize(nwaves);
914 /* all waves created, don't hook into peaks ready anymore */
915 data_ready_connection.disconnect ();
918 zero_line = new ArdourCanvas::SimpleLine (*group);
919 zero_line->property_x1() = (gdouble) 1.0;
920 zero_line->property_x2() = (gdouble) (_region->length() / samples_per_unit) - 1.0;
921 zero_line->property_color_rgba() = (guint) ARDOUR_UI::config()->canvasvar_ZeroLine.get();
928 AudioRegionView::peaks_ready_handler (uint32_t which)
930 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
931 // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
935 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
937 if (gain_line == 0) {
943 /* don't create points that can't be seen */
945 set_envelope_visible (true);
952 nframes_t fx = trackview.editor.pixel_to_frame (x);
954 if (fx > _region->length()) {
958 /* compute vertical fractional position */
960 y = 1.0 - (y / (trackview.current_height() - NAME_HIGHLIGHT_SIZE));
962 /* map using gain line */
964 gain_line->view_to_model_y (y);
966 trackview.session().begin_reversible_command (_("add gain control point"));
967 XMLNode &before = audio_region()->envelope().get_state();
969 if (!audio_region()->envelope_active()) {
970 XMLNode ®ion_before = audio_region()->get_state();
971 audio_region()->set_envelope_active(true);
972 XMLNode ®ion_after = audio_region()->get_state();
973 trackview.session().add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
976 audio_region()->envelope().add (fx, y);
978 XMLNode &after = audio_region()->envelope().get_state();
979 trackview.session().add_command (new MementoCommand<Curve>(audio_region()->envelope(), &before, &after));
980 trackview.session().commit_reversible_command ();
984 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
986 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
987 audio_region()->envelope().erase (cp->model);
991 AudioRegionView::store_flags()
993 XMLNode *node = new XMLNode ("GUI");
995 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
996 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
997 node->add_property ("waveform-rectified", (_flags & WaveformRectified) ? "yes" : "no");
998 node->add_property ("waveform-logscaled", (_flags & WaveformLogScaled) ? "yes" : "no");
1000 _region->add_extra_xml (*node);
1004 AudioRegionView::set_flags (XMLNode* node)
1008 if ((prop = node->property ("waveform-visible")) != 0) {
1009 if (prop->value() == "yes") {
1010 _flags |= WaveformVisible;
1014 if ((prop = node->property ("envelope-visible")) != 0) {
1015 if (prop->value() == "yes") {
1016 _flags |= EnvelopeVisible;
1020 if ((prop = node->property ("waveform-rectified")) != 0) {
1021 if (prop->value() == "yes") {
1022 _flags |= WaveformRectified;
1026 if ((prop = node->property ("waveform-logscaled")) != 0) {
1027 if (prop->value() == "yes") {
1028 _flags |= WaveformLogScaled;
1034 AudioRegionView::set_waveform_shape (WaveformShape shape)
1038 /* this slightly odd approach is to leave the door open to
1039 other "shapes" such as spectral displays, etc.
1052 if (yn != (bool) (_flags & WaveformRectified)) {
1053 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1054 (*wave)->property_rectified() = yn;
1066 _flags |= WaveformRectified;
1068 _flags &= ~WaveformRectified;
1075 AudioRegionView::set_waveform_scale (WaveformScale scale)
1077 bool yn = (scale == LogWaveform);
1079 if (yn != (bool) (_flags & WaveformLogScaled)) {
1080 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1081 (*wave)->property_logscaled() = yn;
1085 _flags |= WaveformLogScaled;
1087 _flags &= ~WaveformLogScaled;
1095 AudioRegionView::add_ghost (AutomationTimeAxisView& atv)
1097 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1100 double unit_position = _region->position () / samples_per_unit;
1101 GhostRegion* ghost = new GhostRegion (atv, unit_position);
1104 nchans = rtv->get_diskstream()->n_channels();
1106 for (uint32_t n = 0; n < nchans; ++n) {
1108 if (n >= audio_region()->n_channels()) {
1112 WaveView *wave = new WaveView(*ghost->group);
1114 wave->property_data_src() = _region.get();
1115 wave->property_cache() = wave_caches[n];
1116 wave->property_cache_updater() = false;
1117 wave->property_channel() = n;
1118 wave->property_length_function() = (gpointer)region_length_from_c;
1119 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1120 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1121 wave->property_x() = 0.0;
1122 wave->property_samples_per_unit() = samples_per_unit;
1123 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1124 wave->property_wave_color() = ARDOUR_UI::config()->canvasvar_GhostTrackWave.get();
1125 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_GhostTrackWave.get();
1126 wave->property_clip_color() = ARDOUR_UI::config()->canvasvar_GhostTrackWaveClip.get();
1127 wave->property_zero_color() = ARDOUR_UI::config()->canvasvar_GhostTrackZeroLine.get();
1128 wave->property_region_start() = _region->start();
1130 ghost->waves.push_back(wave);
1133 ghost->set_height ();
1134 ghost->set_duration (_region->length() / samples_per_unit);
1135 ghosts.push_back (ghost);
1137 ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost));
1143 AudioRegionView::entered ()
1145 if (gain_line && _flags & EnvelopeVisible) {
1146 gain_line->show_all_control_points ();
1150 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1153 if (fade_in_handle) {
1154 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1155 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1160 AudioRegionView::exited ()
1163 gain_line->hide_all_but_selected_control_points ();
1167 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1170 if (fade_in_handle) {
1171 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1172 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1177 AudioRegionView::envelope_active_changed ()
1180 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
1185 AudioRegionView::set_waveview_data_src()
1188 double unit_length= _region->length() / samples_per_unit;
1190 for (uint32_t n = 0; n < waves.size(); ++n) {
1191 // TODO: something else to let it know the channel
1192 waves[n]->property_data_src() = _region.get();
1195 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1197 (*i)->set_duration (unit_length);
1199 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
1200 (*w)->property_data_src() = _region.get();
1207 AudioRegionView::color_handler ()
1210 envelope_active_changed();
1214 AudioRegionView::set_frame_color ()
1220 if (_region->opaque()) {
1228 if (_selected && should_show_selection) {
1229 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_SelectedFrameBase.get(), &r, &g, &b, &a);
1230 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
1232 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1233 if (_region->muted()) {
1234 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get(), MUTED_ALPHA);
1236 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get();
1237 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveFormFill.get();
1242 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_RecordingRect.get(), &r, &g, &b, &a);
1243 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, 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_RecWaveForm.get(), MUTED_ALPHA);
1249 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
1250 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.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();