add auto zoombar/status color, fix 3 batchrender boobies, rotate plugin tweaks, add...
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / spectrogram / spectrogram.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2011 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef SPECTROGRAM_H
23 #define SPECTROGRAM_H
24
25
26
27
28
29
30 #include "bchash.inc"
31 #include "bctimer.inc"
32 #include "fourier.h"
33 #include "guicast.h"
34 #include "mutex.h"
35 #include "pluginaclient.h"
36 #include "vframe.inc"
37
38
39
40
41 class Spectrogram;
42
43 #define MIN_XZOOM 1
44 #define MAX_XZOOM 256
45 #define MIN_WINDOW 1024
46 #define MAX_WINDOW 65536
47 #define DIVISIONS 10
48 #define DIVISION_W 60
49 #define MARGIN 10
50 #define MAX_COLUMNS 1024
51 #define MAX_HISTORY 32
52 #define MIN_HISTORY 1
53 #define MIN_FREQ 1
54 #define MAX_FREQ 30000
55
56 // mode
57 #define VERTICAL 0
58 #define HORIZONTAL 1
59
60
61 class SpectrogramLevel : public BC_FPot
62 {
63 public:
64         SpectrogramLevel(Spectrogram *plugin, int x, int y);
65         int handle_event();
66         Spectrogram *plugin;
67 };
68
69 class SpectrogramMode : public BC_PopupMenu
70 {
71 public:
72         SpectrogramMode(Spectrogram *plugin,
73                 int x,
74                 int y);
75         int handle_event();
76         static const char* mode_to_text(int mode);
77         static int text_to_mode(const char *text);
78         void create_objects();
79         Spectrogram *plugin;
80 };
81
82 class SpectrogramHistory : public BC_IPot
83 {
84 public:
85         SpectrogramHistory(Spectrogram *plugin,
86                 int x,
87                 int y);
88         int handle_event();
89         Spectrogram *plugin;
90 };
91
92 class SpectrogramWindowSize : public BC_PopupMenu
93 {
94 public:
95         SpectrogramWindowSize(Spectrogram *plugin,
96                 int x,
97                 int y,
98                 char *text);
99         int handle_event();
100         Spectrogram *plugin;
101 };
102
103 class SpectrogramWindowSizeTumbler : public BC_Tumbler
104 {
105 public:
106         SpectrogramWindowSizeTumbler(Spectrogram *plugin, int x, int y);
107         int handle_up_event();
108         int handle_down_event();
109         Spectrogram *plugin;
110 };
111
112 class SpectrogramFragmentSize : public BC_PopupMenu
113 {
114 public:
115         SpectrogramFragmentSize(Spectrogram *plugin,
116                 int x,
117                 int y,
118                 char *text);
119         int handle_event();
120         Spectrogram *plugin;
121 };
122
123 class SpectrogramFragmentSizeTumbler : public BC_Tumbler
124 {
125 public:
126         SpectrogramFragmentSizeTumbler(Spectrogram *plugin, int x, int y);
127         int handle_up_event();
128         int handle_down_event();
129         Spectrogram *plugin;
130 };
131
132 class SpectrogramNormalize : public BC_CheckBox
133 {
134 public:
135         SpectrogramNormalize(Spectrogram *plugin, int x, int y);
136         int handle_event();
137         Spectrogram *plugin;
138 };
139
140 class SpectrogramFreq : public BC_TextBox
141 {
142 public:
143         SpectrogramFreq(Spectrogram *plugin, int x, int y);
144         int handle_event();
145         Spectrogram *plugin;
146 };
147
148 class SpectrogramXZoom : public BC_IPot
149 {
150 public:
151         SpectrogramXZoom(Spectrogram *plugin, int x, int y);
152         int handle_event();
153         Spectrogram *plugin;
154 };
155
156 class SpectrogramCanvas : public BC_SubWindow
157 {
158 public:
159         SpectrogramCanvas(Spectrogram *plugin, int x, int y, int w, int h);
160         int button_press_event();
161         int button_release_event();
162         int cursor_motion_event();
163         void calculate_point();
164         void draw_overlay();
165
166         enum
167         {
168                 NONE,
169                 DRAG
170         };
171
172         int current_operation;
173         Spectrogram *plugin;
174 };
175
176
177 class SpectrogramWindow : public PluginClientWindow
178 {
179 public:
180         SpectrogramWindow(Spectrogram *plugin);
181         ~SpectrogramWindow();
182
183         void create_objects();
184         void update_gui();
185         int resize_event(int w, int h);
186         void calculate_frequency(int x, int y, int do_overlay);
187
188         SpectrogramCanvas *canvas;
189
190         BC_Title *level_title;
191         SpectrogramLevel *level;
192         BC_Title *window_size_title;
193         SpectrogramWindowSize *window_size;
194         SpectrogramWindowSizeTumbler *window_size_tumbler;
195
196         BC_Title *mode_title;
197         SpectrogramMode *mode;
198         BC_Title *history_title;
199         SpectrogramHistory *history;
200
201         BC_Title *freq_title;
202 //      SpectrogramFreq *freq;
203         BC_Title *amplitude_title;
204
205
206         BC_Title *xzoom_title;
207         SpectrogramXZoom *xzoom;
208 //      SpectrogramFragmentSizeTumbler *window_fragment_tumbler;
209
210         SpectrogramNormalize *normalize;
211         Spectrogram *plugin;
212         int probe_x, probe_y;
213 };
214
215
216
217
218
219
220 class SpectrogramConfig
221 {
222 public:
223         SpectrogramConfig();
224         int equivalent(SpectrogramConfig &that);
225         void copy_from(SpectrogramConfig &that);
226         void interpolate(SpectrogramConfig &prev,
227                 SpectrogramConfig &next,
228                 int64_t prev_frame,
229                 int64_t next_frame,
230                 int64_t current_frame);
231         double level;
232         int window_size;
233 // Generate this many columns for each window
234         int xzoom;
235 // Frequency probed
236         int frequency;
237         int normalize;
238         int mode;
239         int history_size;
240 };
241
242 // Header for data buffer
243 typedef struct
244 {
245         int window_size;
246 // Total windows in this buffer
247         int total_windows;
248 // Samples per fragment
249         int window_fragment;
250 // Samplerate
251         int sample_rate;
252 // Linearized user level
253         float level;
254 // Nothing goes after this
255 // 1st sample in each window is the max
256         float samples[1];
257 } data_header_t;
258
259 class SpectrogramFrame
260 {
261 public:
262         SpectrogramFrame(int data_size);
263         ~SpectrogramFrame();
264
265         int data_size;
266         float *data;
267 // Draw immediately
268         int force;
269 };
270
271 class Spectrogram : public PluginAClient
272 {
273 public:
274         Spectrogram(PluginServer *server);
275         ~Spectrogram();
276
277         PLUGIN_CLASS_MEMBERS2(SpectrogramConfig)
278         int is_realtime();
279         int process_buffer(int64_t size,
280                 Samples *buffer,
281                 int64_t start_position,
282                 int sample_rate);
283         void read_data(KeyFrame *keyframe);
284         void save_data(KeyFrame *keyframe);
285         void update_gui();
286         void render_gui(void *data, int size);
287         void render_stop();
288
289         void reset();
290
291         int done;
292         int need_reconfigure;
293         FFT *fft;
294 // Data buffer for frequency & magnitude
295         unsigned char *data;
296 // Accumulate data for windowing
297         Samples *audio_buffer;
298 // Total samples in the buffer
299         int buffer_size;
300 // Last window size rendered
301         int window_size;
302 // Temporaries for the FFT
303         double *freq_real;
304         double *freq_imag;
305 // Total windows sent to current GUI
306         int total_windows;
307 // Starting sample in audio_buffer.
308         int64_t audio_buffer_start;
309 // Total floats allocated in data buffer
310         int allocated_data;
311 // Accumulates canvas pixels until the next update_gui
312         ArrayList<SpectrogramFrame*> frame_buffer;
313 // History for vertical mode
314 // Probing data for horizontal mode
315         ArrayList<SpectrogramFrame*> frame_history;
316 // Header from last data buffer
317         data_header_t header;
318 // Time of last GUI update
319         Timer *timer;
320 // Window dimensions
321         int w, h;
322 };
323
324
325 #endif