no longer need ffmpeg patch0 which was for Termux
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / audioscope / audioscope.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 "bccolors.h"
33 #include "guicast.h"
34 #include "mutex.h"
35 #include "pluginaclient.h"
36 #include "vframe.inc"
37
38
39
40
41 class AudioScope;
42
43 #define MIN_WINDOW 32
44 #define MAX_WINDOW 262144
45 #define DIVISIONS 10
46 #define DIVISION_W 60
47 #define MARGIN 10
48 #define MAX_COLUMNS 1024
49 #define CHANNELS 2
50 #define MIN_HISTORY 1
51 #define MAX_HISTORY 32
52
53 // Modes
54 #define XY_MODE 0
55 #define WAVEFORM_NO_TRIGGER 1
56 #define WAVEFORM_RISING_TRIGGER 2
57 #define WAVEFORM_FALLING_TRIGGER 3
58
59
60 #define CHANNEL0_COLOR WHITE
61 #define CHANNEL1_COLOR PINK
62
63 class AudioScopeHistory : public BC_IPot
64 {
65 public:
66         AudioScopeHistory(AudioScope *plugin,
67                 int x,
68                 int y);
69         int handle_event();
70         AudioScope *plugin;
71 };
72
73 class AudioScopeWindowSize : public BC_PopupMenu
74 {
75 public:
76         AudioScopeWindowSize(AudioScope *plugin,
77                 int x,
78                 int y,
79                 char *text);
80         int handle_event();
81         AudioScope *plugin;
82 };
83
84 class AudioScopeWindowSizeTumbler : public BC_Tumbler
85 {
86 public:
87         AudioScopeWindowSizeTumbler(AudioScope *plugin, int x, int y);
88         int handle_up_event();
89         int handle_down_event();
90         AudioScope *plugin;
91 };
92
93 class AudioScopeFragmentSize : public BC_PopupMenu
94 {
95 public:
96         AudioScopeFragmentSize(AudioScope *plugin,
97                 int x,
98                 int y,
99                 char *text);
100         int handle_event();
101         AudioScope *plugin;
102 };
103
104 class AudioScopeFragmentSizeTumbler : public BC_Tumbler
105 {
106 public:
107         AudioScopeFragmentSizeTumbler(AudioScope *plugin, int x, int y);
108         int handle_up_event();
109         int handle_down_event();
110         AudioScope *plugin;
111 };
112
113
114 class AudioScopeMode : public BC_PopupMenu
115 {
116 public:
117         AudioScopeMode(AudioScope *plugin,
118                 int x,
119                 int y);
120         int handle_event();
121         static const char* mode_to_text(int mode);
122         static int text_to_mode(const char *text);
123         void create_objects();
124         AudioScope *plugin;
125 };
126
127 class AudioScopeTriggerLevel : public BC_FPot
128 {
129 public:
130         AudioScopeTriggerLevel(AudioScope *plugin, int x, int y);
131         int handle_event();
132         AudioScope *plugin;
133 };
134
135
136
137 class AudioScopeCanvas : public BC_SubWindow
138 {
139 public:
140         AudioScopeCanvas(AudioScope *plugin,
141                 int x,
142                 int y,
143                 int w,
144                 int h);
145         int button_press_event();
146         int button_release_event();
147         int cursor_motion_event();
148         void calculate_point();
149
150         enum
151         {
152                 NONE,
153                 DRAG
154         };
155
156         int current_operation;
157         AudioScope *plugin;
158 };
159
160
161 class AudioScopeWindow : public PluginClientWindow
162 {
163 public:
164         AudioScopeWindow(AudioScope *plugin);
165         ~AudioScopeWindow();
166
167         void create_objects();
168         void update_gui();
169         int resize_event(int w, int h);
170         void calculate_probe(int x, int y, int do_overlay);
171         void draw_overlay();
172         void draw_trigger();
173         void draw_probe();
174
175         BC_Title *window_size_title;
176         AudioScopeWindowSize *window_size;
177         AudioScopeWindowSizeTumbler *window_size_tumbler;
178         AudioScope *plugin;
179
180         BC_Title *history_size_title;
181         AudioScopeHistory *history_size;
182
183         AudioScopeCanvas *canvas;
184
185         BC_Title *mode_title;
186         AudioScopeMode *mode;
187
188         BC_Title *trigger_level_title;
189         AudioScopeTriggerLevel *trigger_level;
190
191         BC_Title *probe_sample;
192         BC_Title *probe_level0;
193         BC_Title *probe_level1;
194
195         int probe_x;
196         int probe_y;
197 };
198
199
200
201
202
203
204 class AudioScopeConfig
205 {
206 public:
207         AudioScopeConfig();
208         int equivalent(AudioScopeConfig &that);
209         void copy_from(AudioScopeConfig &that);
210         void interpolate(AudioScopeConfig &prev,
211                 AudioScopeConfig &next,
212                 int64_t prev_frame,
213                 int64_t next_frame,
214                 int64_t current_frame);
215         int window_size;
216         int history_size;
217
218         int mode;
219         double trigger_level;
220 };
221
222 // Header for data buffer
223 typedef struct
224 {
225         int window_size;
226 // Total fragments in this buffer
227         int total_windows;
228 // Samplerate
229         int sample_rate;
230         int channels;
231 // Nothing goes after this
232         float samples[1];
233 } data_header_t;
234
235 class AudioScopeFrame
236 {
237 public:
238         AudioScopeFrame(int data_size, int channels);
239         ~AudioScopeFrame();
240
241         int size;
242         int channels;
243         float *data[CHANNELS];
244 // Draw immediately
245         int force;
246 };
247
248 class AudioScope : public PluginAClient
249 {
250 public:
251         AudioScope(PluginServer *server);
252         ~AudioScope();
253
254         PLUGIN_CLASS_MEMBERS2(AudioScopeConfig)
255         int is_realtime();
256         int is_multichannel();
257         int process_buffer(int64_t size,
258                 Samples **buffer,
259                 int64_t start_position,
260                 int sample_rate);
261         void read_data(KeyFrame *keyframe);
262         void save_data(KeyFrame *keyframe);
263         void update_gui();
264         void render_gui(void *data, int size);
265         void render_stop();
266
267         void reset();
268
269         int need_reconfigure;
270 // Data buffer for frequency & magnitude
271         unsigned char *data;
272 // Accumulate data for windowing
273         Samples *audio_buffer[CHANNELS];
274 // Total samples in the buffer
275         int buffer_size;
276 // Last window size rendered
277         int window_size;
278 // Total windows sent to current GUI
279         int total_windows;
280 // Starting sample in audio_buffer.
281         int64_t audio_buffer_start;
282 // Total floats allocated in data buffer
283         int allocated_data;
284 // Accumulates canvas pixels until the next update_gui
285         ArrayList<AudioScopeFrame*> frame_buffer;
286 // Past frames for the shadow effect
287         ArrayList<AudioScopeFrame*> frame_history;
288 // Data for probe
289         AudioScopeFrame *current_frame;
290 // Header from last data buffer
291         data_header_t header;
292 // Time of last GUI update
293         Timer *timer;
294
295         int w;
296         int h;
297 };
298
299
300 #endif