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 (GnomeCanvasGroup *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 GnomeCanvasPoints *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 = gnome_canvas_points_new (4);
105 /* an equilateral triangle */
107 shape->coords[0] = -((sync_mark_width-1)/2);
108 shape->coords[1] = 1;
110 shape->coords[2] = (sync_mark_width - 1)/2;
111 shape->coords[3] = 1;
113 shape->coords[4] = 0;
114 shape->coords[5] = sync_mark_width - 1;
116 shape->coords[6] = -((sync_mark_width-1)/2);
117 shape->coords[7] = 1;
119 // cerr << "set sync mark al points, nc = " << shape->num_points << endl;
120 sync_mark = gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
121 gnome_canvas_polygon_get_type(),
123 "fill_color_rgba", fill_color,
125 gnome_canvas_item_hide (sync_mark);
126 gnome_canvas_points_unref (shape);
129 fade_in_shape = gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
130 gnome_canvas_polygon_get_type(),
131 "fill_color_rgba", fade_color,
133 gtk_object_set_data (GTK_OBJECT(fade_in_shape), "regionview", this);
135 fade_out_shape = gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
136 gnome_canvas_polygon_get_type(),
137 "fill_color_rgba", fade_color,
139 gtk_object_set_data (GTK_OBJECT(fade_out_shape), "regionview", this);
145 UINT_TO_RGBA(fill_color,&r,&g,&b,&a);
148 fade_in_handle = gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
149 gnome_canvas_simplerect_get_type(),
150 "fill_color_rgba", RGBA_TO_UINT(r,g,b,0),
155 gtk_object_set_data (GTK_OBJECT(fade_in_handle), "regionview", this);
157 fade_out_handle = gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
158 gnome_canvas_simplerect_get_type(),
159 "fill_color_rgba", RGBA_TO_UINT(r,g,b,0),
164 gtk_object_set_data (GTK_OBJECT(fade_out_handle), "regionview", this);
167 string foo = region.name();
171 gain_line = new AudioRegionGainLine (foo, tv.session(), *this, group, region.envelope(),
172 PublicEditor::canvas_control_point_event,
173 PublicEditor::canvas_line_event);
175 if (!(_flags & EnvelopeVisible)) {
181 reset_width_dependent_items ((double) region.length() / samples_per_unit);
185 set_height (trackview.height);
188 region_sync_changed ();
189 region_resized (BoundsChanged);
190 set_waveview_data_src();
192 envelope_active_changed ();
193 fade_in_active_changed ();
194 fade_out_active_changed ();
196 region.StateChanged.connect (mem_fun(*this, &AudioRegionView::region_changed));
198 gtk_signal_connect (GTK_OBJECT(group), "event",
199 (GtkSignalFunc) PublicEditor::canvas_region_view_event,
201 gtk_signal_connect (GTK_OBJECT(name_highlight), "event",
202 (GtkSignalFunc) PublicEditor::canvas_region_view_name_highlight_event,
205 gtk_signal_connect (GTK_OBJECT(name_text), "event",
206 (GtkSignalFunc) PublicEditor::canvas_region_view_name_event,
209 gtk_signal_connect (GTK_OBJECT(fade_in_shape), "event",
210 (GtkSignalFunc) PublicEditor::canvas_fade_in_event,
213 gtk_signal_connect (GTK_OBJECT(fade_in_handle), "event",
214 (GtkSignalFunc) PublicEditor::canvas_fade_in_handle_event,
217 gtk_signal_connect (GTK_OBJECT(fade_out_shape), "event",
218 (GtkSignalFunc) PublicEditor::canvas_fade_out_event,
221 gtk_signal_connect (GTK_OBJECT(fade_out_handle), "event",
222 (GtkSignalFunc) PublicEditor::canvas_fade_out_handle_event,
227 /* XXX sync mark drag? */
231 AudioRegionView::~AudioRegionView ()
233 in_destructor = true;
235 AudioRegionViewGoingAway (this); /* EMIT_SIGNAL */
237 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
238 gnome_canvas_waveview_cache_destroy (*cache);
241 /* all waveviews will be destroyed when the group is destroyed */
243 for (vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
255 AudioRegionView::_lock_toggle (GnomeCanvasItem* item, GdkEvent* ev, void* arg)
258 case GDK_BUTTON_RELEASE:
259 static_cast<AudioRegionView*>(arg)->lock_toggle ();
269 AudioRegionView::lock_toggle ()
271 region.set_locked (!region.locked());
275 AudioRegionView::region_changed (Change what_changed)
277 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionView::region_changed), what_changed));
279 if (what_changed & BoundsChanged) {
280 region_resized (what_changed);
281 region_sync_changed ();
283 if (what_changed & Region::MuteChanged) {
286 if (what_changed & Region::OpacityChanged) {
289 if (what_changed & ARDOUR::NameChanged) {
292 if (what_changed & Region::SyncOffsetChanged) {
293 region_sync_changed ();
295 if (what_changed & Region::LayerChanged) {
298 if (what_changed & Region::LockChanged) {
301 if (what_changed & AudioRegion::ScaleAmplitudeChanged) {
302 region_scale_amplitude_changed ();
304 if (what_changed & AudioRegion::FadeInChanged) {
307 if (what_changed & AudioRegion::FadeOutChanged) {
310 if (what_changed & AudioRegion::FadeInActiveChanged) {
311 fade_in_active_changed ();
313 if (what_changed & AudioRegion::FadeOutActiveChanged) {
314 fade_out_active_changed ();
316 if (what_changed & AudioRegion::EnvelopeActiveChanged) {
317 envelope_active_changed ();
322 AudioRegionView::fade_in_changed ()
324 reset_fade_in_shape ();
328 AudioRegionView::fade_out_changed ()
330 reset_fade_out_shape ();
334 AudioRegionView::set_fade_in_active (bool yn)
336 region.set_fade_in_active (yn);
340 AudioRegionView::set_fade_out_active (bool yn)
342 region.set_fade_out_active (yn);
346 AudioRegionView::fade_in_active_changed ()
350 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
352 if (region.fade_in_active()) {
353 col = RGBA_TO_UINT(r,g,b,120);
354 gnome_canvas_item_set (fade_in_shape,
355 "fill_color_rgba", col,
357 "outline_color_rgba", RGBA_TO_UINT(r,g,b,0),
360 col = RGBA_TO_UINT(r,g,b,0);
361 gnome_canvas_item_set (fade_in_shape,
362 "fill_color_rgba", col,
364 "outline_color_rgba", RGBA_TO_UINT(r,g,b,255),
370 AudioRegionView::fade_out_active_changed ()
374 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
376 if (region.fade_out_active()) {
377 col = RGBA_TO_UINT(r,g,b,120);
378 gnome_canvas_item_set (fade_out_shape,
379 "fill_color_rgba", col,
381 "outline_color_rgba", RGBA_TO_UINT(r,g,b,0),
384 col = RGBA_TO_UINT(r,g,b,0);
385 gnome_canvas_item_set (fade_out_shape,
386 "fill_color_rgba", col,
388 "outline_color_rgba", RGBA_TO_UINT(r,g,b,255),
395 AudioRegionView::region_scale_amplitude_changed ()
397 ENSURE_GUI_THREAD (mem_fun(*this, &AudioRegionView::region_scale_amplitude_changed));
399 for (uint32_t n = 0; n < waves.size(); ++n) {
400 // force a reload of the cache
401 gnome_canvas_item_set (waves[n], "data_src", ®ion, NULL);
406 AudioRegionView::region_locked ()
408 /* name will show locked status */
413 AudioRegionView::region_resized (Change what_changed)
417 if (what_changed & ARDOUR::PositionChanged) {
418 set_position (region.position(), 0);
421 if (what_changed & Change (StartChanged|LengthChanged)) {
423 set_duration (region.length(), 0);
425 unit_length = region.length() / samples_per_unit;
427 reset_width_dependent_items (unit_length);
429 for (uint32_t n = 0; n < waves.size(); ++n) {
430 gnome_canvas_item_set (waves[n], "region_start", (guint32) region.start(), NULL);
433 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
435 (*i)->set_duration (unit_length);
437 for (vector<GnomeCanvasItem*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
438 gnome_canvas_item_set ((*w), "region_start", region.start(), NULL);
445 AudioRegionView::reset_width_dependent_items (double pixel_width)
447 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
448 _pixel_width = pixel_width;
451 gnome_canvas_item_set (zero_line, "x2", pixel_width - 1.0, NULL);
454 if (pixel_width <= 6.0) {
455 gnome_canvas_item_hide (fade_in_handle);
456 gnome_canvas_item_hide (fade_out_handle);
459 gnome_canvas_item_hide (fade_in_handle);
460 gnome_canvas_item_hide (fade_out_handle);
462 gnome_canvas_item_show (fade_in_handle);
463 gnome_canvas_item_show (fade_out_handle);
467 reset_fade_shapes ();
471 AudioRegionView::region_layered ()
473 AudioTimeAxisView *atv = dynamic_cast<AudioTimeAxisView*> (&get_time_axis_view());
474 atv->view->region_layered (this);
478 AudioRegionView::region_muted ()
483 for (uint32_t n=0; n < waves.size(); ++n) {
484 if (region.muted()) {
485 gnome_canvas_item_set (waves[n], "wave_color", color_map[cMutedWaveForm], NULL);
487 gnome_canvas_item_set (waves[n], "wave_color", color_map[cWaveForm], NULL);
493 AudioRegionView::region_opacity ()
499 AudioRegionView::raise ()
505 AudioRegionView::raise_to_top ()
507 region.raise_to_top ();
511 AudioRegionView::lower ()
517 AudioRegionView::lower_to_bottom ()
519 region.lower_to_bottom ();
523 AudioRegionView::set_position (jack_nframes_t pos, void* src, double* ignored)
528 if (!(ret = TimeAxisViewItem::set_position (pos, this, &delta))) {
537 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
538 gnome_canvas_item_move ((*i)->group, delta, 0.0);
546 AudioRegionView::set_height (gdouble height)
548 uint32_t wcnt = waves.size();
550 TimeAxisViewItem::set_height (height - 2);
554 for (uint32_t n=0; n < wcnt; ++n) {
557 if ((height) < NAME_HIGHLIGHT_THRESH) {
558 ht = ((height-2*wcnt) / (double) wcnt);
560 ht = (((height-2*wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
563 gdouble yoff = n * (ht+1);
565 gnome_canvas_item_set (waves[n], "height", ht, NULL);
566 gnome_canvas_item_set (waves[n], "y", yoff + 2, NULL);
569 if ((height/wcnt) < NAME_HIGHLIGHT_SIZE) {
572 if (_flags & EnvelopeVisible) {
578 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE));
579 reset_fade_shapes ();
581 gnome_canvas_item_raise_to_top (name_text) ;
585 AudioRegionView::manage_zero_line ()
591 if (_height >= 100) {
592 gdouble wave_midpoint = (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
593 gnome_canvas_item_set (zero_line,
597 gnome_canvas_item_show (zero_line);
599 gnome_canvas_item_hide (zero_line);
604 AudioRegionView::reset_fade_shapes ()
606 reset_fade_in_shape ();
607 reset_fade_out_shape ();
611 AudioRegionView::reset_fade_in_shape ()
613 reset_fade_in_shape_width ((jack_nframes_t) region.fade_in().back()->when);
617 AudioRegionView::reset_fade_in_shape_width (jack_nframes_t width)
619 /* smallest size for a fade is 64 frames */
621 width = std::max ((jack_nframes_t) 64, width);
623 GnomeCanvasPoints* points;
624 double pwidth = width / samples_per_unit;
625 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
629 gnome_canvas_item_hide (fade_in_shape);
630 gnome_canvas_item_hide (fade_in_handle);
634 double handle_center;
635 handle_center = pwidth;
637 if (handle_center > 7.0) {
638 handle_center -= 3.0;
643 gnome_canvas_item_set (fade_in_handle,
644 "x1", handle_center - 3.0,
645 "x2", handle_center + 3.0,
649 gnome_canvas_item_hide (fade_in_shape);
653 gnome_canvas_item_show (fade_in_shape);
655 float curve[npoints];
656 region.fade_in().get_vector (0, region.fade_in().back()->when, curve, npoints);
658 points = get_canvas_points ("fade in shape", npoints+3);
660 if (_height > NAME_HIGHLIGHT_THRESH) {
661 h = _height - NAME_HIGHLIGHT_SIZE;
666 /* points *MUST* be in anti-clockwise order */
669 double xdelta = pwidth/npoints;
671 for (pi = 0, pc = 0; pc < npoints; ++pc) {
672 points->coords[pi++] = 1 + (pc * xdelta);
673 points->coords[pi++] = 2 + (h - (curve[pc] * h));
678 points->coords[pi++] = pwidth;
679 points->coords[pi++] = 2;
681 points->coords[pi++] = 1;
682 points->coords[pi++] = 2;
684 /* connect the dots ... */
686 points->coords[pi++] = points->coords[0];
687 points->coords[pi] = points->coords[1];
689 gnome_canvas_item_set (fade_in_shape, "points", points, NULL);
690 gnome_canvas_points_unref (points);
694 AudioRegionView::reset_fade_out_shape ()
696 reset_fade_out_shape_width ((jack_nframes_t) region.fade_out().back()->when);
700 AudioRegionView::reset_fade_out_shape_width (jack_nframes_t width)
702 /* smallest size for a fade is 64 frames */
704 width = std::max ((jack_nframes_t) 64, width);
706 GnomeCanvasPoints* points;
707 double pwidth = width / samples_per_unit;
708 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
712 gnome_canvas_item_hide (fade_out_shape);
713 gnome_canvas_item_hide (fade_out_handle);
717 double handle_center;
718 handle_center = (region.length() - width) / samples_per_unit;
720 if (handle_center > 7.0) {
721 handle_center -= 3.0;
726 gnome_canvas_item_set (fade_out_handle,
727 "x1", handle_center - 3.0,
728 "x2", handle_center + 3.0,
731 /* don't show shape if its too small */
734 gnome_canvas_item_hide (fade_out_shape);
738 gnome_canvas_item_show (fade_out_shape);
740 float curve[npoints];
741 region.fade_out().get_vector (0, region.fade_out().back()->when, curve, npoints);
743 if (_height > NAME_HIGHLIGHT_THRESH) {
744 h = _height - NAME_HIGHLIGHT_SIZE;
749 /* points *MUST* be in anti-clockwise order */
751 points = get_canvas_points ("fade out shape", npoints+3);
754 double xdelta = pwidth/npoints;
756 for (pi = 0, pc = 0; pc < npoints; ++pc) {
757 points->coords[pi++] = _pixel_width - 1 - pwidth + (pc*xdelta);
758 points->coords[pi++] = 2 + (h - (curve[pc] * h));
763 points->coords[pi++] = _pixel_width;
764 points->coords[pi++] = h;
766 points->coords[pi++] = _pixel_width;
767 points->coords[pi++] = 2;
769 /* connect the dots ... */
771 points->coords[pi++] = points->coords[0];
772 points->coords[pi] = points->coords[1];
774 gnome_canvas_item_set (fade_out_shape, "points", points, NULL);
775 gnome_canvas_points_unref (points);
779 AudioRegionView::set_samples_per_unit (gdouble spu)
781 TimeAxisViewItem::set_samples_per_unit (spu);
783 for (uint32_t n=0; n < waves.size(); ++n) {
784 gnome_canvas_item_set (waves[n], "samples_per_unit", spu, NULL);
787 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
788 (*i)->set_samples_per_unit (spu);
789 (*i)->set_duration (region.length() / samples_per_unit);
793 reset_fade_shapes ();
794 region_sync_changed ();
798 AudioRegionView::set_duration (jack_nframes_t frames, void *src)
800 if (!TimeAxisViewItem::set_duration (frames, src)) {
804 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
805 (*i)->set_duration (region.length() / samples_per_unit);
812 AudioRegionView::set_amplitude_above_axis (gdouble spp)
814 for (uint32_t n=0; n < waves.size(); ++n) {
815 gnome_canvas_item_set (waves[n], "amplitude_above_axis", spp, NULL);
820 AudioRegionView::compute_colors (Gdk::Color& basic_color)
822 TimeAxisViewItem::compute_colors (basic_color);
825 /* gain color computed in envelope_active_changed() */
827 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
828 fade_color = RGBA_TO_UINT(r,g,b,120);
832 AudioRegionView::set_colors ()
834 TimeAxisViewItem::set_colors ();
836 gain_line->set_line_color (region.envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]);
837 gnome_canvas_item_set (sync_mark, "fill_color_rgba", fill_color, NULL);
839 for (uint32_t n=0; n < waves.size(); ++n) {
840 if (region.muted()) {
841 gnome_canvas_item_set (waves[n], "wave_color", color_map[cMutedWaveForm], NULL);
843 gnome_canvas_item_set (waves[n], "wave_color", color_map[cWaveForm], NULL);
849 AudioRegionView::set_frame_color ()
851 if (region.opaque()) {
857 TimeAxisViewItem::set_frame_color ();
861 AudioRegionView::show_region_editor ()
864 editor = new AudioRegionEditor (trackview.session(), region, *this);
866 trackview.editor.ensure_float (*editor);
870 editor->get_window()->raise();
874 AudioRegionView::hide_region_editor()
882 AudioRegionView::region_renamed ()
886 if (region.locked()) {
888 str += region.name();
894 if (region.muted()) {
895 str = string ("!") + str;
898 set_item_name (region.name(), this);
903 AudioRegionView::region_sync_changed ()
906 jack_nframes_t sync_offset;
908 sync_offset = region.sync_offset (sync_dir);
910 /* this has to handle both a genuine change of position, a change of samples_per_unit,
911 and a change in the bounds of the region.
914 if (sync_offset == 0) {
916 /* no sync mark - its the start of the region */
918 gnome_canvas_item_hide (sync_mark);
922 if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > region.length()))) {
924 /* no sync mark - its out of the bounds of the region */
926 gnome_canvas_item_hide (sync_mark);
933 GnomeCanvasPoints* points;
935 args[0].name = X_("points");
937 gtk_object_getv (GTK_OBJECT(sync_mark), 1, args);
938 points = static_cast<GnomeCanvasPoints *> (GTK_VALUE_POINTER(args[0]));
940 double offset = sync_offset / samples_per_unit;
942 points->coords[0] = offset - ((sync_mark_width-1)/2);
943 points->coords[1] = 1;
945 points->coords[2] = offset + (sync_mark_width-1)/2;
946 points->coords[3] = 1;
948 points->coords[4] = offset;
949 points->coords[5] = sync_mark_width - 1;
951 points->coords[6] = offset - ((sync_mark_width-1)/2);
952 points->coords[7] = 1;
954 gnome_canvas_item_show (sync_mark);
955 gnome_canvas_item_set (sync_mark, "points", points, NULL);
957 gnome_canvas_points_unref (points);
963 AudioRegionView::set_waveform_visible (bool yn)
965 if (((_flags & WaveformVisible) != yn)) {
967 for (uint32_t n=0; n < waves.size(); ++n) {
968 gnome_canvas_item_show (waves[n]);
970 _flags |= WaveformVisible;
972 for (uint32_t n=0; n < waves.size(); ++n) {
973 gnome_canvas_item_hide (waves[n]);
975 _flags &= ~WaveformVisible;
982 AudioRegionView::temporarily_hide_envelope ()
988 AudioRegionView::unhide_envelope ()
990 if (_flags & EnvelopeVisible) {
996 AudioRegionView::set_envelope_visible (bool yn)
998 if ((_flags & EnvelopeVisible) != yn) {
1001 _flags |= EnvelopeVisible;
1004 _flags &= ~EnvelopeVisible;
1011 AudioRegionView::create_waves ()
1013 bool create_zero_line = true;
1015 AudioTimeAxisView& atv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
1017 if (!atv.get_diskstream()) {
1021 uint32_t nchans = atv.get_diskstream()->n_channels();
1023 // if (wait_for_waves) {
1024 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
1025 for (uint32_t n = 0; n < nchans; ++n) {
1026 tmp_waves.push_back (0);
1030 for (uint32_t n = 0; n < nchans; ++n) {
1032 if (n >= region.n_channels()) {
1036 wave_caches.push_back (gnome_canvas_waveview_cache_new ());
1038 if (wait_for_waves) {
1039 if (region.source(n).peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n))) {
1040 create_one_wave (n, true);
1042 create_zero_line = false;
1045 create_one_wave (n, true);
1049 if (create_zero_line) {
1050 zero_line = gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
1051 gnome_canvas_simpleline_get_type(),
1052 "x1", (gdouble) 1.0,
1053 "x2", (gdouble) (region.length() / samples_per_unit) - 1.0,
1054 "color_rgba", (guint) color_map[cZeroLine],
1056 manage_zero_line ();
1061 AudioRegionView::create_one_wave (uint32_t which, bool direct)
1063 AudioTimeAxisView& atv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
1064 uint32_t nchans = atv.get_diskstream()->n_channels();
1066 uint32_t nwaves = std::min (nchans, region.n_channels());
1069 if (trackview.height < NAME_HIGHLIGHT_SIZE) {
1070 ht = ((trackview.height) / (double) nchans);
1072 ht = ((trackview.height - NAME_HIGHLIGHT_SIZE) / (double) nchans);
1074 gdouble yoff = which * ht;
1076 GnomeCanvasItem *wave = gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
1077 gnome_canvas_waveview_get_type (),
1078 "data_src", (gpointer) ®ion,
1079 "cache", wave_caches[which],
1080 "cache_updater", (gboolean) true,
1081 "channel", (guint32) which,
1082 "length_function", (gpointer) region_length_from_c,
1083 "sourcefile_length_function",(gpointer) sourcefile_length_from_c,
1084 "peak_function", (gpointer) region_read_peaks_from_c,
1087 "height", (double) ht,
1088 "samples_per_unit", samples_per_unit,
1089 "amplitude_above_axis", _amplitude_above_axis,
1090 "wave_color", (guint32) (region.muted() ? color_map[cMutedWaveForm] : color_map[cWaveForm]),
1091 "region_start",(guint32) region.start(),
1094 if (!(_flags & WaveformVisible)) {
1095 gnome_canvas_item_hide (wave);
1098 /* note: calling this function is serialized by the lock
1099 held in the peak building thread that signals that
1100 peaks are ready for use *or* by the fact that it is
1101 called one by one from the GUI thread.
1104 if (which < nchans) {
1105 tmp_waves[which] = (wave);
1107 /* n-channel track, >n-channel source */
1110 /* see if we're all ready */
1112 for (n = 0; n < nchans; ++n) {
1113 if (tmp_waves[n] == 0) {
1119 /* all waves are ready */
1120 tmp_waves.resize(nwaves);
1125 zero_line = gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
1126 gnome_canvas_simpleline_get_type(),
1127 "x1", (gdouble) 1.0,
1128 "x2", (gdouble) (region.length() / samples_per_unit) - 1.0,
1129 "color_rgba", (guint) color_map[cZeroLine],
1131 manage_zero_line ();
1137 AudioRegionView::peaks_ready_handler (uint32_t which)
1139 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
1143 AudioRegionView::add_gain_point_event (GnomeCanvasItem *item, GdkEvent *ev)
1147 /* don't create points that can't be seen */
1149 set_envelope_visible (true);
1154 gnome_canvas_item_w2i (item, &x, &y);
1156 jack_nframes_t fx = trackview.editor.pixel_to_frame (x);
1158 if (fx > region.length()) {
1162 /* compute vertical fractional position */
1164 y = 1.0 - (y / (trackview.height - NAME_HIGHLIGHT_SIZE));
1166 /* map using gain line */
1168 gain_line->view_to_model_y (y);
1170 trackview.session().begin_reversible_command (_("add gain control point"));
1171 trackview.session().add_undo (region.envelope().get_memento());
1174 if (!region.envelope_active()) {
1175 trackview.session().add_undo( bind( mem_fun(region, &AudioRegion::set_envelope_active), false) );
1176 region.set_envelope_active(true);
1177 trackview.session().add_redo( bind( mem_fun(region, &AudioRegion::set_envelope_active), true) );
1180 region.envelope().add (fx, y);
1182 trackview.session().add_redo_no_execute (region.envelope().get_memento());
1183 trackview.session().commit_reversible_command ();
1187 AudioRegionView::remove_gain_point_event (GnomeCanvasItem *item, GdkEvent *ev)
1189 ControlPoint *cp = reinterpret_cast<ControlPoint *> (gtk_object_get_data(GTK_OBJECT(item), "control_point"));
1190 region.envelope().erase (cp->model);
1194 AudioRegionView::store_flags()
1196 XMLNode *node = new XMLNode ("GUI");
1198 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
1199 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
1201 region.add_extra_xml (*node);
1205 AudioRegionView::set_flags (XMLNode* node)
1209 if ((prop = node->property ("waveform-visible")) != 0) {
1210 if (prop->value() == "yes") {
1211 _flags |= WaveformVisible;
1215 if ((prop = node->property ("envelope-visible")) != 0) {
1216 if (prop->value() == "yes") {
1217 _flags |= EnvelopeVisible;
1223 AudioRegionView::set_waveform_shape (WaveformShape shape)
1227 /* this slightly odd approach is to leave the door open to
1228 other "shapes" such as spectral displays, etc.
1241 if (yn != (bool) (_flags & WaveformRectified)) {
1242 for (vector<GnomeCanvasItem *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1243 gnome_canvas_item_set ((*wave), "rectified", (gboolean) yn, NULL);
1248 gnome_canvas_item_hide (zero_line);
1250 gnome_canvas_item_show (zero_line);
1255 _flags |= WaveformRectified;
1257 _flags &= ~WaveformRectified;
1263 AudioRegionView::get_item_name ()
1265 return region.name();
1269 AudioRegionView::move (double x_delta, double y_delta)
1271 if (region.locked() || (x_delta == 0 && y_delta == 0)) {
1275 gnome_canvas_item_move (get_canvas_group(), x_delta, y_delta);
1277 /* note: ghosts never leave their tracks so y_delta for them is always zero */
1279 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1280 gnome_canvas_item_move ((*i)->group, x_delta, 0.0);
1285 AudioRegionView::add_ghost (AutomationTimeAxisView& atv)
1287 AudioTimeAxisView& myatv (*(dynamic_cast<AudioTimeAxisView*>(&trackview))); // ick
1288 double unit_position = region.position () / samples_per_unit;
1289 GhostRegion* ghost = new GhostRegion (atv, unit_position);
1292 nchans = myatv.get_diskstream()->n_channels();
1294 for (uint32_t n = 0; n < nchans; ++n) {
1296 if (n >= region.n_channels()) {
1300 GnomeCanvasItem *wave = gnome_canvas_item_new (GNOME_CANVAS_GROUP(ghost->group),
1301 gnome_canvas_waveview_get_type (),
1302 "data_src", (gpointer) ®ion,
1303 "cache", wave_caches[n],
1304 "cache_updater", (gboolean) false,
1305 "channel", (guint32) n,
1306 "length_function", (gpointer) region_length_from_c,
1307 "sourcefile_length_function",(gpointer) sourcefile_length_from_c,
1308 "peak_function", (gpointer) region_read_peaks_from_c,
1310 "samples_per_unit", samples_per_unit,
1311 "amplitude_above_axis", _amplitude_above_axis,
1312 "wave_color", color_map[cGhostTrackWave],
1313 "region_start", (guint32) region.start(),
1317 ghost->waves.push_back(wave);
1320 ghost->set_height ();
1321 ghost->set_duration (region.length() / samples_per_unit);
1322 ghosts.push_back (ghost);
1324 ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost));
1330 AudioRegionView::remove_ghost (GhostRegion* ghost)
1332 if (in_destructor) {
1336 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1345 AudioRegionView::get_fill_color ()
1351 AudioRegionView::entered ()
1353 if (_flags & EnvelopeVisible) {
1354 gain_line->show_all_control_points ();
1358 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1361 gnome_canvas_item_set (fade_in_handle, "fill_color_rgba", RGBA_TO_UINT(r,g,b,a), NULL);
1362 gnome_canvas_item_set (fade_out_handle, "fill_color_rgba", RGBA_TO_UINT(r,g,b,a), NULL);
1366 AudioRegionView::exited ()
1368 gain_line->hide_all_but_selected_control_points ();
1371 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1374 gnome_canvas_item_set (fade_in_handle, "fill_color_rgba", RGBA_TO_UINT(r,g,b,a), NULL);
1375 gnome_canvas_item_set (fade_out_handle, "fill_color_rgba", RGBA_TO_UINT(r,g,b,a), NULL);
1379 AudioRegionView::envelope_active_changed ()
1381 gain_line->set_line_color (region.envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]);
1385 AudioRegionView::set_waveview_data_src()
1388 double unit_length= region.length() / samples_per_unit;
1390 for (uint32_t n = 0; n < waves.size(); ++n) {
1391 // TODO: something else to let it know the channel
1392 gnome_canvas_item_set (waves[n], "data_src", ®ion, NULL);
1395 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1397 (*i)->set_duration (unit_length);
1399 for (vector<GnomeCanvasItem*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
1400 gnome_canvas_item_set ((*w), "data_src", ®ion, NULL);