change UIConfig to use accessor/setter methods like RCConfig so that ParameterChanged...
[ardour.git] / libs / canvas / canvas / wave_view.h
1 /*
2     Copyright (C) 2011-2013 Paul Davis
3     Author: Carl Hetherington <cth@carlh.net>
4
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.
9
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.
14
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.
18
19 */
20
21 #include <boost/shared_ptr.hpp>
22 #include <boost/shared_array.hpp>
23
24 #include "pbd/properties.h"
25
26 #include "ardour/types.h"
27
28 #include <glibmm/refptr.h>
29
30 #include "canvas/item.h"
31 #include "canvas/fill.h"
32 #include "canvas/outline.h"
33
34 namespace ARDOUR {
35         class AudioRegion;
36 }
37
38 namespace Gdk {
39         class Pixbuf;
40 }
41
42 class WaveViewTest;
43         
44 namespace ArdourCanvas {
45
46 class WaveView : virtual public Item, public Outline, public Fill
47 {
48 public:
49         enum Shape { 
50                 Normal,
51                 Rectified,
52         };
53
54         WaveView (Group *, boost::shared_ptr<ARDOUR::AudioRegion>);
55
56         void render (Rect const & area, Cairo::RefPtr<Cairo::Context>) const;
57         void compute_bounding_box () const;
58     
59         void set_samples_per_pixel (double);
60         void set_height (Distance);
61         void set_channel (int);
62         void set_region_start (ARDOUR::frameoffset_t);
63
64         void set_fill_color (Color);
65         void set_outline_color (Color);
66         
67         void region_resized ();
68
69         void set_show_zero_line (bool);
70         bool show_zero_line() const { return _show_zero; }
71         void set_zero_color (Color);
72         void set_clip_color (Color);
73         void set_amplitude (double);
74         void set_logscaled (bool);
75         void set_gradient_depth (double);
76         double gradient_depth() const { return _gradient_depth; }
77         void set_shape (Shape);
78         double amplitude() const { return _amplitude; }
79         
80         /* currently missing because we don't need them (yet):
81            set_shape_independent();
82            set_logscaled_independent()
83         */
84
85         static void set_global_gradient_depth (double);
86         static void set_global_logscaled (bool);
87         static void set_global_shape (Shape);
88     
89         static double  global_gradient_depth()  { return _global_gradient_depth; }
90         static bool    global_logscaled()  { return _global_logscaled; }
91         static Shape   global_shape()  { return _global_shape; }
92
93 #ifdef CANVAS_COMPATIBILITY     
94         void*& property_gain_src () {
95                 return _foo_void;
96         }
97         void*& property_gain_function () {
98                 return _foo_void;
99         }
100         double& property_amplitude_above_axis () {
101                 return _foo_double;
102         }
103 private:
104         void* _foo_void;
105         bool _foo_bool;
106         int _foo_int;
107         Color _foo_uint;
108         double _foo_double;
109 #endif
110
111         class CacheEntry
112         {
113         public:
114                 CacheEntry (WaveView const *, int, int);
115                 ~CacheEntry ();
116
117                 int start () const {
118                         return _start;
119                 }
120
121                 int end () const {
122                         return _end;
123                 }
124
125                 boost::shared_array<ARDOUR::PeakData> peaks () const {
126                         return _peaks;
127                 }
128
129                 Cairo::RefPtr<Cairo::ImageSurface> image();
130                 void clear_image ();
131
132         private:
133                 Coord position (Coord) const;
134                 
135                 WaveView const * _wave_view;
136                 int _start;
137                 int _end;
138                 int _n_peaks;
139                 boost::shared_array<ARDOUR::PeakData> _peaks;
140                 Cairo::RefPtr<Cairo::ImageSurface> _image;
141         };
142
143         friend class CacheEntry;
144         friend class ::WaveViewTest;
145
146         void invalidate_whole_cache ();
147         void invalidate_image_cache ();
148
149         boost::shared_ptr<ARDOUR::AudioRegion> _region;
150         int    _channel;
151         double _samples_per_pixel;
152         Coord  _height;
153         Color  _wave_color;
154         bool   _show_zero;
155         Color  _zero_color;
156         Color  _clip_color;
157         bool   _logscaled;
158         Shape  _shape;
159         double _gradient_depth;
160         double _amplitude;
161         bool   _shape_independent;
162         bool   _logscaled_independent;
163         bool   _gradient_depth_independent;
164
165         /** The `start' value to use for the region; we can't use the region's
166          *  value as the crossfade editor needs to alter it.
167          */
168         ARDOUR::frameoffset_t _region_start;
169         
170         mutable std::list<CacheEntry*> _cache;
171        
172         PBD::ScopedConnection invalidation_connection;
173
174         static double _global_gradient_depth;
175         static bool   _global_logscaled;
176         static Shape  _global_shape;
177
178         static PBD::Signal0<void> VisualPropertiesChanged;
179
180         void handle_visual_property_change ();
181 };
182
183 }