2 Copyright (C) 2001 Paul Davis
4 This program is free software; you can redistribute 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/diskstream.h>
32 #include "streamview.h"
33 #include "regionview.h"
34 #include "audio_time_axis.h"
35 #include "simplerect.h"
36 #include "simpleline.h"
38 #include "public_editor.h"
39 #include "region_editor.h"
40 #include "region_gain_line.h"
41 #include "ghostregion.h"
42 #include "audio_time_axis.h"
44 #include "rgb_macros.h"
45 #include "gui_thread.h"
50 using namespace ARDOUR;
51 using namespace Editing;
52 using namespace ArdourCanvas;
54 static const int32_t sync_mark_width = 9;
56 sigc::signal<void,AudioRegionView*> AudioRegionView::AudioRegionViewGoingAway;
58 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, AudioTimeAxisView &tv, AudioRegion& r, double spu,
59 Gdk::Color& basic_color)
60 : TimeAxisViewItem (r.name(), *parent, tv, spu, basic_color, r.position(), r.length(),
61 TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowNameText|
62 TimeAxisViewItem::ShowNameHighlight|
63 TimeAxisViewItem::ShowFrame)),
68 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, AudioTimeAxisView &tv, AudioRegion& r, double spu,
69 Gdk::Color& basic_color, TimeAxisViewItem::Visibility visibility)
70 : TimeAxisViewItem (r.name(), *parent, tv, spu, basic_color, r.position(), r.length(), visibility),
76 AudioRegionView::init (double amplitude_above_axis, Gdk::Color& basic_color, bool wfw)
78 ArdourCanvas::Points shape;
83 in_destructor = false;
84 _amplitude_above_axis = amplitude_above_axis;
91 if ((node = region.extra_xml ("GUI")) != 0) {
94 _flags = WaveformVisible;
98 if (trackview.editor.new_regionviews_display_gain()) {
99 _flags |= EnvelopeVisible;
102 compute_colors (basic_color);
106 name_highlight->set_data ("regionview", this);
107 name_text->set_data ("regionview", this);
109 // shape = new ArdourCanvas::Points ();
111 /* an equilateral triangle */
113 shape.push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
114 shape.push_back (Gnome::Art::Point ((sync_mark_width - 1)/2, 1));
115 shape.push_back (Gnome::Art::Point (0, sync_mark_width - 1));
116 shape.push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
118 sync_mark = new ArdourCanvas::Polygon (*group);
119 sync_mark->property_points() = shape;
120 sync_mark->property_fill_color_rgba() = fill_color;
123 fade_in_shape = new ArdourCanvas::Polygon (*group);
124 fade_in_shape->property_fill_color_rgba() = fade_color;
125 fade_in_shape->set_data ("regionview", this);
127 fade_out_shape = new ArdourCanvas::Polygon (*group);
128 fade_out_shape->property_fill_color_rgba() = fade_color;
129 fade_out_shape->set_data ("regionview", this);
134 UINT_TO_RGBA(fill_color,&r,&g,&b,&a);
137 fade_in_handle = new ArdourCanvas::SimpleRect (*group);
138 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
139 fade_in_handle->property_outline_pixels() = 0;
140 fade_in_handle->property_y1() = 2.0;
141 fade_in_handle->property_y2() = 7.0;
143 fade_in_handle->set_data ("regionview", this);
145 fade_out_handle = new ArdourCanvas::SimpleRect (*group);
146 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
147 fade_out_handle->property_outline_pixels() = 0;
148 fade_out_handle->property_y1() = 2.0;
149 fade_out_handle->property_y2() = 7.0;
151 fade_out_handle->set_data ("regionview", this);
154 string foo = region.name();
158 gain_line = new AudioRegionGainLine (foo, trackview.session(), *this, *group, region.envelope());
160 if (!(_flags & EnvelopeVisible)) {
166 reset_width_dependent_items ((double) region.length() / samples_per_unit);
170 set_height (trackview.height);
173 region_sync_changed ();
174 region_resized (BoundsChanged);
175 set_waveview_data_src();
177 envelope_active_changed ();
178 fade_in_active_changed ();
179 fade_out_active_changed ();
181 region.StateChanged.connect (mem_fun(*this, &AudioRegionView::region_changed));
183 group->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_event), group, this));
184 name_highlight->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event), name_highlight, this));
185 fade_in_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
186 fade_in_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
187 fade_out_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
188 fade_out_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
192 ColorChanged.connect (mem_fun (*this, &AudioRegionView::color_handler));
194 /* XXX sync mark drag? */
197 AudioRegionView::~AudioRegionView ()
199 in_destructor = true;
201 AudioRegionViewGoingAway (this); /* EMIT_SIGNAL */
203 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
204 gnome_canvas_waveview_cache_destroy (*cache);
207 /* all waveviews etc will be destroyed when the group is destroyed */
209 for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
223 AudioRegionView::_lock_toggle (ArdourCanvas::Item* item, GdkEvent* ev, void* arg)
226 case GDK_BUTTON_RELEASE:
227 static_cast<AudioRegionView*>(arg)->lock_toggle ();
237 AudioRegionView::lock_toggle ()
239 region.set_locked (!region.locked());
243 AudioRegionView::region_changed (Change what_changed)
245 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionView::region_changed), what_changed));
247 if (what_changed & BoundsChanged) {
248 region_resized (what_changed);
249 region_sync_changed ();
251 if (what_changed & Region::MuteChanged) {
254 if (what_changed & Region::OpacityChanged) {
257 if (what_changed & ARDOUR::NameChanged) {
260 if (what_changed & Region::SyncOffsetChanged) {
261 region_sync_changed ();
263 if (what_changed & Region::LayerChanged) {
266 if (what_changed & Region::LockChanged) {
269 if (what_changed & AudioRegion::ScaleAmplitudeChanged) {
270 region_scale_amplitude_changed ();
272 if (what_changed & AudioRegion::FadeInChanged) {
275 if (what_changed & AudioRegion::FadeOutChanged) {
278 if (what_changed & AudioRegion::FadeInActiveChanged) {
279 fade_in_active_changed ();
281 if (what_changed & AudioRegion::FadeOutActiveChanged) {
282 fade_out_active_changed ();
284 if (what_changed & AudioRegion::EnvelopeActiveChanged) {
285 envelope_active_changed ();
290 AudioRegionView::fade_in_changed ()
292 reset_fade_in_shape ();
296 AudioRegionView::fade_out_changed ()
298 reset_fade_out_shape ();
302 AudioRegionView::set_fade_in_active (bool yn)
304 region.set_fade_in_active (yn);
308 AudioRegionView::set_fade_out_active (bool yn)
310 region.set_fade_out_active (yn);
314 AudioRegionView::fade_in_active_changed ()
318 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
320 if (region.fade_in_active()) {
321 col = RGBA_TO_UINT(r,g,b,120);
322 fade_in_shape->property_fill_color_rgba() = col;
323 fade_in_shape->property_width_pixels() = 0;
324 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
326 col = RGBA_TO_UINT(r,g,b,0);
327 fade_in_shape->property_fill_color_rgba() = col;
328 fade_in_shape->property_width_pixels() = 1;
329 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
334 AudioRegionView::fade_out_active_changed ()
338 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
340 if (region.fade_out_active()) {
341 col = RGBA_TO_UINT(r,g,b,120);
342 fade_out_shape->property_fill_color_rgba() = col;
343 fade_out_shape->property_width_pixels() = 0;
344 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
346 col = RGBA_TO_UINT(r,g,b,0);
347 fade_out_shape->property_fill_color_rgba() = col;
348 fade_out_shape->property_width_pixels() = 1;
349 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
355 AudioRegionView::region_scale_amplitude_changed ()
357 ENSURE_GUI_THREAD (mem_fun(*this, &AudioRegionView::region_scale_amplitude_changed));
359 for (uint32_t n = 0; n < waves.size(); ++n) {
360 // force a reload of the cache
361 waves[n]->property_data_src() = ®ion;
366 AudioRegionView::region_locked ()
368 /* name will show locked status */
373 AudioRegionView::region_resized (Change what_changed)
377 if (what_changed & ARDOUR::PositionChanged) {
378 set_position (region.position(), 0);
381 if (what_changed & Change (StartChanged|LengthChanged)) {
383 set_duration (region.length(), 0);
385 unit_length = region.length() / samples_per_unit;
387 reset_width_dependent_items (unit_length);
389 for (uint32_t n = 0; n < waves.size(); ++n) {
390 waves[n]->property_region_start() = region.start();
393 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
395 (*i)->set_duration (unit_length);
397 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
398 (*w)->property_region_start() = region.start();
405 AudioRegionView::reset_width_dependent_items (double pixel_width)
407 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
408 _pixel_width = pixel_width;
411 zero_line->property_x2() = pixel_width - 1.0;
414 if (fade_in_handle) {
415 if (pixel_width <= 6.0) {
416 fade_in_handle->hide();
417 fade_out_handle->hide();
420 fade_in_handle->hide();
421 fade_out_handle->hide();
423 fade_in_handle->show();
424 fade_out_handle->show();
429 reset_fade_shapes ();
433 AudioRegionView::region_layered ()
435 AudioTimeAxisView *atv = dynamic_cast<AudioTimeAxisView*> (&get_time_axis_view());
436 atv->view->region_layered (this);
440 AudioRegionView::region_muted ()
445 for (uint32_t n=0; n < waves.size(); ++n) {
446 if (region.muted()) {
447 waves[n]->property_wave_color() = color_map[cMutedWaveForm];
449 waves[n]->property_wave_color() = color_map[cWaveForm];
455 AudioRegionView::region_opacity ()
461 AudioRegionView::raise ()
467 AudioRegionView::raise_to_top ()
469 region.raise_to_top ();
473 AudioRegionView::lower ()
479 AudioRegionView::lower_to_bottom ()
481 region.lower_to_bottom ();
485 AudioRegionView::set_position (jack_nframes_t pos, void* src, double* ignored)
490 if (!(ret = TimeAxisViewItem::set_position (pos, this, &delta))) {
499 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
500 (*i)->group->move (delta, 0.0);
508 AudioRegionView::set_height (gdouble height)
510 uint32_t wcnt = waves.size();
512 TimeAxisViewItem::set_height (height - 2);
516 for (uint32_t n=0; n < wcnt; ++n) {
519 if ((height) < NAME_HIGHLIGHT_THRESH) {
520 ht = ((height-2*wcnt) / (double) wcnt);
522 ht = (((height-2*wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
525 gdouble yoff = n * (ht+1);
527 waves[n]->property_height() = ht;
528 waves[n]->property_y() = yoff + 2;
532 if ((height/wcnt) < NAME_HIGHLIGHT_SIZE) {
535 if (_flags & EnvelopeVisible) {
539 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE));
543 reset_fade_shapes ();
546 name_text->raise_to_top();
551 AudioRegionView::manage_zero_line ()
557 if (_height >= 100) {
558 gdouble wave_midpoint = (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
559 zero_line->property_y1() = wave_midpoint;
560 zero_line->property_y2() = wave_midpoint;
568 AudioRegionView::reset_fade_shapes ()
570 reset_fade_in_shape ();
571 reset_fade_out_shape ();
575 AudioRegionView::reset_fade_in_shape ()
577 reset_fade_in_shape_width ((jack_nframes_t) region.fade_in().back()->when);
581 AudioRegionView::reset_fade_in_shape_width (jack_nframes_t width)
583 if (fade_in_handle == 0) {
587 /* smallest size for a fade is 64 frames */
589 width = std::max ((jack_nframes_t) 64, width);
592 double pwidth = width / samples_per_unit;
593 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
597 fade_in_shape->hide();
598 fade_in_handle->hide();
602 double handle_center;
603 handle_center = pwidth;
605 if (handle_center > 7.0) {
606 handle_center -= 3.0;
611 fade_in_handle->property_x1() = handle_center - 3.0;
612 fade_in_handle->property_x2() = handle_center + 3.0;
615 fade_in_shape->hide();
619 fade_in_shape->show();
621 float curve[npoints];
622 region.fade_in().get_vector (0, region.fade_in().back()->when, curve, npoints);
624 points = get_canvas_points ("fade in shape", npoints+3);
626 if (_height > NAME_HIGHLIGHT_THRESH) {
627 h = _height - NAME_HIGHLIGHT_SIZE;
632 /* points *MUST* be in anti-clockwise order */
635 double xdelta = pwidth/npoints;
637 for (pi = 0, pc = 0; pc < npoints; ++pc) {
638 (*points)[pi].set_x(1 + (pc * xdelta));
639 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
644 (*points)[pi].set_x(pwidth);
645 (*points)[pi++].set_y(2);
647 (*points)[pi].set_x(1);
648 (*points)[pi++].set_y(2);
650 /* connect the dots ... */
652 (*points)[pi] = (*points)[0];
654 fade_in_shape->property_points() = *points;
659 AudioRegionView::reset_fade_out_shape ()
661 reset_fade_out_shape_width ((jack_nframes_t) region.fade_out().back()->when);
665 AudioRegionView::reset_fade_out_shape_width (jack_nframes_t width)
667 if (fade_out_handle == 0) {
671 /* smallest size for a fade is 64 frames */
673 width = std::max ((jack_nframes_t) 64, width);
676 double pwidth = width / samples_per_unit;
677 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
681 fade_out_shape->hide();
682 fade_out_handle->hide();
686 double handle_center;
687 handle_center = (region.length() - width) / samples_per_unit;
689 if (handle_center > 7.0) {
690 handle_center -= 3.0;
695 fade_out_handle->property_x1() = handle_center - 3.0;
696 fade_out_handle->property_x2() = handle_center + 3.0;
698 /* don't show shape if its too small */
701 fade_out_shape->hide();
705 fade_out_shape->show();
707 float curve[npoints];
708 region.fade_out().get_vector (0, region.fade_out().back()->when, curve, npoints);
710 if (_height > NAME_HIGHLIGHT_THRESH) {
711 h = _height - NAME_HIGHLIGHT_SIZE;
716 /* points *MUST* be in anti-clockwise order */
718 points = get_canvas_points ("fade out shape", npoints+3);
721 double xdelta = pwidth/npoints;
723 for (pi = 0, pc = 0; pc < npoints; ++pc) {
724 (*points)[pi].set_x(_pixel_width - 1 - pwidth + (pc*xdelta));
725 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
730 (*points)[pi].set_x(_pixel_width);
731 (*points)[pi++].set_y(h);
733 (*points)[pi].set_x(_pixel_width);
734 (*points)[pi++].set_y(2);
736 /* connect the dots ... */
738 (*points)[pi] = (*points)[0];
740 fade_out_shape->property_points() = *points;
745 AudioRegionView::set_samples_per_unit (gdouble spu)
747 TimeAxisViewItem::set_samples_per_unit (spu);
749 for (uint32_t n=0; n < waves.size(); ++n) {
750 waves[n]->property_samples_per_unit() = spu;
753 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
754 (*i)->set_samples_per_unit (spu);
755 (*i)->set_duration (region.length() / samples_per_unit);
761 reset_fade_shapes ();
762 region_sync_changed ();
766 AudioRegionView::set_duration (jack_nframes_t frames, void *src)
768 if (!TimeAxisViewItem::set_duration (frames, src)) {
772 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
773 (*i)->set_duration (region.length() / samples_per_unit);
780 AudioRegionView::set_amplitude_above_axis (gdouble spp)
782 for (uint32_t n=0; n < waves.size(); ++n) {
783 waves[n]->property_amplitude_above_axis() = spp;
788 AudioRegionView::compute_colors (Gdk::Color& basic_color)
790 TimeAxisViewItem::compute_colors (basic_color);
793 /* gain color computed in envelope_active_changed() */
795 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
796 fade_color = RGBA_TO_UINT(r,g,b,120);
800 AudioRegionView::set_colors ()
802 TimeAxisViewItem::set_colors ();
805 gain_line->set_line_color (region.envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]);
809 sync_mark->property_fill_color_rgba() = fill_color;
812 for (uint32_t n=0; n < waves.size(); ++n) {
813 if (region.muted()) {
814 waves[n]->property_wave_color() = color_map[cMutedWaveForm];
816 waves[n]->property_wave_color() = color_map[cWaveForm];
822 AudioRegionView::set_frame_color ()
824 if (region.opaque()) {
830 TimeAxisViewItem::set_frame_color ();
834 AudioRegionView::show_region_editor ()
837 editor = new AudioRegionEditor (trackview.session(), region, *this);
838 // GTK2FIX : how to ensure float without realizing
839 // editor->realize ();
840 // trackview.editor.ensure_float (*editor);
844 editor->get_window()->raise();
848 AudioRegionView::hide_region_editor()
856 AudioRegionView::region_renamed ()
860 if (region.locked()) {
862 str += region.name();
868 if (region.muted()) {
869 str = string ("!") + str;
872 set_item_name (region.name(), this);
877 AudioRegionView::region_sync_changed ()
879 if (sync_mark == 0) {
884 jack_nframes_t sync_offset;
886 sync_offset = region.sync_offset (sync_dir);
888 /* this has to handle both a genuine change of position, a change of samples_per_unit,
889 and a change in the bounds of the region.
892 if (sync_offset == 0) {
894 /* no sync mark - its the start of the region */
900 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > region.length()))) {
902 /* no sync mark - its out of the bounds of the region */
912 //points = sync_mark->property_points().get_value();
914 double offset = sync_offset / samples_per_unit;
915 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
916 points.push_back (Gnome::Art::Point (offset + ((sync_mark_width-1)/2), 1));
917 points.push_back (Gnome::Art::Point (offset, sync_mark_width - 1));
918 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
919 sync_mark->property_points().set_value (points);
927 AudioRegionView::set_waveform_visible (bool yn)
929 if (((_flags & WaveformVisible) != yn)) {
931 for (uint32_t n=0; n < waves.size(); ++n) {
934 _flags |= WaveformVisible;
936 for (uint32_t n=0; n < waves.size(); ++n) {
939 _flags &= ~WaveformVisible;
946 AudioRegionView::temporarily_hide_envelope ()
954 AudioRegionView::unhide_envelope ()
956 if (gain_line && (_flags & EnvelopeVisible)) {
962 AudioRegionView::set_envelope_visible (bool yn)
964 if (gain_line && ((_flags & EnvelopeVisible) != yn)) {
967 _flags |= EnvelopeVisible;
970 _flags &= ~EnvelopeVisible;
977 AudioRegionView::create_waves ()
979 bool create_zero_line = true;
981 AudioTimeAxisView& atv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
983 if (!atv.get_diskstream()) {
987 uint32_t nchans = atv.get_diskstream()->n_channels();
989 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
990 for (uint32_t n = 0; n < nchans; ++n) {
991 tmp_waves.push_back (0);
994 for (uint32_t n = 0; n < nchans; ++n) {
996 if (n >= region.n_channels()) {
1000 wave_caches.push_back (WaveView::create_cache ());
1002 if (wait_for_waves) {
1003 if (region.source(n).peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n), peaks_ready_connection)) {
1004 create_one_wave (n, true);
1006 create_zero_line = false;
1009 create_one_wave (n, true);
1013 if (create_zero_line) {
1014 zero_line = new ArdourCanvas::SimpleLine (*group);
1015 zero_line->property_x1() = (gdouble) 1.0;
1016 zero_line->property_x2() = (gdouble) (region.length() / samples_per_unit) - 1.0;
1017 zero_line->property_color_rgba() = (guint) color_map[cZeroLine];
1018 manage_zero_line ();
1023 AudioRegionView::create_one_wave (uint32_t which, bool direct)
1025 AudioTimeAxisView& atv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
1026 uint32_t nchans = atv.get_diskstream()->n_channels();
1028 uint32_t nwaves = std::min (nchans, region.n_channels());
1031 if (trackview.height < NAME_HIGHLIGHT_SIZE) {
1032 ht = ((trackview.height) / (double) nchans);
1034 ht = ((trackview.height - NAME_HIGHLIGHT_SIZE) / (double) nchans);
1037 gdouble yoff = which * ht;
1039 WaveView *wave = new WaveView(*group);
1041 wave->property_data_src() = (gpointer) ®ion;
1042 wave->property_cache() = wave_caches[which];
1043 wave->property_cache_updater() = true;
1044 wave->property_channel() = which;
1045 wave->property_length_function() = (gpointer) region_length_from_c;
1046 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1047 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1048 wave->property_x() = 0.0;
1049 wave->property_y() = yoff;
1050 wave->property_height() = (double) ht;
1051 wave->property_samples_per_unit() = samples_per_unit;
1052 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1053 wave->property_wave_color() = region.muted() ? color_map[cMutedWaveForm] : color_map[cWaveForm];
1054 wave->property_region_start() = region.start();
1056 if (!(_flags & WaveformVisible)) {
1060 /* note: calling this function is serialized by the lock
1061 held in the peak building thread that signals that
1062 peaks are ready for use *or* by the fact that it is
1063 called one by one from the GUI thread.
1066 if (which < nchans) {
1067 tmp_waves[which] = wave;
1069 /* n-channel track, >n-channel source */
1072 /* see if we're all ready */
1074 for (n = 0; n < nchans; ++n) {
1075 if (tmp_waves[n] == 0) {
1080 if (n == nwaves && waves.empty()) {
1081 /* all waves are ready */
1082 tmp_waves.resize(nwaves);
1088 zero_line = new ArdourCanvas::SimpleLine (*group);
1089 zero_line->property_x1() = (gdouble) 1.0;
1090 zero_line->property_x2() = (gdouble) (region.length() / samples_per_unit) - 1.0;
1091 zero_line->property_color_rgba() = (guint) color_map[cZeroLine];
1092 manage_zero_line ();
1098 AudioRegionView::peaks_ready_handler (uint32_t which)
1100 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
1102 if (!waves.empty()) {
1103 /* all waves created, don't hook into peaks ready anymore */
1104 peaks_ready_connection.disconnect ();
1109 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1111 if (gain_line == 0) {
1117 /* don't create points that can't be seen */
1119 set_envelope_visible (true);
1126 jack_nframes_t fx = trackview.editor.pixel_to_frame (x);
1128 if (fx > region.length()) {
1132 /* compute vertical fractional position */
1134 y = 1.0 - (y / (trackview.height - NAME_HIGHLIGHT_SIZE));
1136 /* map using gain line */
1138 gain_line->view_to_model_y (y);
1140 trackview.session().begin_reversible_command (_("add gain control point"));
1141 trackview.session().add_undo (region.envelope().get_memento());
1144 if (!region.envelope_active()) {
1145 trackview.session().add_undo( bind( mem_fun(region, &AudioRegion::set_envelope_active), false) );
1146 region.set_envelope_active(true);
1147 trackview.session().add_redo( bind( mem_fun(region, &AudioRegion::set_envelope_active), true) );
1150 region.envelope().add (fx, y);
1152 trackview.session().add_redo_no_execute (region.envelope().get_memento());
1153 trackview.session().commit_reversible_command ();
1157 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1159 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1160 region.envelope().erase (cp->model);
1164 AudioRegionView::store_flags()
1166 XMLNode *node = new XMLNode ("GUI");
1168 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
1169 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
1171 region.add_extra_xml (*node);
1175 AudioRegionView::set_flags (XMLNode* node)
1179 if ((prop = node->property ("waveform-visible")) != 0) {
1180 if (prop->value() == "yes") {
1181 _flags |= WaveformVisible;
1185 if ((prop = node->property ("envelope-visible")) != 0) {
1186 if (prop->value() == "yes") {
1187 _flags |= EnvelopeVisible;
1193 AudioRegionView::set_waveform_shape (WaveformShape shape)
1197 /* this slightly odd approach is to leave the door open to
1198 other "shapes" such as spectral displays, etc.
1211 if (yn != (bool) (_flags & WaveformRectified)) {
1212 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1213 (*wave)->property_rectified() = yn;
1225 _flags |= WaveformRectified;
1227 _flags &= ~WaveformRectified;
1233 AudioRegionView::get_item_name ()
1235 return region.name();
1239 AudioRegionView::move (double x_delta, double y_delta)
1241 if (region.locked() || (x_delta == 0 && y_delta == 0)) {
1245 get_canvas_group()->move (x_delta, y_delta);
1247 /* note: ghosts never leave their tracks so y_delta for them is always zero */
1249 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1250 (*i)->group->move (x_delta, 0.0);
1255 AudioRegionView::add_ghost (AutomationTimeAxisView& atv)
1257 AudioTimeAxisView& myatv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
1258 double unit_position = region.position () / samples_per_unit;
1259 GhostRegion* ghost = new GhostRegion (atv, unit_position);
1262 nchans = myatv.get_diskstream()->n_channels();
1264 for (uint32_t n = 0; n < nchans; ++n) {
1266 if (n >= region.n_channels()) {
1270 WaveView *wave = new WaveView(*ghost->group);
1272 wave->property_data_src() = ®ion;
1273 wave->property_cache() = wave_caches[n];
1274 wave->property_cache_updater() = false;
1275 wave->property_channel() = n;
1276 wave->property_length_function() = (gpointer)region_length_from_c;
1277 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1278 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1279 wave->property_x() = 0.0;
1280 wave->property_samples_per_unit() = samples_per_unit;
1281 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1282 wave->property_wave_color() = color_map[cGhostTrackWave];
1283 wave->property_region_start() = region.start();
1285 ghost->waves.push_back(wave);
1288 ghost->set_height ();
1289 ghost->set_duration (region.length() / samples_per_unit);
1290 ghosts.push_back (ghost);
1292 ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost));
1298 AudioRegionView::remove_ghost (GhostRegion* ghost)
1300 if (in_destructor) {
1304 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1313 AudioRegionView::get_fill_color ()
1319 AudioRegionView::entered ()
1321 if (gain_line && _flags & EnvelopeVisible) {
1322 gain_line->show_all_control_points ();
1326 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1329 if (fade_in_handle) {
1330 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1331 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1336 AudioRegionView::exited ()
1339 gain_line->hide_all_but_selected_control_points ();
1343 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1346 if (fade_in_handle) {
1347 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1348 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1353 AudioRegionView::envelope_active_changed ()
1356 gain_line->set_line_color (region.envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]);
1361 AudioRegionView::set_waveview_data_src()
1364 double unit_length= region.length() / samples_per_unit;
1366 for (uint32_t n = 0; n < waves.size(); ++n) {
1367 // TODO: something else to let it know the channel
1368 waves[n]->property_data_src() = ®ion;
1371 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1373 (*i)->set_duration (unit_length);
1375 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
1376 (*w)->property_data_src() = ®ion;
1383 AudioRegionView::color_handler (ColorID id, uint32_t val)
1386 case cMutedWaveForm:
1391 case cGainLineInactive:
1393 envelope_active_changed();
1398 zero_line->property_color_rgba() = (guint) color_map[cZeroLine];
1402 case cGhostTrackWave: