virtual Fill:: and Outline:: methods so that Canvas::Items that cache image rendering...
[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_shape (Shape);
76         double amplitude() const { return _amplitude; }
77         
78         /* currently missing because we don't need them (yet):
79            set_shape_independent();
80            set_logscaled_independent()
81         */
82
83         static void set_gradient_waveforms (bool);
84         static void set_global_logscaled (bool);
85         static void set_global_shape (Shape);
86     
87         static bool  gradient_waveforms()  { return _gradient_waveforms; }
88         static bool  global_logscaled()  { return _global_logscaled; }
89         static Shape global_shape()  { return _global_shape; }
90
91 #ifdef CANVAS_COMPATIBILITY     
92         void*& property_gain_src () {
93                 return _foo_void;
94         }
95         void*& property_gain_function () {
96                 return _foo_void;
97         }
98         double& property_amplitude_above_axis () {
99                 return _foo_double;
100         }
101 private:
102         void* _foo_void;
103         bool _foo_bool;
104         int _foo_int;
105         Color _foo_uint;
106         double _foo_double;
107 #endif
108
109         class CacheEntry
110         {
111         public:
112                 CacheEntry (WaveView const *, int, int);
113                 ~CacheEntry ();
114
115                 int start () const {
116                         return _start;
117                 }
118
119                 int end () const {
120                         return _end;
121                 }
122
123                 boost::shared_array<ARDOUR::PeakData> peaks () const {
124                         return _peaks;
125                 }
126
127                 Cairo::RefPtr<Cairo::ImageSurface> image();
128                 void clear_image ();
129
130         private:
131                 Coord position (Coord) const;
132                 
133                 WaveView const * _wave_view;
134                 int _start;
135                 int _end;
136                 int _n_peaks;
137                 boost::shared_array<ARDOUR::PeakData> _peaks;
138                 Cairo::RefPtr<Cairo::ImageSurface> _image;
139         };
140
141         friend class CacheEntry;
142         friend class ::WaveViewTest;
143
144         void invalidate_whole_cache ();
145         void invalidate_image_cache ();
146
147         boost::shared_ptr<ARDOUR::AudioRegion> _region;
148         int    _channel;
149         double _samples_per_pixel;
150         Coord  _height;
151         Color  _wave_color;
152         bool   _show_zero;
153         Color  _zero_color;
154         Color  _clip_color;
155         bool   _logscaled;
156         Shape  _shape;
157         double _amplitude;
158         bool   _shape_independent;
159         bool   _logscaled_independent;
160
161         /** The `start' value to use for the region; we can't use the region's
162          *  value as the crossfade editor needs to alter it.
163          */
164         ARDOUR::frameoffset_t _region_start;
165         
166         mutable std::list<CacheEntry*> _cache;
167        
168         PBD::ScopedConnection invalidation_connection;
169
170         static bool _gradient_waveforms;
171         static bool _global_logscaled;
172         static Shape _global_shape;
173
174         static PBD::Signal0<void> VisualPropertiesChanged;
175
176         void handle_visual_property_change ();
177 };
178
179 }