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 gtk_object_set_data (GTK_OBJECT(name_highlight), "regionview", this);
102 gtk_object_set_data (GTK_OBJECT(name_text), "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(),
155 PublicEditor::canvas_control_point_event,
156 PublicEditor::canvas_line_event);
158 if (!(_flags & EnvelopeVisible)) {
164 reset_width_dependent_items ((double) region.length() / samples_per_unit);
168 set_height (trackview.height);
171 region_sync_changed ();
172 region_resized (BoundsChanged);
173 set_waveview_data_src();
175 envelope_active_changed ();
176 fade_in_active_changed ();
177 fade_out_active_changed ();
179 region.StateChanged.connect (mem_fun(*this, &AudioRegionView::region_changed));
181 group->signal_event().connect (bind (mem_fun (editor, &PublicEditor::UNC (PublicEditor::canvas_region_view_event)), group, this));
182 region_view_name_highlight->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_region_view_name_highlight_event), region_view_name_highlight, this));
183 fade_in_shape->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
185 fade_in_handle->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
186 fade_out_shape->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
187 fade_out_handle->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
191 /* XXX sync mark drag? */
195 AudioRegionView::~AudioRegionView ()
197 in_destructor = true;
199 AudioRegionViewGoingAway (this); /* EMIT_SIGNAL */
201 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
202 gnome_canvas_waveview_cache_destroy (*cache);
205 /* all waveviews will be destroyed when the group is destroyed */
207 for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
219 AudioRegionView::_lock_toggle (ArdourCanvas::Item* item, GdkEvent* ev, void* arg)
222 case GDK_BUTTON_RELEASE:
223 static_cast<AudioRegionView*>(arg)->lock_toggle ();
233 AudioRegionView::lock_toggle ()
235 region.set_locked (!region.locked());
239 AudioRegionView::region_changed (Change what_changed)
241 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionView::region_changed), what_changed));
243 if (what_changed & BoundsChanged) {
244 region_resized (what_changed);
245 region_sync_changed ();
247 if (what_changed & Region::MuteChanged) {
250 if (what_changed & Region::OpacityChanged) {
253 if (what_changed & ARDOUR::NameChanged) {
256 if (what_changed & Region::SyncOffsetChanged) {
257 region_sync_changed ();
259 if (what_changed & Region::LayerChanged) {
262 if (what_changed & Region::LockChanged) {
265 if (what_changed & AudioRegion::ScaleAmplitudeChanged) {
266 region_scale_amplitude_changed ();
268 if (what_changed & AudioRegion::FadeInChanged) {
271 if (what_changed & AudioRegion::FadeOutChanged) {
274 if (what_changed & AudioRegion::FadeInActiveChanged) {
275 fade_in_active_changed ();
277 if (what_changed & AudioRegion::FadeOutActiveChanged) {
278 fade_out_active_changed ();
280 if (what_changed & AudioRegion::EnvelopeActiveChanged) {
281 envelope_active_changed ();
286 AudioRegionView::fade_in_changed ()
288 reset_fade_in_shape ();
292 AudioRegionView::fade_out_changed ()
294 reset_fade_out_shape ();
298 AudioRegionView::set_fade_in_active (bool yn)
300 region.set_fade_in_active (yn);
304 AudioRegionView::set_fade_out_active (bool yn)
306 region.set_fade_out_active (yn);
310 AudioRegionView::fade_in_active_changed ()
314 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
316 if (region.fade_in_active()) {
317 col = RGBA_TO_UINT(r,g,b,120);
318 fade_in_shape->set_property ("fill_color_rgba", col);
319 fade_in_shape->set_property ("width_pixels", 0);
320 fade_in_shape->set_property ("outline_color_rgba", RGBA_TO_UINT(r,g,b,0));
322 col = RGBA_TO_UINT(r,g,b,0);
323 fade_in_shape->set_property ("fill_color_rgba", col);
324 fade_in_shape->set_property ("width_pixels", 1);
325 fade_in_shape->set_property ("outline_color_rgba", RGBA_TO_UINT(r,g,b,255));
330 AudioRegionView::fade_out_active_changed ()
334 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
336 if (region.fade_out_active()) {
337 col = RGBA_TO_UINT(r,g,b,120);
338 fade_out_shape->set_property ("fill_color_rgba", col);
339 fade_out_shape->set_property ("width_pixels", 0);
340 fade_out_shape->set_property ("outline_color_rgba", RGBA_TO_UINT(r,g,b,0));
342 col = RGBA_TO_UINT(r,g,b,0);
343 fade_out_shape->set_property ("fill_color_rgba", col);
344 fade_out_shape->set_property ("width_pixels", 1);
345 fade_out_shape->set_property ("outline_color_rgba", RGBA_TO_UINT(r,g,b,255));
351 AudioRegionView::region_scale_amplitude_changed ()
353 ENSURE_GUI_THREAD (mem_fun(*this, &AudioRegionView::region_scale_amplitude_changed));
355 for (uint32_t n = 0; n < waves.size(); ++n) {
356 // force a reload of the cache
357 waves[n]->property_data_src().set_value(®ion);
362 AudioRegionView::region_locked ()
364 /* name will show locked status */
369 AudioRegionView::region_resized (Change what_changed)
373 if (what_changed & ARDOUR::PositionChanged) {
374 set_position (region.position(), 0);
377 if (what_changed & Change (StartChanged|LengthChanged)) {
379 set_duration (region.length(), 0);
381 unit_length = region.length() / samples_per_unit;
383 reset_width_dependent_items (unit_length);
385 for (uint32_t n = 0; n < waves.size(); ++n) {
386 waves[n]->property_region_start().set_value(region.start());
389 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
391 (*i)->set_duration (unit_length);
393 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
394 (*w)->property_region_start().set_value(region.start());
401 AudioRegionView::reset_width_dependent_items (double pixel_width)
403 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
404 _pixel_width = pixel_width;
407 zero_line->set_property ("x2", pixel_width - 1.0);
410 if (pixel_width <= 6.0) {
411 fade_in_handle->hide();
412 fade_out_handle->hide();
415 fade_in_handle->hide();
416 fade_out_handle->hide();
418 fade_in_handle->show();
419 fade_out_handle->show();
423 reset_fade_shapes ();
427 AudioRegionView::region_layered ()
429 AudioTimeAxisView *atv = dynamic_cast<AudioTimeAxisView*> (&get_time_axis_view());
430 atv->view->region_layered (this);
434 AudioRegionView::region_muted ()
439 for (uint32_t n=0; n < waves.size(); ++n) {
440 if (region.muted()) {
441 waves[n]->property_wave_color().set_value(color_map[cMutedWaveForm]);
443 waves[n]->property_wave_color().set_value(color_map[cWaveForm]);
449 AudioRegionView::region_opacity ()
455 AudioRegionView::raise ()
461 AudioRegionView::raise_to_top ()
463 region.raise_to_top ();
467 AudioRegionView::lower ()
473 AudioRegionView::lower_to_bottom ()
475 region.lower_to_bottom ();
479 AudioRegionView::set_position (jack_nframes_t pos, void* src, double* ignored)
484 if (!(ret = TimeAxisViewItem::set_position (pos, this, &delta))) {
493 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
494 (*i)->group->move (delta, 0.0);
502 AudioRegionView::set_height (gdouble height)
504 uint32_t wcnt = waves.size();
506 TimeAxisViewItem::set_height (height - 2);
510 for (uint32_t n=0; n < wcnt; ++n) {
513 if ((height) < NAME_HIGHLIGHT_THRESH) {
514 ht = ((height-2*wcnt) / (double) wcnt);
516 ht = (((height-2*wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
519 gdouble yoff = n * (ht+1);
521 waves[n]->property_height().set_value(ht);
522 waves[n]->property_y().set_value(yoff + 2);
525 if ((height/wcnt) < NAME_HIGHLIGHT_SIZE) {
528 if (_flags & EnvelopeVisible) {
534 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE));
535 reset_fade_shapes ();
537 name_text->raise_to_top();
541 AudioRegionView::manage_zero_line ()
547 if (_height >= 100) {
548 gdouble wave_midpoint = (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
549 zero_line->set_property ("y1", wave_midpoint);
550 zero_line->set_property ("y2", wave_midpoint);
558 AudioRegionView::reset_fade_shapes ()
560 reset_fade_in_shape ();
561 reset_fade_out_shape ();
565 AudioRegionView::reset_fade_in_shape ()
567 reset_fade_in_shape_width ((jack_nframes_t) region.fade_in().back()->when);
571 AudioRegionView::reset_fade_in_shape_width (jack_nframes_t width)
573 /* smallest size for a fade is 64 frames */
575 width = std::max ((jack_nframes_t) 64, width);
578 double pwidth = width / samples_per_unit;
579 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
583 fade_in_shape->hide();
584 fade_in_handle->hide();
588 double handle_center;
589 handle_center = pwidth;
591 if (handle_center > 7.0) {
592 handle_center -= 3.0;
597 fade_in_handle->set_property ("x1", handle_center - 3.0);
598 fade_in_handle->set_property ("x2", handle_center + 3.0);
601 fade_in_shape->hide();
605 fade_in_shape->show();
607 float curve[npoints];
608 region.fade_in().get_vector (0, region.fade_in().back()->when, curve, npoints);
610 points = get_canvas_points ("fade in shape", npoints+3);
612 if (_height > NAME_HIGHLIGHT_THRESH) {
613 h = _height - NAME_HIGHLIGHT_SIZE;
618 /* points *MUST* be in anti-clockwise order */
621 double xdelta = pwidth/npoints;
623 for (pi = 0, pc = 0; pc < npoints; ++pc) {
624 (*points)[pi].set_x(1 + (pc * xdelta));
625 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
630 (*points)[pi].set_x(pwidth);
631 (*points)[pi++].set_y(2);
633 (*points)[pi].set_x(1);
634 (*points)[pi++].set_y(2);
636 /* connect the dots ... */
638 (*points)[pi] = (*points)[0];
640 fade_in_shape->property_points().set_value(*points);
645 AudioRegionView::reset_fade_out_shape ()
647 reset_fade_out_shape_width ((jack_nframes_t) region.fade_out().back()->when);
651 AudioRegionView::reset_fade_out_shape_width (jack_nframes_t width)
653 /* smallest size for a fade is 64 frames */
655 width = std::max ((jack_nframes_t) 64, width);
658 double pwidth = width / samples_per_unit;
659 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
663 fade_out_shape->hide();
664 fade_out_handle->hide();
668 double handle_center;
669 handle_center = (region.length() - width) / samples_per_unit;
671 if (handle_center > 7.0) {
672 handle_center -= 3.0;
677 fade_out_handle->set_property ("x1", handle_center - 3.0);
678 fade_out_handle->set_property ("x2", handle_center + 3.0);
680 /* don't show shape if its too small */
683 fade_out_shape->hide();
687 fade_out_shape->show();
689 float curve[npoints];
690 region.fade_out().get_vector (0, region.fade_out().back()->when, curve, npoints);
692 if (_height > NAME_HIGHLIGHT_THRESH) {
693 h = _height - NAME_HIGHLIGHT_SIZE;
698 /* points *MUST* be in anti-clockwise order */
700 points = get_canvas_points ("fade out shape", npoints+3);
703 double xdelta = pwidth/npoints;
705 for (pi = 0, pc = 0; pc < npoints; ++pc) {
706 (*points)[pi] = _pixel_width - 1 - pwidth + (pc*xdelta);
707 (*points)[pi++] = 2 + (h - (curve[pc] * h));
712 (*points)[pi] = _pixel_width;
715 (*points)[pi] = _pixel_width;
718 /* connect the dots ... */
720 (*points)[pi] = (*points)[0];
722 fade_out_shape->set_property ("points", *points);
727 AudioRegionView::set_samples_per_unit (gdouble spu)
729 TimeAxisViewItem::set_samples_per_unit (spu);
731 for (uint32_t n=0; n < waves.size(); ++n) {
732 waves[n]->property_samples_per_unit().set_value(spu);
735 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
736 (*i)->set_samples_per_unit (spu);
737 (*i)->set_duration (region.length() / samples_per_unit);
741 reset_fade_shapes ();
742 region_sync_changed ();
746 AudioRegionView::set_duration (jack_nframes_t frames, void *src)
748 if (!TimeAxisViewItem::set_duration (frames, src)) {
752 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
753 (*i)->set_duration (region.length() / samples_per_unit);
760 AudioRegionView::set_amplitude_above_axis (gdouble spp)
762 for (uint32_t n=0; n < waves.size(); ++n) {
763 waves[n]->property_amplitude_above_axis().set_value(spp);
768 AudioRegionView::compute_colors (Gdk::Color& basic_color)
770 TimeAxisViewItem::compute_colors (basic_color);
773 /* gain color computed in envelope_active_changed() */
775 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
776 fade_color = RGBA_TO_UINT(r,g,b,120);
780 AudioRegionView::set_colors ()
782 TimeAxisViewItem::set_colors ();
784 gain_line->set_line_color (region.envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]);
785 sync_mark->set_property ("fill_color_rgba", fill_color);
787 for (uint32_t n=0; n < waves.size(); ++n) {
788 if (region.muted()) {
789 waves[n]->property_wave_color().set_value(color_map[cMutedWaveForm]);
791 waves[n]->property_wave_color().set_value(color_map[cWaveForm]);
797 AudioRegionView::set_frame_color ()
799 if (region.opaque()) {
805 TimeAxisViewItem::set_frame_color ();
809 AudioRegionView::show_region_editor ()
812 editor = new AudioRegionEditor (trackview.session(), region, *this);
813 // GTK2FIX : how to ensure float without realizing
814 // editor->realize ();
815 // trackview.editor.ensure_float (*editor);
819 editor->get_window()->raise();
823 AudioRegionView::hide_region_editor()
831 AudioRegionView::region_renamed ()
835 if (region.locked()) {
837 str += region.name();
843 if (region.muted()) {
844 str = string ("!") + str;
847 set_item_name (region.name(), this);
852 AudioRegionView::region_sync_changed ()
855 jack_nframes_t sync_offset;
857 sync_offset = region.sync_offset (sync_dir);
859 /* this has to handle both a genuine change of position, a change of samples_per_unit,
860 and a change in the bounds of the region.
863 if (sync_offset == 0) {
865 /* no sync mark - its the start of the region */
871 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > region.length()))) {
873 /* no sync mark - its out of the bounds of the region */
883 points = sync_mark->property_points().get_value();
885 double offset = sync_offset / samples_per_unit;
887 points[0].set_x(offset - ((sync_mark_width-1)/2));
890 points[1].set_x(offset + (sync_mark_width-1)/2);
893 points[2].set_x(offset);
894 points[2].set_y(sync_mark_width - 1);
896 points[3].set_x(offset - ((sync_mark_width-1)/2));
900 sync_mark->property_points().set_value(points);
907 AudioRegionView::set_waveform_visible (bool yn)
909 if (((_flags & WaveformVisible) != yn)) {
911 for (uint32_t n=0; n < waves.size(); ++n) {
914 _flags |= WaveformVisible;
916 for (uint32_t n=0; n < waves.size(); ++n) {
919 _flags &= ~WaveformVisible;
926 AudioRegionView::temporarily_hide_envelope ()
932 AudioRegionView::unhide_envelope ()
934 if (_flags & EnvelopeVisible) {
940 AudioRegionView::set_envelope_visible (bool yn)
942 if ((_flags & EnvelopeVisible) != yn) {
945 _flags |= EnvelopeVisible;
948 _flags &= ~EnvelopeVisible;
955 AudioRegionView::create_waves ()
957 bool create_zero_line = true;
959 AudioTimeAxisView& atv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
961 if (!atv.get_diskstream()) {
965 uint32_t nchans = atv.get_diskstream()->n_channels();
967 // if (wait_for_waves) {
968 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
969 for (uint32_t n = 0; n < nchans; ++n) {
970 tmp_waves.push_back (0);
974 for (uint32_t n = 0; n < nchans; ++n) {
976 if (n >= region.n_channels()) {
980 wave_caches.push_back (WaveView::create_cache ());
982 if (wait_for_waves) {
983 if (region.source(n).peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n))) {
984 create_one_wave (n, true);
986 create_zero_line = false;
989 create_one_wave (n, true);
993 if (create_zero_line) {
994 zero_line = new ArdourCanvas::Line (*group);
995 zero_line->set_property ("x1", (gdouble) 1.0);
996 zero_line->set_property ("x2", (gdouble) (region.length() / samples_per_unit) - 1.0);
997 zero_line->set_property ("color_rgba", (guint) color_map[cZeroLine]);
1003 AudioRegionView::create_one_wave (uint32_t which, bool direct)
1005 AudioTimeAxisView& atv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
1006 uint32_t nchans = atv.get_diskstream()->n_channels();
1008 uint32_t nwaves = std::min (nchans, region.n_channels());
1011 if (trackview.height < NAME_HIGHLIGHT_SIZE) {
1012 ht = ((trackview.height) / (double) nchans);
1014 ht = ((trackview.height - NAME_HIGHLIGHT_SIZE) / (double) nchans);
1016 gdouble yoff = which * ht;
1018 WaveView *wave = new WaveView(*group);
1020 wave->property_data_src().set_value( (gpointer) ®ion);
1021 wave->property_cache().set_value( wave_caches[which]);
1022 wave->property_cache_updater().set_value( (gboolean) true);
1023 wave->property_channel().set_value( (guint32) which);
1024 wave->property_length_function().set_value( (gpointer) region_length_from_c);
1025 wave->property_sourcefile_length_function().set_value((gpointer) sourcefile_length_from_c);
1026 wave->property_peak_function().set_value( (gpointer) region_read_peaks_from_c);
1027 wave->property_x().set_value( 0.0);
1028 wave->property_y().set_value( yoff);
1029 wave->property_height().set_value( (double) ht);
1030 wave->property_samples_per_unit().set_value( samples_per_unit);
1031 wave->property_amplitude_above_axis().set_value( _amplitude_above_axis);
1032 wave->property_wave_color().set_value(region.muted() ? color_map[cMutedWaveForm] : color_map[cWaveForm]);
1033 wave->property_region_start().set_value(region.start());
1034 // WaveView *wave = gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
1035 // gnome_canvas_waveview_get_type (),
1036 // "data_src", (gpointer) ®ion,
1037 // "cache", wave_caches[which],
1038 // "cache_updater", (gboolean) true,
1039 // "channel", (guint32) which,
1040 // "length_function", (gpointer) region_length_from_c,
1041 // "sourcefile_length_function",(gpointer) sourcefile_length_from_c,
1042 // "peak_function", (gpointer) region_read_peaks_from_c,
1045 // "height", (double) ht,
1046 // "samples_per_unit", samples_per_unit,
1047 // "amplitude_above_axis", _amplitude_above_axis,
1048 // "wave_color", (guint32) (region.muted() ? color_map[cMutedWaveForm] : color_map[cWaveForm]),
1049 // "region_start",(guint32) region.start(),
1052 if (!(_flags & WaveformVisible)) {
1056 /* note: calling this function is serialized by the lock
1057 held in the peak building thread that signals that
1058 peaks are ready for use *or* by the fact that it is
1059 called one by one from the GUI thread.
1062 if (which < nchans) {
1063 tmp_waves[which] = (wave);
1065 /* n-channel track, >n-channel source */
1068 /* see if we're all ready */
1070 for (n = 0; n < nchans; ++n) {
1071 if (tmp_waves[n] == 0) {
1077 /* all waves are ready */
1078 tmp_waves.resize(nwaves);
1083 zero_line = new ArdourCanvas::Line (*group);
1084 zero_line->set_property ("x1", (gdouble) 1.0);
1085 zero_line->set_property ("x2", (gdouble) (region.length() / samples_per_unit) - 1.0);
1086 zero_line->set_property ("color_rgba", (guint) color_map[cZeroLine]);
1087 manage_zero_line ();
1093 AudioRegionView::peaks_ready_handler (uint32_t which)
1095 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
1099 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1103 /* don't create points that can't be seen */
1105 set_envelope_visible (true);
1112 jack_nframes_t fx = trackview.editor.pixel_to_frame (x);
1114 if (fx > region.length()) {
1118 /* compute vertical fractional position */
1120 y = 1.0 - (y / (trackview.height - NAME_HIGHLIGHT_SIZE));
1122 /* map using gain line */
1124 gain_line->view_to_model_y (y);
1126 trackview.session().begin_reversible_command (_("add gain control point"));
1127 trackview.session().add_undo (region.envelope().get_memento());
1130 if (!region.envelope_active()) {
1131 trackview.session().add_undo( bind( mem_fun(region, &AudioRegion::set_envelope_active), false) );
1132 region.set_envelope_active(true);
1133 trackview.session().add_redo( bind( mem_fun(region, &AudioRegion::set_envelope_active), true) );
1136 region.envelope().add (fx, y);
1138 trackview.session().add_redo_no_execute (region.envelope().get_memento());
1139 trackview.session().commit_reversible_command ();
1143 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1145 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1146 region.envelope().erase (cp->model);
1150 AudioRegionView::store_flags()
1152 XMLNode *node = new XMLNode ("GUI");
1154 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
1155 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
1157 region.add_extra_xml (*node);
1161 AudioRegionView::set_flags (XMLNode* node)
1165 if ((prop = node->property ("waveform-visible")) != 0) {
1166 if (prop->value() == "yes") {
1167 _flags |= WaveformVisible;
1171 if ((prop = node->property ("envelope-visible")) != 0) {
1172 if (prop->value() == "yes") {
1173 _flags |= EnvelopeVisible;
1179 AudioRegionView::set_waveform_shape (WaveformShape shape)
1183 /* this slightly odd approach is to leave the door open to
1184 other "shapes" such as spectral displays, etc.
1197 if (yn != (bool) (_flags & WaveformRectified)) {
1198 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1199 (*wave)->property_rectified().set_value(yn);
1211 _flags |= WaveformRectified;
1213 _flags &= ~WaveformRectified;
1219 AudioRegionView::get_item_name ()
1221 return region.name();
1225 AudioRegionView::move (double x_delta, double y_delta)
1227 if (region.locked() || (x_delta == 0 && y_delta == 0)) {
1231 get_canvas_group()->move (x_delta, y_delta);
1233 /* note: ghosts never leave their tracks so y_delta for them is always zero */
1235 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1236 (*i)->group->move (x_delta, 0.0);
1241 AudioRegionView::add_ghost (AutomationTimeAxisView& atv)
1243 AudioTimeAxisView& myatv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
1244 double unit_position = region.position () / samples_per_unit;
1245 GhostRegion* ghost = new GhostRegion (atv, unit_position);
1248 nchans = myatv.get_diskstream()->n_channels();
1250 for (uint32_t n = 0; n < nchans; ++n) {
1252 if (n >= region.n_channels()) {
1256 WaveView *wave = new WaveView(*ghost->group);
1258 wave->property_data_src().set_value( ®ion);
1259 wave->property_cache().set_value( wave_caches[n]);
1260 wave->property_cache_updater().set_value(false);
1261 wave->property_channel().set_value(n);
1262 wave->property_length_function().set_value((gpointer)region_length_from_c);
1263 wave->property_sourcefile_length_function().set_value((gpointer) sourcefile_length_from_c);
1264 wave->property_peak_function().set_value( (gpointer) region_read_peaks_from_c);
1265 wave->property_x().set_value( 0.0);
1266 wave->property_samples_per_unit().set_value( samples_per_unit);
1267 wave->property_amplitude_above_axis().set_value( _amplitude_above_axis);
1268 wave->property_wave_color().set_value(color_map[cGhostTrackWave]);
1269 wave->property_region_start().set_value(region.start());
1270 // WaveView *wave = gnome_canvas_item_new (GNOME_CANVAS_GROUP(ghost->group),
1271 // gnome_canvas_waveview_get_type (),
1272 // "data_src", (gpointer) ®ion,
1273 // "cache", wave_caches[n],
1274 // "cache_updater", (gboolean) false,
1275 // "channel", (guint32) n,
1276 // "length_function", (gpointer) region_length_from_c,
1277 // "sourcefile_length_function",(gpointer) sourcefile_length_from_c,
1278 // "peak_function", (gpointer) region_read_peaks_from_c,
1280 // "samples_per_unit", samples_per_unit,
1281 // "amplitude_above_axis", _amplitude_above_axis,
1282 // "wave_color", color_map[cGhostTrackWave],
1283 // "region_start", (guint32) region.start(),
1287 ghost->waves.push_back(wave);
1290 ghost->set_height ();
1291 ghost->set_duration (region.length() / samples_per_unit);
1292 ghosts.push_back (ghost);
1294 ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost));
1300 AudioRegionView::remove_ghost (GhostRegion* ghost)
1302 if (in_destructor) {
1306 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1315 AudioRegionView::get_fill_color ()
1321 AudioRegionView::entered ()
1323 if (_flags & EnvelopeVisible) {
1324 gain_line->show_all_control_points ();
1328 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1331 fade_in_handle->set_property ("fill_color_rgba", RGBA_TO_UINT(r,g,b,a));
1332 fade_out_handle->set_property ("fill_color_rgba", RGBA_TO_UINT(r,g,b,a));
1336 AudioRegionView::exited ()
1338 gain_line->hide_all_but_selected_control_points ();
1341 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1344 fade_in_handle->set_property ("fill_color_rgba", RGBA_TO_UINT(r,g,b,a));
1345 fade_out_handle->set_property ("fill_color_rgba", RGBA_TO_UINT(r,g,b,a));
1349 AudioRegionView::envelope_active_changed ()
1351 gain_line->set_line_color (region.envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]);
1355 AudioRegionView::set_waveview_data_src()
1358 double unit_length= region.length() / samples_per_unit;
1360 for (uint32_t n = 0; n < waves.size(); ++n) {
1361 // TODO: something else to let it know the channel
1362 waves[n]->property_data_src().set_value(®ion);
1365 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1367 (*i)->set_duration (unit_length);
1369 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
1370 (*w)->property_data_src().set_value(®ion);