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 "canvas-simplerect.h"
37 #include "canvas-simpleline.h"
38 #include "canvas-waveview.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;
54 static const int32_t sync_mark_width = 9;
56 sigc::signal<void,AudioRegionView*> AudioRegionView::AudioRegionViewGoingAway;
58 AudioRegionView::AudioRegionView (Gnome::Canvas::Group *parent, AudioTimeAxisView &tv,
61 double amplitude_above_axis,
62 Gdk::Color& basic_color,
65 : TimeAxisViewItem (r.name(), parent, tv, spu, basic_color, r.position(), r.length(),
66 TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowNameText|
67 TimeAxisViewItem::ShowNameHighlight|
68 TimeAxisViewItem::ShowFrame)),
72 Gnome::Canvas::Points *shape;
77 in_destructor = false;
78 _amplitude_above_axis = amplitude_above_axis;
85 if ((node = region.extra_xml ("GUI")) != 0) {
88 _flags = WaveformVisible;
92 if (trackview.editor.new_regionviews_display_gain()) {
93 _flags |= EnvelopeVisible;
96 compute_colors (basic_color);
100 gtk_object_set_data (GTK_OBJECT(name_highlight), "regionview", this);
101 gtk_object_set_data (GTK_OBJECT(name_text), "regionview", this);
103 shape = new Gnome::Canvas::Points ();
105 /* an equilateral triangle */
107 shape->push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
108 shape->push_back (Gnome::Art::Point ((sync_mark_width - 1)/2, 1));
109 shape->push_back (Gnome::Art::Point (0, sync_mark_width - 1));
110 shape->push_back (Gnome::Art::Point (-((sync_mark_width-1)/2), 1));
112 sync_mark = new Gnome::Canvas::Polygon (*group);
113 sync_mark->set_property ("points", shape);
114 sync_mark->set_property ("fill_color_rgba", fill_color);
116 gnome_canvas_points_unref (shape->gobj());
118 fade_in_shape = new Gnome::Canvas::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 Gnome::Canvas::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 Gnome::Canvas::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 Gnome::Canvas::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 (Gnome::Canvas::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 gnome_canvas_item_set (waves[n], "data_src", ®ion, NULL);
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 gnome_canvas_item_set (waves[n], "region_start", (guint32) region.start(), NULL);
389 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
391 (*i)->set_duration (unit_length);
393 for (vector<GnomeCanvasItem*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
394 gnome_canvas_item_set ((*w), "region_start", region.start(), NULL);
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 gnome_canvas_item_set (waves[n], "wave_color", color_map[cMutedWaveForm], NULL);
443 gnome_canvas_item_set (waves[n], "wave_color", color_map[cWaveForm], NULL);
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 gnome_canvas_item_set (waves[n], "height", ht, NULL);
522 gnome_canvas_item_set (waves[n], "y", yoff + 2, NULL);
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);
577 GnomeCanvasPoints* points;
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->coords[pi++] = 1 + (pc * xdelta);
625 points->coords[pi++] = 2 + (h - (curve[pc] * h));
630 points->coords[pi++] = pwidth;
631 points->coords[pi++] = 2;
633 points->coords[pi++] = 1;
634 points->coords[pi++] = 2;
636 /* connect the dots ... */
638 points->coords[pi++] = points->coords[0];
639 points->coords[pi] = points->coords[1];
641 fade_in_shape->set_property ("points", points);
642 gnome_canvas_points_unref (points);
646 AudioRegionView::reset_fade_out_shape ()
648 reset_fade_out_shape_width ((jack_nframes_t) region.fade_out().back()->when);
652 AudioRegionView::reset_fade_out_shape_width (jack_nframes_t width)
654 /* smallest size for a fade is 64 frames */
656 width = std::max ((jack_nframes_t) 64, width);
658 GnomeCanvasPoints* points;
659 double pwidth = width / samples_per_unit;
660 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
664 fade_out_shape->hide();
665 fade_out_handle->hide();
669 double handle_center;
670 handle_center = (region.length() - width) / samples_per_unit;
672 if (handle_center > 7.0) {
673 handle_center -= 3.0;
678 fade_out_handle->set_property ("x1", handle_center - 3.0);
679 fade_out_handle->set_property ("x2", handle_center + 3.0);
681 /* don't show shape if its too small */
684 fade_out_shape->hide();
688 fade_out_shape->show();
690 float curve[npoints];
691 region.fade_out().get_vector (0, region.fade_out().back()->when, curve, npoints);
693 if (_height > NAME_HIGHLIGHT_THRESH) {
694 h = _height - NAME_HIGHLIGHT_SIZE;
699 /* points *MUST* be in anti-clockwise order */
701 points = get_canvas_points ("fade out shape", npoints+3);
704 double xdelta = pwidth/npoints;
706 for (pi = 0, pc = 0; pc < npoints; ++pc) {
707 points->coords[pi++] = _pixel_width - 1 - pwidth + (pc*xdelta);
708 points->coords[pi++] = 2 + (h - (curve[pc] * h));
713 points->coords[pi++] = _pixel_width;
714 points->coords[pi++] = h;
716 points->coords[pi++] = _pixel_width;
717 points->coords[pi++] = 2;
719 /* connect the dots ... */
721 points->coords[pi++] = points->coords[0];
722 points->coords[pi] = points->coords[1];
724 fade_out_shape->set_property ("points", points);
725 gnome_canvas_points_unref (points);
729 AudioRegionView::set_samples_per_unit (gdouble spu)
731 TimeAxisViewItem::set_samples_per_unit (spu);
733 for (uint32_t n=0; n < waves.size(); ++n) {
734 gnome_canvas_item_set (waves[n], "samples_per_unit", spu, NULL);
737 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
738 (*i)->set_samples_per_unit (spu);
739 (*i)->set_duration (region.length() / samples_per_unit);
743 reset_fade_shapes ();
744 region_sync_changed ();
748 AudioRegionView::set_duration (jack_nframes_t frames, void *src)
750 if (!TimeAxisViewItem::set_duration (frames, src)) {
754 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
755 (*i)->set_duration (region.length() / samples_per_unit);
762 AudioRegionView::set_amplitude_above_axis (gdouble spp)
764 for (uint32_t n=0; n < waves.size(); ++n) {
765 gnome_canvas_item_set (waves[n], "amplitude_above_axis", spp, NULL);
770 AudioRegionView::compute_colors (Gdk::Color& basic_color)
772 TimeAxisViewItem::compute_colors (basic_color);
775 /* gain color computed in envelope_active_changed() */
777 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
778 fade_color = RGBA_TO_UINT(r,g,b,120);
782 AudioRegionView::set_colors ()
784 TimeAxisViewItem::set_colors ();
786 gain_line->set_line_color (region.envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]);
787 sync_mark->set_property ("fill_color_rgba", fill_color);
789 for (uint32_t n=0; n < waves.size(); ++n) {
790 if (region.muted()) {
791 gnome_canvas_item_set (waves[n], "wave_color", color_map[cMutedWaveForm], NULL);
793 gnome_canvas_item_set (waves[n], "wave_color", color_map[cWaveForm], NULL);
799 AudioRegionView::set_frame_color ()
801 if (region.opaque()) {
807 TimeAxisViewItem::set_frame_color ();
811 AudioRegionView::show_region_editor ()
814 editor = new AudioRegionEditor (trackview.session(), region, *this);
815 // GTK2FIX : how to ensure float without realizing
816 // editor->realize ();
817 // trackview.editor.ensure_float (*editor);
821 editor->get_window()->raise();
825 AudioRegionView::hide_region_editor()
833 AudioRegionView::region_renamed ()
837 if (region.locked()) {
839 str += region.name();
845 if (region.muted()) {
846 str = string ("!") + str;
849 set_item_name (region.name(), this);
854 AudioRegionView::region_sync_changed ()
857 jack_nframes_t sync_offset;
859 sync_offset = region.sync_offset (sync_dir);
861 /* this has to handle both a genuine change of position, a change of samples_per_unit,
862 and a change in the bounds of the region.
865 if (sync_offset == 0) {
867 /* no sync mark - its the start of the region */
873 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > region.length()))) {
875 /* no sync mark - its out of the bounds of the region */
884 GnomeCanvasPoints* points;
886 args[0].name = X_("points");
888 sync_mark->get (X_("points"), &points);
890 double offset = sync_offset / samples_per_unit;
892 points->coords[0] = offset - ((sync_mark_width-1)/2);
893 points->coords[1] = 1;
895 points->coords[2] = offset + (sync_mark_width-1)/2;
896 points->coords[3] = 1;
898 points->coords[4] = offset;
899 points->coords[5] = sync_mark_width - 1;
901 points->coords[6] = offset - ((sync_mark_width-1)/2);
902 points->coords[7] = 1;
905 sync_mark->set_property ("points", points);
907 gnome_canvas_points_unref (points);
913 AudioRegionView::set_waveform_visible (bool yn)
915 if (((_flags & WaveformVisible) != yn)) {
917 for (uint32_t n=0; n < waves.size(); ++n) {
918 gnome_canvas_item_show (waves[n]);
920 _flags |= WaveformVisible;
922 for (uint32_t n=0; n < waves.size(); ++n) {
923 gnome_canvas_item_hide (waves[n]);
925 _flags &= ~WaveformVisible;
932 AudioRegionView::temporarily_hide_envelope ()
938 AudioRegionView::unhide_envelope ()
940 if (_flags & EnvelopeVisible) {
946 AudioRegionView::set_envelope_visible (bool yn)
948 if ((_flags & EnvelopeVisible) != yn) {
951 _flags |= EnvelopeVisible;
954 _flags &= ~EnvelopeVisible;
961 AudioRegionView::create_waves ()
963 bool create_zero_line = true;
965 AudioTimeAxisView& atv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
967 if (!atv.get_diskstream()) {
971 uint32_t nchans = atv.get_diskstream()->n_channels();
973 // if (wait_for_waves) {
974 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
975 for (uint32_t n = 0; n < nchans; ++n) {
976 tmp_waves.push_back (0);
980 for (uint32_t n = 0; n < nchans; ++n) {
982 if (n >= region.n_channels()) {
986 wave_caches.push_back (gnome_canvas_waveview_cache_new ());
988 if (wait_for_waves) {
989 if (region.source(n).peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n))) {
990 create_one_wave (n, true);
992 create_zero_line = false;
995 create_one_wave (n, true);
999 if (create_zero_line) {
1000 zero_line = new Gnome::Canvas::Line (*group);
1001 zero_line->set_property ("x1", (gdouble) 1.0);
1002 zero_line->set_property ("x2", (gdouble) (region.length() / samples_per_unit) - 1.0);
1003 zero_line->set_property ("color_rgba", (guint) color_map[cZeroLine]);
1004 manage_zero_line ();
1009 AudioRegionView::create_one_wave (uint32_t which, bool direct)
1011 AudioTimeAxisView& atv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
1012 uint32_t nchans = atv.get_diskstream()->n_channels();
1014 uint32_t nwaves = std::min (nchans, region.n_channels());
1017 if (trackview.height < NAME_HIGHLIGHT_SIZE) {
1018 ht = ((trackview.height) / (double) nchans);
1020 ht = ((trackview.height - NAME_HIGHLIGHT_SIZE) / (double) nchans);
1022 gdouble yoff = which * ht;
1024 GnomeCanvasItem *wave = gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
1025 gnome_canvas_waveview_get_type (),
1026 "data_src", (gpointer) ®ion,
1027 "cache", wave_caches[which],
1028 "cache_updater", (gboolean) true,
1029 "channel", (guint32) which,
1030 "length_function", (gpointer) region_length_from_c,
1031 "sourcefile_length_function",(gpointer) sourcefile_length_from_c,
1032 "peak_function", (gpointer) region_read_peaks_from_c,
1035 "height", (double) ht,
1036 "samples_per_unit", samples_per_unit,
1037 "amplitude_above_axis", _amplitude_above_axis,
1038 "wave_color", (guint32) (region.muted() ? color_map[cMutedWaveForm] : color_map[cWaveForm]),
1039 "region_start",(guint32) region.start(),
1042 if (!(_flags & WaveformVisible)) {
1043 gnome_canvas_item_hide (wave);
1046 /* note: calling this function is serialized by the lock
1047 held in the peak building thread that signals that
1048 peaks are ready for use *or* by the fact that it is
1049 called one by one from the GUI thread.
1052 if (which < nchans) {
1053 tmp_waves[which] = (wave);
1055 /* n-channel track, >n-channel source */
1058 /* see if we're all ready */
1060 for (n = 0; n < nchans; ++n) {
1061 if (tmp_waves[n] == 0) {
1067 /* all waves are ready */
1068 tmp_waves.resize(nwaves);
1073 zero_line = new Gnome::Canvas::Line (*group);
1074 zero_line->set_property ("x1", (gdouble) 1.0);
1075 zero_line->set_property ("x2", (gdouble) (region.length() / samples_per_unit) - 1.0);
1076 zero_line->set_property ("color_rgba", (guint) color_map[cZeroLine]);
1077 manage_zero_line ();
1083 AudioRegionView::peaks_ready_handler (uint32_t which)
1085 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
1089 AudioRegionView::add_gain_point_event (Gnome::Canvas::Item *item, GdkEvent *ev)
1093 /* don't create points that can't be seen */
1095 set_envelope_visible (true);
1102 jack_nframes_t fx = trackview.editor.pixel_to_frame (x);
1104 if (fx > region.length()) {
1108 /* compute vertical fractional position */
1110 y = 1.0 - (y / (trackview.height - NAME_HIGHLIGHT_SIZE));
1112 /* map using gain line */
1114 gain_line->view_to_model_y (y);
1116 trackview.session().begin_reversible_command (_("add gain control point"));
1117 trackview.session().add_undo (region.envelope().get_memento());
1120 if (!region.envelope_active()) {
1121 trackview.session().add_undo( bind( mem_fun(region, &AudioRegion::set_envelope_active), false) );
1122 region.set_envelope_active(true);
1123 trackview.session().add_redo( bind( mem_fun(region, &AudioRegion::set_envelope_active), true) );
1126 region.envelope().add (fx, y);
1128 trackview.session().add_redo_no_execute (region.envelope().get_memento());
1129 trackview.session().commit_reversible_command ();
1133 AudioRegionView::remove_gain_point_event (Gnome::Canvas::Item *item, GdkEvent *ev)
1135 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1136 region.envelope().erase (cp->model);
1140 AudioRegionView::store_flags()
1142 XMLNode *node = new XMLNode ("GUI");
1144 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
1145 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
1147 region.add_extra_xml (*node);
1151 AudioRegionView::set_flags (XMLNode* node)
1155 if ((prop = node->property ("waveform-visible")) != 0) {
1156 if (prop->value() == "yes") {
1157 _flags |= WaveformVisible;
1161 if ((prop = node->property ("envelope-visible")) != 0) {
1162 if (prop->value() == "yes") {
1163 _flags |= EnvelopeVisible;
1169 AudioRegionView::set_waveform_shape (WaveformShape shape)
1173 /* this slightly odd approach is to leave the door open to
1174 other "shapes" such as spectral displays, etc.
1187 if (yn != (bool) (_flags & WaveformRectified)) {
1188 for (vector<GnomeCanvasItem *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1189 gnome_canvas_item_set ((*wave), "rectified", (gboolean) yn, NULL);
1201 _flags |= WaveformRectified;
1203 _flags &= ~WaveformRectified;
1209 AudioRegionView::get_item_name ()
1211 return region.name();
1215 AudioRegionView::move (double x_delta, double y_delta)
1217 if (region.locked() || (x_delta == 0 && y_delta == 0)) {
1221 get_canvas_group()->move (x_delta, y_delta);
1223 /* note: ghosts never leave their tracks so y_delta for them is always zero */
1225 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1226 (*i)->group->move (x_delta, 0.0);
1231 AudioRegionView::add_ghost (AutomationTimeAxisView& atv)
1233 AudioTimeAxisView& myatv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
1234 double unit_position = region.position () / samples_per_unit;
1235 GhostRegion* ghost = new GhostRegion (atv, unit_position);
1238 nchans = myatv.get_diskstream()->n_channels();
1240 for (uint32_t n = 0; n < nchans; ++n) {
1242 if (n >= region.n_channels()) {
1246 GnomeCanvasItem *wave = gnome_canvas_item_new (GNOME_CANVAS_GROUP(ghost->group),
1247 gnome_canvas_waveview_get_type (),
1248 "data_src", (gpointer) ®ion,
1249 "cache", wave_caches[n],
1250 "cache_updater", (gboolean) false,
1251 "channel", (guint32) n,
1252 "length_function", (gpointer) region_length_from_c,
1253 "sourcefile_length_function",(gpointer) sourcefile_length_from_c,
1254 "peak_function", (gpointer) region_read_peaks_from_c,
1256 "samples_per_unit", samples_per_unit,
1257 "amplitude_above_axis", _amplitude_above_axis,
1258 "wave_color", color_map[cGhostTrackWave],
1259 "region_start", (guint32) region.start(),
1263 ghost->waves.push_back(wave);
1266 ghost->set_height ();
1267 ghost->set_duration (region.length() / samples_per_unit);
1268 ghosts.push_back (ghost);
1270 ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost));
1276 AudioRegionView::remove_ghost (GhostRegion* ghost)
1278 if (in_destructor) {
1282 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1291 AudioRegionView::get_fill_color ()
1297 AudioRegionView::entered ()
1299 if (_flags & EnvelopeVisible) {
1300 gain_line->show_all_control_points ();
1304 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1307 fade_in_handle->set_property ("fill_color_rgba", RGBA_TO_UINT(r,g,b,a));
1308 fade_out_handle->set_property ("fill_color_rgba", RGBA_TO_UINT(r,g,b,a));
1312 AudioRegionView::exited ()
1314 gain_line->hide_all_but_selected_control_points ();
1317 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1320 fade_in_handle->set_property ("fill_color_rgba", RGBA_TO_UINT(r,g,b,a));
1321 fade_out_handle->set_property ("fill_color_rgba", RGBA_TO_UINT(r,g,b,a));
1325 AudioRegionView::envelope_active_changed ()
1327 gain_line->set_line_color (region.envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]);
1331 AudioRegionView::set_waveview_data_src()
1334 double unit_length= region.length() / samples_per_unit;
1336 for (uint32_t n = 0; n < waves.size(); ++n) {
1337 // TODO: something else to let it know the channel
1338 gnome_canvas_item_set (waves[n], "data_src", ®ion, NULL);
1341 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1343 (*i)->set_duration (unit_length);
1345 for (vector<GnomeCanvasItem*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
1346 gnome_canvas_item_set ((*w), "data_src", ®ion, NULL);