2 Copyright (C) 2001-2006 Paul Davis
4 This program is free software; you can r>edistribute 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/profile.h"
31 #include "ardour/session.h"
33 #include "pbd/memento_command.h"
34 #include "pbd/stacktrace.h"
36 #include "evoral/Curve.hpp"
38 #include "streamview.h"
39 #include "audio_region_view.h"
40 #include "audio_time_axis.h"
41 #include "simplerect.h"
42 #include "simpleline.h"
44 #include "public_editor.h"
45 #include "audio_region_editor.h"
46 #include "region_gain_line.h"
47 #include "control_point.h"
48 #include "ghostregion.h"
49 #include "audio_time_axis.h"
51 #include "rgb_macros.h"
52 #include "gui_thread.h"
53 #include "ardour_ui.h"
57 #define MUTED_ALPHA 10
60 using namespace ARDOUR
;
62 using namespace Editing
;
63 using namespace ArdourCanvas
;
65 static const int32_t sync_mark_width
= 9;
67 AudioRegionView::AudioRegionView (ArdourCanvas::Group
*parent
, RouteTimeAxisView
&tv
, boost::shared_ptr
<AudioRegion
> r
, double spu
,
68 Gdk::Color
const & basic_color
)
69 : RegionView (parent
, tv
, r
, spu
, basic_color
)
75 , fade_position_line(0)
77 , _amplitude_above_axis(1.0)
84 AudioRegionView::AudioRegionView (ArdourCanvas::Group
*parent
, RouteTimeAxisView
&tv
, boost::shared_ptr
<AudioRegion
> r
, double spu
,
85 Gdk::Color
const & basic_color
, bool recording
, TimeAxisViewItem::Visibility visibility
)
86 : RegionView (parent
, tv
, r
, spu
, basic_color
, recording
, visibility
)
92 , fade_position_line(0)
94 , _amplitude_above_axis(1.0)
100 AudioRegionView::AudioRegionView (const AudioRegionView
& other
, boost::shared_ptr
<AudioRegion
> other_region
)
101 : RegionView (other
, boost::shared_ptr
<Region
> (other_region
))
106 , fade_position_line(0)
108 , _amplitude_above_axis (other
._amplitude_above_axis
)
109 , _flags (other
._flags
)
115 UINT_TO_RGBA (other
.fill_color
, &r
, &g
, &b
, &a
);
116 c
.set_rgb_p (r
/255.0, g
/255.0, b
/255.0);
122 AudioRegionView::init (Gdk::Color
const & basic_color
, bool wfd
)
124 // FIXME: Some redundancy here with RegionView::init. Need to figure out
125 // where order is important and where it isn't...
127 RegionView::init (basic_color
, wfd
);
131 _amplitude_above_axis
= 1.0;
134 if ((node
= _region
->extra_xml ("GUI")) != 0) {
137 _flags
= WaveformVisible
;
141 /* make envelope visible if it has anything interesting in it */
142 boost::shared_ptr
<AutomationList
> env
= audio_region()->envelope ();
143 if (env
->size() > 2 || (env
->size() == 2 && env
->front()->value
!= env
->back()->value
)) {
144 _flags
|= EnvelopeVisible
;
147 compute_colors (basic_color
);
151 fade_in_shape
= new ArdourCanvas::Polygon (*group
);
152 fade_in_shape
->property_fill_color_rgba() = fade_color
;
153 fade_in_shape
->set_data ("regionview", this);
155 fade_out_shape
= new ArdourCanvas::Polygon (*group
);
156 fade_out_shape
->property_fill_color_rgba() = fade_color
;
157 fade_out_shape
->set_data ("regionview", this);
160 fade_in_handle
= new ArdourCanvas::SimpleRect (*group
);
161 fade_in_handle
->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fill_color
, 0);
162 fade_in_handle
->property_outline_pixels() = 0;
164 fade_in_handle
->set_data ("regionview", this);
166 fade_out_handle
= new ArdourCanvas::SimpleRect (*group
);
167 fade_out_handle
->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fill_color
, 0);
168 fade_out_handle
->property_outline_pixels() = 0;
170 fade_out_handle
->set_data ("regionview", this);
172 fade_position_line
= new ArdourCanvas::SimpleLine (*group
);
173 fade_position_line
->property_color_rgba() = 0xBBBBBBAA;
174 fade_position_line
->property_y1() = 7;
175 fade_position_line
->property_y2() = _height
- TimeAxisViewItem::NAME_HIGHLIGHT_SIZE
- 1;
177 fade_position_line
->hide();
180 setup_fade_handle_positions ();
182 if (!trackview
.session()->config
.get_show_region_fades()) {
183 set_fade_visibility (false);
186 const string line_name
= _region
->name() + ":gain";
188 if (!Profile
->get_sae()) {
189 gain_line
= new AudioRegionGainLine (line_name
, *this, *group
, audio_region()->envelope());
192 if (!(_flags
& EnvelopeVisible
)) {
200 set_height (trackview
.current_height());
203 region_sync_changed ();
205 region_resized (ARDOUR::bounds_change
);
206 set_waveview_data_src();
208 envelope_active_changed ();
209 fade_in_active_changed ();
210 fade_out_active_changed ();
212 reset_width_dependent_items (_pixel_width
);
214 fade_in_shape
->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event
), fade_in_shape
, this));
215 if (fade_in_handle
) {
216 fade_in_handle
->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event
), fade_in_handle
, this));
219 fade_out_shape
->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event
), fade_out_shape
, this));
221 if (fade_out_handle
) {
222 fade_out_handle
->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event
), fade_out_handle
, this));
227 /* XXX sync mark drag? */
230 AudioRegionView::~AudioRegionView ()
232 in_destructor
= true;
234 RegionViewGoingAway (this); /* EMIT_SIGNAL */
236 for (vector
<GnomeCanvasWaveViewCache
*>::iterator cache
= wave_caches
.begin(); cache
!= wave_caches
.end() ; ++cache
) {
237 gnome_canvas_waveview_cache_destroy (*cache
);
240 for (vector
<ScopedConnection
*>::iterator i
= _data_ready_connections
.begin(); i
!= _data_ready_connections
.end(); ++i
) {
244 for (list
<std::pair
<framepos_t
, ArdourCanvas::Line
*> >::iterator i
= feature_lines
.begin(); i
!= feature_lines
.end(); ++i
) {
245 delete ((*i
).second
);
248 /* all waveviews etc will be destroyed when the group is destroyed */
253 boost::shared_ptr
<ARDOUR::AudioRegion
>
254 AudioRegionView::audio_region() const
256 // "Guaranteed" to succeed...
257 return boost::dynamic_pointer_cast
<AudioRegion
>(_region
);
261 AudioRegionView::region_changed (const PropertyChange
& what_changed
)
263 ENSURE_GUI_THREAD (*this, &AudioRegionView::region_changed
, what_changed
);
264 // cerr << "AudioRegionView::region_changed() called" << endl;
266 RegionView::region_changed (what_changed
);
268 if (what_changed
.contains (ARDOUR::Properties::scale_amplitude
)) {
269 region_scale_amplitude_changed ();
271 if (what_changed
.contains (ARDOUR::Properties::fade_in
)) {
274 if (what_changed
.contains (ARDOUR::Properties::fade_out
)) {
277 if (what_changed
.contains (ARDOUR::Properties::fade_in_active
)) {
278 fade_in_active_changed ();
280 if (what_changed
.contains (ARDOUR::Properties::fade_out_active
)) {
281 fade_out_active_changed ();
283 if (what_changed
.contains (ARDOUR::Properties::envelope_active
)) {
284 envelope_active_changed ();
286 if (what_changed
.contains (ARDOUR::Properties::valid_transients
)) {
287 transients_changed ();
292 AudioRegionView::fade_in_changed ()
294 reset_fade_in_shape ();
298 AudioRegionView::fade_out_changed ()
300 reset_fade_out_shape ();
303 AudioRegionView::fade_in_active_changed ()
305 if (audio_region()->fade_in_active()) {
306 fade_in_shape
->property_fill_color_rgba() = RGBA_TO_UINT(45,45,45,90); // FIXME make a themeable colour
307 fade_in_shape
->property_width_pixels() = 1;
309 fade_in_shape
->property_fill_color_rgba() = RGBA_TO_UINT(45,45,45,20); // FIXME make a themeable colour
310 fade_in_shape
->property_width_pixels() = 1;
315 AudioRegionView::fade_out_active_changed ()
317 if (audio_region()->fade_out_active()) {
318 fade_out_shape
->property_fill_color_rgba() = RGBA_TO_UINT(45,45,45,90); // FIXME make a themeable colour
319 fade_out_shape
->property_width_pixels() = 1;
321 fade_out_shape
->property_fill_color_rgba() = RGBA_TO_UINT(45,45,45,20); // FIXME make a themeable colour
322 fade_out_shape
->property_width_pixels() = 1;
328 AudioRegionView::region_scale_amplitude_changed ()
330 ENSURE_GUI_THREAD (*this, &AudioRegionView::region_scale_amplitude_changed
)
332 for (uint32_t n
= 0; n
< waves
.size(); ++n
) {
333 // force a reload of the cache
334 waves
[n
]->property_data_src() = _region
.get();
339 AudioRegionView::region_renamed ()
341 std::string str
= RegionView::make_name ();
343 if (audio_region()->speed_mismatch (trackview
.session()->frame_rate())) {
344 str
= string ("*") + str
;
347 if (_region
->muted()) {
348 str
= string ("!") + str
;
351 set_item_name (str
, this);
356 AudioRegionView::region_resized (const PropertyChange
& what_changed
)
358 AudioGhostRegion
* agr
;
360 RegionView::region_resized(what_changed
);
361 PropertyChange interesting_stuff
;
363 interesting_stuff
.add (ARDOUR::Properties::start
);
364 interesting_stuff
.add (ARDOUR::Properties::length
);
366 if (what_changed
.contains (interesting_stuff
)) {
368 for (uint32_t n
= 0; n
< waves
.size(); ++n
) {
369 waves
[n
]->property_region_start() = _region
->start();
372 for (vector
<GhostRegion
*>::iterator i
= ghosts
.begin(); i
!= ghosts
.end(); ++i
) {
373 if ((agr
= dynamic_cast<AudioGhostRegion
*>(*i
)) != 0) {
375 for (vector
<WaveView
*>::iterator w
= agr
->waves
.begin(); w
!= agr
->waves
.end(); ++w
) {
376 (*w
)->property_region_start() = _region
->start();
381 /* hide transient lines that extend beyond the region end */
383 list
<std::pair
<framepos_t
, ArdourCanvas::Line
*> >::iterator l
;
385 for (l
= feature_lines
.begin(); l
!= feature_lines
.end(); ++l
) {
386 if (l
->first
> _region
->length() - 1) {
396 AudioRegionView::reset_width_dependent_items (double pixel_width
)
398 RegionView::reset_width_dependent_items(pixel_width
);
399 assert(_pixel_width
== pixel_width
);
401 if (fade_in_handle
) {
402 if (pixel_width
<= 6.0 || _height
< 5.0 || !trackview
.session()->config
.get_show_region_fades()) {
403 fade_in_handle
->hide();
404 fade_out_handle
->hide();
407 fade_in_handle
->show();
408 fade_out_handle
->show();
412 AnalysisFeatureList analysis_features
= _region
->transients();
413 AnalysisFeatureList::const_iterator i
;
415 list
<std::pair
<framepos_t
, ArdourCanvas::Line
*> >::iterator l
;
417 for (i
= analysis_features
.begin(), l
= feature_lines
.begin(); i
!= analysis_features
.end() && l
!= feature_lines
.end(); ++i
, ++l
) {
419 float x_pos
= trackview
.editor().frame_to_pixel (*i
);
421 ArdourCanvas::Points points
;
422 points
.push_back(Gnome::Art::Point(x_pos
, 2.0)); // first x-coord needs to be a non-normal value
423 points
.push_back(Gnome::Art::Point(x_pos
, _height
- TimeAxisViewItem::NAME_HIGHLIGHT_SIZE
- 1));
426 (*l
).second
->property_points() = points
;
429 reset_fade_shapes ();
433 AudioRegionView::region_muted ()
435 RegionView::region_muted();
437 for (uint32_t n
=0; n
< waves
.size(); ++n
) {
438 if (_region
->muted()) {
439 waves
[n
]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm
.get(), MUTED_ALPHA
);
441 waves
[n
]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm
.get();
447 AudioRegionView::setup_fade_handle_positions()
449 /* position of fade handle offset from the top of the region view */
450 double const handle_pos
= 2;
451 /* height of fade handles */
452 double const handle_height
= 5;
454 if (fade_in_handle
) {
455 fade_in_handle
->property_y1() = handle_pos
;
456 fade_in_handle
->property_y2() = handle_pos
+ handle_height
;
459 if (fade_out_handle
) {
460 fade_out_handle
->property_y1() = handle_pos
;
461 fade_out_handle
->property_y2() = handle_pos
+ handle_height
;
466 AudioRegionView::set_height (gdouble height
)
468 RegionView::set_height (height
);
470 uint32_t wcnt
= waves
.size();
472 for (uint32_t n
= 0; n
< wcnt
; ++n
) {
475 if (height
< NAME_HIGHLIGHT_THRESH
) {
476 ht
= ((height
- 2 * wcnt
) / (double) wcnt
);
478 ht
= (((height
- 2 * wcnt
) - NAME_HIGHLIGHT_SIZE
) / (double) wcnt
);
481 gdouble yoff
= n
* (ht
+ 1);
483 waves
[n
]->property_height() = ht
;
484 waves
[n
]->property_y() = yoff
+ 2;
489 if ((height
/wcnt
) < NAME_HIGHLIGHT_THRESH
) {
492 if (_flags
& EnvelopeVisible
) {
497 gain_line
->set_height ((uint32_t) rint (height
- NAME_HIGHLIGHT_SIZE
) - 2);
500 reset_fade_shapes ();
502 /* Update hights for any active feature lines */
503 list
<std::pair
<framepos_t
, ArdourCanvas::Line
*> >::iterator l
;
505 for (l
= feature_lines
.begin(); l
!= feature_lines
.end(); ++l
) {
507 float pos_x
= trackview
.editor().frame_to_pixel((*l
).first
);
509 ArdourCanvas::Points points
;
511 points
.push_back(Gnome::Art::Point(pos_x
, 2.0)); // first x-coord needs to be a non-normal value
512 points
.push_back(Gnome::Art::Point(pos_x
, _height
- TimeAxisViewItem::NAME_HIGHLIGHT_SIZE
- 1));
514 (*l
).second
->property_points() = points
;
517 if (fade_position_line
) {
519 if (height
< NAME_HIGHLIGHT_THRESH
) {
520 fade_position_line
->property_y2() = _height
- 1;
523 fade_position_line
->property_y2() = _height
- TimeAxisViewItem::NAME_HIGHLIGHT_SIZE
- 1;
528 name_pixbuf
->raise_to_top();
533 AudioRegionView::reset_fade_shapes ()
535 reset_fade_in_shape ();
536 reset_fade_out_shape ();
540 AudioRegionView::reset_fade_in_shape ()
542 reset_fade_in_shape_width ((framecnt_t
) audio_region()->fade_in()->back()->when
);
546 AudioRegionView::reset_fade_in_shape_width (framecnt_t width
)
548 if (fade_in_handle
== 0) {
552 /* smallest size for a fade is 64 frames */
554 width
= std::max ((framecnt_t
) 64, width
);
558 /* round here to prevent little visual glitches with sub-pixel placement */
559 double const pwidth
= rint (width
/ samples_per_unit
);
560 uint32_t npoints
= std::min (gdk_screen_width(), (int) pwidth
);
564 fade_in_shape
->hide();
565 fade_in_handle
->hide();
569 double const handle_center
= pwidth
;
571 /* Put the fade in handle so that its left side is at the end-of-fade line */
572 fade_in_handle
->property_x1() = handle_center
;
573 fade_in_handle
->property_x2() = handle_center
+ 6;
576 fade_in_shape
->hide();
580 if (trackview
.session()->config
.get_show_region_fades()) {
581 fade_in_shape
->show();
584 float curve
[npoints
];
585 audio_region()->fade_in()->curve().get_vector (0, audio_region()->fade_in()->back()->when
, curve
, npoints
);
587 points
= get_canvas_points ("fade in shape", npoints
+ 3);
589 if (_height
>= NAME_HIGHLIGHT_THRESH
) {
590 h
= _height
- NAME_HIGHLIGHT_SIZE
- 2;
595 /* points *MUST* be in anti-clockwise order */
598 double xdelta
= pwidth
/npoints
;
600 for (pi
= 0, pc
= 0; pc
< npoints
; ++pc
) {
601 (*points
)[pi
].set_x(1 + (pc
* xdelta
));
602 (*points
)[pi
++].set_y(2 + (h
- (curve
[pc
] * h
)));
607 (*points
)[pi
].set_x(pwidth
);
608 (*points
)[pi
++].set_y(2);
610 (*points
)[pi
].set_x(1);
611 (*points
)[pi
++].set_y(2);
613 /* connect the dots ... */
615 (*points
)[pi
] = (*points
)[0];
617 fade_in_shape
->property_points() = *points
;
620 /* ensure trim handle stays on top */
621 if (frame_handle_start
) {
622 frame_handle_start
->raise_to_top();
627 AudioRegionView::reset_fade_out_shape ()
629 reset_fade_out_shape_width ((framecnt_t
) audio_region()->fade_out()->back()->when
);
633 AudioRegionView::reset_fade_out_shape_width (framecnt_t width
)
635 if (fade_out_handle
== 0) {
639 /* smallest size for a fade is 64 frames */
641 width
= std::max ((framecnt_t
) 64, width
);
645 /* round here to prevent little visual glitches with sub-pixel placement */
646 double const pwidth
= rint (width
/ samples_per_unit
);
647 uint32_t npoints
= std::min (gdk_screen_width(), (int) pwidth
);
651 fade_out_shape
->hide();
652 fade_out_handle
->hide();
656 double const handle_center
= (_region
->length() - width
) / samples_per_unit
;
658 /* Put the fade out handle so that its right side is at the end-of-fade line;
659 * it's `one out' for precise pixel accuracy.
661 fade_out_handle
->property_x1() = handle_center
- 5;
662 fade_out_handle
->property_x2() = handle_center
+ 1;
664 /* don't show shape if its too small */
667 fade_out_shape
->hide();
671 if (trackview
.session()->config
.get_show_region_fades()) {
672 fade_out_shape
->show();
675 float curve
[npoints
];
676 audio_region()->fade_out()->curve().get_vector (0, audio_region()->fade_out()->back()->when
, curve
, npoints
);
678 if (_height
>= NAME_HIGHLIGHT_THRESH
) {
679 h
= _height
- NAME_HIGHLIGHT_SIZE
- 2;
684 /* points *MUST* be in anti-clockwise order */
686 points
= get_canvas_points ("fade out shape", npoints
+ 3);
689 double xdelta
= pwidth
/npoints
;
691 for (pi
= 0, pc
= 0; pc
< npoints
; ++pc
) {
692 (*points
)[pi
].set_x(_pixel_width
- pwidth
+ (pc
* xdelta
));
693 (*points
)[pi
++].set_y(2 + (h
- (curve
[pc
] * h
)));
698 (*points
)[pi
].set_x(_pixel_width
);
699 (*points
)[pi
++].set_y(h
);
701 (*points
)[pi
].set_x(_pixel_width
);
702 (*points
)[pi
++].set_y(2);
704 /* connect the dots ... */
706 (*points
)[pi
] = (*points
)[0];
708 fade_out_shape
->property_points() = *points
;
711 /* ensure trim handle stays on top */
712 if (frame_handle_end
) {
713 frame_handle_end
->raise_to_top();
718 AudioRegionView::set_samples_per_unit (gdouble spu
)
720 RegionView::set_samples_per_unit (spu
);
722 if (_flags
& WaveformVisible
) {
723 for (uint32_t n
=0; n
< waves
.size(); ++n
) {
724 waves
[n
]->property_samples_per_unit() = spu
;
732 reset_fade_shapes ();
736 AudioRegionView::set_amplitude_above_axis (gdouble spp
)
738 for (uint32_t n
=0; n
< waves
.size(); ++n
) {
739 waves
[n
]->property_amplitude_above_axis() = spp
;
744 AudioRegionView::compute_colors (Gdk::Color
const & basic_color
)
746 RegionView::compute_colors (basic_color
);
748 /* gain color computed in envelope_active_changed() */
750 fade_color
= UINT_RGBA_CHANGE_A (fill_color
, 120);
754 AudioRegionView::set_colors ()
756 RegionView::set_colors();
759 gain_line
->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine
.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive
.get());
762 for (uint32_t n
=0; n
< waves
.size(); ++n
) {
763 if (_region
->muted()) {
764 waves
[n
]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm
.get(), MUTED_ALPHA
);
766 waves
[n
]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm
.get();
769 waves
[n
]->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip
.get();
770 waves
[n
]->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine
.get();
775 AudioRegionView::set_waveform_visible (bool yn
)
777 if (((_flags
& WaveformVisible
) != yn
)) {
779 for (uint32_t n
=0; n
< waves
.size(); ++n
) {
780 /* make sure the zoom level is correct, since we don't update
781 this when waveforms are hidden.
783 waves
[n
]->property_samples_per_unit() = samples_per_unit
;
786 _flags
|= WaveformVisible
;
788 for (uint32_t n
=0; n
< waves
.size(); ++n
) {
791 _flags
&= ~WaveformVisible
;
798 AudioRegionView::temporarily_hide_envelope ()
806 AudioRegionView::unhide_envelope ()
808 if (gain_line
&& (_flags
& EnvelopeVisible
)) {
814 AudioRegionView::set_envelope_visible (bool yn
)
816 if (gain_line
&& ((_flags
& EnvelopeVisible
) != yn
)) {
819 _flags
|= EnvelopeVisible
;
822 _flags
&= ~EnvelopeVisible
;
829 AudioRegionView::create_waves ()
831 // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
832 RouteTimeAxisView
& atv (*(dynamic_cast<RouteTimeAxisView
*>(&trackview
))); // ick
838 ChanCount nchans
= atv
.track()->n_channels();
840 // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data
841 // << " and channels = " << nchans.n_audio() << endl;
843 /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
844 for (uint32_t n
= 0; n
< nchans
.n_audio(); ++n
) {
845 tmp_waves
.push_back (0);
848 for (vector
<ScopedConnection
*>::iterator i
= _data_ready_connections
.begin(); i
!= _data_ready_connections
.end(); ++i
) {
852 _data_ready_connections
.clear ();
854 for (uint32_t i
= 0; i
< nchans
.n_audio(); ++i
) {
855 _data_ready_connections
.push_back (0);
858 for (uint32_t n
= 0; n
< nchans
.n_audio(); ++n
) {
860 if (n
>= audio_region()->n_channels()) {
864 wave_caches
.push_back (WaveView::create_cache ());
866 // cerr << "\tchannel " << n << endl;
869 if (audio_region()->audio_source(n
)->peaks_ready (boost::bind (&AudioRegionView::peaks_ready_handler
, this, n
), &_data_ready_connections
[n
], gui_context())) {
870 // cerr << "\tData is ready\n";
871 create_one_wave (n
, true);
873 // cerr << "\tdata is not ready\n";
874 // we'll get a PeaksReady signal from the source in the future
875 // and will call create_one_wave(n) then.
879 // cerr << "\tdon't delay, display today!\n";
880 create_one_wave (n
, true);
887 AudioRegionView::create_one_wave (uint32_t which
, bool /*direct*/)
889 //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
890 RouteTimeAxisView
& atv (*(dynamic_cast<RouteTimeAxisView
*>(&trackview
))); // ick
891 uint32_t nchans
= atv
.track()->n_channels().n_audio();
893 uint32_t nwaves
= std::min (nchans
, audio_region()->n_channels());
896 if (trackview
.current_height() < NAME_HIGHLIGHT_THRESH
) {
897 ht
= ((trackview
.current_height()) / (double) nchans
);
899 ht
= ((trackview
.current_height() - NAME_HIGHLIGHT_SIZE
) / (double) nchans
);
902 gdouble yoff
= which
* ht
;
904 WaveView
*wave
= new WaveView(*group
);
906 wave
->property_data_src() = (gpointer
) _region
.get();
907 wave
->property_cache() = wave_caches
[which
];
908 wave
->property_cache_updater() = true;
909 wave
->property_channel() = which
;
910 wave
->property_length_function() = (gpointer
) region_length_from_c
;
911 wave
->property_sourcefile_length_function() = (gpointer
) sourcefile_length_from_c
;
912 wave
->property_peak_function() = (gpointer
) region_read_peaks_from_c
;
913 wave
->property_x() = 0.0;
914 wave
->property_y() = yoff
;
915 wave
->property_height() = (double) ht
;
916 wave
->property_samples_per_unit() = samples_per_unit
;
917 wave
->property_amplitude_above_axis() = _amplitude_above_axis
;
920 wave
->property_wave_color() = _region
->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm
.get(), MUTED_ALPHA
) : ARDOUR_UI::config()->canvasvar_RecWaveForm
.get();
921 wave
->property_fill_color() = ARDOUR_UI::config()->canvasvar_RecWaveFormFill
.get();
923 wave
->property_wave_color() = _region
->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm
.get(), MUTED_ALPHA
) : ARDOUR_UI::config()->canvasvar_WaveForm
.get();
924 wave
->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill
.get();
927 wave
->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip
.get();
928 wave
->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine
.get();
929 wave
->property_zero_line() = true;
930 wave
->property_region_start() = _region
->start();
931 wave
->property_rectified() = (bool) (_flags
& WaveformRectified
);
932 wave
->property_logscaled() = (bool) (_flags
& WaveformLogScaled
);
934 if (!(_flags
& WaveformVisible
)) {
938 /* note: calling this function is serialized by the lock
939 held in the peak building thread that signals that
940 peaks are ready for use *or* by the fact that it is
941 called one by one from the GUI thread.
944 if (which
< nchans
) {
945 tmp_waves
[which
] = wave
;
947 /* n-channel track, >n-channel source */
950 /* see if we're all ready */
952 for (n
= 0; n
< nchans
; ++n
) {
953 if (tmp_waves
[n
] == 0) {
958 if (n
== nwaves
&& waves
.empty()) {
959 /* all waves are ready */
960 tmp_waves
.resize(nwaves
);
965 /* all waves created, don't hook into peaks ready anymore */
966 delete _data_ready_connections
[which
];
967 _data_ready_connections
[which
] = 0;
972 AudioRegionView::peaks_ready_handler (uint32_t which
)
974 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AudioRegionView::create_one_wave
, this, which
, false));
975 // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
979 AudioRegionView::add_gain_point_event (ArdourCanvas::Item
*item
, GdkEvent
*ev
)
981 if (gain_line
== 0) {
987 /* don't create points that can't be seen */
989 set_envelope_visible (true);
996 framepos_t fx
= trackview
.editor().pixel_to_frame (x
);
998 if (fx
> _region
->length()) {
1002 /* compute vertical fractional position */
1004 y
= 1.0 - (y
/ (_height
- NAME_HIGHLIGHT_SIZE
));
1006 /* map using gain line */
1008 gain_line
->view_to_model_coord (x
, y
);
1010 /* XXX STATEFUL: can't convert to stateful diff until we
1011 can represent automation data with it.
1014 trackview
.session()->begin_reversible_command (_("add gain control point"));
1015 XMLNode
&before
= audio_region()->envelope()->get_state();
1017 if (!audio_region()->envelope_active()) {
1018 XMLNode
®ion_before
= audio_region()->get_state();
1019 audio_region()->set_envelope_active(true);
1020 XMLNode
®ion_after
= audio_region()->get_state();
1021 trackview
.session()->add_command (new MementoCommand
<AudioRegion
>(*(audio_region().get()), ®ion_before
, ®ion_after
));
1024 audio_region()->envelope()->add (fx
, y
);
1026 XMLNode
&after
= audio_region()->envelope()->get_state();
1027 trackview
.session()->add_command (new MementoCommand
<AutomationList
>(*audio_region()->envelope().get(), &before
, &after
));
1028 trackview
.session()->commit_reversible_command ();
1032 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item
*item
, GdkEvent */
*ev*/
)
1034 ControlPoint
*cp
= reinterpret_cast<ControlPoint
*> (item
->get_data ("control_point"));
1035 audio_region()->envelope()->erase (cp
->model());
1039 AudioRegionView::store_flags()
1041 XMLNode
*node
= new XMLNode ("GUI");
1043 node
->add_property ("waveform-visible", (_flags
& WaveformVisible
) ? "yes" : "no");
1044 node
->add_property ("envelope-visible", (_flags
& EnvelopeVisible
) ? "yes" : "no");
1045 node
->add_property ("waveform-rectified", (_flags
& WaveformRectified
) ? "yes" : "no");
1046 node
->add_property ("waveform-logscaled", (_flags
& WaveformLogScaled
) ? "yes" : "no");
1048 _region
->add_extra_xml (*node
);
1052 AudioRegionView::set_flags (XMLNode
* node
)
1056 if ((prop
= node
->property ("waveform-visible")) != 0) {
1057 if (string_is_affirmative (prop
->value())) {
1058 _flags
|= WaveformVisible
;
1062 if ((prop
= node
->property ("envelope-visible")) != 0) {
1063 if (string_is_affirmative (prop
->value())) {
1064 _flags
|= EnvelopeVisible
;
1068 if ((prop
= node
->property ("waveform-rectified")) != 0) {
1069 if (string_is_affirmative (prop
->value())) {
1070 _flags
|= WaveformRectified
;
1074 if ((prop
= node
->property ("waveform-logscaled")) != 0) {
1075 if (string_is_affirmative (prop
->value())) {
1076 _flags
|= WaveformLogScaled
;
1082 AudioRegionView::set_waveform_shape (WaveformShape shape
)
1086 /* this slightly odd approach is to leave the door open to
1087 other "shapes" such as spectral displays, etc.
1100 if (yn
!= (bool) (_flags
& WaveformRectified
)) {
1101 for (vector
<WaveView
*>::iterator wave
= waves
.begin(); wave
!= waves
.end() ; ++wave
) {
1102 (*wave
)->property_rectified() = yn
;
1106 _flags
|= WaveformRectified
;
1108 _flags
&= ~WaveformRectified
;
1115 AudioRegionView::set_waveform_scale (WaveformScale scale
)
1117 bool yn
= (scale
== Logarithmic
);
1119 if (yn
!= (bool) (_flags
& WaveformLogScaled
)) {
1120 for (vector
<WaveView
*>::iterator wave
= waves
.begin(); wave
!= waves
.end() ; ++wave
) {
1121 (*wave
)->property_logscaled() = yn
;
1125 _flags
|= WaveformLogScaled
;
1127 _flags
&= ~WaveformLogScaled
;
1135 AudioRegionView::add_ghost (TimeAxisView
& tv
)
1137 RouteTimeAxisView
* rtv
= dynamic_cast<RouteTimeAxisView
*>(&trackview
);
1140 double unit_position
= _region
->position () / samples_per_unit
;
1141 AudioGhostRegion
* ghost
= new AudioGhostRegion (tv
, trackview
, unit_position
);
1144 nchans
= rtv
->track()->n_channels().n_audio();
1146 for (uint32_t n
= 0; n
< nchans
; ++n
) {
1148 if (n
>= audio_region()->n_channels()) {
1152 WaveView
*wave
= new WaveView(*ghost
->group
);
1154 wave
->property_data_src() = _region
.get();
1155 wave
->property_cache() = wave_caches
[n
];
1156 wave
->property_cache_updater() = false;
1157 wave
->property_channel() = n
;
1158 wave
->property_length_function() = (gpointer
)region_length_from_c
;
1159 wave
->property_sourcefile_length_function() = (gpointer
) sourcefile_length_from_c
;
1160 wave
->property_peak_function() = (gpointer
) region_read_peaks_from_c
;
1161 wave
->property_x() = 0.0;
1162 wave
->property_samples_per_unit() = samples_per_unit
;
1163 wave
->property_amplitude_above_axis() = _amplitude_above_axis
;
1165 wave
->property_region_start() = _region
->start();
1167 ghost
->waves
.push_back(wave
);
1170 ghost
->set_height ();
1171 ghost
->set_duration (_region
->length() / samples_per_unit
);
1172 ghost
->set_colors();
1173 ghosts
.push_back (ghost
);
1179 AudioRegionView::entered (bool internal_editing
)
1181 trackview
.editor().set_current_trimmable (_region
);
1182 trackview
.editor().set_current_movable (_region
);
1184 if (gain_line
&& _flags
& EnvelopeVisible
) {
1185 gain_line
->show_all_control_points ();
1188 if (fade_in_handle
&& !internal_editing
) {
1189 fade_in_handle
->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fade_color
, 255);
1190 fade_out_handle
->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fade_color
, 255);
1195 AudioRegionView::exited ()
1197 trackview
.editor().set_current_trimmable (boost::shared_ptr
<Trimmable
>());
1198 trackview
.editor().set_current_movable (boost::shared_ptr
<Movable
>());
1201 gain_line
->hide_all_but_selected_control_points ();
1204 if (fade_in_handle
) {
1205 fade_in_handle
->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fade_color
, 0);
1206 fade_out_handle
->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fade_color
, 0);
1211 AudioRegionView::envelope_active_changed ()
1214 gain_line
->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine
.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive
.get());
1219 AudioRegionView::set_waveview_data_src()
1221 AudioGhostRegion
* agr
;
1222 double unit_length
= _region
->length() / samples_per_unit
;
1224 for (uint32_t n
= 0; n
< waves
.size(); ++n
) {
1225 // TODO: something else to let it know the channel
1226 waves
[n
]->property_data_src() = _region
.get();
1229 for (vector
<GhostRegion
*>::iterator i
= ghosts
.begin(); i
!= ghosts
.end(); ++i
) {
1231 (*i
)->set_duration (unit_length
);
1233 if((agr
= dynamic_cast<AudioGhostRegion
*>(*i
)) != 0) {
1234 for (vector
<WaveView
*>::iterator w
= agr
->waves
.begin(); w
!= agr
->waves
.end(); ++w
) {
1235 (*w
)->property_data_src() = _region
.get();
1243 AudioRegionView::color_handler ()
1245 //case cMutedWaveForm:
1247 //case cWaveFormClip:
1251 //case cGainLineInactive:
1253 envelope_active_changed();
1258 AudioRegionView::set_frame_color ()
1264 if (_region
->opaque()) {
1270 TimeAxisViewItem::set_frame_color ();
1276 if (_region
->muted()) {
1277 wc
= UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_SelectedWaveForm
.get(), MUTED_ALPHA
);
1279 wc
= ARDOUR_UI::config()->canvasvar_SelectedWaveForm
.get();
1281 fc
= ARDOUR_UI::config()->canvasvar_SelectedWaveFormFill
.get();
1284 if (_region
->muted()) {
1285 wc
= UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm
.get(), MUTED_ALPHA
);
1287 wc
= ARDOUR_UI::config()->canvasvar_RecWaveForm
.get();
1289 fc
= ARDOUR_UI::config()->canvasvar_RecWaveFormFill
.get();
1291 if (_region
->muted()) {
1292 wc
= UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm
.get(), MUTED_ALPHA
);
1294 wc
= ARDOUR_UI::config()->canvasvar_WaveForm
.get();
1296 fc
= ARDOUR_UI::config()->canvasvar_WaveFormFill
.get();
1300 for (vector
<ArdourCanvas::WaveView
*>::iterator w
= waves
.begin(); w
!= waves
.end(); ++w
) {
1301 if (_region
->muted()) {
1302 (*w
)->property_wave_color() = wc
;
1304 (*w
)->property_wave_color() = wc
;
1305 (*w
)->property_fill_color() = fc
;
1311 AudioRegionView::set_fade_visibility (bool yn
)
1314 if (fade_in_shape
) {
1315 fade_in_shape
->show();
1317 if (fade_out_shape
) {
1318 fade_out_shape
->show ();
1320 if (fade_in_handle
) {
1321 fade_in_handle
->show ();
1323 if (fade_out_handle
) {
1324 fade_out_handle
->show ();
1327 if (fade_in_shape
) {
1328 fade_in_shape
->hide();
1330 if (fade_out_shape
) {
1331 fade_out_shape
->hide ();
1333 if (fade_in_handle
) {
1334 fade_in_handle
->hide ();
1336 if (fade_out_handle
) {
1337 fade_out_handle
->hide ();
1343 AudioRegionView::update_coverage_frames (LayerDisplay d
)
1345 RegionView::update_coverage_frames (d
);
1347 if (fade_in_handle
) {
1348 fade_in_handle
->raise_to_top ();
1349 fade_out_handle
->raise_to_top ();
1354 AudioRegionView::show_region_editor ()
1357 editor
= new AudioRegionEditor (trackview
.session(), audio_region());
1361 editor
->set_position (Gtk::WIN_POS_MOUSE
);
1367 AudioRegionView::show_fade_line (framepos_t pos
)
1369 fade_position_line
->property_x1() = trackview
.editor().frame_to_pixel (pos
);
1370 fade_position_line
->property_x2() = trackview
.editor().frame_to_pixel (pos
);
1371 fade_position_line
->show ();
1372 fade_position_line
->raise_to_top ();
1376 AudioRegionView::hide_fade_line ()
1378 fade_position_line
->hide ();
1383 AudioRegionView::transients_changed ()
1385 AnalysisFeatureList analysis_features
= _region
->transients();
1387 while (feature_lines
.size() < analysis_features
.size()) {
1389 ArdourCanvas::Line
* canvas_item
= new ArdourCanvas::Line(*group
);
1391 ArdourCanvas::Points points
;
1393 points
.push_back(Gnome::Art::Point(-1.0, 2.0)); // first x-coord needs to be a non-normal value
1394 points
.push_back(Gnome::Art::Point(1.0, _height
- TimeAxisViewItem::NAME_HIGHLIGHT_SIZE
- 1));
1396 canvas_item
->property_points() = points
;
1397 canvas_item
->property_width_pixels() = 1;
1398 canvas_item
->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_ZeroLine
.get();
1399 canvas_item
->property_first_arrowhead() = TRUE
;
1400 canvas_item
->property_last_arrowhead() = TRUE
;
1401 canvas_item
->property_arrow_shape_a() = 11.0;
1402 canvas_item
->property_arrow_shape_b() = 0.0;
1403 canvas_item
->property_arrow_shape_c() = 4.0;
1405 canvas_item
->raise_to_top ();
1406 canvas_item
->show ();
1408 canvas_item
->set_data ("regionview", this);
1409 canvas_item
->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_feature_line_event
), canvas_item
, this));
1411 feature_lines
.push_back (make_pair(0, canvas_item
));
1414 while (feature_lines
.size() > analysis_features
.size()) {
1415 ArdourCanvas::Line
* line
= feature_lines
.back().second
;
1416 feature_lines
.pop_back ();
1420 AnalysisFeatureList::const_iterator i
;
1421 list
<std::pair
<framepos_t
, ArdourCanvas::Line
*> >::iterator l
;
1423 for (i
= analysis_features
.begin(), l
= feature_lines
.begin(); i
!= analysis_features
.end() && l
!= feature_lines
.end(); ++i
, ++l
) {
1425 ArdourCanvas::Points points
;
1427 float *pos
= new float;
1428 *pos
= trackview
.editor().frame_to_pixel (*i
);
1430 points
.push_back(Gnome::Art::Point(*pos
, 2.0)); // first x-coord needs to be a non-normal value
1431 points
.push_back(Gnome::Art::Point(*pos
, _height
- TimeAxisViewItem::NAME_HIGHLIGHT_SIZE
- 1));
1433 (*l
).second
->property_points() = points
;
1434 (*l
).second
->set_data ("position", pos
);
1441 AudioRegionView::update_transient(float /*old_pos*/, float new_pos
)
1443 /* Find frame at old pos, calulate new frame then update region transients*/
1444 list
<std::pair
<framepos_t
, ArdourCanvas::Line
*> >::iterator l
;
1446 for (l
= feature_lines
.begin(); l
!= feature_lines
.end(); ++l
) {
1448 /* Line has been updated in drag so we compare to new_pos */
1450 float* pos
= (float*) (*l
).second
->get_data ("position");
1452 if (rint(new_pos
) == rint(*pos
)) {
1454 framepos_t old_frame
= (*l
).first
;
1455 framepos_t new_frame
= trackview
.editor().pixel_to_frame (new_pos
);
1457 _region
->update_transient (old_frame
, new_frame
);
1465 AudioRegionView::remove_transient(float pos
)
1467 /* Find frame at old pos, calulate new frame then update region transients*/
1468 list
<std::pair
<framepos_t
, ArdourCanvas::Line
*> >::iterator l
;
1470 for (l
= feature_lines
.begin(); l
!= feature_lines
.end(); ++l
) {
1472 /* Line has been updated in drag so we compare to new_pos */
1473 float *line_pos
= (float*) (*l
).second
->get_data ("position");
1475 if (rint(pos
) == rint(*line_pos
)) {
1476 _region
->remove_transient ((*l
).first
);
1483 AudioRegionView::thaw_after_trim ()
1485 RegionView::thaw_after_trim ();