r269@gandalf: fugalh | 2006-08-03 20:18:05 -0600
[ardour.git] / gtk2_ardour / fft_graph.h
1 /*
2     Copyright (C) 2006 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __ardour_fft_graph_h
21 #define __ardour_fft_graph_h
22
23 #include <ardour/types.h>
24 #include <fftw3.h>
25
26 #include <gtkmm/drawingarea.h>
27 #include <gtkmm/treemodel.h>
28 #include <gdkmm/color.h>
29
30 #include <glibmm/refptr.h>
31
32 #include <string>
33
34 #include "fft_result.h"
35
36 class AnalysisWindow;
37
38 class FFTGraph : public Gtk::DrawingArea
39 {
40         public:
41                 
42                 FFTGraph(int windowSize);
43                 ~FFTGraph();
44
45                 void set_analysis_window(AnalysisWindow *a_window);
46                 
47                 int windowSize() const { return _windowSize; }
48                 void setWindowSize(int windowSize);
49
50                 void redraw();
51                 bool on_expose_event (GdkEventExpose* event);
52                 
53                 void on_size_request(Gtk::Requisition* requisition);
54                 void on_size_allocate(Gtk::Allocation & alloc);
55                 FFTResult *prepareResult(Gdk::Color color, std::string trackname);
56                 
57         private:
58
59                 void setWindowSize_internal(int windowSize);
60
61                 void draw_scales(Glib::RefPtr<Gdk::Window> window);
62                 
63                 static const int scaleWidth = 512;
64                 static const int scaleHeight = 420;
65
66                 static const int h_margin = 20;
67                 static const int v_margin = 20;
68
69                 int width;
70                 int height;
71                 
72                 void analyze(float *window, float *composite);
73                 int _windowSize;
74                 int _dataSize;
75
76                 Glib::RefPtr<Pango::Layout> layout;
77                 Glib::RefPtr<Gdk::GC> graph_gc;
78                 AnalysisWindow *_a_window;
79
80                 fftwf_plan _plan;
81
82                 float *_out;
83                 float *_in;
84                 float *_hanning;
85                 int *_logScale;
86
87         friend class FFTResult;
88 };
89
90 #endif /* __ardour_fft_graph_h */