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/audiosource.h>
31 #include <ardour/audio_diskstream.h>
32 #include <pbd/memento_command.h>
34 #include "streamview.h"
35 #include "regionview.h"
36 #include "audio_time_axis.h"
37 #include "simplerect.h"
38 #include "simpleline.h"
40 #include "public_editor.h"
41 #include "region_editor.h"
42 #include "region_gain_line.h"
43 #include "ghostregion.h"
44 #include "audio_time_axis.h"
46 #include "rgb_macros.h"
47 #include "gui_thread.h"
52 using namespace ARDOUR;
54 using namespace Editing;
55 using namespace ArdourCanvas;
57 static const int32_t sync_mark_width = 9;
59 sigc::signal<void,AudioRegionView*> AudioRegionView::AudioRegionViewGoingAway;
61 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, AudioTimeAxisView &tv, AudioRegion& r, double spu,
62 Gdk::Color& basic_color)
63 : TimeAxisViewItem (r.name(), *parent, tv, spu, basic_color, r.position(), r.length(),
64 TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowNameText|
65 TimeAxisViewItem::ShowNameHighlight|
66 TimeAxisViewItem::ShowFrame)),
71 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, AudioTimeAxisView &tv, AudioRegion& r, double spu,
72 Gdk::Color& basic_color, TimeAxisViewItem::Visibility visibility)
73 : TimeAxisViewItem (r.name(), *parent, tv, spu, basic_color, r.position(), r.length(), visibility),
79 AudioRegionView::init (double amplitude_above_axis, Gdk::Color& basic_color, bool wfw)
81 ArdourCanvas::Points shape;
86 in_destructor = false;
87 _amplitude_above_axis = amplitude_above_axis;
94 if ((node = region.extra_xml ("GUI")) != 0) {
97 _flags = WaveformVisible;
101 if (trackview.editor.new_regionviews_display_gain()) {
102 _flags |= EnvelopeVisible;
105 compute_colors (basic_color);
109 name_highlight->set_data ("regionview", this);
110 name_text->set_data ("regionview", this);
112 // shape = new ArdourCanvas::Points ();
114 /* an equilateral triangle */
116 shape.push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
117 shape.push_back (Gnome::Art::Point ((sync_mark_width - 1)/2, 1));
118 shape.push_back (Gnome::Art::Point (0, sync_mark_width - 1));
119 shape.push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
121 sync_mark = new ArdourCanvas::Polygon (*group);
122 sync_mark->property_points() = shape;
123 sync_mark->property_fill_color_rgba() = fill_color;
126 fade_in_shape = new ArdourCanvas::Polygon (*group);
127 fade_in_shape->property_fill_color_rgba() = fade_color;
128 fade_in_shape->set_data ("regionview", this);
130 fade_out_shape = new ArdourCanvas::Polygon (*group);
131 fade_out_shape->property_fill_color_rgba() = fade_color;
132 fade_out_shape->set_data ("regionview", this);
137 UINT_TO_RGBA(fill_color,&r,&g,&b,&a);
140 fade_in_handle = new ArdourCanvas::SimpleRect (*group);
141 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
142 fade_in_handle->property_outline_pixels() = 0;
143 fade_in_handle->property_y1() = 2.0;
144 fade_in_handle->property_y2() = 7.0;
146 fade_in_handle->set_data ("regionview", this);
148 fade_out_handle = new ArdourCanvas::SimpleRect (*group);
149 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
150 fade_out_handle->property_outline_pixels() = 0;
151 fade_out_handle->property_y1() = 2.0;
152 fade_out_handle->property_y2() = 7.0;
154 fade_out_handle->set_data ("regionview", this);
157 string foo = region.name();
161 gain_line = new AudioRegionGainLine (foo, trackview.session(), *this, *group, region.envelope());
163 if (!(_flags & EnvelopeVisible)) {
169 reset_width_dependent_items ((double) region.length() / samples_per_unit);
173 set_height (trackview.height);
176 region_sync_changed ();
177 region_resized (BoundsChanged);
178 set_waveview_data_src();
180 envelope_active_changed ();
181 fade_in_active_changed ();
182 fade_out_active_changed ();
184 region.StateChanged.connect (mem_fun(*this, &AudioRegionView::region_changed));
186 group->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_event), group, this));
187 name_highlight->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event), name_highlight, this));
188 fade_in_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
189 fade_in_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
190 fade_out_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
191 fade_out_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
195 ColorChanged.connect (mem_fun (*this, &AudioRegionView::color_handler));
197 /* XXX sync mark drag? */
200 AudioRegionView::~AudioRegionView ()
202 in_destructor = true;
204 AudioRegionViewGoingAway (this); /* EMIT_SIGNAL */
206 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
207 gnome_canvas_waveview_cache_destroy (*cache);
210 /* all waveviews etc will be destroyed when the group is destroyed */
212 for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
226 AudioRegionView::_lock_toggle (ArdourCanvas::Item* item, GdkEvent* ev, void* arg)
229 case GDK_BUTTON_RELEASE:
230 static_cast<AudioRegionView*>(arg)->lock_toggle ();
240 AudioRegionView::lock_toggle ()
242 region.set_locked (!region.locked());
246 AudioRegionView::region_changed (Change what_changed)
248 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionView::region_changed), what_changed));
250 if (what_changed & BoundsChanged) {
251 region_resized (what_changed);
252 region_sync_changed ();
254 if (what_changed & Region::MuteChanged) {
257 if (what_changed & Region::OpacityChanged) {
260 if (what_changed & ARDOUR::NameChanged) {
263 if (what_changed & Region::SyncOffsetChanged) {
264 region_sync_changed ();
266 if (what_changed & Region::LayerChanged) {
269 if (what_changed & Region::LockChanged) {
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 ();
305 AudioRegionView::set_fade_in_active (bool yn)
307 region.set_fade_in_active (yn);
311 AudioRegionView::set_fade_out_active (bool yn)
313 region.set_fade_out_active (yn);
317 AudioRegionView::fade_in_active_changed ()
321 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
323 if (region.fade_in_active()) {
324 col = RGBA_TO_UINT(r,g,b,120);
325 fade_in_shape->property_fill_color_rgba() = col;
326 fade_in_shape->property_width_pixels() = 0;
327 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
329 col = RGBA_TO_UINT(r,g,b,0);
330 fade_in_shape->property_fill_color_rgba() = col;
331 fade_in_shape->property_width_pixels() = 1;
332 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
337 AudioRegionView::fade_out_active_changed ()
341 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
343 if (region.fade_out_active()) {
344 col = RGBA_TO_UINT(r,g,b,120);
345 fade_out_shape->property_fill_color_rgba() = col;
346 fade_out_shape->property_width_pixels() = 0;
347 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
349 col = RGBA_TO_UINT(r,g,b,0);
350 fade_out_shape->property_fill_color_rgba() = col;
351 fade_out_shape->property_width_pixels() = 1;
352 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
358 AudioRegionView::region_scale_amplitude_changed ()
360 ENSURE_GUI_THREAD (mem_fun(*this, &AudioRegionView::region_scale_amplitude_changed));
362 for (uint32_t n = 0; n < waves.size(); ++n) {
363 // force a reload of the cache
364 waves[n]->property_data_src() = ®ion;
369 AudioRegionView::region_locked ()
371 /* name will show locked status */
376 AudioRegionView::region_resized (Change what_changed)
380 if (what_changed & ARDOUR::PositionChanged) {
381 set_position (region.position(), 0);
384 if (what_changed & Change (StartChanged|LengthChanged)) {
386 set_duration (region.length(), 0);
388 unit_length = region.length() / samples_per_unit;
390 reset_width_dependent_items (unit_length);
392 for (uint32_t n = 0; n < waves.size(); ++n) {
393 waves[n]->property_region_start() = region.start();
396 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
398 (*i)->set_duration (unit_length);
400 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
401 (*w)->property_region_start() = region.start();
408 AudioRegionView::reset_width_dependent_items (double pixel_width)
410 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
411 _pixel_width = pixel_width;
414 zero_line->property_x2() = pixel_width - 1.0;
417 if (fade_in_handle) {
418 if (pixel_width <= 6.0) {
419 fade_in_handle->hide();
420 fade_out_handle->hide();
423 fade_in_handle->hide();
424 fade_out_handle->hide();
426 fade_in_handle->show();
427 fade_out_handle->show();
432 reset_fade_shapes ();
436 AudioRegionView::region_layered ()
438 AudioTimeAxisView *atv = dynamic_cast<AudioTimeAxisView*> (&get_time_axis_view());
439 atv->view->region_layered (this);
443 AudioRegionView::region_muted ()
448 for (uint32_t n=0; n < waves.size(); ++n) {
449 if (region.muted()) {
450 waves[n]->property_wave_color() = color_map[cMutedWaveForm];
452 waves[n]->property_wave_color() = color_map[cWaveForm];
458 AudioRegionView::region_opacity ()
464 AudioRegionView::raise ()
470 AudioRegionView::raise_to_top ()
472 region.raise_to_top ();
476 AudioRegionView::lower ()
482 AudioRegionView::lower_to_bottom ()
484 region.lower_to_bottom ();
488 AudioRegionView::set_position (jack_nframes_t pos, void* src, double* ignored)
493 if (!(ret = TimeAxisViewItem::set_position (pos, this, &delta))) {
502 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
503 (*i)->group->move (delta, 0.0);
511 AudioRegionView::set_height (gdouble height)
513 uint32_t wcnt = waves.size();
515 TimeAxisViewItem::set_height (height - 2);
519 for (uint32_t n=0; n < wcnt; ++n) {
522 if ((height) < NAME_HIGHLIGHT_THRESH) {
523 ht = ((height-2*wcnt) / (double) wcnt);
525 ht = (((height-2*wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
528 gdouble yoff = n * (ht+1);
530 waves[n]->property_height() = ht;
531 waves[n]->property_y() = yoff + 2;
535 if ((height/wcnt) < NAME_HIGHLIGHT_SIZE) {
538 if (_flags & EnvelopeVisible) {
542 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE));
546 reset_fade_shapes ();
549 name_text->raise_to_top();
554 AudioRegionView::manage_zero_line ()
560 if (_height >= 100) {
561 gdouble wave_midpoint = (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
562 zero_line->property_y1() = wave_midpoint;
563 zero_line->property_y2() = wave_midpoint;
571 AudioRegionView::reset_fade_shapes ()
573 reset_fade_in_shape ();
574 reset_fade_out_shape ();
578 AudioRegionView::reset_fade_in_shape ()
580 reset_fade_in_shape_width ((jack_nframes_t) region.fade_in().back()->when);
584 AudioRegionView::reset_fade_in_shape_width (jack_nframes_t width)
586 if (fade_in_handle == 0) {
590 /* smallest size for a fade is 64 frames */
592 width = std::max ((jack_nframes_t) 64, width);
595 double pwidth = width / samples_per_unit;
596 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
600 fade_in_shape->hide();
601 fade_in_handle->hide();
605 double handle_center;
606 handle_center = pwidth;
608 if (handle_center > 7.0) {
609 handle_center -= 3.0;
614 fade_in_handle->property_x1() = handle_center - 3.0;
615 fade_in_handle->property_x2() = handle_center + 3.0;
618 fade_in_shape->hide();
622 fade_in_shape->show();
624 float curve[npoints];
625 region.fade_in().get_vector (0, region.fade_in().back()->when, curve, npoints);
627 points = get_canvas_points ("fade in shape", npoints+3);
629 if (_height > NAME_HIGHLIGHT_THRESH) {
630 h = _height - NAME_HIGHLIGHT_SIZE;
635 /* points *MUST* be in anti-clockwise order */
638 double xdelta = pwidth/npoints;
640 for (pi = 0, pc = 0; pc < npoints; ++pc) {
641 (*points)[pi].set_x(1 + (pc * xdelta));
642 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
647 (*points)[pi].set_x(pwidth);
648 (*points)[pi++].set_y(2);
650 (*points)[pi].set_x(1);
651 (*points)[pi++].set_y(2);
653 /* connect the dots ... */
655 (*points)[pi] = (*points)[0];
657 fade_in_shape->property_points() = *points;
662 AudioRegionView::reset_fade_out_shape ()
664 reset_fade_out_shape_width ((jack_nframes_t) region.fade_out().back()->when);
668 AudioRegionView::reset_fade_out_shape_width (jack_nframes_t width)
670 if (fade_out_handle == 0) {
674 /* smallest size for a fade is 64 frames */
676 width = std::max ((jack_nframes_t) 64, width);
679 double pwidth = width / samples_per_unit;
680 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
684 fade_out_shape->hide();
685 fade_out_handle->hide();
689 double handle_center;
690 handle_center = (region.length() - width) / samples_per_unit;
692 if (handle_center > 7.0) {
693 handle_center -= 3.0;
698 fade_out_handle->property_x1() = handle_center - 3.0;
699 fade_out_handle->property_x2() = handle_center + 3.0;
701 /* don't show shape if its too small */
704 fade_out_shape->hide();
708 fade_out_shape->show();
710 float curve[npoints];
711 region.fade_out().get_vector (0, region.fade_out().back()->when, curve, npoints);
713 if (_height > NAME_HIGHLIGHT_THRESH) {
714 h = _height - NAME_HIGHLIGHT_SIZE;
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 - 1 - 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;
748 AudioRegionView::set_samples_per_unit (gdouble spu)
750 TimeAxisViewItem::set_samples_per_unit (spu);
752 for (uint32_t n=0; n < waves.size(); ++n) {
753 waves[n]->property_samples_per_unit() = spu;
756 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
757 (*i)->set_samples_per_unit (spu);
758 (*i)->set_duration (region.length() / samples_per_unit);
764 reset_fade_shapes ();
765 region_sync_changed ();
769 AudioRegionView::set_duration (jack_nframes_t frames, void *src)
771 if (!TimeAxisViewItem::set_duration (frames, src)) {
775 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
776 (*i)->set_duration (region.length() / samples_per_unit);
783 AudioRegionView::set_amplitude_above_axis (gdouble spp)
785 for (uint32_t n=0; n < waves.size(); ++n) {
786 waves[n]->property_amplitude_above_axis() = spp;
791 AudioRegionView::compute_colors (Gdk::Color& basic_color)
793 TimeAxisViewItem::compute_colors (basic_color);
796 /* gain color computed in envelope_active_changed() */
798 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
799 fade_color = RGBA_TO_UINT(r,g,b,120);
803 AudioRegionView::set_colors ()
805 TimeAxisViewItem::set_colors ();
808 gain_line->set_line_color (region.envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]);
812 sync_mark->property_fill_color_rgba() = fill_color;
815 for (uint32_t n=0; n < waves.size(); ++n) {
816 if (region.muted()) {
817 waves[n]->property_wave_color() = color_map[cMutedWaveForm];
819 waves[n]->property_wave_color() = color_map[cWaveForm];
825 AudioRegionView::set_frame_color ()
827 if (region.opaque()) {
833 TimeAxisViewItem::set_frame_color ();
837 AudioRegionView::show_region_editor ()
840 editor = new AudioRegionEditor (trackview.session(), region, *this);
841 // GTK2FIX : how to ensure float without realizing
842 // editor->realize ();
843 // trackview.editor.ensure_float (*editor);
847 editor->get_window()->raise();
851 AudioRegionView::hide_region_editor()
859 AudioRegionView::region_renamed ()
863 if (region.locked()) {
865 str += region.name();
871 if (region.speed_mismatch (trackview.session().frame_rate())) {
872 str = string ("*") + str;
875 if (region.muted()) {
876 str = string ("!") + str;
879 set_item_name (str, this);
884 AudioRegionView::region_sync_changed ()
886 if (sync_mark == 0) {
891 jack_nframes_t sync_offset;
893 sync_offset = region.sync_offset (sync_dir);
895 /* this has to handle both a genuine change of position, a change of samples_per_unit,
896 and a change in the bounds of the region.
899 if (sync_offset == 0) {
901 /* no sync mark - its the start of the region */
907 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > region.length()))) {
909 /* no sync mark - its out of the bounds of the region */
919 //points = sync_mark->property_points().get_value();
921 double offset = sync_offset / samples_per_unit;
922 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
923 points.push_back (Gnome::Art::Point (offset + ((sync_mark_width-1)/2), 1));
924 points.push_back (Gnome::Art::Point (offset, sync_mark_width - 1));
925 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
926 sync_mark->property_points().set_value (points);
934 AudioRegionView::set_waveform_visible (bool yn)
936 if (((_flags & WaveformVisible) != yn)) {
938 for (uint32_t n=0; n < waves.size(); ++n) {
941 _flags |= WaveformVisible;
943 for (uint32_t n=0; n < waves.size(); ++n) {
946 _flags &= ~WaveformVisible;
953 AudioRegionView::temporarily_hide_envelope ()
961 AudioRegionView::unhide_envelope ()
963 if (gain_line && (_flags & EnvelopeVisible)) {
969 AudioRegionView::set_envelope_visible (bool yn)
971 if (gain_line && ((_flags & EnvelopeVisible) != yn)) {
974 _flags |= EnvelopeVisible;
977 _flags &= ~EnvelopeVisible;
984 AudioRegionView::create_waves ()
986 bool create_zero_line = true;
988 AudioTimeAxisView& atv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
990 if (!atv.get_diskstream()) {
994 uint32_t nchans = atv.get_diskstream()->n_channels();
996 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
997 for (uint32_t n = 0; n < nchans; ++n) {
998 tmp_waves.push_back (0);
1001 for (uint32_t n = 0; n < nchans; ++n) {
1003 if (n >= region.n_channels()) {
1007 wave_caches.push_back (WaveView::create_cache ());
1009 if (wait_for_waves) {
1010 if (region.source(n).peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n), peaks_ready_connection)) {
1011 create_one_wave (n, true);
1013 create_zero_line = false;
1016 create_one_wave (n, true);
1020 if (create_zero_line) {
1021 zero_line = new ArdourCanvas::SimpleLine (*group);
1022 zero_line->property_x1() = (gdouble) 1.0;
1023 zero_line->property_x2() = (gdouble) (region.length() / samples_per_unit) - 1.0;
1024 zero_line->property_color_rgba() = (guint) color_map[cZeroLine];
1025 manage_zero_line ();
1030 AudioRegionView::create_one_wave (uint32_t which, bool direct)
1032 AudioTimeAxisView& atv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
1033 uint32_t nchans = atv.get_diskstream()->n_channels();
1035 uint32_t nwaves = std::min (nchans, region.n_channels());
1038 if (trackview.height < NAME_HIGHLIGHT_SIZE) {
1039 ht = ((trackview.height) / (double) nchans);
1041 ht = ((trackview.height - NAME_HIGHLIGHT_SIZE) / (double) nchans);
1044 gdouble yoff = which * ht;
1046 WaveView *wave = new WaveView(*group);
1048 wave->property_data_src() = (gpointer) ®ion;
1049 wave->property_cache() = wave_caches[which];
1050 wave->property_cache_updater() = true;
1051 wave->property_channel() = which;
1052 wave->property_length_function() = (gpointer) region_length_from_c;
1053 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1054 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1055 wave->property_x() = 0.0;
1056 wave->property_y() = yoff;
1057 wave->property_height() = (double) ht;
1058 wave->property_samples_per_unit() = samples_per_unit;
1059 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1060 wave->property_wave_color() = region.muted() ? color_map[cMutedWaveForm] : color_map[cWaveForm];
1061 wave->property_region_start() = region.start();
1063 if (!(_flags & WaveformVisible)) {
1067 /* note: calling this function is serialized by the lock
1068 held in the peak building thread that signals that
1069 peaks are ready for use *or* by the fact that it is
1070 called one by one from the GUI thread.
1073 if (which < nchans) {
1074 tmp_waves[which] = wave;
1076 /* n-channel track, >n-channel source */
1079 /* see if we're all ready */
1081 for (n = 0; n < nchans; ++n) {
1082 if (tmp_waves[n] == 0) {
1087 if (n == nwaves && waves.empty()) {
1088 /* all waves are ready */
1089 tmp_waves.resize(nwaves);
1095 zero_line = new ArdourCanvas::SimpleLine (*group);
1096 zero_line->property_x1() = (gdouble) 1.0;
1097 zero_line->property_x2() = (gdouble) (region.length() / samples_per_unit) - 1.0;
1098 zero_line->property_color_rgba() = (guint) color_map[cZeroLine];
1099 manage_zero_line ();
1105 AudioRegionView::peaks_ready_handler (uint32_t which)
1107 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
1109 if (!waves.empty()) {
1110 /* all waves created, don't hook into peaks ready anymore */
1111 peaks_ready_connection.disconnect ();
1116 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1118 if (gain_line == 0) {
1124 /* don't create points that can't be seen */
1126 set_envelope_visible (true);
1133 jack_nframes_t fx = trackview.editor.pixel_to_frame (x);
1135 if (fx > region.length()) {
1139 /* compute vertical fractional position */
1141 y = 1.0 - (y / (trackview.height - NAME_HIGHLIGHT_SIZE));
1143 /* map using gain line */
1145 gain_line->view_to_model_y (y);
1147 trackview.session().begin_reversible_command (_("add gain control point"));
1148 XMLNode &before = region.envelope().get_state();
1151 if (!region.envelope_active()) {
1152 XMLNode &before = region.get_state();
1153 region.set_envelope_active(true);
1154 XMLNode &after = region.get_state();
1155 trackview.session().add_command(new MementoCommand<AudioRegion>(region, before, after));
1158 region.envelope().add (fx, y);
1160 XMLNode &after = region.envelope().get_state();
1161 trackview.session().add_command(new MementoCommand<Curve>(region.envelope(), before, after));
1162 trackview.session().commit_reversible_command ();
1166 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1168 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1169 region.envelope().erase (cp->model);
1173 AudioRegionView::store_flags()
1175 XMLNode *node = new XMLNode ("GUI");
1177 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
1178 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
1180 region.add_extra_xml (*node);
1184 AudioRegionView::set_flags (XMLNode* node)
1188 if ((prop = node->property ("waveform-visible")) != 0) {
1189 if (prop->value() == "yes") {
1190 _flags |= WaveformVisible;
1194 if ((prop = node->property ("envelope-visible")) != 0) {
1195 if (prop->value() == "yes") {
1196 _flags |= EnvelopeVisible;
1202 AudioRegionView::set_waveform_shape (WaveformShape shape)
1206 /* this slightly odd approach is to leave the door open to
1207 other "shapes" such as spectral displays, etc.
1220 if (yn != (bool) (_flags & WaveformRectified)) {
1221 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1222 (*wave)->property_rectified() = yn;
1234 _flags |= WaveformRectified;
1236 _flags &= ~WaveformRectified;
1242 AudioRegionView::move (double x_delta, double y_delta)
1244 if (region.locked() || (x_delta == 0 && y_delta == 0)) {
1248 get_canvas_group()->move (x_delta, y_delta);
1250 /* note: ghosts never leave their tracks so y_delta for them is always zero */
1252 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1253 (*i)->group->move (x_delta, 0.0);
1258 AudioRegionView::add_ghost (AutomationTimeAxisView& atv)
1260 AudioTimeAxisView& myatv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
1261 double unit_position = region.position () / samples_per_unit;
1262 GhostRegion* ghost = new GhostRegion (atv, unit_position);
1265 nchans = myatv.get_diskstream()->n_channels();
1267 for (uint32_t n = 0; n < nchans; ++n) {
1269 if (n >= region.n_channels()) {
1273 WaveView *wave = new WaveView(*ghost->group);
1275 wave->property_data_src() = ®ion;
1276 wave->property_cache() = wave_caches[n];
1277 wave->property_cache_updater() = false;
1278 wave->property_channel() = n;
1279 wave->property_length_function() = (gpointer)region_length_from_c;
1280 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1281 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1282 wave->property_x() = 0.0;
1283 wave->property_samples_per_unit() = samples_per_unit;
1284 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1285 wave->property_wave_color() = color_map[cGhostTrackWave];
1286 wave->property_region_start() = region.start();
1288 ghost->waves.push_back(wave);
1291 ghost->set_height ();
1292 ghost->set_duration (region.length() / samples_per_unit);
1293 ghosts.push_back (ghost);
1295 ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost));
1301 AudioRegionView::remove_ghost (GhostRegion* ghost)
1303 if (in_destructor) {
1307 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1316 AudioRegionView::get_fill_color ()
1322 AudioRegionView::entered ()
1324 if (gain_line && _flags & EnvelopeVisible) {
1325 gain_line->show_all_control_points ();
1329 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1332 if (fade_in_handle) {
1333 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1334 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1339 AudioRegionView::exited ()
1342 gain_line->hide_all_but_selected_control_points ();
1346 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1349 if (fade_in_handle) {
1350 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1351 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1356 AudioRegionView::envelope_active_changed ()
1359 gain_line->set_line_color (region.envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]);
1364 AudioRegionView::set_waveview_data_src()
1367 double unit_length= region.length() / samples_per_unit;
1369 for (uint32_t n = 0; n < waves.size(); ++n) {
1370 // TODO: something else to let it know the channel
1371 waves[n]->property_data_src() = ®ion;
1374 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1376 (*i)->set_duration (unit_length);
1378 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
1379 (*w)->property_data_src() = ®ion;
1386 AudioRegionView::color_handler (ColorID id, uint32_t val)
1389 case cMutedWaveForm:
1394 case cGainLineInactive:
1396 envelope_active_changed();
1401 zero_line->property_color_rgba() = (guint) color_map[cZeroLine];
1405 case cGhostTrackWave: