2 Copyright (C) 2011-2013 Paul Davis
3 Author: Carl Hetherington <cth@carlh.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <boost/shared_ptr.hpp>
22 #include <boost/shared_array.hpp>
24 #include "pbd/properties.h"
26 #include "ardour/types.h"
28 #include <glibmm/refptr.h>
30 #include "canvas/item.h"
31 #include "canvas/fill.h"
32 #include "canvas/outline.h"
44 namespace ArdourCanvas {
46 class WaveView : virtual public Item, public Outline, public Fill
54 /* Displays a single channel of waveform data for the given Region.
56 x = 0 in the waveview corresponds to the first waveform datum taken
57 from region->start() samples into the source data.
59 x = N in the waveview corresponds to the (N * spp)'th sample
60 measured from region->start() into the source data.
62 when drawing, we will map the zeroth-pixel of the waveview
65 The waveview itself contains a set of pre-rendered Cairo::ImageSurfaces
66 that cache sections of the display. This is filled on-demand and
67 never cleared until something explicitly marks the cache invalid
68 (such as a change in samples_per_pixel, the log scaling, rectified or
69 other view parameters).
73 WaveView (Group *, boost::shared_ptr<ARDOUR::AudioRegion>);
75 void render (Rect const & area, Cairo::RefPtr<Cairo::Context>) const;
76 void compute_bounding_box () const;
78 void set_samples_per_pixel (double);
79 void set_height (Distance);
80 void set_channel (int);
81 void set_region_start (ARDOUR::frameoffset_t);
83 void set_fill_color (Color);
84 void set_outline_color (Color);
86 void region_resized ();
89 void set_show_zero_line (bool);
90 bool show_zero_line() const { return _show_zero; }
91 void set_zero_color (Color);
92 void set_clip_color (Color);
93 void set_logscaled (bool);
94 void set_gradient_depth (double);
95 double gradient_depth() const { return _gradient_depth; }
96 void set_shape (Shape);
99 /* currently missing because we don't need them (yet):
100 set_shape_independent();
101 set_logscaled_independent()
104 static void set_global_gradient_depth (double);
105 static void set_global_logscaled (bool);
106 static void set_global_shape (Shape);
108 static double global_gradient_depth() { return _global_gradient_depth; }
109 static bool global_logscaled() { return _global_logscaled; }
110 static Shape global_shape() { return _global_shape; }
112 void set_amplitude_above_axis (double v);
113 double amplitude_above_axis () const { return _amplitude_above_axis; }
115 #ifdef CANVAS_COMPATIBILITY
116 void*& property_gain_src () {
119 void*& property_gain_function () {
127 /** A cached, pre-rendered image of some section of a waveform.
129 It spans a range given relative to the start of the source
130 of the waveform data, so a range from N..M corresponds
131 to the sample range N..M within the source.
133 Invalidated by a changes to:
144 CacheEntry (WaveView const *, double, double);
147 double pixel_start () const {
151 double pixel_end () const {
155 double sample_start () const {
156 return _sample_start;
159 double sample_end () const {
163 boost::shared_array<ARDOUR::PeakData> peaks () const {
167 Cairo::RefPtr<Cairo::ImageSurface> image();
171 Coord position (Coord) const;
173 WaveView const * _wave_view;
177 ARDOUR::framecnt_t _sample_start;
178 ARDOUR::framecnt_t _sample_end;
181 boost::shared_array<ARDOUR::PeakData> _peaks;
182 Cairo::RefPtr<Cairo::ImageSurface> _image;
185 friend class CacheEntry;
186 friend class ::WaveViewTest;
188 void invalidate_whole_cache ();
189 void invalidate_image_cache ();
191 boost::shared_ptr<ARDOUR::AudioRegion> _region;
193 double _samples_per_pixel;
201 double _gradient_depth;
202 bool _shape_independent;
203 bool _logscaled_independent;
204 bool _gradient_depth_independent;
205 double _amplitude_above_axis;
207 /** The `start' value to use for the region; we can't use the region's
208 * value as the crossfade editor needs to alter it.
210 ARDOUR::frameoffset_t _region_start;
212 mutable std::list<CacheEntry*> _cache;
214 PBD::ScopedConnection invalidation_connection;
216 static double _global_gradient_depth;
217 static bool _global_logscaled;
218 static Shape _global_shape;
220 static PBD::Signal0<void> VisualPropertiesChanged;
222 void handle_visual_property_change ();