7258374b7680edd89a0fa56c28c2f53cfdc65c3b
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / scopewindow.h
1 /*
2  * CINELERRA
3  * Copyright (C) 1997-2011 Adam Williams <broadcast at earthling dot net>
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  */
20
21 #ifndef SCOPEWINDOW_H
22 #define SCOPEWINDOW_H
23
24
25 #include "boxblur.inc"
26 #include "guicast.h"
27 #include "loadbalance.h"
28 #include "mwindow.h"
29 #include "overlayframe.inc"
30 #include "pluginclient.h"
31 #include "recordmonitor.inc"
32 #include "scopewindow.inc"
33 #include "theme.inc"
34
35 enum {
36         SCOPE_HISTOGRAM, SCOPE_HISTOGRAM_RGB,
37         SCOPE_WAVEFORM, SCOPE_WAVEFORM_RGB, SCOPE_WAVEFORM_PLY,
38         SCOPE_VECTORSCOPE, SCOPE_VECTORWHEEL,
39 };
40
41 // Number of divisions in histogram.
42 // 65536 + min and max range to speed up the tabulation
43 #define TOTAL_BINS 0x13333
44 #define HIST_SECTIONS 4
45 #define FLOAT_RANGE 1.2
46 // Minimum value in percentage
47 #define HISTOGRAM_MIN -10
48 #define FLOAT_MIN -0.1
49 // Maximum value in percentage
50 #define HISTOGRAM_MAX 110
51 #define FLOAT_MAX 1.1
52
53 #define MIN_SCOPE_W xS(320)
54 #define MIN_SCOPE_H yS(320)
55
56
57 #define WAVEFORM_DIVISIONS 12
58 #define VECTORSCOPE_DIVISIONS 11
59
60 class ScopePackage : public LoadPackage
61 {
62 public:
63         ScopePackage();
64         int row1, row2;
65 };
66
67
68 class ScopeUnit : public LoadClient
69 {
70 public:
71         ScopeUnit(ScopeGUI *gui, ScopeEngine *server);
72         void process_package(LoadPackage *package);
73         int bins[HIST_SECTIONS][TOTAL_BINS];
74         ScopeGUI *gui;
75 };
76
77 class ScopeEngine : public LoadServer
78 {
79 public:
80         ScopeEngine(ScopeGUI *gui, int cpus);
81         virtual ~ScopeEngine();
82         void init_packages();
83         LoadClient* new_client();
84         LoadPackage* new_package();
85         void process();
86         ScopeGUI *gui;
87 };
88
89 class ScopePanel : public BC_SubWindow
90 {
91 public:
92         ScopePanel(ScopeGUI *gui, int x, int y, int w, int h);
93         void create_objects();
94         virtual void update_point(int x, int y);
95         virtual void draw_point();
96         virtual void clear_point();
97         int button_press_event();
98         int cursor_motion_event();
99         int button_release_event();
100         int is_dragging;
101         ScopeGUI *gui;
102 };
103
104 class ScopeWaveform : public ScopePanel
105 {
106 public:
107         ScopeWaveform(ScopeGUI *gui, int x, int y, int w, int h);
108         virtual void update_point(int x, int y);
109         virtual void draw_point();
110         virtual void clear_point();
111         int drag_x;
112         int drag_y;
113 };
114
115
116 class ScopeVectorscope : public ScopePanel
117 {
118 public:
119         ScopeVectorscope(ScopeGUI *gui, int x, int y, int w, int h);
120         virtual void update_point(int x, int y);
121         virtual void draw_point();
122         virtual void clear_point();
123         void draw_point(float th, float r, int color);
124         void draw_radient(float th, float r1, float r2, int color);
125
126         int drag_radius;
127         float drag_angle;
128 };
129
130 class ScopeHistogram : public ScopePanel
131 {
132 public:
133         ScopeHistogram(ScopeGUI *gui, int x, int y, int w, int h);
134         void clear_point();
135         void update_point(int x, int y);
136         void draw_point();
137         void draw(int flash, int flush);
138         void draw_mode(int mode, int color, int y, int h);
139         int drag_x;
140 };
141
142
143 class ScopeScopesOn : public BC_MenuItem
144 {
145 public:
146         ScopeScopesOn(ScopeMenu *scope_menu, const char *text, int id);
147         int handle_event();
148
149         ScopeMenu *scope_menu;
150         int id;
151 };
152
153 class ScopeMenu : public BC_PopupMenu
154 {
155 public:
156         ScopeMenu(ScopeGUI *gui, int x, int y);
157         void create_objects();
158         void update_toggles();
159
160         ScopeGUI *gui;
161         ScopeScopesOn *hist_on;
162         ScopeScopesOn *hist_rgb_on;
163         ScopeScopesOn *wave_on;
164         ScopeScopesOn *wave_rgb_on;
165         ScopeScopesOn *wave_ply_on;
166         ScopeScopesOn *vect_on;
167         ScopeScopesOn *vect_wheel;
168 };
169
170
171 class ScopeGratPaths : public ArrayList<const char *>
172 {
173 public:
174         ScopeGratPaths() { set_array_delete(); }
175         ~ScopeGratPaths() { remove_all_objects(); }
176 };
177
178 class ScopeGratItem : public BC_MenuItem
179 {
180 public:
181         ScopeGratItem(ScopeVectGrats *vect_grats, const char *text, int idx);
182         int handle_event();
183
184         ScopeVectGrats *vect_grats;
185         int idx;
186 };
187
188 class ScopeVectGrats : public BC_PopupMenu
189 {
190 public:
191         ScopeVectGrats(ScopeGUI *gui, int x, int y);
192         void create_objects();
193
194         ScopeGUI *gui;
195 };
196
197
198 class ScopeGainReset : public BC_Button
199 {
200 public:
201         ScopeGainReset(ScopeGain *gain, int x, int y);
202         static int calculate_w(BC_Theme *theme);
203         int handle_event();
204
205         ScopeGain *gain;
206 };
207
208 class ScopeGainSlider : public BC_ISlider
209 {
210 public:
211         ScopeGainSlider(ScopeGain *gain, int x, int y, int w);
212
213         int handle_event();
214         ScopeGain *gain;
215 };
216
217 class ScopeGain
218 {
219 public:
220         ScopeGain(ScopeGUI *gui, int x, int y, int w, int *value);
221         ~ScopeGain();
222         static int calculate_h();
223         void create_objects();
224         void reposition_window(int x, int y);
225         int handle_event();
226
227         ScopeGUI *gui;
228         int x, y, w, *value;
229         int reset_w;
230         ScopeGainReset *reset;
231         ScopeGainSlider *slider;
232
233         int get_x() { return x; }
234         int get_y() { return y; }
235         int get_w() { return w; }
236         int get_h() { return calculate_h(); }
237 };
238
239 class ScopeWaveSlider : public ScopeGain
240 {
241 public:
242         ScopeWaveSlider(ScopeGUI *gui, int x, int y, int w);
243 };
244
245 class ScopeVectSlider : public ScopeGain
246 {
247 public:
248         ScopeVectSlider(ScopeGUI *gui, int x, int y, int w);
249 };
250
251
252 class ScopeSmooth : public BC_CheckBox
253 {
254 public:
255         ScopeSmooth(ScopeGUI *gui, int x, int y);
256         int handle_event();
257         ScopeGUI *gui;
258 };
259
260
261 class ScopeGUI : public PluginClientWindow
262 {
263 public:
264         ScopeGUI(Theme *theme, int x, int y, int w, int h, int cpus);
265         ScopeGUI(PluginClient *plugin, int w, int h);
266         virtual ~ScopeGUI();
267
268         void reset();
269         virtual void create_objects();
270         void create_panels();
271         virtual int resize_event(int w, int h);
272         virtual int translation_event();
273         virtual void update_scope() {}
274
275 // Called for user storage when toggles change
276         virtual void toggle_event();
277
278 // update toggles
279         void update_toggles();
280         void calculate_sizes(int w, int h);
281         void allocate_vframes();
282         void draw_overlays(int overlays, int borders, int flush);
283         void update_graticule(int idx);
284         void draw_colorwheel(VFrame *dst, int bg_color);
285         void draw_scope();
286         void process(VFrame *output_frame);
287         void draw(int flash, int flush);
288         void clear_points(int flash);
289
290         Theme *theme;
291         VFrame *output_frame;
292         VFrame *data_frame, *temp_frame;
293         ScopeEngine *engine;
294         BoxBlur *box_blur;
295         VFrame *waveform_vframe;
296         VFrame *vector_vframe;
297         VFrame *wheel_vframe;
298         ScopeHistogram *histogram;
299         ScopeWaveform *waveform;
300         ScopeVectorscope *vectorscope;
301         ScopeMenu *scope_menu;
302         ScopeWaveSlider *wave_slider;
303         ScopeVectSlider *vect_slider;
304         ScopeVectGrats *vect_grats;
305         ScopeSmooth *smooth;
306         VFrame *grat_image;
307         OverlayFrame *overlay;
308
309         int x, y, w, h;
310         int vector_x, vector_y, vector_w, vector_h;
311         int vector_cx, vector_cy, radius;
312         int wave_x, wave_y, wave_w, wave_h;
313         int hist_x, hist_y, hist_w, hist_h;
314         int text_color, dark_color;
315
316         ScopeGratPaths grat_paths;
317         int grat_idx, use_graticule;
318
319         int cpus;
320         int use_hist, use_wave, use_vector;
321         int use_hist_parade, use_wave_parade;
322
323         int bins[HIST_SECTIONS][TOTAL_BINS];
324         int frame_w, use_smooth;
325         int use_wave_gain, use_vect_gain;
326 };
327
328 #endif