75cda4d45738f9d10fe5899a831886d724fa5c85
[ardour.git] / gtk2_ardour / fft_graph.h
1 /*
2     Copyright (C) 2006 Paul Davis
3     Author: Sampo Savoleinen
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 #ifndef __ardour_fft_graph_h
22 #define __ardour_fft_graph_h
23
24 #include "ardour/types.h"
25 #include <fftw3.h>
26
27 #include <gtkmm/drawingarea.h>
28 #include <gtkmm/treemodel.h>
29 #include <gdkmm/color.h>
30
31 #include <glibmm/refptr.h>
32
33 #include <string>
34
35 #include "fft_result.h"
36
37 class AnalysisWindow;
38
39 class FFTGraph : public Gtk::DrawingArea
40 {
41 public:
42
43         FFTGraph (int windowSize);
44         ~FFTGraph ();
45
46         void set_analysis_window (AnalysisWindow *a_window);
47
48         int windowSize () const { return _windowSize; }
49         void setWindowSize (int windowSize);
50
51         void redraw ();
52         bool on_expose_event (GdkEventExpose* event);
53
54         void on_size_request (Gtk::Requisition* requisition);
55         void on_size_allocate (Gtk::Allocation & alloc);
56         FFTResult *prepareResult (Gdk::Color color, std::string trackname);
57
58         void set_show_minmax      (bool v) { _show_minmax       = v; redraw (); }
59         void set_show_normalized  (bool v) { _show_normalized   = v; redraw (); }
60         void set_show_proportioanl(bool v) { _show_proportional = v; redraw (); }
61
62 private:
63
64         void update_size ();
65
66         void setWindowSize_internal (int windowSize);
67
68         int draw_scales (Glib::RefPtr<Gdk::Window> window);
69
70         static const int minScaleWidth = 512;
71         static const int minScaleHeight = 420;
72
73         static const int hl_margin = 40; // this should scale with font (dBFS labels)
74         static const int hr_margin = 12;
75         static const int v_margin  = 12;
76
77         int currentScaleWidth;
78         Glib::RefPtr<Gdk::GC> graph_gc;
79
80         int width;
81         int height;
82
83         unsigned int _windowSize;
84         unsigned int _dataSize;
85
86         Glib::RefPtr<Pango::Layout> layout;
87         AnalysisWindow *_a_window;
88
89         fftwf_plan _plan;
90
91         float* _out;
92         float* _in;
93         float* _hanning;
94         int*   _logScale;
95
96         bool _show_minmax;
97         bool _show_normalized;
98         bool _show_proportional;
99
100         float _fft_start;
101         float _fft_end;
102         float _fft_log_base;
103
104         friend class FFTResult;
105 };
106
107 #endif /* __ardour_fft_graph_h */