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 string line_name = _region->name();
207 if (!Profile->get_sae()) {
208 gain_line = new AudioRegionGainLine (line_name, trackview.session(), *this, *group, audio_region()->envelope());
211 if (!(_flags & EnvelopeVisible)) {
219 set_height (trackview.current_height());
222 region_sync_changed ();
223 region_resized (BoundsChanged);
224 set_waveview_data_src();
226 envelope_active_changed ();
227 fade_in_active_changed ();
228 fade_out_active_changed ();
230 reset_width_dependent_items (_pixel_width);
232 fade_in_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
233 fade_in_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
234 fade_out_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
235 fade_out_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
239 /* XXX sync mark drag? */
242 AudioRegionView::~AudioRegionView ()
244 in_destructor = true;
246 RegionViewGoingAway (this); /* EMIT_SIGNAL */
248 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
249 gnome_canvas_waveview_cache_destroy (*cache);
252 /* all waveviews etc will be destroyed when the group is destroyed */
257 boost::shared_ptr<ARDOUR::AudioRegion>
258 AudioRegionView::audio_region() const
260 // "Guaranteed" to succeed...
261 return boost::dynamic_pointer_cast<AudioRegion>(_region);
265 AudioRegionView::region_changed (Change what_changed)
267 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionView::region_changed), what_changed));
268 //cerr << "AudioRegionView::region_changed() called" << endl;
270 RegionView::region_changed(what_changed);
272 if (what_changed & AudioRegion::ScaleAmplitudeChanged) {
273 region_scale_amplitude_changed ();
275 if (what_changed & AudioRegion::FadeInChanged) {
278 if (what_changed & AudioRegion::FadeOutChanged) {
281 if (what_changed & AudioRegion::FadeInActiveChanged) {
282 fade_in_active_changed ();
284 if (what_changed & AudioRegion::FadeOutActiveChanged) {
285 fade_out_active_changed ();
287 if (what_changed & AudioRegion::EnvelopeActiveChanged) {
288 envelope_active_changed ();
293 AudioRegionView::fade_in_changed ()
295 reset_fade_in_shape ();
299 AudioRegionView::fade_out_changed ()
301 reset_fade_out_shape ();
304 AudioRegionView::fade_in_active_changed ()
308 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
310 if (audio_region()->fade_in_active()) {
311 col = RGBA_TO_UINT(r,g,b,120);
312 fade_in_shape->property_fill_color_rgba() = col;
313 fade_in_shape->property_width_pixels() = 0;
314 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
316 col = RGBA_TO_UINT(r,g,b,0);
317 fade_in_shape->property_fill_color_rgba() = col;
318 fade_in_shape->property_width_pixels() = 1;
319 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
324 AudioRegionView::fade_out_active_changed ()
328 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
330 if (audio_region()->fade_out_active()) {
331 col = RGBA_TO_UINT(r,g,b,120);
332 fade_out_shape->property_fill_color_rgba() = col;
333 fade_out_shape->property_width_pixels() = 0;
334 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
336 col = RGBA_TO_UINT(r,g,b,0);
337 fade_out_shape->property_fill_color_rgba() = col;
338 fade_out_shape->property_width_pixels() = 1;
339 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
345 AudioRegionView::region_scale_amplitude_changed ()
347 ENSURE_GUI_THREAD (mem_fun(*this, &AudioRegionView::region_scale_amplitude_changed));
349 for (uint32_t n = 0; n < waves.size(); ++n) {
350 // force a reload of the cache
351 waves[n]->property_data_src() = _region.get();
356 AudioRegionView::region_renamed ()
358 Glib::ustring str = RegionView::make_name ();
360 if (audio_region()->speed_mismatch (trackview.session().frame_rate())) {
361 str = string ("*") + str;
364 if (_region->muted()) {
365 str = string ("!") + str;
368 set_item_name (str, this);
373 AudioRegionView::region_resized (Change what_changed)
375 AudioGhostRegion* agr;
377 RegionView::region_resized(what_changed);
379 if (what_changed & Change (StartChanged|LengthChanged)) {
381 for (uint32_t n = 0; n < waves.size(); ++n) {
382 waves[n]->property_region_start() = _region->start();
385 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
386 if((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
388 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
389 (*w)->property_region_start() = _region->start();
397 AudioRegionView::reset_width_dependent_items (double pixel_width)
399 RegionView::reset_width_dependent_items(pixel_width);
400 assert(_pixel_width == pixel_width);
403 zero_line->property_x2() = pixel_width - 1.0;
406 if (fade_in_handle) {
407 if (pixel_width <= 6.0) {
408 fade_in_handle->hide();
409 fade_out_handle->hide();
412 fade_in_handle->hide();
413 fade_out_handle->hide();
415 if (Config->get_show_region_fades()) {
416 fade_in_handle->show();
417 fade_out_handle->show();
423 reset_fade_shapes ();
427 AudioRegionView::region_muted ()
429 RegionView::region_muted();
431 for (uint32_t n=0; n < waves.size(); ++n) {
432 if (_region->muted()) {
433 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
435 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
441 AudioRegionView::setup_fade_handle_positions()
443 /* position of fade handle offset from the top of the region view */
444 double const handle_pos = 2;
445 /* height of fade handles */
446 double const handle_height = 5;
448 if (fade_in_handle) {
449 fade_in_handle->property_y1() = handle_pos;
450 fade_in_handle->property_y2() = handle_pos + handle_height;
453 if (fade_out_handle) {
454 fade_out_handle->property_y1() = handle_pos;
455 fade_out_handle->property_y2() = handle_pos + handle_height;
460 AudioRegionView::set_height (gdouble height)
462 RegionView::set_height (height);
464 uint32_t wcnt = waves.size();
471 for (uint32_t n=0; n < wcnt; ++n) {
474 if ((height) < NAME_HIGHLIGHT_THRESH) {
475 ht = ((height-2*wcnt) / (double) wcnt);
477 ht = (((height-2*wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
480 gdouble yoff = n * (ht+1);
482 waves[n]->property_height() = ht;
483 waves[n]->property_y() = yoff + 2;
487 if ((height/wcnt) < NAME_HIGHLIGHT_THRESH) {
490 if (_flags & EnvelopeVisible) {
494 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE));
498 reset_fade_shapes ();
501 name_text->raise_to_top();
506 AudioRegionView::manage_zero_line ()
512 if (_height >= 100) {
513 double const wave_midpoint = (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
514 zero_line->property_y1() = wave_midpoint;
515 zero_line->property_y2() = wave_midpoint;
523 AudioRegionView::reset_fade_shapes ()
525 reset_fade_in_shape ();
526 reset_fade_out_shape ();
530 AudioRegionView::reset_fade_in_shape ()
532 reset_fade_in_shape_width ((nframes_t) audio_region()->fade_in()->back()->when);
536 AudioRegionView::reset_fade_in_shape_width (nframes_t width)
538 if (fade_in_handle == 0) {
542 /* smallest size for a fade is 64 frames */
544 width = std::max ((nframes_t) 64, width);
547 double pwidth = width / samples_per_unit;
548 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
552 fade_in_shape->hide();
553 fade_in_handle->hide();
557 double handle_center;
558 handle_center = pwidth;
560 if (handle_center > 7.0) {
561 handle_center -= 3.0;
566 fade_in_handle->property_x1() = handle_center - 3.0;
567 fade_in_handle->property_x2() = handle_center + 3.0;
570 fade_in_shape->hide();
574 if (Config->get_show_region_fades()) {
575 fade_in_shape->show();
578 float curve[npoints];
579 audio_region()->fade_in()->curve().get_vector (0, audio_region()->fade_in()->back()->when, curve, npoints);
581 points = get_canvas_points ("fade in shape", npoints+3);
583 if (_height >= NAME_HIGHLIGHT_THRESH) {
584 h = _height - NAME_HIGHLIGHT_SIZE;
589 /* points *MUST* be in anti-clockwise order */
592 double xdelta = pwidth/npoints;
594 for (pi = 0, pc = 0; pc < npoints; ++pc) {
595 (*points)[pi].set_x(1 + (pc * xdelta));
596 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
601 (*points)[pi].set_x(pwidth);
602 (*points)[pi++].set_y(2);
604 (*points)[pi].set_x(1);
605 (*points)[pi++].set_y(2);
607 /* connect the dots ... */
609 (*points)[pi] = (*points)[0];
611 fade_in_shape->property_points() = *points;
616 AudioRegionView::reset_fade_out_shape ()
618 reset_fade_out_shape_width ((nframes_t) audio_region()->fade_out()->back()->when);
622 AudioRegionView::reset_fade_out_shape_width (nframes_t width)
624 if (fade_out_handle == 0) {
628 /* smallest size for a fade is 64 frames */
630 width = std::max ((nframes_t) 64, width);
633 double pwidth = width / samples_per_unit;
634 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
638 fade_out_shape->hide();
639 fade_out_handle->hide();
643 double handle_center;
644 handle_center = (_region->length() - width) / samples_per_unit;
646 if (handle_center > 7.0) {
647 handle_center -= 3.0;
652 fade_out_handle->property_x1() = handle_center - 3.0;
653 fade_out_handle->property_x2() = handle_center + 3.0;
655 /* don't show shape if its too small */
658 fade_out_shape->hide();
662 if (Config->get_show_region_fades()) {
663 fade_out_shape->show();
666 float curve[npoints];
667 audio_region()->fade_out()->curve().get_vector (0, audio_region()->fade_out()->back()->when, curve, npoints);
669 if (_height >= NAME_HIGHLIGHT_THRESH) {
670 h = _height - NAME_HIGHLIGHT_SIZE;
675 /* points *MUST* be in anti-clockwise order */
677 points = get_canvas_points ("fade out shape", npoints+3);
680 double xdelta = pwidth/npoints;
682 for (pi = 0, pc = 0; pc < npoints; ++pc) {
683 (*points)[pi].set_x(_pixel_width - 1 - pwidth + (pc*xdelta));
684 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
689 (*points)[pi].set_x(_pixel_width);
690 (*points)[pi++].set_y(h);
692 (*points)[pi].set_x(_pixel_width);
693 (*points)[pi++].set_y(2);
695 /* connect the dots ... */
697 (*points)[pi] = (*points)[0];
699 fade_out_shape->property_points() = *points;
704 AudioRegionView::set_samples_per_unit (gdouble spu)
706 RegionView::set_samples_per_unit (spu);
708 if (_flags & WaveformVisible) {
709 for (uint32_t n=0; n < waves.size(); ++n) {
710 waves[n]->property_samples_per_unit() = spu;
718 reset_fade_shapes ();
722 AudioRegionView::set_amplitude_above_axis (gdouble spp)
724 for (uint32_t n=0; n < waves.size(); ++n) {
725 waves[n]->property_amplitude_above_axis() = spp;
730 AudioRegionView::compute_colors (Gdk::Color& basic_color)
732 RegionView::compute_colors(basic_color);
736 /* gain color computed in envelope_active_changed() */
738 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
739 fade_color = RGBA_TO_UINT(r,g,b,120);
743 AudioRegionView::set_colors ()
745 RegionView::set_colors();
748 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
751 for (uint32_t n=0; n < waves.size(); ++n) {
752 if (_region->muted()) {
753 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
755 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
758 waves[n]->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
759 waves[n]->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
764 AudioRegionView::show_region_editor ()
767 editor = new AudioRegionEditor (trackview.session(), audio_region(), *this);
768 // GTK2FIX : how to ensure float without realizing
769 // editor->realize ();
770 // trackview.editor.ensure_float (*editor);
778 AudioRegionView::set_waveform_visible (bool yn)
780 if (((_flags & WaveformVisible) != yn)) {
782 for (uint32_t n=0; n < waves.size(); ++n) {
783 /* make sure the zoom level is correct, since we don't update
784 this when waveforms are hidden.
786 waves[n]->property_samples_per_unit() = samples_per_unit;
789 _flags |= WaveformVisible;
791 for (uint32_t n=0; n < waves.size(); ++n) {
794 _flags &= ~WaveformVisible;
801 AudioRegionView::temporarily_hide_envelope ()
809 AudioRegionView::unhide_envelope ()
811 if (gain_line && (_flags & EnvelopeVisible)) {
817 AudioRegionView::set_envelope_visible (bool yn)
819 if (gain_line && ((_flags & EnvelopeVisible) != yn)) {
822 _flags |= EnvelopeVisible;
825 _flags &= ~EnvelopeVisible;
832 AudioRegionView::create_waves ()
834 // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
835 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
837 if (!atv.get_diskstream()) {
841 ChanCount nchans = atv.get_diskstream()->n_channels();
843 // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data
844 // << " and channels = " << nchans.n_audio() << endl;
846 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
847 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
848 tmp_waves.push_back (0);
851 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
853 if (n >= audio_region()->n_channels()) {
857 wave_caches.push_back (WaveView::create_cache ());
859 // cerr << "\tchannel " << n << endl;
862 if (audio_region()->audio_source(n)->peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n), data_ready_connection)) {
863 // cerr << "\tData is ready\n";
864 cerr << "\tData is ready\n";
865 // cerr << "\tData is ready\n";
866 create_one_wave (n, true);
868 // cerr << "\tdata is not ready\n";
869 // we'll get a PeaksReady signal from the source in the future
870 // and will call create_one_wave(n) then.
874 // cerr << "\tdon't delay, display today!\n";
875 create_one_wave (n, true);
882 AudioRegionView::create_one_wave (uint32_t which, bool direct)
884 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
885 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
886 uint32_t nchans = atv.get_diskstream()->n_channels().n_audio();
888 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
891 if (trackview.current_height() < NAME_HIGHLIGHT_THRESH) {
892 ht = ((trackview.current_height()) / (double) nchans);
894 ht = ((trackview.current_height() - NAME_HIGHLIGHT_SIZE) / (double) nchans);
897 gdouble yoff = which * ht;
899 WaveView *wave = new WaveView(*group);
901 wave->property_data_src() = (gpointer) _region.get();
902 wave->property_cache() = wave_caches[which];
903 wave->property_cache_updater() = true;
904 wave->property_channel() = which;
905 wave->property_length_function() = (gpointer) region_length_from_c;
906 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
907 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
908 wave->property_x() = 0.0;
909 wave->property_y() = yoff;
910 wave->property_height() = (double) ht;
911 wave->property_samples_per_unit() = samples_per_unit;
912 wave->property_amplitude_above_axis() = _amplitude_above_axis;
915 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
916 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
918 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_WaveForm.get();
919 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
922 wave->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
923 wave->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
924 wave->property_region_start() = _region->start();
925 wave->property_rectified() = (bool) (_flags & WaveformRectified);
926 wave->property_logscaled() = (bool) (_flags & WaveformLogScaled);
928 if (!(_flags & WaveformVisible)) {
932 /* note: calling this function is serialized by the lock
933 held in the peak building thread that signals that
934 peaks are ready for use *or* by the fact that it is
935 called one by one from the GUI thread.
938 if (which < nchans) {
939 tmp_waves[which] = wave;
941 /* n-channel track, >n-channel source */
944 /* see if we're all ready */
946 for (n = 0; n < nchans; ++n) {
947 if (tmp_waves[n] == 0) {
952 if (n == nwaves && waves.empty()) {
953 /* all waves are ready */
954 tmp_waves.resize(nwaves);
959 /* all waves created, don't hook into peaks ready anymore */
960 data_ready_connection.disconnect ();
964 zero_line = new ArdourCanvas::SimpleLine (*group);
965 zero_line->property_x1() = (gdouble) 1.0;
966 zero_line->property_x2() = (gdouble) (_region->length() / samples_per_unit) - 1.0;
967 zero_line->property_color_rgba() = (guint) ARDOUR_UI::config()->canvasvar_ZeroLine.get();
975 AudioRegionView::peaks_ready_handler (uint32_t which)
977 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
978 // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
982 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
984 if (gain_line == 0) {
990 /* don't create points that can't be seen */
992 set_envelope_visible (true);
999 nframes_t fx = trackview.editor().pixel_to_frame (x);
1001 if (fx > _region->length()) {
1005 /* compute vertical fractional position */
1007 y = 1.0 - (y / (_height - NAME_HIGHLIGHT_SIZE));
1009 /* map using gain line */
1011 gain_line->view_to_model_coord (x, y);
1013 trackview.session().begin_reversible_command (_("add gain control point"));
1014 XMLNode &before = audio_region()->envelope()->get_state();
1016 if (!audio_region()->envelope_active()) {
1017 XMLNode ®ion_before = audio_region()->get_state();
1018 audio_region()->set_envelope_active(true);
1019 XMLNode ®ion_after = audio_region()->get_state();
1020 trackview.session().add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
1023 audio_region()->envelope()->add (fx, y);
1025 XMLNode &after = audio_region()->envelope()->get_state();
1026 trackview.session().add_command (new MementoCommand<AutomationList>(*audio_region()->envelope().get(), &before, &after));
1027 trackview.session().commit_reversible_command ();
1031 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1033 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1034 audio_region()->envelope()->erase (cp->model());
1038 AudioRegionView::store_flags()
1040 XMLNode *node = new XMLNode ("GUI");
1042 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
1043 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
1044 node->add_property ("waveform-rectified", (_flags & WaveformRectified) ? "yes" : "no");
1045 node->add_property ("waveform-logscaled", (_flags & WaveformLogScaled) ? "yes" : "no");
1047 _region->add_extra_xml (*node);
1051 AudioRegionView::set_flags (XMLNode* node)
1055 if ((prop = node->property ("waveform-visible")) != 0) {
1056 if (prop->value() == "yes") {
1057 _flags |= WaveformVisible;
1061 if ((prop = node->property ("envelope-visible")) != 0) {
1062 if (prop->value() == "yes") {
1063 _flags |= EnvelopeVisible;
1067 if ((prop = node->property ("waveform-rectified")) != 0) {
1068 if (prop->value() == "yes") {
1069 _flags |= WaveformRectified;
1073 if ((prop = node->property ("waveform-logscaled")) != 0) {
1074 if (prop->value() == "yes") {
1075 _flags |= WaveformLogScaled;
1081 AudioRegionView::set_waveform_shape (WaveformShape shape)
1085 /* this slightly odd approach is to leave the door open to
1086 other "shapes" such as spectral displays, etc.
1099 if (yn != (bool) (_flags & WaveformRectified)) {
1100 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1101 (*wave)->property_rectified() = yn;
1113 _flags |= WaveformRectified;
1115 _flags &= ~WaveformRectified;
1122 AudioRegionView::set_waveform_scale (WaveformScale scale)
1124 bool yn = (scale == LogWaveform);
1126 if (yn != (bool) (_flags & WaveformLogScaled)) {
1127 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1128 (*wave)->property_logscaled() = yn;
1132 _flags |= WaveformLogScaled;
1134 _flags &= ~WaveformLogScaled;
1142 AudioRegionView::add_ghost (TimeAxisView& tv)
1144 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1147 double unit_position = _region->position () / samples_per_unit;
1148 AudioGhostRegion* ghost = new AudioGhostRegion (tv, trackview, unit_position);
1151 nchans = rtv->get_diskstream()->n_channels().n_audio();
1153 for (uint32_t n = 0; n < nchans; ++n) {
1155 if (n >= audio_region()->n_channels()) {
1159 WaveView *wave = new WaveView(*ghost->group);
1161 wave->property_data_src() = _region.get();
1162 wave->property_cache() = wave_caches[n];
1163 wave->property_cache_updater() = false;
1164 wave->property_channel() = n;
1165 wave->property_length_function() = (gpointer)region_length_from_c;
1166 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1167 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1168 wave->property_x() = 0.0;
1169 wave->property_samples_per_unit() = samples_per_unit;
1170 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1172 wave->property_region_start() = _region->start();
1174 ghost->waves.push_back(wave);
1177 ghost->set_height ();
1178 ghost->set_duration (_region->length() / samples_per_unit);
1179 ghost->set_colors();
1180 ghosts.push_back (ghost);
1182 ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost));
1188 AudioRegionView::entered ()
1190 if (gain_line && _flags & EnvelopeVisible) {
1191 gain_line->show_all_control_points ();
1195 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1198 if (fade_in_handle) {
1199 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1200 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1205 AudioRegionView::exited ()
1208 gain_line->hide_all_but_selected_control_points ();
1212 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1215 if (fade_in_handle) {
1216 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1217 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1222 AudioRegionView::envelope_active_changed ()
1225 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
1230 AudioRegionView::set_waveview_data_src()
1232 AudioGhostRegion* agr;
1233 double unit_length= _region->length() / samples_per_unit;
1235 for (uint32_t n = 0; n < waves.size(); ++n) {
1236 // TODO: something else to let it know the channel
1237 waves[n]->property_data_src() = _region.get();
1240 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1242 (*i)->set_duration (unit_length);
1244 if((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
1245 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
1246 (*w)->property_data_src() = _region.get();
1254 AudioRegionView::color_handler ()
1256 //case cMutedWaveForm:
1258 //case cWaveFormClip:
1262 //case cGainLineInactive:
1264 envelope_active_changed();
1269 AudioRegionView::set_frame_color ()
1275 if (_region->opaque()) {
1283 if (_selected && should_show_selection) {
1284 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_SelectedFrameBase.get(), &r, &g, &b, &a);
1285 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
1287 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1288 if (_region->muted()) {
1289 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get(), MUTED_ALPHA);
1291 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get();
1292 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveFormFill.get();
1297 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_RecordingRect.get(), &r, &g, &b, &a);
1298 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, a);
1300 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1301 if (_region->muted()) {
1302 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA);
1304 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
1305 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
1309 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_FrameBase.get(), &r, &g, &b, &a);
1310 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
1312 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1313 if (_region->muted()) {
1314 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
1316 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
1317 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
1325 AudioRegionView::set_fade_visibility (bool yn)
1328 if (fade_in_shape) {
1329 fade_in_shape->show();
1331 if (fade_out_shape) {
1332 fade_out_shape->show ();
1334 if (fade_in_handle) {
1335 fade_in_handle->show ();
1337 if (fade_out_handle) {
1338 fade_out_handle->show ();
1341 if (fade_in_shape) {
1342 fade_in_shape->hide();
1344 if (fade_out_shape) {
1345 fade_out_shape->hide ();
1347 if (fade_in_handle) {
1348 fade_in_handle->hide ();
1350 if (fade_out_handle) {
1351 fade_out_handle->hide ();