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;
53 using namespace Editing;
54 using namespace ArdourCanvas;
56 static const int32_t sync_mark_width = 9;
58 sigc::signal<void,AudioRegionView*> AudioRegionView::AudioRegionViewGoingAway;
60 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, AudioTimeAxisView &tv, AudioRegion& r, double spu,
61 Gdk::Color& basic_color)
62 : TimeAxisViewItem (r.name(), *parent, tv, spu, basic_color, r.position(), r.length(),
63 TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowNameText|
64 TimeAxisViewItem::ShowNameHighlight|
65 TimeAxisViewItem::ShowFrame)),
70 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, AudioTimeAxisView &tv, AudioRegion& r, double spu,
71 Gdk::Color& basic_color, TimeAxisViewItem::Visibility visibility)
72 : TimeAxisViewItem (r.name(), *parent, tv, spu, basic_color, r.position(), r.length(), visibility),
78 AudioRegionView::init (double amplitude_above_axis, Gdk::Color& basic_color, bool wfw)
80 ArdourCanvas::Points shape;
85 in_destructor = false;
86 _amplitude_above_axis = amplitude_above_axis;
93 if ((node = region.extra_xml ("GUI")) != 0) {
96 _flags = WaveformVisible;
100 if (trackview.editor.new_regionviews_display_gain()) {
101 _flags |= EnvelopeVisible;
104 compute_colors (basic_color);
108 name_highlight->set_data ("regionview", this);
109 name_text->set_data ("regionview", this);
111 // shape = new ArdourCanvas::Points ();
113 /* an equilateral triangle */
115 shape.push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
116 shape.push_back (Gnome::Art::Point ((sync_mark_width - 1)/2, 1));
117 shape.push_back (Gnome::Art::Point (0, sync_mark_width - 1));
118 shape.push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
120 sync_mark = new ArdourCanvas::Polygon (*group);
121 sync_mark->property_points() = shape;
122 sync_mark->property_fill_color_rgba() = fill_color;
125 fade_in_shape = new ArdourCanvas::Polygon (*group);
126 fade_in_shape->property_fill_color_rgba() = fade_color;
127 fade_in_shape->set_data ("regionview", this);
129 fade_out_shape = new ArdourCanvas::Polygon (*group);
130 fade_out_shape->property_fill_color_rgba() = fade_color;
131 fade_out_shape->set_data ("regionview", this);
136 UINT_TO_RGBA(fill_color,&r,&g,&b,&a);
139 fade_in_handle = new ArdourCanvas::SimpleRect (*group);
140 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
141 fade_in_handle->property_outline_pixels() = 0;
142 fade_in_handle->property_y1() = 2.0;
143 fade_in_handle->property_y2() = 7.0;
145 fade_in_handle->set_data ("regionview", this);
147 fade_out_handle = new ArdourCanvas::SimpleRect (*group);
148 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
149 fade_out_handle->property_outline_pixels() = 0;
150 fade_out_handle->property_y1() = 2.0;
151 fade_out_handle->property_y2() = 7.0;
153 fade_out_handle->set_data ("regionview", this);
156 string foo = region.name();
160 gain_line = new AudioRegionGainLine (foo, trackview.session(), *this, *group, region.envelope());
162 if (!(_flags & EnvelopeVisible)) {
168 reset_width_dependent_items ((double) region.length() / samples_per_unit);
172 set_height (trackview.height);
175 region_sync_changed ();
176 region_resized (BoundsChanged);
177 set_waveview_data_src();
179 envelope_active_changed ();
180 fade_in_active_changed ();
181 fade_out_active_changed ();
183 region.StateChanged.connect (mem_fun(*this, &AudioRegionView::region_changed));
185 group->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_event), group, this));
186 name_highlight->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event), name_highlight, this));
187 fade_in_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
188 fade_in_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
189 fade_out_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
190 fade_out_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
194 ColorChanged.connect (mem_fun (*this, &AudioRegionView::color_handler));
196 /* XXX sync mark drag? */
199 AudioRegionView::~AudioRegionView ()
201 in_destructor = true;
203 AudioRegionViewGoingAway (this); /* EMIT_SIGNAL */
205 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
206 gnome_canvas_waveview_cache_destroy (*cache);
209 /* all waveviews etc will be destroyed when the group is destroyed */
211 for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
225 AudioRegionView::_lock_toggle (ArdourCanvas::Item* item, GdkEvent* ev, void* arg)
228 case GDK_BUTTON_RELEASE:
229 static_cast<AudioRegionView*>(arg)->lock_toggle ();
239 AudioRegionView::lock_toggle ()
241 region.set_locked (!region.locked());
245 AudioRegionView::region_changed (Change what_changed)
247 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionView::region_changed), what_changed));
249 if (what_changed & BoundsChanged) {
250 region_resized (what_changed);
251 region_sync_changed ();
253 if (what_changed & Region::MuteChanged) {
256 if (what_changed & Region::OpacityChanged) {
259 if (what_changed & ARDOUR::NameChanged) {
262 if (what_changed & Region::SyncOffsetChanged) {
263 region_sync_changed ();
265 if (what_changed & Region::LayerChanged) {
268 if (what_changed & Region::LockChanged) {
271 if (what_changed & AudioRegion::ScaleAmplitudeChanged) {
272 region_scale_amplitude_changed ();
274 if (what_changed & AudioRegion::FadeInChanged) {
277 if (what_changed & AudioRegion::FadeOutChanged) {
280 if (what_changed & AudioRegion::FadeInActiveChanged) {
281 fade_in_active_changed ();
283 if (what_changed & AudioRegion::FadeOutActiveChanged) {
284 fade_out_active_changed ();
286 if (what_changed & AudioRegion::EnvelopeActiveChanged) {
287 envelope_active_changed ();
292 AudioRegionView::fade_in_changed ()
294 reset_fade_in_shape ();
298 AudioRegionView::fade_out_changed ()
300 reset_fade_out_shape ();
304 AudioRegionView::set_fade_in_active (bool yn)
306 region.set_fade_in_active (yn);
310 AudioRegionView::set_fade_out_active (bool yn)
312 region.set_fade_out_active (yn);
316 AudioRegionView::fade_in_active_changed ()
320 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
322 if (region.fade_in_active()) {
323 col = RGBA_TO_UINT(r,g,b,120);
324 fade_in_shape->property_fill_color_rgba() = col;
325 fade_in_shape->property_width_pixels() = 0;
326 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
328 col = RGBA_TO_UINT(r,g,b,0);
329 fade_in_shape->property_fill_color_rgba() = col;
330 fade_in_shape->property_width_pixels() = 1;
331 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
336 AudioRegionView::fade_out_active_changed ()
340 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
342 if (region.fade_out_active()) {
343 col = RGBA_TO_UINT(r,g,b,120);
344 fade_out_shape->property_fill_color_rgba() = col;
345 fade_out_shape->property_width_pixels() = 0;
346 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
348 col = RGBA_TO_UINT(r,g,b,0);
349 fade_out_shape->property_fill_color_rgba() = col;
350 fade_out_shape->property_width_pixels() = 1;
351 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
357 AudioRegionView::region_scale_amplitude_changed ()
359 ENSURE_GUI_THREAD (mem_fun(*this, &AudioRegionView::region_scale_amplitude_changed));
361 for (uint32_t n = 0; n < waves.size(); ++n) {
362 // force a reload of the cache
363 waves[n]->property_data_src() = ®ion;
368 AudioRegionView::region_locked ()
370 /* name will show locked status */
375 AudioRegionView::region_resized (Change what_changed)
379 if (what_changed & ARDOUR::PositionChanged) {
380 set_position (region.position(), 0);
383 if (what_changed & Change (StartChanged|LengthChanged)) {
385 set_duration (region.length(), 0);
387 unit_length = region.length() / samples_per_unit;
389 reset_width_dependent_items (unit_length);
391 for (uint32_t n = 0; n < waves.size(); ++n) {
392 waves[n]->property_region_start() = region.start();
395 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
397 (*i)->set_duration (unit_length);
399 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
400 (*w)->property_region_start() = region.start();
407 AudioRegionView::reset_width_dependent_items (double pixel_width)
409 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
410 _pixel_width = pixel_width;
413 zero_line->property_x2() = pixel_width - 1.0;
416 if (fade_in_handle) {
417 if (pixel_width <= 6.0) {
418 fade_in_handle->hide();
419 fade_out_handle->hide();
422 fade_in_handle->hide();
423 fade_out_handle->hide();
425 fade_in_handle->show();
426 fade_out_handle->show();
431 reset_fade_shapes ();
435 AudioRegionView::region_layered ()
437 AudioTimeAxisView *atv = dynamic_cast<AudioTimeAxisView*> (&get_time_axis_view());
438 atv->view->region_layered (this);
442 AudioRegionView::region_muted ()
447 for (uint32_t n=0; n < waves.size(); ++n) {
448 if (region.muted()) {
449 waves[n]->property_wave_color() = color_map[cMutedWaveForm];
451 waves[n]->property_wave_color() = color_map[cWaveForm];
457 AudioRegionView::region_opacity ()
463 AudioRegionView::raise ()
469 AudioRegionView::raise_to_top ()
471 region.raise_to_top ();
475 AudioRegionView::lower ()
481 AudioRegionView::lower_to_bottom ()
483 region.lower_to_bottom ();
487 AudioRegionView::set_position (jack_nframes_t pos, void* src, double* ignored)
492 if (!(ret = TimeAxisViewItem::set_position (pos, this, &delta))) {
501 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
502 (*i)->group->move (delta, 0.0);
510 AudioRegionView::set_height (gdouble height)
512 uint32_t wcnt = waves.size();
514 TimeAxisViewItem::set_height (height - 2);
518 for (uint32_t n=0; n < wcnt; ++n) {
521 if ((height) < NAME_HIGHLIGHT_THRESH) {
522 ht = ((height-2*wcnt) / (double) wcnt);
524 ht = (((height-2*wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
527 gdouble yoff = n * (ht+1);
529 waves[n]->property_height() = ht;
530 waves[n]->property_y() = yoff + 2;
534 if ((height/wcnt) < NAME_HIGHLIGHT_SIZE) {
537 if (_flags & EnvelopeVisible) {
541 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE));
545 reset_fade_shapes ();
548 name_text->raise_to_top();
553 AudioRegionView::manage_zero_line ()
559 if (_height >= 100) {
560 gdouble wave_midpoint = (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
561 zero_line->property_y1() = wave_midpoint;
562 zero_line->property_y2() = wave_midpoint;
570 AudioRegionView::reset_fade_shapes ()
572 reset_fade_in_shape ();
573 reset_fade_out_shape ();
577 AudioRegionView::reset_fade_in_shape ()
579 reset_fade_in_shape_width ((jack_nframes_t) region.fade_in().back()->when);
583 AudioRegionView::reset_fade_in_shape_width (jack_nframes_t width)
585 if (fade_in_handle == 0) {
589 /* smallest size for a fade is 64 frames */
591 width = std::max ((jack_nframes_t) 64, width);
594 double pwidth = width / samples_per_unit;
595 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
599 fade_in_shape->hide();
600 fade_in_handle->hide();
604 double handle_center;
605 handle_center = pwidth;
607 if (handle_center > 7.0) {
608 handle_center -= 3.0;
613 fade_in_handle->property_x1() = handle_center - 3.0;
614 fade_in_handle->property_x2() = handle_center + 3.0;
617 fade_in_shape->hide();
621 fade_in_shape->show();
623 float curve[npoints];
624 region.fade_in().get_vector (0, region.fade_in().back()->when, curve, npoints);
626 points = get_canvas_points ("fade in shape", npoints+3);
628 if (_height > NAME_HIGHLIGHT_THRESH) {
629 h = _height - NAME_HIGHLIGHT_SIZE;
634 /* points *MUST* be in anti-clockwise order */
637 double xdelta = pwidth/npoints;
639 for (pi = 0, pc = 0; pc < npoints; ++pc) {
640 (*points)[pi].set_x(1 + (pc * xdelta));
641 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
646 (*points)[pi].set_x(pwidth);
647 (*points)[pi++].set_y(2);
649 (*points)[pi].set_x(1);
650 (*points)[pi++].set_y(2);
652 /* connect the dots ... */
654 (*points)[pi] = (*points)[0];
656 fade_in_shape->property_points() = *points;
661 AudioRegionView::reset_fade_out_shape ()
663 reset_fade_out_shape_width ((jack_nframes_t) region.fade_out().back()->when);
667 AudioRegionView::reset_fade_out_shape_width (jack_nframes_t width)
669 if (fade_out_handle == 0) {
673 /* smallest size for a fade is 64 frames */
675 width = std::max ((jack_nframes_t) 64, width);
678 double pwidth = width / samples_per_unit;
679 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
683 fade_out_shape->hide();
684 fade_out_handle->hide();
688 double handle_center;
689 handle_center = (region.length() - width) / samples_per_unit;
691 if (handle_center > 7.0) {
692 handle_center -= 3.0;
697 fade_out_handle->property_x1() = handle_center - 3.0;
698 fade_out_handle->property_x2() = handle_center + 3.0;
700 /* don't show shape if its too small */
703 fade_out_shape->hide();
707 fade_out_shape->show();
709 float curve[npoints];
710 region.fade_out().get_vector (0, region.fade_out().back()->when, curve, npoints);
712 if (_height > NAME_HIGHLIGHT_THRESH) {
713 h = _height - NAME_HIGHLIGHT_SIZE;
718 /* points *MUST* be in anti-clockwise order */
720 points = get_canvas_points ("fade out shape", npoints+3);
723 double xdelta = pwidth/npoints;
725 for (pi = 0, pc = 0; pc < npoints; ++pc) {
726 (*points)[pi].set_x(_pixel_width - 1 - pwidth + (pc*xdelta));
727 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
732 (*points)[pi].set_x(_pixel_width);
733 (*points)[pi++].set_y(h);
735 (*points)[pi].set_x(_pixel_width);
736 (*points)[pi++].set_y(2);
738 /* connect the dots ... */
740 (*points)[pi] = (*points)[0];
742 fade_out_shape->property_points() = *points;
747 AudioRegionView::set_samples_per_unit (gdouble spu)
749 TimeAxisViewItem::set_samples_per_unit (spu);
751 for (uint32_t n=0; n < waves.size(); ++n) {
752 waves[n]->property_samples_per_unit() = spu;
755 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
756 (*i)->set_samples_per_unit (spu);
757 (*i)->set_duration (region.length() / samples_per_unit);
763 reset_fade_shapes ();
764 region_sync_changed ();
768 AudioRegionView::set_duration (jack_nframes_t frames, void *src)
770 if (!TimeAxisViewItem::set_duration (frames, src)) {
774 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
775 (*i)->set_duration (region.length() / samples_per_unit);
782 AudioRegionView::set_amplitude_above_axis (gdouble spp)
784 for (uint32_t n=0; n < waves.size(); ++n) {
785 waves[n]->property_amplitude_above_axis() = spp;
790 AudioRegionView::compute_colors (Gdk::Color& basic_color)
792 TimeAxisViewItem::compute_colors (basic_color);
795 /* gain color computed in envelope_active_changed() */
797 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
798 fade_color = RGBA_TO_UINT(r,g,b,120);
802 AudioRegionView::set_colors ()
804 TimeAxisViewItem::set_colors ();
807 gain_line->set_line_color (region.envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]);
811 sync_mark->property_fill_color_rgba() = fill_color;
814 for (uint32_t n=0; n < waves.size(); ++n) {
815 if (region.muted()) {
816 waves[n]->property_wave_color() = color_map[cMutedWaveForm];
818 waves[n]->property_wave_color() = color_map[cWaveForm];
824 AudioRegionView::set_frame_color ()
826 if (region.opaque()) {
832 TimeAxisViewItem::set_frame_color ();
836 AudioRegionView::show_region_editor ()
839 editor = new AudioRegionEditor (trackview.session(), region, *this);
840 // GTK2FIX : how to ensure float without realizing
841 // editor->realize ();
842 // trackview.editor.ensure_float (*editor);
846 editor->get_window()->raise();
850 AudioRegionView::hide_region_editor()
858 AudioRegionView::region_renamed ()
862 if (region.locked()) {
864 str += region.name();
870 if (region.speed_mismatch (trackview.session().frame_rate())) {
871 str = string ("*") + str;
874 if (region.muted()) {
875 str = string ("!") + str;
878 set_item_name (str, this);
883 AudioRegionView::region_sync_changed ()
885 if (sync_mark == 0) {
890 jack_nframes_t sync_offset;
892 sync_offset = region.sync_offset (sync_dir);
894 /* this has to handle both a genuine change of position, a change of samples_per_unit,
895 and a change in the bounds of the region.
898 if (sync_offset == 0) {
900 /* no sync mark - its the start of the region */
906 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > region.length()))) {
908 /* no sync mark - its out of the bounds of the region */
918 //points = sync_mark->property_points().get_value();
920 double offset = sync_offset / samples_per_unit;
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)/2), 1));
923 points.push_back (Gnome::Art::Point (offset, sync_mark_width - 1));
924 points.push_back (Gnome::Art::Point (offset - ((sync_mark_width-1)/2), 1));
925 sync_mark->property_points().set_value (points);
933 AudioRegionView::set_waveform_visible (bool yn)
935 if (((_flags & WaveformVisible) != yn)) {
937 for (uint32_t n=0; n < waves.size(); ++n) {
940 _flags |= WaveformVisible;
942 for (uint32_t n=0; n < waves.size(); ++n) {
945 _flags &= ~WaveformVisible;
952 AudioRegionView::temporarily_hide_envelope ()
960 AudioRegionView::unhide_envelope ()
962 if (gain_line && (_flags & EnvelopeVisible)) {
968 AudioRegionView::set_envelope_visible (bool yn)
970 if (gain_line && ((_flags & EnvelopeVisible) != yn)) {
973 _flags |= EnvelopeVisible;
976 _flags &= ~EnvelopeVisible;
983 AudioRegionView::create_waves ()
985 bool create_zero_line = true;
987 AudioTimeAxisView& atv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
989 if (!atv.get_diskstream()) {
993 uint32_t nchans = atv.get_diskstream()->n_channels();
995 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
996 for (uint32_t n = 0; n < nchans; ++n) {
997 tmp_waves.push_back (0);
1000 for (uint32_t n = 0; n < nchans; ++n) {
1002 if (n >= region.n_channels()) {
1006 wave_caches.push_back (WaveView::create_cache ());
1008 if (wait_for_waves) {
1009 if (region.source(n).peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n), peaks_ready_connection)) {
1010 create_one_wave (n, true);
1012 create_zero_line = false;
1015 create_one_wave (n, true);
1019 if (create_zero_line) {
1020 zero_line = new ArdourCanvas::SimpleLine (*group);
1021 zero_line->property_x1() = (gdouble) 1.0;
1022 zero_line->property_x2() = (gdouble) (region.length() / samples_per_unit) - 1.0;
1023 zero_line->property_color_rgba() = (guint) color_map[cZeroLine];
1024 manage_zero_line ();
1029 AudioRegionView::create_one_wave (uint32_t which, bool direct)
1031 AudioTimeAxisView& atv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
1032 uint32_t nchans = atv.get_diskstream()->n_channels();
1034 uint32_t nwaves = std::min (nchans, region.n_channels());
1037 if (trackview.height < NAME_HIGHLIGHT_SIZE) {
1038 ht = ((trackview.height) / (double) nchans);
1040 ht = ((trackview.height - NAME_HIGHLIGHT_SIZE) / (double) nchans);
1043 gdouble yoff = which * ht;
1045 WaveView *wave = new WaveView(*group);
1047 wave->property_data_src() = (gpointer) ®ion;
1048 wave->property_cache() = wave_caches[which];
1049 wave->property_cache_updater() = true;
1050 wave->property_channel() = which;
1051 wave->property_length_function() = (gpointer) region_length_from_c;
1052 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1053 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1054 wave->property_x() = 0.0;
1055 wave->property_y() = yoff;
1056 wave->property_height() = (double) ht;
1057 wave->property_samples_per_unit() = samples_per_unit;
1058 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1059 wave->property_wave_color() = region.muted() ? color_map[cMutedWaveForm] : color_map[cWaveForm];
1060 wave->property_region_start() = region.start();
1062 if (!(_flags & WaveformVisible)) {
1066 /* note: calling this function is serialized by the lock
1067 held in the peak building thread that signals that
1068 peaks are ready for use *or* by the fact that it is
1069 called one by one from the GUI thread.
1072 if (which < nchans) {
1073 tmp_waves[which] = wave;
1075 /* n-channel track, >n-channel source */
1078 /* see if we're all ready */
1080 for (n = 0; n < nchans; ++n) {
1081 if (tmp_waves[n] == 0) {
1086 if (n == nwaves && waves.empty()) {
1087 /* all waves are ready */
1088 tmp_waves.resize(nwaves);
1094 zero_line = new ArdourCanvas::SimpleLine (*group);
1095 zero_line->property_x1() = (gdouble) 1.0;
1096 zero_line->property_x2() = (gdouble) (region.length() / samples_per_unit) - 1.0;
1097 zero_line->property_color_rgba() = (guint) color_map[cZeroLine];
1098 manage_zero_line ();
1104 AudioRegionView::peaks_ready_handler (uint32_t which)
1106 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
1108 if (!waves.empty()) {
1109 /* all waves created, don't hook into peaks ready anymore */
1110 peaks_ready_connection.disconnect ();
1115 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1117 if (gain_line == 0) {
1123 /* don't create points that can't be seen */
1125 set_envelope_visible (true);
1132 jack_nframes_t fx = trackview.editor.pixel_to_frame (x);
1134 if (fx > region.length()) {
1138 /* compute vertical fractional position */
1140 y = 1.0 - (y / (trackview.height - NAME_HIGHLIGHT_SIZE));
1142 /* map using gain line */
1144 gain_line->view_to_model_y (y);
1146 trackview.session().begin_reversible_command (_("add gain control point"));
1147 trackview.session().add_undo (region.envelope().get_memento());
1150 if (!region.envelope_active()) {
1151 trackview.session().add_undo( bind( mem_fun(region, &AudioRegion::set_envelope_active), false) );
1152 region.set_envelope_active(true);
1153 trackview.session().add_redo( bind( mem_fun(region, &AudioRegion::set_envelope_active), true) );
1156 region.envelope().add (fx, y);
1158 trackview.session().add_redo_no_execute (region.envelope().get_memento());
1159 trackview.session().commit_reversible_command ();
1163 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
1165 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1166 region.envelope().erase (cp->model);
1170 AudioRegionView::store_flags()
1172 XMLNode *node = new XMLNode ("GUI");
1174 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
1175 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
1177 region.add_extra_xml (*node);
1181 AudioRegionView::set_flags (XMLNode* node)
1185 if ((prop = node->property ("waveform-visible")) != 0) {
1186 if (prop->value() == "yes") {
1187 _flags |= WaveformVisible;
1191 if ((prop = node->property ("envelope-visible")) != 0) {
1192 if (prop->value() == "yes") {
1193 _flags |= EnvelopeVisible;
1199 AudioRegionView::set_waveform_shape (WaveformShape shape)
1203 /* this slightly odd approach is to leave the door open to
1204 other "shapes" such as spectral displays, etc.
1217 if (yn != (bool) (_flags & WaveformRectified)) {
1218 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1219 (*wave)->property_rectified() = yn;
1231 _flags |= WaveformRectified;
1233 _flags &= ~WaveformRectified;
1239 AudioRegionView::move (double x_delta, double y_delta)
1241 if (region.locked() || (x_delta == 0 && y_delta == 0)) {
1245 get_canvas_group()->move (x_delta, y_delta);
1247 /* note: ghosts never leave their tracks so y_delta for them is always zero */
1249 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1250 (*i)->group->move (x_delta, 0.0);
1255 AudioRegionView::add_ghost (AutomationTimeAxisView& atv)
1257 AudioTimeAxisView& myatv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
1258 double unit_position = region.position () / samples_per_unit;
1259 GhostRegion* ghost = new GhostRegion (atv, unit_position);
1262 nchans = myatv.get_diskstream()->n_channels();
1264 for (uint32_t n = 0; n < nchans; ++n) {
1266 if (n >= region.n_channels()) {
1270 WaveView *wave = new WaveView(*ghost->group);
1272 wave->property_data_src() = ®ion;
1273 wave->property_cache() = wave_caches[n];
1274 wave->property_cache_updater() = false;
1275 wave->property_channel() = n;
1276 wave->property_length_function() = (gpointer)region_length_from_c;
1277 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1278 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1279 wave->property_x() = 0.0;
1280 wave->property_samples_per_unit() = samples_per_unit;
1281 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1282 wave->property_wave_color() = color_map[cGhostTrackWave];
1283 wave->property_region_start() = region.start();
1285 ghost->waves.push_back(wave);
1288 ghost->set_height ();
1289 ghost->set_duration (region.length() / samples_per_unit);
1290 ghosts.push_back (ghost);
1292 ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost));
1298 AudioRegionView::remove_ghost (GhostRegion* ghost)
1300 if (in_destructor) {
1304 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1313 AudioRegionView::get_fill_color ()
1319 AudioRegionView::entered ()
1321 if (gain_line && _flags & EnvelopeVisible) {
1322 gain_line->show_all_control_points ();
1326 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1329 if (fade_in_handle) {
1330 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1331 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1336 AudioRegionView::exited ()
1339 gain_line->hide_all_but_selected_control_points ();
1343 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1346 if (fade_in_handle) {
1347 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1348 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1353 AudioRegionView::envelope_active_changed ()
1356 gain_line->set_line_color (region.envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]);
1361 AudioRegionView::set_waveview_data_src()
1364 double unit_length= region.length() / samples_per_unit;
1366 for (uint32_t n = 0; n < waves.size(); ++n) {
1367 // TODO: something else to let it know the channel
1368 waves[n]->property_data_src() = ®ion;
1371 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1373 (*i)->set_duration (unit_length);
1375 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
1376 (*w)->property_data_src() = ®ion;
1383 AudioRegionView::color_handler (ColorID id, uint32_t val)
1386 case cMutedWaveForm:
1391 case cGainLineInactive:
1393 envelope_active_changed();
1398 zero_line->property_color_rgba() = (guint) color_map[cZeroLine];
1402 case cGhostTrackWave: