fix crash when copy'ing latent plugins
[ardour.git] / gtk2_ardour / fft_result.h
1 /*
2  * Copyright (C) 2006, 2016 Paul Davis
3  * Written by Sampo Savolainen & Robin Gareus
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  */
19
20 #ifndef __ardour_fft_result_h
21 #define __ardour_fft_result_h
22
23 #include <math.h>
24 #include <fftw3.h>
25
26 #include <gdkmm/color.h>
27
28 #include <string>
29
30 class FFTGraph;
31
32 class FFTResult
33 {
34 public:
35
36         ~FFTResult ();
37
38         void analyzeWindow (float *window);
39         void finalize ();
40
41         unsigned int length () const { return _dataSize; }
42
43         float avgAt (unsigned int x, bool p) const
44         { return p ? _data_prop_avg[x] : _data_flat_avg[x]; }
45         float maxAt (unsigned int x, bool p) const
46         { return p ? _data_prop_max[x] : _data_flat_max[x]; }
47         float minAt (unsigned int x, bool p) const
48         { return p ? _data_prop_min[x] : _data_flat_min[x]; }
49
50         float minimum (bool p) const
51         { return p ? _min_prop : _min_flat; }
52         float maximum (bool p) const
53         { return p ? _max_prop : _max_flat; }
54
55         const Gdk::Color& get_color () const { return _color; }
56
57 private:
58         FFTResult (FFTGraph *graph, Gdk::Color color, std::string trackname);
59         friend class FFTGraph;
60
61         int _averages;
62
63         float* _data_flat_avg;
64         float* _data_flat_max;
65         float* _data_flat_min;
66         float* _data_prop_avg;
67         float* _data_prop_max;
68         float* _data_prop_min;
69
70         unsigned int _windowSize;
71         unsigned int _dataSize;
72
73         float _min_flat;
74         float _max_flat;
75         float _min_prop;
76         float _max_prop;
77
78         FFTGraph *_graph;
79
80         Gdk::Color _color;
81         std::string _trackname;
82
83         static float power_to_db (float v) { return v > 1e-20 ? 10.0f * log10f (v) : -200.0f; }
84 };
85
86 #endif /* __ardour_fft_result_h */