2 Copyright (C) 2001-2006 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.
25 #include <gtkmm2ext/gtk_ui.h>
27 #include <ardour/playlist.h>
28 #include <ardour/audioregion.h>
29 #include <ardour/audiosource.h>
30 #include <ardour/audio_diskstream.h>
31 #include <pbd/memento_command.h>
32 #include <pbd/stacktrace.h>
34 #include "streamview.h"
35 #include "audio_region_view.h"
36 #include "audio_time_axis.h"
37 #include "simplerect.h"
38 #include "simpleline.h"
40 #include "public_editor.h"
41 #include "audio_region_editor.h"
42 #include "region_gain_line.h"
43 #include "control_point.h"
44 #include "ghostregion.h"
45 #include "audio_time_axis.h"
47 #include "rgb_macros.h"
48 #include "gui_thread.h"
49 #include "ardour_ui.h"
53 #define MUTED_ALPHA 0x50
56 using namespace ARDOUR;
58 using namespace Editing;
59 using namespace ArdourCanvas;
61 static const int32_t sync_mark_width = 9;
63 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
64 Gdk::Color& basic_color)
65 : RegionView (parent, tv, r, spu, basic_color)
73 , _amplitude_above_axis(1.0)
79 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
80 Gdk::Color& basic_color, TimeAxisViewItem::Visibility visibility)
81 : RegionView (parent, tv, r, spu, basic_color, visibility)
89 , _amplitude_above_axis(1.0)
96 AudioRegionView::AudioRegionView (const AudioRegionView& other)
104 , _amplitude_above_axis(1.0)
112 UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
113 c.set_rgb_p (r/255.0, g/255.0, b/255.0);
119 AudioRegionView::init (Gdk::Color& basic_color, bool wfd)
121 // FIXME: Some redundancy here with RegionView::init. Need to figure out
122 // where order is important and where it isn't...
124 RegionView::init(basic_color, false);
128 _amplitude_above_axis = 1.0;
132 if ((node = _region->extra_xml ("GUI")) != 0) {
135 _flags = WaveformVisible;
139 if (trackview.editor.new_regionviews_display_gain()) {
140 _flags |= EnvelopeVisible;
143 compute_colors (basic_color);
147 fade_in_shape = new ArdourCanvas::Polygon (*group);
148 fade_in_shape->property_fill_color_rgba() = fade_color;
149 fade_in_shape->set_data ("regionview", this);
151 fade_out_shape = new ArdourCanvas::Polygon (*group);
152 fade_out_shape->property_fill_color_rgba() = fade_color;
153 fade_out_shape->set_data ("regionview", this);
158 UINT_TO_RGBA(fill_color,&r,&g,&b,&a);
161 fade_in_handle = new ArdourCanvas::SimpleRect (*group);
162 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
163 fade_in_handle->property_outline_pixels() = 0;
165 fade_in_handle->set_data ("regionview", this);
167 fade_out_handle = new ArdourCanvas::SimpleRect (*group);
168 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,0);
169 fade_out_handle->property_outline_pixels() = 0;
171 fade_out_handle->set_data ("regionview", this);
174 setup_fade_handle_positions ();
176 string line_name = _region->name();
180 gain_line = new AudioRegionGainLine (line_name, trackview.session(), *this, *group, audio_region()->envelope());
182 if (!(_flags & EnvelopeVisible)) {
190 set_y_position_and_height (0, trackview.height);
193 region_sync_changed ();
194 region_resized (BoundsChanged);
195 set_waveview_data_src();
197 envelope_active_changed ();
198 fade_in_active_changed ();
199 fade_out_active_changed ();
201 fade_in_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
202 fade_in_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
203 fade_out_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
204 fade_out_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
208 /* XXX sync mark drag? */
211 AudioRegionView::~AudioRegionView ()
213 in_destructor = true;
215 RegionViewGoingAway (this); /* EMIT_SIGNAL */
217 for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
218 gnome_canvas_waveview_cache_destroy (*cache);
221 /* all waveviews etc will be destroyed when the group is destroyed */
228 boost::shared_ptr<ARDOUR::AudioRegion>
229 AudioRegionView::audio_region() const
231 // "Guaranteed" to succeed...
232 return boost::dynamic_pointer_cast<AudioRegion>(_region);
236 AudioRegionView::region_changed (Change what_changed)
238 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionView::region_changed), what_changed));
240 RegionView::region_changed(what_changed);
242 if (what_changed & AudioRegion::ScaleAmplitudeChanged) {
243 region_scale_amplitude_changed ();
245 if (what_changed & AudioRegion::FadeInChanged) {
248 if (what_changed & AudioRegion::FadeOutChanged) {
251 if (what_changed & AudioRegion::FadeInActiveChanged) {
252 fade_in_active_changed ();
254 if (what_changed & AudioRegion::FadeOutActiveChanged) {
255 fade_out_active_changed ();
257 if (what_changed & AudioRegion::EnvelopeActiveChanged) {
258 envelope_active_changed ();
263 AudioRegionView::fade_in_changed ()
265 reset_fade_in_shape ();
269 AudioRegionView::fade_out_changed ()
271 reset_fade_out_shape ();
274 AudioRegionView::fade_in_active_changed ()
278 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
280 if (audio_region()->fade_in_active()) {
281 col = RGBA_TO_UINT(r,g,b,120);
282 fade_in_shape->property_fill_color_rgba() = col;
283 fade_in_shape->property_width_pixels() = 0;
284 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
286 col = RGBA_TO_UINT(r,g,b,0);
287 fade_in_shape->property_fill_color_rgba() = col;
288 fade_in_shape->property_width_pixels() = 1;
289 fade_in_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
294 AudioRegionView::fade_out_active_changed ()
298 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
300 if (audio_region()->fade_out_active()) {
301 col = RGBA_TO_UINT(r,g,b,120);
302 fade_out_shape->property_fill_color_rgba() = col;
303 fade_out_shape->property_width_pixels() = 0;
304 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,0);
306 col = RGBA_TO_UINT(r,g,b,0);
307 fade_out_shape->property_fill_color_rgba() = col;
308 fade_out_shape->property_width_pixels() = 1;
309 fade_out_shape->property_outline_color_rgba() = RGBA_TO_UINT(r,g,b,255);
315 AudioRegionView::region_scale_amplitude_changed ()
317 ENSURE_GUI_THREAD (mem_fun(*this, &AudioRegionView::region_scale_amplitude_changed));
319 for (uint32_t n = 0; n < waves.size(); ++n) {
320 // force a reload of the cache
321 waves[n]->property_data_src() = _region.get();
326 AudioRegionView::region_renamed ()
328 Glib::ustring str = RegionView::make_name ();
330 if (audio_region()->speed_mismatch (trackview.session().frame_rate())) {
331 str = string ("*") + str;
334 if (_region->muted()) {
335 str = string ("!") + str;
338 set_item_name (str, this);
343 AudioRegionView::region_resized (Change what_changed)
345 RegionView::region_resized(what_changed);
347 if (what_changed & Change (StartChanged|LengthChanged)) {
349 for (uint32_t n = 0; n < waves.size(); ++n) {
350 waves[n]->property_region_start() = _region->start();
353 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
355 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
356 (*w)->property_region_start() = _region->start();
363 AudioRegionView::reset_width_dependent_items (double pixel_width)
365 RegionView::reset_width_dependent_items(pixel_width);
366 assert(_pixel_width == pixel_width);
369 zero_line->property_x2() = pixel_width - 1.0;
372 if (fade_in_handle) {
373 if (pixel_width <= 6.0) {
374 fade_in_handle->hide();
375 fade_out_handle->hide();
378 fade_in_handle->hide();
379 fade_out_handle->hide();
381 fade_in_handle->show();
382 fade_out_handle->show();
387 reset_fade_shapes ();
391 AudioRegionView::region_muted ()
393 RegionView::region_muted();
395 for (uint32_t n=0; n < waves.size(); ++n) {
396 if (_region->muted()) {
397 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
399 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
405 AudioRegionView::set_y_position_and_height (double y, double h)
407 RegionView::set_y_position_and_height(y, h - 1);
412 uint32_t const wcnt = waves.size();
413 for (uint32_t n = 0; n < wcnt; ++n) {
416 if (h <= NAME_HIGHLIGHT_THRESH) {
417 ht = ((_height - 2 * wcnt) / (double) wcnt);
419 ht = (((_height - 2 * wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
422 double const yoff = n * (ht + 1);
424 waves[n]->property_height() = ht;
425 waves[n]->property_y() = _y_position + yoff + 2;
429 if ((_height / wcnt) < NAME_HIGHLIGHT_SIZE) {
432 if (_flags & EnvelopeVisible) {
436 gain_line->set_y_position_and_height ((uint32_t) _y_position, (uint32_t) rint (_height - NAME_HIGHLIGHT_SIZE));
439 setup_fade_handle_positions ();
441 reset_fade_shapes ();
444 name_text->raise_to_top();
449 AudioRegionView::setup_fade_handle_positions()
451 /* position of fade handle offset from the top of the region view */
452 double const handle_pos = 2;
453 /* height of fade handles */
454 double const handle_height = 5;
456 if (fade_in_handle) {
457 fade_in_handle->property_y1() = _y_position + handle_pos;
458 fade_in_handle->property_y2() = _y_position + handle_pos + handle_height;
461 if (fade_out_handle) {
462 fade_out_handle->property_y1() = _y_position + handle_pos;
463 fade_out_handle->property_y2() = _y_position + handle_pos + handle_height;
468 AudioRegionView::manage_zero_line ()
474 if (_height >= 100) {
475 double const wave_midpoint = _y_position + (_height - NAME_HIGHLIGHT_SIZE) / 2.0;
476 zero_line->property_y1() = wave_midpoint;
477 zero_line->property_y2() = wave_midpoint;
485 AudioRegionView::reset_fade_shapes ()
487 reset_fade_in_shape ();
488 reset_fade_out_shape ();
492 AudioRegionView::reset_fade_in_shape ()
494 reset_fade_in_shape_width ((nframes_t) audio_region()->fade_in()->back()->when);
498 AudioRegionView::reset_fade_in_shape_width (nframes_t width)
500 if (fade_in_handle == 0) {
504 /* smallest size for a fade is 64 frames */
506 width = std::max ((nframes_t) 64, width);
509 double pwidth = width / samples_per_unit;
510 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
514 fade_in_shape->hide();
515 fade_in_handle->hide();
519 double handle_center;
520 handle_center = pwidth;
522 if (handle_center > 7.0) {
523 handle_center -= 3.0;
528 fade_in_handle->property_x1() = handle_center - 3.0;
529 fade_in_handle->property_x2() = handle_center + 3.0;
532 fade_in_shape->hide();
536 fade_in_shape->show();
538 float curve[npoints];
539 audio_region()->fade_in()->curve().get_vector (0, audio_region()->fade_in()->back()->when, curve, npoints);
541 points = get_canvas_points ("fade in shape", npoints+3);
543 if (_height > NAME_HIGHLIGHT_THRESH) {
544 h = _height - NAME_HIGHLIGHT_SIZE;
549 /* points *MUST* be in anti-clockwise order */
552 double xdelta = pwidth/npoints;
554 for (pi = 0, pc = 0; pc < npoints; ++pc) {
555 (*points)[pi].set_x(1 + (pc * xdelta));
556 (*points)[pi++].set_y(_y_position + 2 + (h - (curve[pc] * h)));
561 (*points)[pi].set_x(pwidth);
562 (*points)[pi++].set_y(_y_position + 2);
564 (*points)[pi].set_x(1);
565 (*points)[pi++].set_y(_y_position + 2);
567 /* connect the dots ... */
569 (*points)[pi] = (*points)[0];
571 fade_in_shape->property_points() = *points;
576 AudioRegionView::reset_fade_out_shape ()
578 reset_fade_out_shape_width ((nframes_t) audio_region()->fade_out()->back()->when);
582 AudioRegionView::reset_fade_out_shape_width (nframes_t width)
584 if (fade_out_handle == 0) {
588 /* smallest size for a fade is 64 frames */
590 width = std::max ((nframes_t) 64, width);
593 double pwidth = width / samples_per_unit;
594 uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
598 fade_out_shape->hide();
599 fade_out_handle->hide();
603 double handle_center;
604 handle_center = (_region->length() - width) / samples_per_unit;
606 if (handle_center > 7.0) {
607 handle_center -= 3.0;
612 fade_out_handle->property_x1() = handle_center - 3.0;
613 fade_out_handle->property_x2() = handle_center + 3.0;
615 /* don't show shape if its too small */
618 fade_out_shape->hide();
622 fade_out_shape->show();
624 float curve[npoints];
625 audio_region()->fade_out()->curve().get_vector (0, audio_region()->fade_out()->back()->when, curve, npoints);
627 if (_height > NAME_HIGHLIGHT_THRESH) {
628 h = _height - NAME_HIGHLIGHT_SIZE;
633 /* points *MUST* be in anti-clockwise order */
635 points = get_canvas_points ("fade out shape", npoints+3);
638 double xdelta = pwidth/npoints;
640 for (pi = 0, pc = 0; pc < npoints; ++pc) {
641 (*points)[pi].set_x(_pixel_width - 1 - pwidth + (pc*xdelta));
642 (*points)[pi++].set_y(_y_position + 2 + (h - (curve[pc] * h)));
647 (*points)[pi].set_x(_pixel_width);
648 (*points)[pi++].set_y(_y_position + h);
650 (*points)[pi].set_x(_pixel_width);
651 (*points)[pi++].set_y(_y_position + 2);
653 /* connect the dots ... */
655 (*points)[pi] = (*points)[0];
657 fade_out_shape->property_points() = *points;
662 AudioRegionView::set_samples_per_unit (gdouble spu)
664 RegionView::set_samples_per_unit (spu);
666 if (_flags & WaveformVisible) {
667 for (uint32_t n=0; n < waves.size(); ++n) {
668 waves[n]->property_samples_per_unit() = spu;
676 reset_fade_shapes ();
680 AudioRegionView::set_amplitude_above_axis (gdouble spp)
682 for (uint32_t n=0; n < waves.size(); ++n) {
683 waves[n]->property_amplitude_above_axis() = spp;
688 AudioRegionView::compute_colors (Gdk::Color& basic_color)
690 RegionView::compute_colors(basic_color);
694 /* gain color computed in envelope_active_changed() */
696 UINT_TO_RGBA (fill_color, &r, &g, &b, &a);
697 fade_color = RGBA_TO_UINT(r,g,b,120);
701 AudioRegionView::set_colors ()
703 RegionView::set_colors();
706 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
709 for (uint32_t n=0; n < waves.size(); ++n) {
710 if (_region->muted()) {
711 waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
713 waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
716 waves[n]->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
717 waves[n]->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
722 AudioRegionView::show_region_editor ()
725 editor = new AudioRegionEditor (trackview.session(), audio_region(), *this);
726 // GTK2FIX : how to ensure float without realizing
727 // editor->realize ();
728 // trackview.editor.ensure_float (*editor);
736 AudioRegionView::set_waveform_visible (bool yn)
738 if (((_flags & WaveformVisible) != yn)) {
740 for (uint32_t n=0; n < waves.size(); ++n) {
741 /* make sure the zoom level is correct, since we don't update
742 this when waveforms are hidden.
744 waves[n]->property_samples_per_unit() = samples_per_unit;
747 _flags |= WaveformVisible;
749 for (uint32_t n=0; n < waves.size(); ++n) {
752 _flags &= ~WaveformVisible;
759 AudioRegionView::temporarily_hide_envelope ()
767 AudioRegionView::unhide_envelope ()
769 if (gain_line && (_flags & EnvelopeVisible)) {
775 AudioRegionView::set_envelope_visible (bool yn)
777 if (gain_line && ((_flags & EnvelopeVisible) != yn)) {
780 _flags |= EnvelopeVisible;
783 _flags &= ~EnvelopeVisible;
790 AudioRegionView::create_waves ()
792 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
794 if (!atv.get_diskstream()) {
798 uint32_t nchans = atv.get_diskstream()->n_channels().n_audio();
800 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
801 for (uint32_t n = 0; n < nchans; ++n) {
802 tmp_waves.push_back (0);
805 for (uint32_t n = 0; n < nchans; ++n) {
807 if (n >= audio_region()->n_channels()) {
811 wave_caches.push_back (WaveView::create_cache ());
814 if (audio_region()->audio_source(n)->peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n), data_ready_connection)) {
815 create_one_wave (n, true);
819 create_one_wave (n, true);
825 AudioRegionView::create_one_wave (uint32_t which, bool direct)
827 RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
828 uint32_t nchans = atv.get_diskstream()->n_channels().n_audio();
830 uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
833 if (trackview.height < NAME_HIGHLIGHT_SIZE) {
834 ht = ((trackview.height) / (double) nchans);
836 ht = ((trackview.height - NAME_HIGHLIGHT_SIZE) / (double) nchans);
839 gdouble yoff = which * ht;
841 WaveView *wave = new WaveView(*group);
843 wave->property_data_src() = (gpointer) _region.get();
844 wave->property_cache() = wave_caches[which];
845 wave->property_cache_updater() = true;
846 wave->property_channel() = which;
847 wave->property_length_function() = (gpointer) region_length_from_c;
848 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
849 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
850 wave->property_x() = 0.0;
851 wave->property_y() = yoff;
852 wave->property_height() = (double) ht;
853 wave->property_samples_per_unit() = samples_per_unit;
854 wave->property_amplitude_above_axis() = _amplitude_above_axis;
855 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_WaveForm.get();
856 wave->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
857 wave->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
858 wave->property_region_start() = _region->start();
859 wave->property_rectified() = (bool) (_flags & WaveformRectified);
860 wave->property_logscaled() = (bool) (_flags & WaveformLogScaled);
862 if (!(_flags & WaveformVisible)) {
866 /* note: calling this function is serialized by the lock
867 held in the peak building thread that signals that
868 peaks are ready for use *or* by the fact that it is
869 called one by one from the GUI thread.
872 if (which < nchans) {
873 tmp_waves[which] = wave;
875 /* n-channel track, >n-channel source */
878 /* see if we're all ready */
880 for (n = 0; n < nchans; ++n) {
881 if (tmp_waves[n] == 0) {
886 if (n == nwaves && waves.empty()) {
887 /* all waves are ready */
888 tmp_waves.resize(nwaves);
893 /* all waves created, don't hook into peaks ready anymore */
894 data_ready_connection.disconnect ();
898 zero_line = new ArdourCanvas::SimpleLine (*group);
899 zero_line->property_x1() = (gdouble) 1.0;
900 zero_line->property_x2() = (gdouble) (_region->length() / samples_per_unit) - 1.0;
901 zero_line->property_color_rgba() = (guint) ARDOUR_UI::config()->canvasvar_ZeroLine.get();
908 AudioRegionView::peaks_ready_handler (uint32_t which)
910 Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &AudioRegionView::create_one_wave), which, false));
914 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
916 if (gain_line == 0) {
922 /* don't create points that can't be seen */
924 set_envelope_visible (true);
931 nframes_t fx = trackview.editor.pixel_to_frame (x);
933 if (fx > _region->length()) {
937 /* compute vertical fractional position */
939 y = 1.0 - ((y - _y_position) / (_height - NAME_HIGHLIGHT_SIZE));
941 /* map using gain line */
943 gain_line->view_to_model_y (y);
945 trackview.session().begin_reversible_command (_("add gain control point"));
946 XMLNode &before = audio_region()->envelope()->get_state();
948 if (!audio_region()->envelope_active()) {
949 XMLNode ®ion_before = audio_region()->get_state();
950 audio_region()->set_envelope_active(true);
951 XMLNode ®ion_after = audio_region()->get_state();
952 trackview.session().add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), ®ion_before, ®ion_after));
955 audio_region()->envelope()->add (fx, y);
957 XMLNode &after = audio_region()->envelope()->get_state();
958 trackview.session().add_command (new MementoCommand<AutomationList>(*audio_region()->envelope().get(), &before, &after));
959 trackview.session().commit_reversible_command ();
963 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
965 ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
966 audio_region()->envelope()->erase (cp->model());
970 AudioRegionView::store_flags()
972 XMLNode *node = new XMLNode ("GUI");
974 node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
975 node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no");
976 node->add_property ("waveform-rectified", (_flags & WaveformRectified) ? "yes" : "no");
977 node->add_property ("waveform-logscaled", (_flags & WaveformLogScaled) ? "yes" : "no");
979 _region->add_extra_xml (*node);
983 AudioRegionView::set_flags (XMLNode* node)
987 if ((prop = node->property ("waveform-visible")) != 0) {
988 if (prop->value() == "yes") {
989 _flags |= WaveformVisible;
993 if ((prop = node->property ("envelope-visible")) != 0) {
994 if (prop->value() == "yes") {
995 _flags |= EnvelopeVisible;
999 if ((prop = node->property ("waveform-rectified")) != 0) {
1000 if (prop->value() == "yes") {
1001 _flags |= WaveformRectified;
1005 if ((prop = node->property ("waveform-logscaled")) != 0) {
1006 if (prop->value() == "yes") {
1007 _flags |= WaveformLogScaled;
1013 AudioRegionView::set_waveform_shape (WaveformShape shape)
1017 /* this slightly odd approach is to leave the door open to
1018 other "shapes" such as spectral displays, etc.
1031 if (yn != (bool) (_flags & WaveformRectified)) {
1032 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1033 (*wave)->property_rectified() = yn;
1045 _flags |= WaveformRectified;
1047 _flags &= ~WaveformRectified;
1054 AudioRegionView::set_waveform_scale (WaveformScale scale)
1056 bool yn = (scale == LogWaveform);
1058 if (yn != (bool) (_flags & WaveformLogScaled)) {
1059 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1060 (*wave)->property_logscaled() = yn;
1064 _flags |= WaveformLogScaled;
1066 _flags &= ~WaveformLogScaled;
1074 AudioRegionView::add_ghost (AutomationTimeAxisView& atv)
1076 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1079 double unit_position = _region->position () / samples_per_unit;
1080 GhostRegion* ghost = new GhostRegion (atv, unit_position);
1083 nchans = rtv->get_diskstream()->n_channels().n_audio();
1085 for (uint32_t n = 0; n < nchans; ++n) {
1087 if (n >= audio_region()->n_channels()) {
1091 WaveView *wave = new WaveView(*ghost->group);
1093 wave->property_data_src() = _region.get();
1094 wave->property_cache() = wave_caches[n];
1095 wave->property_cache_updater() = false;
1096 wave->property_channel() = n;
1097 wave->property_length_function() = (gpointer)region_length_from_c;
1098 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1099 wave->property_peak_function() = (gpointer) region_read_peaks_from_c;
1100 wave->property_x() = 0.0;
1101 wave->property_samples_per_unit() = samples_per_unit;
1102 wave->property_amplitude_above_axis() = _amplitude_above_axis;
1103 wave->property_wave_color() = ARDOUR_UI::config()->canvasvar_GhostTrackWave.get();
1104 wave->property_clip_color() = ARDOUR_UI::config()->canvasvar_GhostTrackWaveClip.get();
1105 wave->property_zero_color() = ARDOUR_UI::config()->canvasvar_GhostTrackZeroLine.get();
1106 wave->property_region_start() = _region->start();
1108 ghost->waves.push_back(wave);
1111 ghost->set_height ();
1112 ghost->set_duration (_region->length() / samples_per_unit);
1113 ghosts.push_back (ghost);
1115 ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost));
1121 AudioRegionView::entered ()
1123 if (gain_line && _flags & EnvelopeVisible) {
1124 gain_line->show_all_control_points ();
1128 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1131 if (fade_in_handle) {
1132 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1133 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1138 AudioRegionView::exited ()
1141 gain_line->hide_all_but_selected_control_points ();
1145 UINT_TO_RGBA(fade_color,&r,&g,&b,&a);
1148 if (fade_in_handle) {
1149 fade_in_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1150 fade_out_handle->property_fill_color_rgba() = RGBA_TO_UINT(r,g,b,a);
1155 AudioRegionView::envelope_active_changed ()
1158 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
1163 AudioRegionView::set_waveview_data_src()
1166 double unit_length= _region->length() / samples_per_unit;
1168 for (uint32_t n = 0; n < waves.size(); ++n) {
1169 // TODO: something else to let it know the channel
1170 waves[n]->property_data_src() = _region.get();
1173 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1175 (*i)->set_duration (unit_length);
1177 for (vector<WaveView*>::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) {
1178 (*w)->property_data_src() = _region.get();
1185 AudioRegionView::color_handler ()
1187 //case cMutedWaveForm:
1189 //case cWaveFormClip:
1193 //case cGainLineInactive:
1195 envelope_active_changed();