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>
33 #include "streamview.h"
34 #include "regionview.h"
35 #include "audio_time_axis.h"
36 #include "simplerect.h"
37 #include "simpleline.h"
39 #include "public_editor.h"
40 #include "region_editor.h"
41 #include "region_gain_line.h"
42 #include "ghostregion.h"
43 #include "audio_time_axis.h"
45 #include "rgb_macros.h"
46 #include "gui_thread.h"
51 using namespace ARDOUR;
52 using namespace Editing;
53 using namespace ArdourCanvas;
55 static const int32_t sync_mark_width = 9;
57 sigc::signal<void,AudioRegionView*> AudioRegionView::AudioRegionViewGoingAway;
59 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, AudioTimeAxisView &tv, AudioRegion& r, double spu,
60 Gdk::Color& basic_color)
61 : TimeAxisViewItem (r.name(), *parent, tv, spu, basic_color, r.position(), r.length(),
62 TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowNameText|
63 TimeAxisViewItem::ShowNameHighlight|
64 TimeAxisViewItem::ShowFrame)),
69 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, AudioTimeAxisView &tv, AudioRegion& r, double spu,
70 Gdk::Color& basic_color, TimeAxisViewItem::Visibility visibility)
71 : TimeAxisViewItem (r.name(), *parent, tv, spu, basic_color, r.position(), r.length(), visibility),
77 AudioRegionView::init (double amplitude_above_axis, Gdk::Color& basic_color, bool wfw)
79 ArdourCanvas::Points shape;
84 in_destructor = false;
85 _amplitude_above_axis = amplitude_above_axis;
92 if ((node = region.extra_xml ("GUI")) != 0) {
95 _flags = WaveformVisible;
99 if (trackview.editor.new_regionviews_display_gain()) {
100 _flags |= EnvelopeVisible;
103 compute_colors (basic_color);
107 name_highlight->set_data ("regionview", this);
108 name_text->set_data ("regionview", this);
110 // shape = new ArdourCanvas::Points ();
112 /* an equilateral triangle */
114 shape.push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
115 shape.push_back (Gnome::Art::Point ((sync_mark_width - 1)/2, 1));
116 shape.push_back (Gnome::Art::Point (0, sync_mark_width - 1));
117 shape.push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
119 sync_mark = new ArdourCanvas::Polygon (*group);
120 sync_mark->property_points() = shape;
121 sync_mark->property_fill_color_rgba() = fill_color;
124 fade_in_shape = new ArdourCanvas::Polygon (*group);
125 fade_in_shape->property_fill_color_rgba() = fade_color;
126 fade_in_shape->set_data ("regionview", this);
128 fade_out_shape = new ArdourCanvas::Polygon (*group);
129 fade_out_shape->property_fill_color_rgba() = fade_color;
130 fade_out_shape->set_data ("regionview", this);
135 UINT_TO_RGBA(fill_color,&r,&g,&b,&a);
138 fade_in_handle = new ArdourCanvas::SimpleRect (*group);
139 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
140 fade_in_handle->property_outline_pixels() = 0;
141 fade_in_handle->property_y1() = 2.0;
142 fade_in_handle->property_y2() = 7.0;
144 fade_in_handle->set_data ("regionview", this);
146 fade_out_handle = new ArdourCanvas::SimpleRect (*group);
147 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
148 fade_out_handle->property_outline_pixels() = 0;
149 fade_out_handle->property_y1() = 2.0;
150 fade_out_handle->property_y2() = 7.0;
152 fade_out_handle->set_data ("regionview", this);
155 string foo = region.name();
159 gain_line = new AudioRegionGainLine (foo, trackview.session(), *this, *group, region.envelope());
161 if (!(_flags & EnvelopeVisible)) {
167 reset_width_dependent_items ((double) region.length() / samples_per_unit);
171 set_height (trackview.height);
174 region_sync_changed ();
175 region_resized (BoundsChanged);
176 set_waveview_data_src();
178 envelope_active_changed ();
179 fade_in_active_changed ();
180 fade_out_active_changed ();
182 region.StateChanged.connect (mem_fun(*this, &AudioRegionView::region_changed));
184 group->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_event), group, this));
185 name_highlight->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event), name_highlight, this));
186 fade_in_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
187 fade_in_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
188 fade_out_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
189 fade_out_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
193 ColorChanged.connect (mem_fun (*this, &AudioRegionView::color_handler));
195 /* XXX sync mark drag? */
198 AudioRegionView::~AudioRegionView ()
200 in_destructor = true;
202 AudioRegionViewGoingAway (this); /* EMIT_SIGNAL */
204 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
205 gnome_canvas_waveview_cache_destroy (*cache);
208 /* all waveviews etc will be destroyed when the group is destroyed */
210 for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
224 AudioRegionView::_lock_toggle (ArdourCanvas::Item* item, GdkEvent* ev, void* arg)
227 case GDK_BUTTON_RELEASE:
228 static_cast<AudioRegionView*>(arg)->lock_toggle ();
238 AudioRegionView::lock_toggle ()
240 region.set_locked (!region.locked());
244 AudioRegionView::region_changed (Change what_changed)
246 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionView::region_changed), what_changed));
248 if (what_changed & BoundsChanged) {
249 region_resized (what_changed);
250 region_sync_changed ();
252 if (what_changed & Region::MuteChanged) {
255 if (what_changed & Region::OpacityChanged) {
258 if (what_changed & ARDOUR::NameChanged) {
261 if (what_changed & Region::SyncOffsetChanged) {
262 region_sync_changed ();
264 if (what_changed & Region::LayerChanged) {
267 if (what_changed & Region::LockChanged) {
270 if (what_changed & AudioRegion::ScaleAmplitudeChanged) {
271 region_scale_amplitude_changed ();
273 if (what_changed & AudioRegion::FadeInChanged) {
276 if (what_changed & AudioRegion::FadeOutChanged) {
279 if (what_changed & AudioRegion::FadeInActiveChanged) {
280 fade_in_active_changed ();
282 if (what_changed & AudioRegion::FadeOutActiveChanged) {
283 fade_out_active_changed ();
285 if (what_changed & AudioRegion::EnvelopeActiveChanged) {
286 envelope_active_changed ();
291 AudioRegionView::fade_in_changed ()
293 reset_fade_in_shape ();
297 AudioRegionView::fade_out_changed ()
299 reset_fade_out_shape ();
303 AudioRegionView::set_fade_in_active (bool yn)
305 region.set_fade_in_active (yn);
309 AudioRegionView::set_fade_out_active (bool yn)
311 region.set_fade_out_active (yn);
315 AudioRegionView::fade_in_active_changed ()
319 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
321 if (region.fade_in_active()) {
322 col = RGBA_TO_UINT(r,g,b,120);
323 fade_in_shape->property_fill_color_rgba() = col;
324 fade_in_shape->property_width_pixels() = 0;
325 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
327 col = RGBA_TO_UINT(r,g,b,0);
328 fade_in_shape->property_fill_color_rgba() = col;
329 fade_in_shape->property_width_pixels() = 1;
330 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
335 AudioRegionView::fade_out_active_changed ()
339 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
341 if (region.fade_out_active()) {
342 col = RGBA_TO_UINT(r,g,b,120);
343 fade_out_shape->property_fill_color_rgba() = col;
344 fade_out_shape->property_width_pixels() = 0;
345 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
347 col = RGBA_TO_UINT(r,g,b,0);
348 fade_out_shape->property_fill_color_rgba() = col;
349 fade_out_shape->property_width_pixels() = 1;
350 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
356 AudioRegionView::region_scale_amplitude_changed ()
358 ENSURE_GUI_THREAD (mem_fun(*this, &AudioRegionView::region_scale_amplitude_changed));
360 for (uint32_t n = 0; n < waves.size(); ++n) {
361 // force a reload of the cache
362 waves[n]->property_data_src() = ®ion;
367 AudioRegionView::region_locked ()
369 /* name will show locked status */
374 AudioRegionView::region_resized (Change what_changed)
378 if (what_changed & ARDOUR::PositionChanged) {
379 set_position (region.position(), 0);
382 if (what_changed & Change (StartChanged|LengthChanged)) {
384 set_duration (region.length(), 0);
386 unit_length = region.length() / samples_per_unit;
388 reset_width_dependent_items (unit_length);
390 for (uint32_t n = 0; n < waves.size(); ++n) {
391 waves[n]->property_region_start() = region.start();
394 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
396 (*i)->set_duration (unit_length);
398 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
399 (*w)->property_region_start() = region.start();
406 AudioRegionView::reset_width_dependent_items (double pixel_width)
408 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
409 _pixel_width = pixel_width;
412 zero_line->property_x2() = pixel_width - 1.0;
415 if (fade_in_handle) {
416 if (pixel_width <= 6.0) {
417 fade_in_handle->hide();
418 fade_out_handle->hide();
421 fade_in_handle->hide();
422 fade_out_handle->hide();
424 fade_in_handle->show();
425 fade_out_handle->show();
430 reset_fade_shapes ();
434 AudioRegionView::region_layered ()
436 AudioTimeAxisView *atv = dynamic_cast<AudioTimeAxisView*> (&get_time_axis_view());
437 atv->view->region_layered (this);
441 AudioRegionView::region_muted ()
446 for (uint32_t n=0; n < waves.size(); ++n) {
447 if (region.muted()) {
448 waves[n]->property_wave_color() = color_map[cMutedWaveForm];
450 waves[n]->property_wave_color() = color_map[cWaveForm];
456 AudioRegionView::region_opacity ()
462 AudioRegionView::raise ()
468 AudioRegionView::raise_to_top ()
470 region.raise_to_top ();
474 AudioRegionView::lower ()
480 AudioRegionView::lower_to_bottom ()
482 region.lower_to_bottom ();
486 AudioRegionView::set_position (jack_nframes_t pos, void* src, double* ignored)
491 if (!(ret = TimeAxisViewItem::set_position (pos, this, &delta))) {
500 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
501 (*i)->group->move (delta, 0.0);
509 AudioRegionView::set_height (gdouble height)
511 uint32_t wcnt = waves.size();
513 TimeAxisViewItem::set_height (height - 2);
517 for (uint32_t n=0; n < wcnt; ++n) {
520 if ((height) < NAME_HIGHLIGHT_THRESH) {
521 ht = ((height-2*wcnt) / (double) wcnt);
523 ht = (((height-2*wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
526 gdouble yoff = n * (ht+1);
528 waves[n]->property_height() = ht;
529 waves[n]->property_y() = yoff + 2;
533 if ((height/wcnt) < NAME_HIGHLIGHT_SIZE) {
536 if (_flags & EnvelopeVisible) {
540 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE));
544 reset_fade_shapes ();
547 name_text->raise_to_top();
552 AudioRegionView::manage_zero_line ()
558 if (_height >= 100) {
559 gdouble wave_midpoint = (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
560 zero_line->property_y1() = wave_midpoint;
561 zero_line->property_y2() = wave_midpoint;
569 AudioRegionView::reset_fade_shapes ()
571 reset_fade_in_shape ();
572 reset_fade_out_shape ();
576 AudioRegionView::reset_fade_in_shape ()
578 reset_fade_in_shape_width ((jack_nframes_t) region.fade_in().back()->when);
582 AudioRegionView::reset_fade_in_shape_width (jack_nframes_t width)
584 if (fade_in_handle == 0) {
588 /* smallest size for a fade is 64 frames */
590 width = std::max ((jack_nframes_t) 64, width);
593 double pwidth = width / samples_per_unit;
594 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
598 fade_in_shape->hide();
599 fade_in_handle->hide();
603 double handle_center;
604 handle_center = pwidth;
606 if (handle_center > 7.0) {
607 handle_center -= 3.0;
612 fade_in_handle->property_x1() = handle_center - 3.0;
613 fade_in_handle->property_x2() = handle_center + 3.0;
616 fade_in_shape->hide();
620 fade_in_shape->show();
622 float curve[npoints];
623 region.fade_in().get_vector (0, region.fade_in().back()->when, curve, npoints);
625 points = get_canvas_points ("fade in shape", npoints+3);
627 if (_height > NAME_HIGHLIGHT_THRESH) {
628 h = _height - NAME_HIGHLIGHT_SIZE;
633 /* points *MUST* be in anti-clockwise order */
636 double xdelta = pwidth/npoints;
638 for (pi = 0, pc = 0; pc < npoints; ++pc) {
639 (*points)[pi].set_x(1 + (pc * xdelta));
640 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
645 (*points)[pi].set_x(pwidth);
646 (*points)[pi++].set_y(2);
648 (*points)[pi].set_x(1);
649 (*points)[pi++].set_y(2);
651 /* connect the dots ... */
653 (*points)[pi] = (*points)[0];
655 fade_in_shape->property_points() = *points;
660 AudioRegionView::reset_fade_out_shape ()
662 reset_fade_out_shape_width ((jack_nframes_t) region.fade_out().back()->when);
666 AudioRegionView::reset_fade_out_shape_width (jack_nframes_t width)
668 if (fade_out_handle == 0) {
672 /* smallest size for a fade is 64 frames */
674 width = std::max ((jack_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 -= 3.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 fade_out_shape->show();
708 float curve[npoints];
709 region.fade_out().get_vector (0, region.fade_out().back()->when, curve, npoints);
711 if (_height > NAME_HIGHLIGHT_THRESH) {
712 h = _height - NAME_HIGHLIGHT_SIZE;
717 /* points *MUST* be in anti-clockwise order */
719 points = get_canvas_points ("fade out shape", npoints+3);
722 double xdelta = pwidth/npoints;
724 for (pi = 0, pc = 0; pc < npoints; ++pc) {
725 (*points)[pi].set_x(_pixel_width - 1 - pwidth + (pc*xdelta));
726 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
731 (*points)[pi].set_x(_pixel_width);
732 (*points)[pi++].set_y(h);
734 (*points)[pi].set_x(_pixel_width);
735 (*points)[pi++].set_y(2);
737 /* connect the dots ... */
739 (*points)[pi] = (*points)[0];
741 fade_out_shape->property_points() = *points;
746 AudioRegionView::set_samples_per_unit (gdouble spu)
748 TimeAxisViewItem::set_samples_per_unit (spu);
750 for (uint32_t n=0; n < waves.size(); ++n) {
751 waves[n]->property_samples_per_unit() = spu;
754 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
755 (*i)->set_samples_per_unit (spu);
756 (*i)->set_duration (region.length() / samples_per_unit);
762 reset_fade_shapes ();
763 region_sync_changed ();
767 AudioRegionView::set_duration (jack_nframes_t frames, void *src)
769 if (!TimeAxisViewItem::set_duration (frames, src)) {
773 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
774 (*i)->set_duration (region.length() / samples_per_unit);
781 AudioRegionView::set_amplitude_above_axis (gdouble spp)
783 for (uint32_t n=0; n < waves.size(); ++n) {
784 waves[n]->property_amplitude_above_axis() = spp;
789 AudioRegionView::compute_colors (Gdk::Color& basic_color)
791 TimeAxisViewItem::compute_colors (basic_color);
794 /* gain color computed in envelope_active_changed() */
796 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
797 fade_color = RGBA_TO_UINT(r,g,b,120);
801 AudioRegionView::set_colors ()
803 TimeAxisViewItem::set_colors ();
806 gain_line->set_line_color (region.envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]);
810 sync_mark->property_fill_color_rgba() = fill_color;
813 for (uint32_t n=0; n < waves.size(); ++n) {
814 if (region.muted()) {
815 waves[n]->property_wave_color() = color_map[cMutedWaveForm];
817 waves[n]->property_wave_color() = color_map[cWaveForm];
823 AudioRegionView::set_frame_color ()
825 if (region.opaque()) {
831 TimeAxisViewItem::set_frame_color ();
835 AudioRegionView::show_region_editor ()
838 editor = new AudioRegionEditor (trackview.session(), region, *this);
839 // GTK2FIX : how to ensure float without realizing
840 // editor->realize ();
841 // trackview.editor.ensure_float (*editor);
845 editor->get_window()->raise();
849 AudioRegionView::hide_region_editor()
857 AudioRegionView::region_renamed ()
861 if (region.locked()) {
863 str += region.name();
869 if (region.speed_mismatch (trackview.session().frame_rate())) {
870 str = string ("*") + str;
873 if (region.muted()) {
874 str = string ("!") + str;
877 set_item_name (str, this);
882 AudioRegionView::region_sync_changed ()
884 if (sync_mark == 0) {
889 jack_nframes_t sync_offset;
891 sync_offset = region.sync_offset (sync_dir);
893 /* this has to handle both a genuine change of position, a change of samples_per_unit,
894 and a change in the bounds of the region.
897 if (sync_offset == 0) {
899 /* no sync mark - its the start of the region */
905 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > region.length()))) {
907 /* no sync mark - its out of the bounds of the region */
917 //points = sync_mark->property_points().get_value();
919 double offset = sync_offset / samples_per_unit;
920 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
921 points.push_back (Gnome::Art::Point (offset + ((sync_mark_width-1)/2), 1));
922 points.push_back (Gnome::Art::Point (offset, sync_mark_width - 1));
923 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
924 sync_mark->property_points().set_value (points);
932 AudioRegionView::set_waveform_visible (bool yn)
934 if (((_flags & WaveformVisible) != yn)) {
936 for (uint32_t n=0; n < waves.size(); ++n) {
939 _flags |= WaveformVisible;
941 for (uint32_t n=0; n < waves.size(); ++n) {
944 _flags &= ~WaveformVisible;
951 AudioRegionView::temporarily_hide_envelope ()
959 AudioRegionView::unhide_envelope ()
961 if (gain_line && (_flags & EnvelopeVisible)) {
967 AudioRegionView::set_envelope_visible (bool yn)
969 if (gain_line && ((_flags & EnvelopeVisible) != yn)) {
972 _flags |= EnvelopeVisible;
975 _flags &= ~EnvelopeVisible;
982 AudioRegionView::create_waves ()
984 bool create_zero_line = true;
986 AudioTimeAxisView& atv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
988 if (!atv.get_diskstream()) {
992 uint32_t nchans = atv.get_diskstream()->n_channels();
994 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
995 for (uint32_t n = 0; n < nchans; ++n) {
996 tmp_waves.push_back (0);
999 for (uint32_t n = 0; n < nchans; ++n) {
1001 if (n >= region.n_channels()) {
1005 wave_caches.push_back (WaveView::create_cache ());
1007 if (wait_for_waves) {
1008 if (region.source(n).peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n), peaks_ready_connection)) {
1009 create_one_wave (n, true);
1011 create_zero_line = false;
1014 create_one_wave (n, true);
1018 if (create_zero_line) {
1019 zero_line = new ArdourCanvas::SimpleLine (*group);
1020 zero_line->property_x1() = (gdouble) 1.0;
1021 zero_line->property_x2() = (gdouble) (region.length() / samples_per_unit) - 1.0;
1022 zero_line->property_color_rgba() = (guint) color_map[cZeroLine];
1023 manage_zero_line ();
1028 AudioRegionView::create_one_wave (uint32_t which, bool direct)
1030 AudioTimeAxisView& atv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
1031 uint32_t nchans = atv.get_diskstream()->n_channels();
1033 uint32_t nwaves = std::min (nchans, region.n_channels());
1036 if (trackview.height < NAME_HIGHLIGHT_SIZE) {
1037 ht = ((trackview.height) / (double) nchans);
1039 ht = ((trackview.height - NAME_HIGHLIGHT_SIZE) / (double) nchans);
1042 gdouble yoff = which * ht;
1044 WaveView *wave = new WaveView(*group);
1046 wave->property_data_src() = (gpointer) ®ion;
1047 wave->property_cache() = wave_caches[which];
1048 wave->property_cache_updater() = true;
1049 wave->property_channel() = which;
1050 wave->property_length_function() = (gpointer) region_length_from_c;
1051 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1052 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1053 wave->property_x() = 0.0;
1054 wave->property_y() = yoff;
1055 wave->property_height() = (double) ht;
1056 wave->property_samples_per_unit() = samples_per_unit;
1057 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1058 wave->property_wave_color() = region.muted() ? color_map[cMutedWaveForm] : color_map[cWaveForm];
1059 wave->property_region_start() = region.start();
1061 if (!(_flags & WaveformVisible)) {
1065 /* note: calling this function is serialized by the lock
1066 held in the peak building thread that signals that
1067 peaks are ready for use *or* by the fact that it is
1068 called one by one from the GUI thread.
1071 if (which < nchans) {
1072 tmp_waves[which] = wave;
1074 /* n-channel track, >n-channel source */
1077 /* see if we're all ready */
1079 for (n = 0; n < nchans; ++n) {
1080 if (tmp_waves[n] == 0) {
1085 if (n == nwaves && waves.empty()) {
1086 /* all waves are ready */
1087 tmp_waves.resize(nwaves);
1093 zero_line = new ArdourCanvas::SimpleLine (*group);
1094 zero_line->property_x1() = (gdouble) 1.0;
1095 zero_line->property_x2() = (gdouble) (region.length() / samples_per_unit) - 1.0;
1096 zero_line->property_color_rgba() = (guint) color_map[cZeroLine];
1097 manage_zero_line ();
1103 AudioRegionView::peaks_ready_handler (uint32_t which)
1105 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
1107 if (!waves.empty()) {
1108 /* all waves created, don't hook into peaks ready anymore */
1109 peaks_ready_connection.disconnect ();
1114 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1116 if (gain_line == 0) {
1122 /* don't create points that can't be seen */
1124 set_envelope_visible (true);
1131 jack_nframes_t fx = trackview.editor.pixel_to_frame (x);
1133 if (fx > region.length()) {
1137 /* compute vertical fractional position */
1139 y = 1.0 - (y / (trackview.height - NAME_HIGHLIGHT_SIZE));
1141 /* map using gain line */
1143 gain_line->view_to_model_y (y);
1145 trackview.session().begin_reversible_command (_("add gain control point"));
1146 trackview.session().add_undo (region.envelope().get_memento());
1149 if (!region.envelope_active()) {
1150 trackview.session().add_undo( bind( mem_fun(region, &AudioRegion::set_envelope_active), false) );
1151 region.set_envelope_active(true);
1152 trackview.session().add_redo( bind( mem_fun(region, &AudioRegion::set_envelope_active), true) );
1155 region.envelope().add (fx, y);
1157 trackview.session().add_redo_no_execute (region.envelope().get_memento());
1158 trackview.session().commit_reversible_command ();
1162 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1164 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1165 region.envelope().erase (cp->model);
1169 AudioRegionView::store_flags()
1171 XMLNode *node = new XMLNode ("GUI");
1173 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
1174 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
1176 region.add_extra_xml (*node);
1180 AudioRegionView::set_flags (XMLNode* node)
1184 if ((prop = node->property ("waveform-visible")) != 0) {
1185 if (prop->value() == "yes") {
1186 _flags |= WaveformVisible;
1190 if ((prop = node->property ("envelope-visible")) != 0) {
1191 if (prop->value() == "yes") {
1192 _flags |= EnvelopeVisible;
1198 AudioRegionView::set_waveform_shape (WaveformShape shape)
1202 /* this slightly odd approach is to leave the door open to
1203 other "shapes" such as spectral displays, etc.
1216 if (yn != (bool) (_flags & WaveformRectified)) {
1217 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1218 (*wave)->property_rectified() = yn;
1230 _flags |= WaveformRectified;
1232 _flags &= ~WaveformRectified;
1238 AudioRegionView::get_item_name ()
1240 return region.name();
1244 AudioRegionView::move (double x_delta, double y_delta)
1246 if (region.locked() || (x_delta == 0 && y_delta == 0)) {
1250 get_canvas_group()->move (x_delta, y_delta);
1252 /* note: ghosts never leave their tracks so y_delta for them is always zero */
1254 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1255 (*i)->group->move (x_delta, 0.0);
1260 AudioRegionView::add_ghost (AutomationTimeAxisView& atv)
1262 AudioTimeAxisView& myatv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
1263 double unit_position = region.position () / samples_per_unit;
1264 GhostRegion* ghost = new GhostRegion (atv, unit_position);
1267 nchans = myatv.get_diskstream()->n_channels();
1269 for (uint32_t n = 0; n < nchans; ++n) {
1271 if (n >= region.n_channels()) {
1275 WaveView *wave = new WaveView(*ghost->group);
1277 wave->property_data_src() = ®ion;
1278 wave->property_cache() = wave_caches[n];
1279 wave->property_cache_updater() = false;
1280 wave->property_channel() = n;
1281 wave->property_length_function() = (gpointer)region_length_from_c;
1282 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1283 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1284 wave->property_x() = 0.0;
1285 wave->property_samples_per_unit() = samples_per_unit;
1286 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1287 wave->property_wave_color() = color_map[cGhostTrackWave];
1288 wave->property_region_start() = region.start();
1290 ghost->waves.push_back(wave);
1293 ghost->set_height ();
1294 ghost->set_duration (region.length() / samples_per_unit);
1295 ghosts.push_back (ghost);
1297 ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost));
1303 AudioRegionView::remove_ghost (GhostRegion* ghost)
1305 if (in_destructor) {
1309 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1318 AudioRegionView::get_fill_color ()
1324 AudioRegionView::entered ()
1326 if (gain_line && _flags & EnvelopeVisible) {
1327 gain_line->show_all_control_points ();
1331 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1334 if (fade_in_handle) {
1335 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1336 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1341 AudioRegionView::exited ()
1344 gain_line->hide_all_but_selected_control_points ();
1348 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1351 if (fade_in_handle) {
1352 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1353 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1358 AudioRegionView::envelope_active_changed ()
1361 gain_line->set_line_color (region.envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]);
1366 AudioRegionView::set_waveview_data_src()
1369 double unit_length= region.length() / samples_per_unit;
1371 for (uint32_t n = 0; n < waves.size(); ++n) {
1372 // TODO: something else to let it know the channel
1373 waves[n]->property_data_src() = ®ion;
1376 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1378 (*i)->set_duration (unit_length);
1380 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
1381 (*w)->property_data_src() = ®ion;
1388 AudioRegionView::color_handler (ColorID id, uint32_t val)
1391 case cMutedWaveForm:
1396 case cGainLineInactive:
1398 envelope_active_changed();
1403 zero_line->property_color_rgba() = (guint) color_map[cZeroLine];
1407 case cGhostTrackWave: