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() = shape;
115 sync_mark->property_fill_color_rgba() = fill_color;
118 fade_in_shape = new ArdourCanvas::Polygon (*group);
119 fade_in_shape->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->property_fill_color_rgba() = fade_color;
124 fade_out_shape->set_data ("regionview", this);
129 UINT_TO_RGBA(fill_color,&r,&g,&b,&a);
132 fade_in_handle = new ArdourCanvas::SimpleRect (*group);
133 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
134 fade_in_handle->property_outline_pixels() = 0;
135 fade_in_handle->property_y1() = 2.0;
136 fade_in_handle->property_y2() = 7.0;
138 fade_in_handle->set_data ("regionview", this);
140 fade_out_handle = new ArdourCanvas::SimpleRect (*group);
141 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
142 fade_out_handle->property_outline_pixels() = 0;
143 fade_out_handle->property_y1() = 2.0;
144 fade_out_handle->property_y2() = 7.0;
146 fade_out_handle->set_data ("regionview", this);
149 string foo = region.name();
153 gain_line = new AudioRegionGainLine (foo, tv.session(), *this, *group, region.envelope());
155 if (!(_flags & EnvelopeVisible)) {
161 reset_width_dependent_items ((double) region.length() / samples_per_unit);
165 set_height (trackview.height);
168 region_sync_changed ();
169 region_resized (BoundsChanged);
170 set_waveview_data_src();
172 envelope_active_changed ();
173 fade_in_active_changed ();
174 fade_out_active_changed ();
176 region.StateChanged.connect (mem_fun(*this, &AudioRegionView::region_changed));
178 group->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_event), group, this));
179 name_highlight->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event), name_highlight, this));
180 fade_in_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
181 fade_in_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
182 fade_out_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
183 fade_out_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
187 /* XXX sync mark drag? */
190 AudioRegionView::~AudioRegionView ()
192 in_destructor = true;
194 AudioRegionViewGoingAway (this); /* EMIT_SIGNAL */
196 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
197 gnome_canvas_waveview_cache_destroy (*cache);
200 /* all waveviews will be destroyed when the group is destroyed */
202 for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
214 AudioRegionView::_lock_toggle (ArdourCanvas::Item* item, GdkEvent* ev, void* arg)
217 case GDK_BUTTON_RELEASE:
218 static_cast<AudioRegionView*>(arg)->lock_toggle ();
228 AudioRegionView::lock_toggle ()
230 region.set_locked (!region.locked());
234 AudioRegionView::region_changed (Change what_changed)
236 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionView::region_changed), what_changed));
238 if (what_changed & BoundsChanged) {
239 region_resized (what_changed);
240 region_sync_changed ();
242 if (what_changed & Region::MuteChanged) {
245 if (what_changed & Region::OpacityChanged) {
248 if (what_changed & ARDOUR::NameChanged) {
251 if (what_changed & Region::SyncOffsetChanged) {
252 region_sync_changed ();
254 if (what_changed & Region::LayerChanged) {
257 if (what_changed & Region::LockChanged) {
260 if (what_changed & AudioRegion::ScaleAmplitudeChanged) {
261 region_scale_amplitude_changed ();
263 if (what_changed & AudioRegion::FadeInChanged) {
266 if (what_changed & AudioRegion::FadeOutChanged) {
269 if (what_changed & AudioRegion::FadeInActiveChanged) {
270 fade_in_active_changed ();
272 if (what_changed & AudioRegion::FadeOutActiveChanged) {
273 fade_out_active_changed ();
275 if (what_changed & AudioRegion::EnvelopeActiveChanged) {
276 envelope_active_changed ();
281 AudioRegionView::fade_in_changed ()
283 reset_fade_in_shape ();
287 AudioRegionView::fade_out_changed ()
289 reset_fade_out_shape ();
293 AudioRegionView::set_fade_in_active (bool yn)
295 region.set_fade_in_active (yn);
299 AudioRegionView::set_fade_out_active (bool yn)
301 region.set_fade_out_active (yn);
305 AudioRegionView::fade_in_active_changed ()
309 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
311 if (region.fade_in_active()) {
312 col = RGBA_TO_UINT(r,g,b,120);
313 fade_in_shape->property_fill_color_rgba() = col;
314 fade_in_shape->property_width_pixels() = 0;
315 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
317 col = RGBA_TO_UINT(r,g,b,0);
318 fade_in_shape->property_fill_color_rgba() = col;
319 fade_in_shape->property_width_pixels() = 1;
320 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
325 AudioRegionView::fade_out_active_changed ()
329 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
331 if (region.fade_out_active()) {
332 col = RGBA_TO_UINT(r,g,b,120);
333 fade_out_shape->property_fill_color_rgba() = col;
334 fade_out_shape->property_width_pixels() = 0;
335 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
337 col = RGBA_TO_UINT(r,g,b,0);
338 fade_out_shape->property_fill_color_rgba() = col;
339 fade_out_shape->property_width_pixels() = 1;
340 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
346 AudioRegionView::region_scale_amplitude_changed ()
348 ENSURE_GUI_THREAD (mem_fun(*this, &AudioRegionView::region_scale_amplitude_changed));
350 for (uint32_t n = 0; n < waves.size(); ++n) {
351 // force a reload of the cache
352 waves[n]->property_data_src() = ®ion;
357 AudioRegionView::region_locked ()
359 /* name will show locked status */
364 AudioRegionView::region_resized (Change what_changed)
368 if (what_changed & ARDOUR::PositionChanged) {
369 set_position (region.position(), 0);
372 if (what_changed & Change (StartChanged|LengthChanged)) {
374 set_duration (region.length(), 0);
376 unit_length = region.length() / samples_per_unit;
378 reset_width_dependent_items (unit_length);
380 for (uint32_t n = 0; n < waves.size(); ++n) {
381 waves[n]->property_region_start() = region.start();
384 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
386 (*i)->set_duration (unit_length);
388 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
389 (*w)->property_region_start() = region.start();
396 AudioRegionView::reset_width_dependent_items (double pixel_width)
398 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
399 _pixel_width = pixel_width;
402 zero_line->property_x2() = pixel_width - 1.0;
405 if (pixel_width <= 6.0) {
406 fade_in_handle->hide();
407 fade_out_handle->hide();
410 fade_in_handle->hide();
411 fade_out_handle->hide();
413 fade_in_handle->show();
414 fade_out_handle->show();
418 reset_fade_shapes ();
422 AudioRegionView::region_layered ()
424 AudioTimeAxisView *atv = dynamic_cast<AudioTimeAxisView*> (&get_time_axis_view());
425 atv->view->region_layered (this);
429 AudioRegionView::region_muted ()
434 for (uint32_t n=0; n < waves.size(); ++n) {
435 if (region.muted()) {
436 waves[n]->property_wave_color() = color_map[cMutedWaveForm];
438 waves[n]->property_wave_color() = color_map[cWaveForm];
444 AudioRegionView::region_opacity ()
450 AudioRegionView::raise ()
456 AudioRegionView::raise_to_top ()
458 region.raise_to_top ();
462 AudioRegionView::lower ()
468 AudioRegionView::lower_to_bottom ()
470 region.lower_to_bottom ();
474 AudioRegionView::set_position (jack_nframes_t pos, void* src, double* ignored)
479 if (!(ret = TimeAxisViewItem::set_position (pos, this, &delta))) {
488 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
489 (*i)->group->move (delta, 0.0);
497 AudioRegionView::set_height (gdouble height)
499 uint32_t wcnt = waves.size();
501 TimeAxisViewItem::set_height (height - 2);
505 for (uint32_t n=0; n < wcnt; ++n) {
508 if ((height) < NAME_HIGHLIGHT_THRESH) {
509 ht = ((height-2*wcnt) / (double) wcnt);
511 ht = (((height-2*wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
514 gdouble yoff = n * (ht+1);
516 waves[n]->property_height() = ht;
517 waves[n]->property_y() = yoff + 2;
520 if ((height/wcnt) < NAME_HIGHLIGHT_SIZE) {
523 if (_flags & EnvelopeVisible) {
529 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE));
530 reset_fade_shapes ();
532 name_text->raise_to_top();
536 AudioRegionView::manage_zero_line ()
542 if (_height >= 100) {
543 gdouble wave_midpoint = (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
544 zero_line->property_y1() = wave_midpoint;
545 zero_line->property_y2() = wave_midpoint;
553 AudioRegionView::reset_fade_shapes ()
555 reset_fade_in_shape ();
556 reset_fade_out_shape ();
560 AudioRegionView::reset_fade_in_shape ()
562 reset_fade_in_shape_width ((jack_nframes_t) region.fade_in().back()->when);
566 AudioRegionView::reset_fade_in_shape_width (jack_nframes_t width)
568 /* smallest size for a fade is 64 frames */
570 width = std::max ((jack_nframes_t) 64, width);
573 double pwidth = width / samples_per_unit;
574 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
578 fade_in_shape->hide();
579 fade_in_handle->hide();
583 double handle_center;
584 handle_center = pwidth;
586 if (handle_center > 7.0) {
587 handle_center -= 3.0;
592 fade_in_handle->property_x1() = handle_center - 3.0;
593 fade_in_handle->property_x2() = handle_center + 3.0;
596 fade_in_shape->hide();
600 fade_in_shape->show();
602 float curve[npoints];
603 region.fade_in().get_vector (0, region.fade_in().back()->when, curve, npoints);
605 points = get_canvas_points ("fade in shape", npoints+3);
607 if (_height > NAME_HIGHLIGHT_THRESH) {
608 h = _height - NAME_HIGHLIGHT_SIZE;
613 /* points *MUST* be in anti-clockwise order */
616 double xdelta = pwidth/npoints;
618 for (pi = 0, pc = 0; pc < npoints; ++pc) {
619 (*points)[pi].set_x(1 + (pc * xdelta));
620 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
625 (*points)[pi].set_x(pwidth);
626 (*points)[pi++].set_y(2);
628 (*points)[pi].set_x(1);
629 (*points)[pi++].set_y(2);
631 /* connect the dots ... */
633 (*points)[pi] = (*points)[0];
635 fade_in_shape->property_points() = *points;
640 AudioRegionView::reset_fade_out_shape ()
642 reset_fade_out_shape_width ((jack_nframes_t) region.fade_out().back()->when);
646 AudioRegionView::reset_fade_out_shape_width (jack_nframes_t width)
648 /* smallest size for a fade is 64 frames */
650 width = std::max ((jack_nframes_t) 64, width);
653 double pwidth = width / samples_per_unit;
654 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
658 fade_out_shape->hide();
659 fade_out_handle->hide();
663 double handle_center;
664 handle_center = (region.length() - width) / samples_per_unit;
666 if (handle_center > 7.0) {
667 handle_center -= 3.0;
672 fade_out_handle->property_x1() = handle_center - 3.0;
673 fade_out_handle->property_x2() = handle_center + 3.0;
675 /* don't show shape if its too small */
678 fade_out_shape->hide();
682 fade_out_shape->show();
684 float curve[npoints];
685 region.fade_out().get_vector (0, region.fade_out().back()->when, curve, npoints);
687 if (_height > NAME_HIGHLIGHT_THRESH) {
688 h = _height - NAME_HIGHLIGHT_SIZE;
693 /* points *MUST* be in anti-clockwise order */
695 points = get_canvas_points ("fade out shape", npoints+3);
698 double xdelta = pwidth/npoints;
700 for (pi = 0, pc = 0; pc < npoints; ++pc) {
701 (*points)[pi] = _pixel_width - 1 - pwidth + (pc*xdelta);
702 (*points)[pi++] = 2 + (h - (curve[pc] * h));
707 (*points)[pi] = _pixel_width;
710 (*points)[pi] = _pixel_width;
713 /* connect the dots ... */
715 (*points)[pi] = (*points)[0];
717 fade_out_shape->property_points() = *points;
722 AudioRegionView::set_samples_per_unit (gdouble spu)
724 TimeAxisViewItem::set_samples_per_unit (spu);
726 for (uint32_t n=0; n < waves.size(); ++n) {
727 waves[n]->property_samples_per_unit() = spu;
730 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
731 (*i)->set_samples_per_unit (spu);
732 (*i)->set_duration (region.length() / samples_per_unit);
736 reset_fade_shapes ();
737 region_sync_changed ();
741 AudioRegionView::set_duration (jack_nframes_t frames, void *src)
743 if (!TimeAxisViewItem::set_duration (frames, src)) {
747 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
748 (*i)->set_duration (region.length() / samples_per_unit);
755 AudioRegionView::set_amplitude_above_axis (gdouble spp)
757 for (uint32_t n=0; n < waves.size(); ++n) {
758 waves[n]->property_amplitude_above_axis() = spp;
763 AudioRegionView::compute_colors (Gdk::Color& basic_color)
765 TimeAxisViewItem::compute_colors (basic_color);
768 /* gain color computed in envelope_active_changed() */
770 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
771 fade_color = RGBA_TO_UINT(r,g,b,120);
775 AudioRegionView::set_colors ()
777 TimeAxisViewItem::set_colors ();
779 gain_line->set_line_color (region.envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]);
780 sync_mark->property_fill_color_rgba() = fill_color;
782 for (uint32_t n=0; n < waves.size(); ++n) {
783 if (region.muted()) {
784 waves[n]->property_wave_color() = color_map[cMutedWaveForm];
786 waves[n]->property_wave_color() = color_map[cWaveForm];
792 AudioRegionView::set_frame_color ()
794 if (region.opaque()) {
800 TimeAxisViewItem::set_frame_color ();
804 AudioRegionView::show_region_editor ()
807 editor = new AudioRegionEditor (trackview.session(), region, *this);
808 // GTK2FIX : how to ensure float without realizing
809 // editor->realize ();
810 // trackview.editor.ensure_float (*editor);
814 editor->get_window()->raise();
818 AudioRegionView::hide_region_editor()
826 AudioRegionView::region_renamed ()
830 if (region.locked()) {
832 str += region.name();
838 if (region.muted()) {
839 str = string ("!") + str;
842 set_item_name (region.name(), this);
847 AudioRegionView::region_sync_changed ()
850 jack_nframes_t sync_offset;
852 sync_offset = region.sync_offset (sync_dir);
854 /* this has to handle both a genuine change of position, a change of samples_per_unit,
855 and a change in the bounds of the region.
858 if (sync_offset == 0) {
860 /* no sync mark - its the start of the region */
866 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > region.length()))) {
868 /* no sync mark - its out of the bounds of the region */
878 points = sync_mark->property_points().get_value();
880 double offset = sync_offset / samples_per_unit;
882 points[0].set_x(offset - ((sync_mark_width-1)/2));
885 points[1].set_x(offset + (sync_mark_width-1)/2);
888 points[2].set_x(offset);
889 points[2].set_y(sync_mark_width - 1);
891 points[3].set_x(offset - ((sync_mark_width-1)/2));
895 sync_mark->property_points() = points;
902 AudioRegionView::set_waveform_visible (bool yn)
904 if (((_flags & WaveformVisible) != yn)) {
906 for (uint32_t n=0; n < waves.size(); ++n) {
909 _flags |= WaveformVisible;
911 for (uint32_t n=0; n < waves.size(); ++n) {
914 _flags &= ~WaveformVisible;
921 AudioRegionView::temporarily_hide_envelope ()
927 AudioRegionView::unhide_envelope ()
929 if (_flags & EnvelopeVisible) {
935 AudioRegionView::set_envelope_visible (bool yn)
937 if ((_flags & EnvelopeVisible) != yn) {
940 _flags |= EnvelopeVisible;
943 _flags &= ~EnvelopeVisible;
950 AudioRegionView::create_waves ()
952 bool create_zero_line = true;
954 AudioTimeAxisView& atv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
956 if (!atv.get_diskstream()) {
960 uint32_t nchans = atv.get_diskstream()->n_channels();
962 // if (wait_for_waves) {
963 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
964 for (uint32_t n = 0; n < nchans; ++n) {
965 tmp_waves.push_back (0);
969 for (uint32_t n = 0; n < nchans; ++n) {
971 if (n >= region.n_channels()) {
975 wave_caches.push_back (WaveView::create_cache ());
977 if (wait_for_waves) {
978 if (region.source(n).peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n))) {
979 create_one_wave (n, true);
981 create_zero_line = false;
984 create_one_wave (n, true);
988 if (create_zero_line) {
989 zero_line = new ArdourCanvas::SimpleLine (*group);
990 zero_line->property_x1() = (gdouble) 1.0;
991 zero_line->property_x2() = (gdouble) (region.length() / samples_per_unit) - 1.0;
992 zero_line->property_color_rgba() = (guint) color_map[cZeroLine];
998 AudioRegionView::create_one_wave (uint32_t which, bool direct)
1000 AudioTimeAxisView& atv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
1001 uint32_t nchans = atv.get_diskstream()->n_channels();
1003 uint32_t nwaves = std::min (nchans, region.n_channels());
1006 if (trackview.height < NAME_HIGHLIGHT_SIZE) {
1007 ht = ((trackview.height) / (double) nchans);
1009 ht = ((trackview.height - NAME_HIGHLIGHT_SIZE) / (double) nchans);
1011 gdouble yoff = which * ht;
1013 WaveView *wave = new WaveView(*group);
1015 wave->property_data_src() = (gpointer) ®ion;
1016 wave->property_cache() = wave_caches[which];
1017 wave->property_cache_updater() = true;
1018 wave->property_channel() = which;
1019 wave->property_length_function() = (gpointer) region_length_from_c;
1020 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1021 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1022 wave->property_x() = 0.0;
1023 wave->property_y() = yoff;
1024 wave->property_height() = (double) ht;
1025 wave->property_samples_per_unit() = samples_per_unit;
1026 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1027 wave->property_wave_color() = region.muted() ? color_map[cMutedWaveForm] : color_map[cWaveForm];
1028 wave->property_region_start() = region.start();
1029 // WaveView *wave = gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
1030 // gnome_canvas_waveview_get_type (),
1031 // "data_src", (gpointer) ®ion,
1032 // "cache", wave_caches[which],
1033 // "cache_updater", (gboolean) true,
1034 // "channel", (guint32) which,
1035 // "length_function", (gpointer) region_length_from_c,
1036 // "sourcefile_length_function",(gpointer) sourcefile_length_from_c,
1037 // "peak_function", (gpointer) region_read_peaks_from_c,
1040 // "height", (double) ht,
1041 // "samples_per_unit", samples_per_unit,
1042 // "amplitude_above_axis", _amplitude_above_axis,
1043 // "wave_color", (guint32) (region.muted() ? color_map[cMutedWaveForm] : color_map[cWaveForm]),
1044 // "region_start",(guint32) region.start(),
1047 if (!(_flags & WaveformVisible)) {
1051 /* note: calling this function is serialized by the lock
1052 held in the peak building thread that signals that
1053 peaks are ready for use *or* by the fact that it is
1054 called one by one from the GUI thread.
1057 if (which < nchans) {
1058 tmp_waves[which] = (wave);
1060 /* n-channel track, >n-channel source */
1063 /* see if we're all ready */
1065 for (n = 0; n < nchans; ++n) {
1066 if (tmp_waves[n] == 0) {
1072 /* all waves are ready */
1073 tmp_waves.resize(nwaves);
1078 zero_line = new ArdourCanvas::SimpleLine (*group);
1079 zero_line->property_x1() = (gdouble) 1.0;
1080 zero_line->property_x2() = (gdouble) (region.length() / samples_per_unit) - 1.0;
1081 zero_line->property_color_rgba() = (guint) color_map[cZeroLine];
1082 manage_zero_line ();
1088 AudioRegionView::peaks_ready_handler (uint32_t which)
1090 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
1094 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1098 /* don't create points that can't be seen */
1100 set_envelope_visible (true);
1107 jack_nframes_t fx = trackview.editor.pixel_to_frame (x);
1109 if (fx > region.length()) {
1113 /* compute vertical fractional position */
1115 y = 1.0 - (y / (trackview.height - NAME_HIGHLIGHT_SIZE));
1117 /* map using gain line */
1119 gain_line->view_to_model_y (y);
1121 trackview.session().begin_reversible_command (_("add gain control point"));
1122 trackview.session().add_undo (region.envelope().get_memento());
1125 if (!region.envelope_active()) {
1126 trackview.session().add_undo( bind( mem_fun(region, &AudioRegion::set_envelope_active), false) );
1127 region.set_envelope_active(true);
1128 trackview.session().add_redo( bind( mem_fun(region, &AudioRegion::set_envelope_active), true) );
1131 region.envelope().add (fx, y);
1133 trackview.session().add_redo_no_execute (region.envelope().get_memento());
1134 trackview.session().commit_reversible_command ();
1138 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1140 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1141 region.envelope().erase (cp->model);
1145 AudioRegionView::store_flags()
1147 XMLNode *node = new XMLNode ("GUI");
1149 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
1150 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
1152 region.add_extra_xml (*node);
1156 AudioRegionView::set_flags (XMLNode* node)
1160 if ((prop = node->property ("waveform-visible")) != 0) {
1161 if (prop->value() == "yes") {
1162 _flags |= WaveformVisible;
1166 if ((prop = node->property ("envelope-visible")) != 0) {
1167 if (prop->value() == "yes") {
1168 _flags |= EnvelopeVisible;
1174 AudioRegionView::set_waveform_shape (WaveformShape shape)
1178 /* this slightly odd approach is to leave the door open to
1179 other "shapes" such as spectral displays, etc.
1192 if (yn != (bool) (_flags & WaveformRectified)) {
1193 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1194 (*wave)->property_rectified() = yn;
1206 _flags |= WaveformRectified;
1208 _flags &= ~WaveformRectified;
1214 AudioRegionView::get_item_name ()
1216 return region.name();
1220 AudioRegionView::move (double x_delta, double y_delta)
1222 if (region.locked() || (x_delta == 0 && y_delta == 0)) {
1226 get_canvas_group()->move (x_delta, y_delta);
1228 /* note: ghosts never leave their tracks so y_delta for them is always zero */
1230 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1231 (*i)->group->move (x_delta, 0.0);
1236 AudioRegionView::add_ghost (AutomationTimeAxisView& atv)
1238 AudioTimeAxisView& myatv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
1239 double unit_position = region.position () / samples_per_unit;
1240 GhostRegion* ghost = new GhostRegion (atv, unit_position);
1243 nchans = myatv.get_diskstream()->n_channels();
1245 for (uint32_t n = 0; n < nchans; ++n) {
1247 if (n >= region.n_channels()) {
1251 WaveView *wave = new WaveView(*ghost->group);
1253 wave->property_data_src() = ®ion;
1254 wave->property_cache() = wave_caches[n];
1255 wave->property_cache_updater() = false;
1256 wave->property_channel() = n;
1257 wave->property_length_function() = (gpointer)region_length_from_c;
1258 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1259 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1260 wave->property_x() = 0.0;
1261 wave->property_samples_per_unit() = samples_per_unit;
1262 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1263 wave->property_wave_color() = color_map[cGhostTrackWave];
1264 wave->property_region_start() = region.start();
1265 // WaveView *wave = gnome_canvas_item_new (GNOME_CANVAS_GROUP(ghost->group),
1266 // gnome_canvas_waveview_get_type (),
1267 // "data_src", (gpointer) ®ion,
1268 // "cache", wave_caches[n],
1269 // "cache_updater", (gboolean) false,
1270 // "channel", (guint32) n,
1271 // "length_function", (gpointer) region_length_from_c,
1272 // "sourcefile_length_function",(gpointer) sourcefile_length_from_c,
1273 // "peak_function", (gpointer) region_read_peaks_from_c,
1275 // "samples_per_unit", samples_per_unit,
1276 // "amplitude_above_axis", _amplitude_above_axis,
1277 // "wave_color", color_map[cGhostTrackWave],
1278 // "region_start", (guint32) region.start(),
1282 ghost->waves.push_back(wave);
1285 ghost->set_height ();
1286 ghost->set_duration (region.length() / samples_per_unit);
1287 ghosts.push_back (ghost);
1289 ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost));
1295 AudioRegionView::remove_ghost (GhostRegion* ghost)
1297 if (in_destructor) {
1301 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1310 AudioRegionView::get_fill_color ()
1316 AudioRegionView::entered ()
1318 if (_flags & EnvelopeVisible) {
1319 gain_line->show_all_control_points ();
1323 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1326 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1327 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1331 AudioRegionView::exited ()
1333 gain_line->hide_all_but_selected_control_points ();
1336 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1339 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1340 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1344 AudioRegionView::envelope_active_changed ()
1346 gain_line->set_line_color (region.envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]);
1350 AudioRegionView::set_waveview_data_src()
1353 double unit_length= region.length() / samples_per_unit;
1355 for (uint32_t n = 0; n < waves.size(); ++n) {
1356 // TODO: something else to let it know the channel
1357 waves[n]->property_data_src() = ®ion;
1360 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1362 (*i)->set_duration (unit_length);
1364 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
1365 (*w)->property_data_src() = ®ion;