Merge branch 'master' into cairocanvas
[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         WaveView (Group *, boost::shared_ptr<ARDOUR::AudioRegion>);
50
51         void render (Rect const & area, Cairo::RefPtr<Cairo::Context>) const;
52         void compute_bounding_box () const;
53
54         XMLNode* get_state () const;
55         void set_state (XMLNode const *);
56
57         void set_frames_per_pixel (double);
58         void set_height (Distance);
59         void set_channel (int);
60         void set_region_start (ARDOUR::frameoffset_t);
61         
62         void region_resized ();
63
64         /* XXX */
65         void rebuild () {}
66
67 #ifdef CANVAS_COMPATIBILITY     
68         void*& property_gain_src () {
69                 return _foo_void;
70         }
71         void*& property_gain_function () {
72                 return _foo_void;
73         }
74         bool& property_rectified () {
75                 return _foo_bool;
76         }
77         bool& property_logscaled () {
78                 return _foo_bool;
79         }
80         double& property_amplitude_above_axis () {
81                 return _foo_double;
82         }
83         Color& property_clip_color () {
84                 return _foo_uint;
85         }
86         Color& property_zero_color () {
87                 return _foo_uint;
88         }
89
90 private:
91         void* _foo_void;
92         bool _foo_bool;
93         int _foo_int;
94         Color _foo_uint;
95         double _foo_double;
96 #endif
97
98         class CacheEntry
99         {
100         public:
101                 CacheEntry (WaveView const *, int, int);
102                 ~CacheEntry ();
103
104                 int start () const {
105                         return _start;
106                 }
107
108                 int end () const {
109                         return _end;
110                 }
111
112                 boost::shared_array<ARDOUR::PeakData> peaks () const {
113                         return _peaks;
114                 }
115
116                 Cairo::RefPtr<Cairo::ImageSurface> image();
117                 void clear_image ();
118
119         private:
120                 Coord position (float) const;
121                 
122                 WaveView const * _wave_view;
123                 int _start;
124                 int _end;
125                 int _n_peaks;
126                 boost::shared_array<ARDOUR::PeakData> _peaks;
127                 Cairo::RefPtr<Cairo::ImageSurface> _image;
128         };
129
130         friend class CacheEntry;
131         friend class ::WaveViewTest;
132
133         void invalidate_whole_cache ();
134         void invalidate_image_cache ();
135
136         boost::shared_ptr<ARDOUR::AudioRegion> _region;
137         int _channel;
138         double _frames_per_pixel;
139         Coord _height;
140         Color _wave_color;
141         /** The `start' value to use for the region; we can't use the region's
142          *  value as the crossfade editor needs to alter it.
143          */
144         ARDOUR::frameoffset_t _region_start;
145         
146         mutable std::list<CacheEntry*> _cache;
147 };
148
149 }