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/sndfilesource.h>
31 #include <ardour/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,
62 double amplitude_above_axis,
63 Gdk::Color& basic_color,
66 : TimeAxisViewItem (r.name(), *parent, tv, spu, basic_color, r.position(), r.length(),
67 TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowNameText|
68 TimeAxisViewItem::ShowNameHighlight|
69 TimeAxisViewItem::ShowFrame)),
73 ArdourCanvas::Points shape;
78 in_destructor = false;
79 _amplitude_above_axis = amplitude_above_axis;
86 if ((node = region.extra_xml ("GUI")) != 0) {
89 _flags = WaveformVisible;
93 if (trackview.editor.new_regionviews_display_gain()) {
94 _flags |= EnvelopeVisible;
97 compute_colors (basic_color);
101 name_highlight->set_data ("regionview", this);
102 name_text->set_data ("regionview", this);
104 // shape = new ArdourCanvas::Points ();
106 /* an equilateral triangle */
108 shape.push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
109 shape.push_back (Gnome::Art::Point ((sync_mark_width - 1)/2, 1));
110 shape.push_back (Gnome::Art::Point (0, sync_mark_width - 1));
111 shape.push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
113 sync_mark = new ArdourCanvas::Polygon (*group);
114 sync_mark->property_points().set_value(shape);
115 sync_mark->set_property ("fill_color_rgba", fill_color);
118 fade_in_shape = new ArdourCanvas::Polygon (*group);
119 fade_in_shape->set_property ("fill_color_rgba", fade_color);
120 fade_in_shape->set_data ("regionview", this);
122 fade_out_shape = new ArdourCanvas::Polygon (*group);
123 fade_out_shape->set_property ("fill_color_rgba", fade_color);
124 fade_out_shape->set_data ("regionview", this);
130 UINT_TO_RGBA(fill_color,&r,&g,&b,&a);
133 fade_in_handle = new ArdourCanvas::SimpleRect (*group);
134 fade_in_handle->set_property ("fill_color_rgba", RGBA_TO_UINT(r,g,b,0));
135 fade_in_handle->set_property ("outline_pixels", 0);
136 fade_in_handle->set_property ("y1", 2.0);
137 fade_in_handle->set_property ("y2", 7.0);
139 fade_in_handle->set_data ("regionview", this);
141 fade_out_handle = new ArdourCanvas::SimpleRect (*group);
142 fade_out_handle->set_property ("fill_color_rgba", RGBA_TO_UINT(r,g,b,0));
143 fade_out_handle->set_property ("outline_pixels", 0);
144 fade_out_handle->set_property ("y1", 2.0);
145 fade_out_handle->set_property ("y2", 7.0);
147 gtk_object_set_data (GTK_OBJECT(fade_out_handle), "regionview", this);
150 string foo = region.name();
154 gain_line = new AudioRegionGainLine (foo, tv.session(), *this, *group, region.envelope());
156 if (!(_flags & EnvelopeVisible)) {
162 reset_width_dependent_items ((double) region.length() / samples_per_unit);
166 set_height (trackview.height);
169 region_sync_changed ();
170 region_resized (BoundsChanged);
171 set_waveview_data_src();
173 envelope_active_changed ();
174 fade_in_active_changed ();
175 fade_out_active_changed ();
177 region.StateChanged.connect (mem_fun(*this, &AudioRegionView::region_changed));
179 group->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_event), group, this));
180 name_highlight->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event), name_highlight, this));
181 fade_in_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
182 fade_in_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
183 fade_out_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
184 fade_out_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
188 /* XXX sync mark drag? */
192 AudioRegionView::~AudioRegionView ()
194 in_destructor = true;
196 AudioRegionViewGoingAway (this); /* EMIT_SIGNAL */
198 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
199 gnome_canvas_waveview_cache_destroy (*cache);
202 /* all waveviews will be destroyed when the group is destroyed */
204 for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
216 AudioRegionView::_lock_toggle (ArdourCanvas::Item* item, GdkEvent* ev, void* arg)
219 case GDK_BUTTON_RELEASE:
220 static_cast<AudioRegionView*>(arg)->lock_toggle ();
230 AudioRegionView::lock_toggle ()
232 region.set_locked (!region.locked());
236 AudioRegionView::region_changed (Change what_changed)
238 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionView::region_changed), what_changed));
240 if (what_changed & BoundsChanged) {
241 region_resized (what_changed);
242 region_sync_changed ();
244 if (what_changed & Region::MuteChanged) {
247 if (what_changed & Region::OpacityChanged) {
250 if (what_changed & ARDOUR::NameChanged) {
253 if (what_changed & Region::SyncOffsetChanged) {
254 region_sync_changed ();
256 if (what_changed & Region::LayerChanged) {
259 if (what_changed & Region::LockChanged) {
262 if (what_changed & AudioRegion::ScaleAmplitudeChanged) {
263 region_scale_amplitude_changed ();
265 if (what_changed & AudioRegion::FadeInChanged) {
268 if (what_changed & AudioRegion::FadeOutChanged) {
271 if (what_changed & AudioRegion::FadeInActiveChanged) {
272 fade_in_active_changed ();
274 if (what_changed & AudioRegion::FadeOutActiveChanged) {
275 fade_out_active_changed ();
277 if (what_changed & AudioRegion::EnvelopeActiveChanged) {
278 envelope_active_changed ();
283 AudioRegionView::fade_in_changed ()
285 reset_fade_in_shape ();
289 AudioRegionView::fade_out_changed ()
291 reset_fade_out_shape ();
295 AudioRegionView::set_fade_in_active (bool yn)
297 region.set_fade_in_active (yn);
301 AudioRegionView::set_fade_out_active (bool yn)
303 region.set_fade_out_active (yn);
307 AudioRegionView::fade_in_active_changed ()
311 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
313 if (region.fade_in_active()) {
314 col = RGBA_TO_UINT(r,g,b,120);
315 fade_in_shape->set_property ("fill_color_rgba", col);
316 fade_in_shape->set_property ("width_pixels", 0);
317 fade_in_shape->set_property ("outline_color_rgba", RGBA_TO_UINT(r,g,b,0));
319 col = RGBA_TO_UINT(r,g,b,0);
320 fade_in_shape->set_property ("fill_color_rgba", col);
321 fade_in_shape->set_property ("width_pixels", 1);
322 fade_in_shape->set_property ("outline_color_rgba", RGBA_TO_UINT(r,g,b,255));
327 AudioRegionView::fade_out_active_changed ()
331 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
333 if (region.fade_out_active()) {
334 col = RGBA_TO_UINT(r,g,b,120);
335 fade_out_shape->set_property ("fill_color_rgba", col);
336 fade_out_shape->set_property ("width_pixels", 0);
337 fade_out_shape->set_property ("outline_color_rgba", RGBA_TO_UINT(r,g,b,0));
339 col = RGBA_TO_UINT(r,g,b,0);
340 fade_out_shape->set_property ("fill_color_rgba", col);
341 fade_out_shape->set_property ("width_pixels", 1);
342 fade_out_shape->set_property ("outline_color_rgba", RGBA_TO_UINT(r,g,b,255));
348 AudioRegionView::region_scale_amplitude_changed ()
350 ENSURE_GUI_THREAD (mem_fun(*this, &AudioRegionView::region_scale_amplitude_changed));
352 for (uint32_t n = 0; n < waves.size(); ++n) {
353 // force a reload of the cache
354 waves[n]->property_data_src().set_value(®ion);
359 AudioRegionView::region_locked ()
361 /* name will show locked status */
366 AudioRegionView::region_resized (Change what_changed)
370 if (what_changed & ARDOUR::PositionChanged) {
371 set_position (region.position(), 0);
374 if (what_changed & Change (StartChanged|LengthChanged)) {
376 set_duration (region.length(), 0);
378 unit_length = region.length() / samples_per_unit;
380 reset_width_dependent_items (unit_length);
382 for (uint32_t n = 0; n < waves.size(); ++n) {
383 waves[n]->property_region_start().set_value(region.start());
386 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
388 (*i)->set_duration (unit_length);
390 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
391 (*w)->property_region_start().set_value(region.start());
398 AudioRegionView::reset_width_dependent_items (double pixel_width)
400 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
401 _pixel_width = pixel_width;
404 zero_line->set_property ("x2", pixel_width - 1.0);
407 if (pixel_width <= 6.0) {
408 fade_in_handle->hide();
409 fade_out_handle->hide();
412 fade_in_handle->hide();
413 fade_out_handle->hide();
415 fade_in_handle->show();
416 fade_out_handle->show();
420 reset_fade_shapes ();
424 AudioRegionView::region_layered ()
426 AudioTimeAxisView *atv = dynamic_cast<AudioTimeAxisView*> (&get_time_axis_view());
427 atv->view->region_layered (this);
431 AudioRegionView::region_muted ()
436 for (uint32_t n=0; n < waves.size(); ++n) {
437 if (region.muted()) {
438 waves[n]->property_wave_color().set_value(color_map[cMutedWaveForm]);
440 waves[n]->property_wave_color().set_value(color_map[cWaveForm]);
446 AudioRegionView::region_opacity ()
452 AudioRegionView::raise ()
458 AudioRegionView::raise_to_top ()
460 region.raise_to_top ();
464 AudioRegionView::lower ()
470 AudioRegionView::lower_to_bottom ()
472 region.lower_to_bottom ();
476 AudioRegionView::set_position (jack_nframes_t pos, void* src, double* ignored)
481 if (!(ret = TimeAxisViewItem::set_position (pos, this, &delta))) {
490 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
491 (*i)->group->move (delta, 0.0);
499 AudioRegionView::set_height (gdouble height)
501 uint32_t wcnt = waves.size();
503 TimeAxisViewItem::set_height (height - 2);
507 for (uint32_t n=0; n < wcnt; ++n) {
510 if ((height) < NAME_HIGHLIGHT_THRESH) {
511 ht = ((height-2*wcnt) / (double) wcnt);
513 ht = (((height-2*wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
516 gdouble yoff = n * (ht+1);
518 waves[n]->property_height().set_value(ht);
519 waves[n]->property_y().set_value(yoff + 2);
522 if ((height/wcnt) < NAME_HIGHLIGHT_SIZE) {
525 if (_flags & EnvelopeVisible) {
531 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE));
532 reset_fade_shapes ();
534 name_text->raise_to_top();
538 AudioRegionView::manage_zero_line ()
544 if (_height >= 100) {
545 gdouble wave_midpoint = (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
546 zero_line->set_property ("y1", wave_midpoint);
547 zero_line->set_property ("y2", wave_midpoint);
555 AudioRegionView::reset_fade_shapes ()
557 reset_fade_in_shape ();
558 reset_fade_out_shape ();
562 AudioRegionView::reset_fade_in_shape ()
564 reset_fade_in_shape_width ((jack_nframes_t) region.fade_in().back()->when);
568 AudioRegionView::reset_fade_in_shape_width (jack_nframes_t width)
570 /* smallest size for a fade is 64 frames */
572 width = std::max ((jack_nframes_t) 64, width);
575 double pwidth = width / samples_per_unit;
576 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
580 fade_in_shape->hide();
581 fade_in_handle->hide();
585 double handle_center;
586 handle_center = pwidth;
588 if (handle_center > 7.0) {
589 handle_center -= 3.0;
594 fade_in_handle->set_property ("x1", handle_center - 3.0);
595 fade_in_handle->set_property ("x2", handle_center + 3.0);
598 fade_in_shape->hide();
602 fade_in_shape->show();
604 float curve[npoints];
605 region.fade_in().get_vector (0, region.fade_in().back()->when, curve, npoints);
607 points = get_canvas_points ("fade in shape", npoints+3);
609 if (_height > NAME_HIGHLIGHT_THRESH) {
610 h = _height - NAME_HIGHLIGHT_SIZE;
615 /* points *MUST* be in anti-clockwise order */
618 double xdelta = pwidth/npoints;
620 for (pi = 0, pc = 0; pc < npoints; ++pc) {
621 (*points)[pi].set_x(1 + (pc * xdelta));
622 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
627 (*points)[pi].set_x(pwidth);
628 (*points)[pi++].set_y(2);
630 (*points)[pi].set_x(1);
631 (*points)[pi++].set_y(2);
633 /* connect the dots ... */
635 (*points)[pi] = (*points)[0];
637 fade_in_shape->property_points().set_value(*points);
642 AudioRegionView::reset_fade_out_shape ()
644 reset_fade_out_shape_width ((jack_nframes_t) region.fade_out().back()->when);
648 AudioRegionView::reset_fade_out_shape_width (jack_nframes_t width)
650 /* smallest size for a fade is 64 frames */
652 width = std::max ((jack_nframes_t) 64, width);
655 double pwidth = width / samples_per_unit;
656 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
660 fade_out_shape->hide();
661 fade_out_handle->hide();
665 double handle_center;
666 handle_center = (region.length() - width) / samples_per_unit;
668 if (handle_center > 7.0) {
669 handle_center -= 3.0;
674 fade_out_handle->set_property ("x1", handle_center - 3.0);
675 fade_out_handle->set_property ("x2", handle_center + 3.0);
677 /* don't show shape if its too small */
680 fade_out_shape->hide();
684 fade_out_shape->show();
686 float curve[npoints];
687 region.fade_out().get_vector (0, region.fade_out().back()->when, curve, npoints);
689 if (_height > NAME_HIGHLIGHT_THRESH) {
690 h = _height - NAME_HIGHLIGHT_SIZE;
695 /* points *MUST* be in anti-clockwise order */
697 points = get_canvas_points ("fade out shape", npoints+3);
700 double xdelta = pwidth/npoints;
702 for (pi = 0, pc = 0; pc < npoints; ++pc) {
703 (*points)[pi] = _pixel_width - 1 - pwidth + (pc*xdelta);
704 (*points)[pi++] = 2 + (h - (curve[pc] * h));
709 (*points)[pi] = _pixel_width;
712 (*points)[pi] = _pixel_width;
715 /* connect the dots ... */
717 (*points)[pi] = (*points)[0];
719 fade_out_shape->set_property ("points", *points);
724 AudioRegionView::set_samples_per_unit (gdouble spu)
726 TimeAxisViewItem::set_samples_per_unit (spu);
728 for (uint32_t n=0; n < waves.size(); ++n) {
729 waves[n]->property_samples_per_unit().set_value(spu);
732 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
733 (*i)->set_samples_per_unit (spu);
734 (*i)->set_duration (region.length() / samples_per_unit);
738 reset_fade_shapes ();
739 region_sync_changed ();
743 AudioRegionView::set_duration (jack_nframes_t frames, void *src)
745 if (!TimeAxisViewItem::set_duration (frames, src)) {
749 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
750 (*i)->set_duration (region.length() / samples_per_unit);
757 AudioRegionView::set_amplitude_above_axis (gdouble spp)
759 for (uint32_t n=0; n < waves.size(); ++n) {
760 waves[n]->property_amplitude_above_axis().set_value(spp);
765 AudioRegionView::compute_colors (Gdk::Color& basic_color)
767 TimeAxisViewItem::compute_colors (basic_color);
770 /* gain color computed in envelope_active_changed() */
772 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
773 fade_color = RGBA_TO_UINT(r,g,b,120);
777 AudioRegionView::set_colors ()
779 TimeAxisViewItem::set_colors ();
781 gain_line->set_line_color (region.envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]);
782 sync_mark->set_property ("fill_color_rgba", fill_color);
784 for (uint32_t n=0; n < waves.size(); ++n) {
785 if (region.muted()) {
786 waves[n]->property_wave_color().set_value(color_map[cMutedWaveForm]);
788 waves[n]->property_wave_color().set_value(color_map[cWaveForm]);
794 AudioRegionView::set_frame_color ()
796 if (region.opaque()) {
802 TimeAxisViewItem::set_frame_color ();
806 AudioRegionView::show_region_editor ()
809 editor = new AudioRegionEditor (trackview.session(), region, *this);
810 // GTK2FIX : how to ensure float without realizing
811 // editor->realize ();
812 // trackview.editor.ensure_float (*editor);
816 editor->get_window()->raise();
820 AudioRegionView::hide_region_editor()
828 AudioRegionView::region_renamed ()
832 if (region.locked()) {
834 str += region.name();
840 if (region.muted()) {
841 str = string ("!") + str;
844 set_item_name (region.name(), this);
849 AudioRegionView::region_sync_changed ()
852 jack_nframes_t sync_offset;
854 sync_offset = region.sync_offset (sync_dir);
856 /* this has to handle both a genuine change of position, a change of samples_per_unit,
857 and a change in the bounds of the region.
860 if (sync_offset == 0) {
862 /* no sync mark - its the start of the region */
868 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > region.length()))) {
870 /* no sync mark - its out of the bounds of the region */
880 points = sync_mark->property_points().get_value();
882 double offset = sync_offset / samples_per_unit;
884 points[0].set_x(offset - ((sync_mark_width-1)/2));
887 points[1].set_x(offset + (sync_mark_width-1)/2);
890 points[2].set_x(offset);
891 points[2].set_y(sync_mark_width - 1);
893 points[3].set_x(offset - ((sync_mark_width-1)/2));
897 sync_mark->property_points().set_value(points);
904 AudioRegionView::set_waveform_visible (bool yn)
906 if (((_flags & WaveformVisible) != yn)) {
908 for (uint32_t n=0; n < waves.size(); ++n) {
911 _flags |= WaveformVisible;
913 for (uint32_t n=0; n < waves.size(); ++n) {
916 _flags &= ~WaveformVisible;
923 AudioRegionView::temporarily_hide_envelope ()
929 AudioRegionView::unhide_envelope ()
931 if (_flags & EnvelopeVisible) {
937 AudioRegionView::set_envelope_visible (bool yn)
939 if ((_flags & EnvelopeVisible) != yn) {
942 _flags |= EnvelopeVisible;
945 _flags &= ~EnvelopeVisible;
952 AudioRegionView::create_waves ()
954 bool create_zero_line = true;
956 AudioTimeAxisView& atv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
958 if (!atv.get_diskstream()) {
962 uint32_t nchans = atv.get_diskstream()->n_channels();
964 // if (wait_for_waves) {
965 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
966 for (uint32_t n = 0; n < nchans; ++n) {
967 tmp_waves.push_back (0);
971 for (uint32_t n = 0; n < nchans; ++n) {
973 if (n >= region.n_channels()) {
977 wave_caches.push_back (WaveView::create_cache ());
979 if (wait_for_waves) {
980 if (region.source(n).peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n))) {
981 create_one_wave (n, true);
983 create_zero_line = false;
986 create_one_wave (n, true);
990 if (create_zero_line) {
991 zero_line = new ArdourCanvas::Line (*group);
992 zero_line->set_property ("x1", (gdouble) 1.0);
993 zero_line->set_property ("x2", (gdouble) (region.length() / samples_per_unit) - 1.0);
994 zero_line->set_property ("color_rgba", (guint) color_map[cZeroLine]);
1000 AudioRegionView::create_one_wave (uint32_t which, bool direct)
1002 AudioTimeAxisView& atv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
1003 uint32_t nchans = atv.get_diskstream()->n_channels();
1005 uint32_t nwaves = std::min (nchans, region.n_channels());
1008 if (trackview.height < NAME_HIGHLIGHT_SIZE) {
1009 ht = ((trackview.height) / (double) nchans);
1011 ht = ((trackview.height - NAME_HIGHLIGHT_SIZE) / (double) nchans);
1013 gdouble yoff = which * ht;
1015 WaveView *wave = new WaveView(*group);
1017 wave->property_data_src().set_value( (gpointer) ®ion);
1018 wave->property_cache().set_value( wave_caches[which]);
1019 wave->property_cache_updater().set_value( (gboolean) true);
1020 wave->property_channel().set_value( (guint32) which);
1021 wave->property_length_function().set_value( (gpointer) region_length_from_c);
1022 wave->property_sourcefile_length_function().set_value((gpointer) sourcefile_length_from_c);
1023 wave->property_peak_function().set_value( (gpointer) region_read_peaks_from_c);
1024 wave->property_x().set_value( 0.0);
1025 wave->property_y().set_value( yoff);
1026 wave->property_height().set_value( (double) ht);
1027 wave->property_samples_per_unit().set_value( samples_per_unit);
1028 wave->property_amplitude_above_axis().set_value( _amplitude_above_axis);
1029 wave->property_wave_color().set_value(region.muted() ? color_map[cMutedWaveForm] : color_map[cWaveForm]);
1030 wave->property_region_start().set_value(region.start());
1031 // WaveView *wave = gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
1032 // gnome_canvas_waveview_get_type (),
1033 // "data_src", (gpointer) ®ion,
1034 // "cache", wave_caches[which],
1035 // "cache_updater", (gboolean) true,
1036 // "channel", (guint32) which,
1037 // "length_function", (gpointer) region_length_from_c,
1038 // "sourcefile_length_function",(gpointer) sourcefile_length_from_c,
1039 // "peak_function", (gpointer) region_read_peaks_from_c,
1042 // "height", (double) ht,
1043 // "samples_per_unit", samples_per_unit,
1044 // "amplitude_above_axis", _amplitude_above_axis,
1045 // "wave_color", (guint32) (region.muted() ? color_map[cMutedWaveForm] : color_map[cWaveForm]),
1046 // "region_start",(guint32) region.start(),
1049 if (!(_flags & WaveformVisible)) {
1053 /* note: calling this function is serialized by the lock
1054 held in the peak building thread that signals that
1055 peaks are ready for use *or* by the fact that it is
1056 called one by one from the GUI thread.
1059 if (which < nchans) {
1060 tmp_waves[which] = (wave);
1062 /* n-channel track, >n-channel source */
1065 /* see if we're all ready */
1067 for (n = 0; n < nchans; ++n) {
1068 if (tmp_waves[n] == 0) {
1074 /* all waves are ready */
1075 tmp_waves.resize(nwaves);
1080 zero_line = new ArdourCanvas::Line (*group);
1081 zero_line->set_property ("x1", (gdouble) 1.0);
1082 zero_line->set_property ("x2", (gdouble) (region.length() / samples_per_unit) - 1.0);
1083 zero_line->set_property ("color_rgba", (guint) color_map[cZeroLine]);
1084 manage_zero_line ();
1090 AudioRegionView::peaks_ready_handler (uint32_t which)
1092 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
1096 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1100 /* don't create points that can't be seen */
1102 set_envelope_visible (true);
1109 jack_nframes_t fx = trackview.editor.pixel_to_frame (x);
1111 if (fx > region.length()) {
1115 /* compute vertical fractional position */
1117 y = 1.0 - (y / (trackview.height - NAME_HIGHLIGHT_SIZE));
1119 /* map using gain line */
1121 gain_line->view_to_model_y (y);
1123 trackview.session().begin_reversible_command (_("add gain control point"));
1124 trackview.session().add_undo (region.envelope().get_memento());
1127 if (!region.envelope_active()) {
1128 trackview.session().add_undo( bind( mem_fun(region, &AudioRegion::set_envelope_active), false) );
1129 region.set_envelope_active(true);
1130 trackview.session().add_redo( bind( mem_fun(region, &AudioRegion::set_envelope_active), true) );
1133 region.envelope().add (fx, y);
1135 trackview.session().add_redo_no_execute (region.envelope().get_memento());
1136 trackview.session().commit_reversible_command ();
1140 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1142 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1143 region.envelope().erase (cp->model);
1147 AudioRegionView::store_flags()
1149 XMLNode *node = new XMLNode ("GUI");
1151 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
1152 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
1154 region.add_extra_xml (*node);
1158 AudioRegionView::set_flags (XMLNode* node)
1162 if ((prop = node->property ("waveform-visible")) != 0) {
1163 if (prop->value() == "yes") {
1164 _flags |= WaveformVisible;
1168 if ((prop = node->property ("envelope-visible")) != 0) {
1169 if (prop->value() == "yes") {
1170 _flags |= EnvelopeVisible;
1176 AudioRegionView::set_waveform_shape (WaveformShape shape)
1180 /* this slightly odd approach is to leave the door open to
1181 other "shapes" such as spectral displays, etc.
1194 if (yn != (bool) (_flags & WaveformRectified)) {
1195 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1196 (*wave)->property_rectified().set_value(yn);
1208 _flags |= WaveformRectified;
1210 _flags &= ~WaveformRectified;
1216 AudioRegionView::get_item_name ()
1218 return region.name();
1222 AudioRegionView::move (double x_delta, double y_delta)
1224 if (region.locked() || (x_delta == 0 && y_delta == 0)) {
1228 get_canvas_group()->move (x_delta, y_delta);
1230 /* note: ghosts never leave their tracks so y_delta for them is always zero */
1232 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1233 (*i)->group->move (x_delta, 0.0);
1238 AudioRegionView::add_ghost (AutomationTimeAxisView& atv)
1240 AudioTimeAxisView& myatv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
1241 double unit_position = region.position () / samples_per_unit;
1242 GhostRegion* ghost = new GhostRegion (atv, unit_position);
1245 nchans = myatv.get_diskstream()->n_channels();
1247 for (uint32_t n = 0; n < nchans; ++n) {
1249 if (n >= region.n_channels()) {
1253 WaveView *wave = new WaveView(*ghost->group);
1255 wave->property_data_src().set_value( ®ion);
1256 wave->property_cache().set_value( wave_caches[n]);
1257 wave->property_cache_updater().set_value(false);
1258 wave->property_channel().set_value(n);
1259 wave->property_length_function().set_value((gpointer)region_length_from_c);
1260 wave->property_sourcefile_length_function().set_value((gpointer) sourcefile_length_from_c);
1261 wave->property_peak_function().set_value( (gpointer) region_read_peaks_from_c);
1262 wave->property_x().set_value( 0.0);
1263 wave->property_samples_per_unit().set_value( samples_per_unit);
1264 wave->property_amplitude_above_axis().set_value( _amplitude_above_axis);
1265 wave->property_wave_color().set_value(color_map[cGhostTrackWave]);
1266 wave->property_region_start().set_value(region.start());
1267 // WaveView *wave = gnome_canvas_item_new (GNOME_CANVAS_GROUP(ghost->group),
1268 // gnome_canvas_waveview_get_type (),
1269 // "data_src", (gpointer) ®ion,
1270 // "cache", wave_caches[n],
1271 // "cache_updater", (gboolean) false,
1272 // "channel", (guint32) n,
1273 // "length_function", (gpointer) region_length_from_c,
1274 // "sourcefile_length_function",(gpointer) sourcefile_length_from_c,
1275 // "peak_function", (gpointer) region_read_peaks_from_c,
1277 // "samples_per_unit", samples_per_unit,
1278 // "amplitude_above_axis", _amplitude_above_axis,
1279 // "wave_color", color_map[cGhostTrackWave],
1280 // "region_start", (guint32) region.start(),
1284 ghost->waves.push_back(wave);
1287 ghost->set_height ();
1288 ghost->set_duration (region.length() / samples_per_unit);
1289 ghosts.push_back (ghost);
1291 ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost));
1297 AudioRegionView::remove_ghost (GhostRegion* ghost)
1299 if (in_destructor) {
1303 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1312 AudioRegionView::get_fill_color ()
1318 AudioRegionView::entered ()
1320 if (_flags & EnvelopeVisible) {
1321 gain_line->show_all_control_points ();
1325 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1328 fade_in_handle->set_property ("fill_color_rgba", RGBA_TO_UINT(r,g,b,a));
1329 fade_out_handle->set_property ("fill_color_rgba", RGBA_TO_UINT(r,g,b,a));
1333 AudioRegionView::exited ()
1335 gain_line->hide_all_but_selected_control_points ();
1338 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1341 fade_in_handle->set_property ("fill_color_rgba", RGBA_TO_UINT(r,g,b,a));
1342 fade_out_handle->set_property ("fill_color_rgba", RGBA_TO_UINT(r,g,b,a));
1346 AudioRegionView::envelope_active_changed ()
1348 gain_line->set_line_color (region.envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]);
1352 AudioRegionView::set_waveview_data_src()
1355 double unit_length= region.length() / samples_per_unit;
1357 for (uint32_t n = 0; n < waves.size(); ++n) {
1358 // TODO: something else to let it know the channel
1359 waves[n]->property_data_src().set_value(®ion);
1362 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1364 (*i)->set_duration (unit_length);
1366 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
1367 (*w)->property_data_src().set_value(®ion);