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/profile.h"
31 #include "ardour/session.h"
33 #include "pbd/memento_command.h"
34 #include "pbd/stacktrace.h"
36 #include "evoral/Curve.hpp"
38 #include "streamview.h"
39 #include "audio_region_view.h"
40 #include "audio_time_axis.h"
41 #include "simplerect.h"
42 #include "simpleline.h"
44 #include "public_editor.h"
45 #include "audio_region_editor.h"
46 #include "region_gain_line.h"
47 #include "control_point.h"
48 #include "ghostregion.h"
49 #include "audio_time_axis.h"
51 #include "rgb_macros.h"
52 #include "gui_thread.h"
53 #include "ardour_ui.h"
57 #define MUTED_ALPHA 10
60 using namespace ARDOUR;
62 using namespace Editing;
63 using namespace ArdourCanvas;
65 static const int32_t sync_mark_width = 9;
67 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
68 Gdk::Color const & basic_color)
69 : RegionView (parent, tv, r, spu, basic_color)
76 , fade_position_line(0)
78 , _amplitude_above_axis(1.0)
85 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
86 Gdk::Color const & basic_color, bool recording, TimeAxisViewItem::Visibility visibility)
87 : RegionView (parent, tv, r, spu, basic_color, recording, visibility)
94 , fade_position_line(0)
96 , _amplitude_above_axis(1.0)
103 AudioRegionView::AudioRegionView (const AudioRegionView& other)
104 : sigc::trackable(other)
111 , fade_position_line(0)
113 , _amplitude_above_axis(1.0)
120 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
121 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
126 AudioRegionView::AudioRegionView (const AudioRegionView& other, boost::shared_ptr<AudioRegion> other_region)
127 : RegionView (other, boost::shared_ptr<Region> (other_region))
133 , fade_position_line(0)
135 , _amplitude_above_axis(1.0)
142 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
143 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
149 AudioRegionView::init (Gdk::Color const & basic_color, bool wfd)
151 // FIXME: Some redundancy here with RegionView::init. Need to figure out
152 // where order is important and where it isn't...
154 RegionView::init (basic_color, wfd);
158 _amplitude_above_axis = 1.0;
162 if ((node = _region->extra_xml ("GUI")) != 0) {
165 _flags = WaveformVisible;
169 /* make envelope visible if it has anything interesting in it */
170 boost::shared_ptr<AutomationList> env = audio_region()->envelope ();
171 if (env->size() > 2 || (env->size() == 2 && env->front()->value != env->back()->value)) {
172 _flags |= EnvelopeVisible;
175 compute_colors (basic_color);
179 fade_in_shape = new ArdourCanvas::Polygon (*group);
180 fade_in_shape->property_fill_color_rgba() = fade_color;
181 fade_in_shape->set_data ("regionview", this);
183 fade_out_shape = new ArdourCanvas::Polygon (*group);
184 fade_out_shape->property_fill_color_rgba() = fade_color;
185 fade_out_shape->set_data ("regionview", this);
189 UINT_TO_RGBA(fill_color,&r,&g,&b,&a);
191 fade_in_handle = new ArdourCanvas::SimpleRect (*group);
192 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
193 fade_in_handle->property_outline_pixels() = 0;
195 fade_in_handle->set_data ("regionview", this);
197 fade_out_handle = new ArdourCanvas::SimpleRect (*group);
198 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
199 fade_out_handle->property_outline_pixels() = 0;
201 fade_out_handle->set_data ("regionview", this);
203 fade_position_line = new ArdourCanvas::SimpleLine (*group);
204 fade_position_line->property_color_rgba() = 0xBBBBBBAA;
205 fade_position_line->property_y1() = 7;
206 fade_position_line->property_y2() = _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1;
208 fade_position_line->hide();
211 setup_fade_handle_positions ();
213 if (!trackview.session()->config.get_show_region_fades()) {
214 set_fade_visibility (false);
217 const string line_name = _region->name() + ":gain";
219 if (!Profile->get_sae()) {
220 gain_line = new AudioRegionGainLine (line_name, *this, *group, audio_region()->envelope());
223 if (!(_flags & EnvelopeVisible)) {
231 set_height (trackview.current_height());
234 region_sync_changed ();
236 region_resized (ARDOUR::bounds_change);
237 set_waveview_data_src();
239 envelope_active_changed ();
240 fade_in_active_changed ();
241 fade_out_active_changed ();
243 reset_width_dependent_items (_pixel_width);
245 fade_in_shape->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
246 if (fade_in_handle) {
247 fade_in_handle->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
250 fade_out_shape->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
252 if (fade_out_handle) {
253 fade_out_handle->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
258 /* XXX sync mark drag? */
261 AudioRegionView::~AudioRegionView ()
263 in_destructor = true;
265 RegionViewGoingAway (this); /* EMIT_SIGNAL */
267 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
268 gnome_canvas_waveview_cache_destroy (*cache);
271 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
275 for (list<std::pair<nframes64_t, ArdourCanvas::SimpleLine*> >::iterator i = feature_lines.begin(); i != feature_lines.end(); ++i) {
276 delete ((*i).second);
279 /* all waveviews etc will be destroyed when the group is destroyed */
284 boost::shared_ptr<ARDOUR::AudioRegion>
285 AudioRegionView::audio_region() const
287 // "Guaranteed" to succeed...
288 return boost::dynamic_pointer_cast<AudioRegion>(_region);
292 AudioRegionView::region_changed (const PropertyChange& what_changed)
294 ENSURE_GUI_THREAD (*this, &AudioRegionView::region_changed, what_changed);
295 // cerr << "AudioRegionView::region_changed() called" << endl;
297 RegionView::region_changed (what_changed);
299 if (what_changed.contains (ARDOUR::Properties::scale_amplitude)) {
300 region_scale_amplitude_changed ();
302 if (what_changed.contains (ARDOUR::Properties::fade_in)) {
305 if (what_changed.contains (ARDOUR::Properties::fade_out)) {
308 if (what_changed.contains (ARDOUR::Properties::fade_in_active)) {
309 fade_in_active_changed ();
311 if (what_changed.contains (ARDOUR::Properties::fade_out_active)) {
312 fade_out_active_changed ();
314 if (what_changed.contains (ARDOUR::Properties::envelope_active)) {
315 envelope_active_changed ();
317 if (what_changed.contains (ARDOUR::Properties::valid_transients)) {
318 transients_changed ();
323 AudioRegionView::fade_in_changed ()
325 reset_fade_in_shape ();
329 AudioRegionView::fade_out_changed ()
331 reset_fade_out_shape ();
334 AudioRegionView::fade_in_active_changed ()
336 if (audio_region()->fade_in_active()) {
337 fade_in_shape->property_fill_color_rgba() = RGBA_TO_UINT(45,45,45,90); // FIXME make a themeable colour
338 fade_in_shape->property_width_pixels() = 1;
340 fade_in_shape->property_fill_color_rgba() = RGBA_TO_UINT(45,45,45,20); // FIXME make a themeable colour
341 fade_in_shape->property_width_pixels() = 1;
346 AudioRegionView::fade_out_active_changed ()
348 if (audio_region()->fade_out_active()) {
349 fade_out_shape->property_fill_color_rgba() = RGBA_TO_UINT(45,45,45,90); // FIXME make a themeable colour
350 fade_out_shape->property_width_pixels() = 1;
352 fade_out_shape->property_fill_color_rgba() = RGBA_TO_UINT(45,45,45,20); // FIXME make a themeable colour
353 fade_out_shape->property_width_pixels() = 1;
359 AudioRegionView::region_scale_amplitude_changed ()
361 ENSURE_GUI_THREAD (*this, &AudioRegionView::region_scale_amplitude_changed)
363 for (uint32_t n = 0; n < waves.size(); ++n) {
364 // force a reload of the cache
365 waves[n]->property_data_src() = _region.get();
370 AudioRegionView::region_renamed ()
372 Glib::ustring str = RegionView::make_name ();
374 if (audio_region()->speed_mismatch (trackview.session()->frame_rate())) {
375 str = string ("*") + str;
378 if (_region->muted()) {
379 str = string ("!") + str;
382 set_item_name (str, this);
387 AudioRegionView::region_resized (const PropertyChange& what_changed)
389 AudioGhostRegion* agr;
391 RegionView::region_resized(what_changed);
392 PropertyChange interesting_stuff;
394 interesting_stuff.add (ARDOUR::Properties::start);
395 interesting_stuff.add (ARDOUR::Properties::length);
397 if (what_changed.contains (interesting_stuff)) {
399 for (uint32_t n = 0; n < waves.size(); ++n) {
400 waves[n]->property_region_start() = _region->start();
403 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
404 if ((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
406 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
407 (*w)->property_region_start() = _region->start();
412 /* hide transient lines that extend beyond the region end */
414 list<std::pair<nframes64_t, ArdourCanvas::SimpleLine*> >::iterator l;
416 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
417 if ((*l).first > _region->length()- 1){
428 AudioRegionView::reset_width_dependent_items (double pixel_width)
430 RegionView::reset_width_dependent_items(pixel_width);
431 assert(_pixel_width == pixel_width);
434 zero_line->property_x2() = pixel_width - 1.0;
437 if (fade_in_handle) {
438 if (pixel_width <= 6.0 || _height < 5.0 || !trackview.session()->config.get_show_region_fades()) {
439 fade_in_handle->hide();
440 fade_out_handle->hide();
443 fade_in_handle->show();
444 fade_out_handle->show();
448 AnalysisFeatureList analysis_features = _region->transients();
449 AnalysisFeatureList::const_iterator i;
450 list<std::pair<nframes64_t, ArdourCanvas::SimpleLine*> >::iterator l;
452 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
453 (*l).second->property_x1() = trackview.editor().frame_to_pixel (*i);
454 (*l).second->property_x2() = trackview.editor().frame_to_pixel (*i);
457 reset_fade_shapes ();
461 AudioRegionView::region_muted ()
463 RegionView::region_muted();
465 for (uint32_t n=0; n < waves.size(); ++n) {
466 if (_region->muted()) {
467 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
469 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
475 AudioRegionView::setup_fade_handle_positions()
477 /* position of fade handle offset from the top of the region view */
478 double const handle_pos = 2;
479 /* height of fade handles */
480 double const handle_height = 5;
482 if (fade_in_handle) {
483 fade_in_handle->property_y1() = handle_pos;
484 fade_in_handle->property_y2() = handle_pos + handle_height;
487 if (fade_out_handle) {
488 fade_out_handle->property_y1() = handle_pos;
489 fade_out_handle->property_y2() = handle_pos + handle_height;
494 AudioRegionView::set_height (gdouble height)
496 RegionView::set_height (height);
498 uint32_t wcnt = waves.size();
500 for (uint32_t n = 0; n < wcnt; ++n) {
503 if (height < NAME_HIGHLIGHT_THRESH) {
504 ht = ((height - 2 * wcnt) / (double) wcnt);
506 ht = (((height - 2 * wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
509 gdouble yoff = n * (ht + 1);
511 waves[n]->property_height() = ht;
512 waves[n]->property_y() = yoff + 2;
517 if ((height/wcnt) < NAME_HIGHLIGHT_THRESH) {
520 if (_flags & EnvelopeVisible) {
525 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE) - 2);
529 reset_fade_shapes ();
531 /* Update hights for any active feature lines */
532 list<std::pair<nframes64_t, ArdourCanvas::SimpleLine*> >::iterator l;
534 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
535 (*l).second->property_y2() = _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1;
539 name_pixbuf->raise_to_top();
544 AudioRegionView::manage_zero_line ()
550 if (_height >= 100) {
551 double const wave_midpoint = (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
552 zero_line->property_y1() = wave_midpoint;
553 zero_line->property_y2() = wave_midpoint;
561 AudioRegionView::reset_fade_shapes ()
563 reset_fade_in_shape ();
564 reset_fade_out_shape ();
568 AudioRegionView::reset_fade_in_shape ()
570 reset_fade_in_shape_width ((nframes_t) audio_region()->fade_in()->back()->when);
574 AudioRegionView::reset_fade_in_shape_width (nframes_t width)
576 if (fade_in_handle == 0) {
580 /* smallest size for a fade is 64 frames */
582 width = std::max ((nframes_t) 64, width);
586 double pwidth = width / samples_per_unit;
587 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
591 fade_in_shape->hide();
592 fade_in_handle->hide();
596 double handle_center;
597 handle_center = pwidth;
599 if (handle_center > 7.0) {
600 handle_center -= 2.0;
605 fade_in_handle->property_x1() = handle_center - 3.0;
606 fade_in_handle->property_x2() = handle_center + 3.0;
609 fade_in_shape->hide();
613 if (trackview.session()->config.get_show_region_fades()) {
614 fade_in_shape->show();
617 float curve[npoints];
618 audio_region()->fade_in()->curve().get_vector (0, audio_region()->fade_in()->back()->when, curve, npoints);
620 points = get_canvas_points ("fade in shape", npoints + 3);
622 if (_height >= NAME_HIGHLIGHT_THRESH) {
623 h = _height - NAME_HIGHLIGHT_SIZE - 2;
628 /* points *MUST* be in anti-clockwise order */
631 double xdelta = pwidth/npoints;
633 for (pi = 0, pc = 0; pc < npoints; ++pc) {
634 (*points)[pi].set_x(1 + (pc * xdelta));
635 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
640 (*points)[pi].set_x(pwidth);
641 (*points)[pi++].set_y(2);
643 (*points)[pi].set_x(1);
644 (*points)[pi++].set_y(2);
646 /* connect the dots ... */
648 (*points)[pi] = (*points)[0];
650 fade_in_shape->property_points() = *points;
653 /* ensure trim handle stays on top */
654 if (frame_handle_start) {
655 frame_handle_start->raise_to_top();
660 AudioRegionView::reset_fade_out_shape ()
662 reset_fade_out_shape_width ((nframes_t) audio_region()->fade_out()->back()->when);
666 AudioRegionView::reset_fade_out_shape_width (nframes_t width)
668 if (fade_out_handle == 0) {
672 /* smallest size for a fade is 64 frames */
674 width = std::max ((nframes_t) 64, width);
677 double pwidth = width / samples_per_unit;
678 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
682 fade_out_shape->hide();
683 fade_out_handle->hide();
687 double handle_center;
688 handle_center = (_region->length() - width) / samples_per_unit;
690 if (handle_center > 7.0) {
691 handle_center -= 2.0;
696 fade_out_handle->property_x1() = handle_center - 3.0;
697 fade_out_handle->property_x2() = handle_center + 3.0;
699 /* don't show shape if its too small */
702 fade_out_shape->hide();
706 if (trackview.session()->config.get_show_region_fades()) {
707 fade_out_shape->show();
710 float curve[npoints];
711 audio_region()->fade_out()->curve().get_vector (0, audio_region()->fade_out()->back()->when, curve, npoints);
713 if (_height >= NAME_HIGHLIGHT_THRESH) {
714 h = _height - NAME_HIGHLIGHT_SIZE - 2;
719 /* points *MUST* be in anti-clockwise order */
721 points = get_canvas_points ("fade out shape", npoints + 3);
724 double xdelta = pwidth/npoints;
726 for (pi = 0, pc = 0; pc < npoints; ++pc) {
727 (*points)[pi].set_x(_pixel_width - pwidth + (pc * xdelta));
728 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
733 (*points)[pi].set_x(_pixel_width);
734 (*points)[pi++].set_y(h);
736 (*points)[pi].set_x(_pixel_width);
737 (*points)[pi++].set_y(2);
739 /* connect the dots ... */
741 (*points)[pi] = (*points)[0];
743 fade_out_shape->property_points() = *points;
746 /* ensure trim handle stays on top */
747 if (frame_handle_end) {
748 frame_handle_end->raise_to_top();
753 AudioRegionView::set_samples_per_unit (gdouble spu)
755 RegionView::set_samples_per_unit (spu);
757 if (_flags & WaveformVisible) {
758 for (uint32_t n=0; n < waves.size(); ++n) {
759 waves[n]->property_samples_per_unit() = spu;
767 reset_fade_shapes ();
771 AudioRegionView::set_amplitude_above_axis (gdouble spp)
773 for (uint32_t n=0; n < waves.size(); ++n) {
774 waves[n]->property_amplitude_above_axis() = spp;
779 AudioRegionView::compute_colors (Gdk::Color const & basic_color)
781 RegionView::compute_colors (basic_color);
785 /* gain color computed in envelope_active_changed() */
787 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
788 fade_color = RGBA_TO_UINT(r,g,b,120);
792 AudioRegionView::set_colors ()
794 RegionView::set_colors();
797 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
800 for (uint32_t n=0; n < waves.size(); ++n) {
801 if (_region->muted()) {
802 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
804 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
807 waves[n]->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
808 waves[n]->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
813 AudioRegionView::set_waveform_visible (bool yn)
815 if (((_flags & WaveformVisible) != yn)) {
817 for (uint32_t n=0; n < waves.size(); ++n) {
818 /* make sure the zoom level is correct, since we don't update
819 this when waveforms are hidden.
821 waves[n]->property_samples_per_unit() = samples_per_unit;
824 _flags |= WaveformVisible;
826 for (uint32_t n=0; n < waves.size(); ++n) {
829 _flags &= ~WaveformVisible;
836 AudioRegionView::temporarily_hide_envelope ()
844 AudioRegionView::unhide_envelope ()
846 if (gain_line && (_flags & EnvelopeVisible)) {
852 AudioRegionView::set_envelope_visible (bool yn)
854 if (gain_line && ((_flags & EnvelopeVisible) != yn)) {
857 _flags |= EnvelopeVisible;
860 _flags &= ~EnvelopeVisible;
867 AudioRegionView::create_waves ()
869 // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
870 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
876 ChanCount nchans = atv.track()->n_channels();
878 // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data
879 // << " and channels = " << nchans.n_audio() << endl;
881 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
882 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
883 tmp_waves.push_back (0);
886 for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
890 _data_ready_connections.clear ();
892 for (uint32_t i = 0; i < nchans.n_audio(); ++i) {
893 _data_ready_connections.push_back (0);
896 for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
898 if (n >= audio_region()->n_channels()) {
902 wave_caches.push_back (WaveView::create_cache ());
904 // cerr << "\tchannel " << n << endl;
907 if (audio_region()->audio_source(n)->peaks_ready (boost::bind (&AudioRegionView::peaks_ready_handler, this, n), &_data_ready_connections[n], gui_context())) {
908 // cerr << "\tData is ready\n";
909 create_one_wave (n, true);
911 // cerr << "\tdata is not ready\n";
912 // we'll get a PeaksReady signal from the source in the future
913 // and will call create_one_wave(n) then.
917 // cerr << "\tdon't delay, display today!\n";
918 create_one_wave (n, true);
925 AudioRegionView::create_one_wave (uint32_t which, bool /*direct*/)
927 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
928 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
929 uint32_t nchans = atv.track()->n_channels().n_audio();
931 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
934 if (trackview.current_height() < NAME_HIGHLIGHT_THRESH) {
935 ht = ((trackview.current_height()) / (double) nchans);
937 ht = ((trackview.current_height() - NAME_HIGHLIGHT_SIZE) / (double) nchans);
940 gdouble yoff = which * ht;
942 WaveView *wave = new WaveView(*group);
944 wave->property_data_src() = (gpointer) _region.get();
945 wave->property_cache() = wave_caches[which];
946 wave->property_cache_updater() = true;
947 wave->property_channel() = which;
948 wave->property_length_function() = (gpointer) region_length_from_c;
949 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
950 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
951 wave->property_x() = 0.0;
952 wave->property_y() = yoff;
953 wave->property_height() = (double) ht;
954 wave->property_samples_per_unit() = samples_per_unit;
955 wave->property_amplitude_above_axis() = _amplitude_above_axis;
958 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
959 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
961 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_WaveForm.get();
962 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
965 wave->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
966 wave->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
967 wave->property_region_start() = _region->start();
968 wave->property_rectified() = (bool) (_flags & WaveformRectified);
969 wave->property_logscaled() = (bool) (_flags & WaveformLogScaled);
971 if (!(_flags & WaveformVisible)) {
975 /* note: calling this function is serialized by the lock
976 held in the peak building thread that signals that
977 peaks are ready for use *or* by the fact that it is
978 called one by one from the GUI thread.
981 if (which < nchans) {
982 tmp_waves[which] = wave;
984 /* n-channel track, >n-channel source */
987 /* see if we're all ready */
989 for (n = 0; n < nchans; ++n) {
990 if (tmp_waves[n] == 0) {
995 if (n == nwaves && waves.empty()) {
996 /* all waves are ready */
997 tmp_waves.resize(nwaves);
1002 /* all waves created, don't hook into peaks ready anymore */
1003 delete _data_ready_connections[which];
1004 _data_ready_connections[which] = 0;
1008 zero_line = new ArdourCanvas::SimpleLine (*group);
1009 zero_line->property_x1() = (gdouble) 1.0;
1010 zero_line->property_x2() = (gdouble) (_region->length() / samples_per_unit) - 1.0;
1011 zero_line->property_color_rgba() = (guint) ARDOUR_UI::config()->canvasvar_ZeroLine.get();
1012 manage_zero_line ();
1019 AudioRegionView::peaks_ready_handler (uint32_t which)
1021 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AudioRegionView::create_one_wave, this, which, false));
1022 // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
1026 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1028 if (gain_line == 0) {
1034 /* don't create points that can't be seen */
1036 set_envelope_visible (true);
1043 nframes_t fx = trackview.editor().pixel_to_frame (x);
1045 if (fx > _region->length()) {
1049 /* compute vertical fractional position */
1051 y = 1.0 - (y / (_height - NAME_HIGHLIGHT_SIZE));
1053 /* map using gain line */
1055 gain_line->view_to_model_coord (x, y);
1057 /* XXX STATEFUL: can't convert to stateful diff until we
1058 can represent automation data with it.
1061 trackview.session()->begin_reversible_command (_("add gain control point"));
1062 XMLNode &before = audio_region()->envelope()->get_state();
1064 if (!audio_region()->envelope_active()) {
1065 XMLNode ®ion_before = audio_region()->get_state();
1066 audio_region()->set_envelope_active(true);
1067 XMLNode ®ion_after = audio_region()->get_state();
1068 trackview.session()->add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
1071 audio_region()->envelope()->add (fx, y);
1073 XMLNode &after = audio_region()->envelope()->get_state();
1074 trackview.session()->add_command (new MementoCommand<AutomationList>(*audio_region()->envelope().get(), &before, &after));
1075 trackview.session()->commit_reversible_command ();
1079 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent */*ev*/)
1081 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1082 audio_region()->envelope()->erase (cp->model());
1086 AudioRegionView::store_flags()
1088 XMLNode *node = new XMLNode ("GUI");
1090 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
1091 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
1092 node->add_property ("waveform-rectified", (_flags & WaveformRectified) ? "yes" : "no");
1093 node->add_property ("waveform-logscaled", (_flags & WaveformLogScaled) ? "yes" : "no");
1095 _region->add_extra_xml (*node);
1099 AudioRegionView::set_flags (XMLNode* node)
1103 if ((prop = node->property ("waveform-visible")) != 0) {
1104 if (string_is_affirmative (prop->value())) {
1105 _flags |= WaveformVisible;
1109 if ((prop = node->property ("envelope-visible")) != 0) {
1110 if (string_is_affirmative (prop->value())) {
1111 _flags |= EnvelopeVisible;
1115 if ((prop = node->property ("waveform-rectified")) != 0) {
1116 if (string_is_affirmative (prop->value())) {
1117 _flags |= WaveformRectified;
1121 if ((prop = node->property ("waveform-logscaled")) != 0) {
1122 if (string_is_affirmative (prop->value())) {
1123 _flags |= WaveformLogScaled;
1129 AudioRegionView::set_waveform_shape (WaveformShape shape)
1133 /* this slightly odd approach is to leave the door open to
1134 other "shapes" such as spectral displays, etc.
1147 if (yn != (bool) (_flags & WaveformRectified)) {
1148 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1149 (*wave)->property_rectified() = yn;
1161 _flags |= WaveformRectified;
1163 _flags &= ~WaveformRectified;
1170 AudioRegionView::set_waveform_scale (WaveformScale scale)
1172 bool yn = (scale == Logarithmic);
1174 if (yn != (bool) (_flags & WaveformLogScaled)) {
1175 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1176 (*wave)->property_logscaled() = yn;
1180 _flags |= WaveformLogScaled;
1182 _flags &= ~WaveformLogScaled;
1190 AudioRegionView::add_ghost (TimeAxisView& tv)
1192 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1195 double unit_position = _region->position () / samples_per_unit;
1196 AudioGhostRegion* ghost = new AudioGhostRegion (tv, trackview, unit_position);
1199 nchans = rtv->track()->n_channels().n_audio();
1201 for (uint32_t n = 0; n < nchans; ++n) {
1203 if (n >= audio_region()->n_channels()) {
1207 WaveView *wave = new WaveView(*ghost->group);
1209 wave->property_data_src() = _region.get();
1210 wave->property_cache() = wave_caches[n];
1211 wave->property_cache_updater() = false;
1212 wave->property_channel() = n;
1213 wave->property_length_function() = (gpointer)region_length_from_c;
1214 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1215 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1216 wave->property_x() = 0.0;
1217 wave->property_samples_per_unit() = samples_per_unit;
1218 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1220 wave->property_region_start() = _region->start();
1222 ghost->waves.push_back(wave);
1225 ghost->set_height ();
1226 ghost->set_duration (_region->length() / samples_per_unit);
1227 ghost->set_colors();
1228 ghosts.push_back (ghost);
1234 AudioRegionView::entered (bool internal_editing)
1236 if (gain_line && _flags & EnvelopeVisible) {
1237 gain_line->show_all_control_points ();
1241 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1244 if (fade_in_handle && !internal_editing) {
1245 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1246 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1251 AudioRegionView::exited ()
1254 gain_line->hide_all_but_selected_control_points ();
1258 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1261 if (fade_in_handle) {
1262 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1263 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1268 AudioRegionView::envelope_active_changed ()
1271 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
1276 AudioRegionView::set_waveview_data_src()
1278 AudioGhostRegion* agr;
1279 double unit_length= _region->length() / samples_per_unit;
1281 for (uint32_t n = 0; n < waves.size(); ++n) {
1282 // TODO: something else to let it know the channel
1283 waves[n]->property_data_src() = _region.get();
1286 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1288 (*i)->set_duration (unit_length);
1290 if((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
1291 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
1292 (*w)->property_data_src() = _region.get();
1300 AudioRegionView::color_handler ()
1302 //case cMutedWaveForm:
1304 //case cWaveFormClip:
1308 //case cGainLineInactive:
1310 envelope_active_changed();
1315 AudioRegionView::set_frame_color ()
1321 if (_region->opaque()) {
1329 if (_selected && should_show_selection) {
1330 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_SelectedFrameBase.get(), &r, &g, &b, &a);
1331 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
1333 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1334 if (_region->muted()) {
1335 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get(), MUTED_ALPHA);
1337 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get();
1338 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_SelectedWaveFormFill.get();
1343 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_RecordingRect.get(), &r, &g, &b, &a);
1344 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, a);
1346 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1347 if (_region->muted()) {
1348 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA);
1350 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
1351 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
1355 UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_FrameBase.get(), &r, &g, &b, &a);
1356 frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
1358 for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1359 if (_region->muted()) {
1360 (*w)->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
1362 (*w)->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
1363 (*w)->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
1371 AudioRegionView::set_fade_visibility (bool yn)
1374 if (fade_in_shape) {
1375 fade_in_shape->show();
1377 if (fade_out_shape) {
1378 fade_out_shape->show ();
1380 if (fade_in_handle) {
1381 fade_in_handle->show ();
1383 if (fade_out_handle) {
1384 fade_out_handle->show ();
1387 if (fade_in_shape) {
1388 fade_in_shape->hide();
1390 if (fade_out_shape) {
1391 fade_out_shape->hide ();
1393 if (fade_in_handle) {
1394 fade_in_handle->hide ();
1396 if (fade_out_handle) {
1397 fade_out_handle->hide ();
1403 AudioRegionView::update_coverage_frames (LayerDisplay d)
1405 RegionView::update_coverage_frames (d);
1407 if (fade_in_handle) {
1408 fade_in_handle->raise_to_top ();
1409 fade_out_handle->raise_to_top ();
1414 AudioRegionView::show_region_editor ()
1417 editor = new AudioRegionEditor (trackview.session(), audio_region());
1421 editor->set_position (Gtk::WIN_POS_MOUSE);
1427 AudioRegionView::show_fade_line (nframes64_t pos)
1429 fade_position_line->property_x1() = trackview.editor().frame_to_pixel (pos);
1430 fade_position_line->property_x2() = trackview.editor().frame_to_pixel (pos);
1431 fade_position_line->show ();
1432 fade_position_line->raise_to_top ();
1436 AudioRegionView::hide_fade_line ()
1438 fade_position_line->hide ();
1443 AudioRegionView::transients_changed ()
1445 AnalysisFeatureList analysis_features = _region->transients();
1447 while (feature_lines.size() < analysis_features.size()) {
1448 ArdourCanvas::SimpleLine* l = new ArdourCanvas::SimpleLine (*group);
1449 l->property_color_rgba() = (guint) ARDOUR_UI::config()->canvasvar_ZeroLine.get();
1450 feature_lines.push_back (make_pair(0, l));
1453 while (feature_lines.size() > analysis_features.size()) {
1454 ArdourCanvas::SimpleLine *line = feature_lines.back().second;
1455 feature_lines.pop_back ();
1459 AnalysisFeatureList::const_iterator i;
1460 list<std::pair<nframes64_t, ArdourCanvas::SimpleLine*> >::iterator l;
1462 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
1464 (*l).second->property_x1() = trackview.editor().frame_to_pixel (*i);
1465 (*l).second->property_x2() = trackview.editor().frame_to_pixel (*i);
1466 (*l).second->property_y1() = 2;
1467 (*l).second->property_y2() = _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1;
1468 (*l).second->set_data("regionview", this);
1469 (*l).second->show ();
1470 (*l).second->raise_to_top ();
1472 (*l).second->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_feature_line_event), (*l).second, this));
1477 AudioRegionView::update_transient(float /*old_pos*/, float new_pos)
1479 /* Find frame at old pos, calulate new frame then update region transients*/
1480 list<std::pair<nframes64_t, ArdourCanvas::SimpleLine*> >::iterator l;
1482 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1483 /* Simple line x1 has been updated in drag so we compare to new_pos */
1484 if (rint(new_pos) == rint((*l).second->property_x1())) {
1486 nframes64_t old_frame = (*l).first;
1487 nframes64_t new_frame = trackview.editor().pixel_to_frame (new_pos);
1489 _region->update_transient (old_frame, new_frame);
1497 AudioRegionView::remove_transient(float pos)
1499 /* Find frame at old pos, calulate new frame then update region transients*/
1500 list<std::pair<nframes64_t, ArdourCanvas::SimpleLine*> >::iterator l;
1502 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1503 /* Simple line x1 has been updated in drag so we compare to new_pos */
1504 if (rint(pos) == rint((*l).second->property_x1())) {
1505 _region->remove_transient ((*l).first);