remove whitespace at eol
[goodguy/history.git] / cinelerra-5.1 / plugins / graphic / graphic.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 GRAPHIC_H
23 #define GRAPHIC_H
24
25 #include "guicast.h"
26 #include "fourier.h"
27 #include "pluginaclient.h"
28
29
30 #define MAX_WINDOW 262144
31 //#define WINDOW_SIZE 16384
32 #define MAXMAGNITUDE 15
33 #define MAXFREQ 20000
34 #define MIN_DB -15
35 #define MAX_DB 15
36
37
38 class GraphicGUI;
39 class GraphicEQ;
40
41
42
43 class GraphicPoint
44 {
45 public:
46         GraphicPoint();
47 // Frequency in Hz
48         int freq;
49 // Amplitude in DB
50         double value;
51 };
52
53
54
55 class GraphicConfig
56 {
57 public:
58         GraphicConfig();
59         ~GraphicConfig();
60
61         int equivalent(GraphicConfig &that);
62         void copy_from(GraphicConfig &that);
63         void interpolate(GraphicConfig &prev,
64                 GraphicConfig &next,
65                 int64_t prev_frame,
66                 int64_t next_frame,
67                 int64_t current_frame);
68         void insert_point(GraphicPoint *point);
69         void delete_point(int number);
70
71         ArrayList<GraphicPoint*> points;
72 //      double wetness;
73         int window_size;
74 };
75
76
77
78 class GraphicCanvas : public BC_SubWindow
79 {
80 public:
81         GraphicCanvas(GraphicEQ *plugin, GraphicGUI *gui, int x, int y, int w, int h);
82         virtual ~GraphicCanvas();
83         int button_press_event();
84         int cursor_motion_event();
85         int button_release_event();
86         void process(int buttonpress, int motion, int draw);
87         int freq_to_y(int freq,
88                 ArrayList<GraphicPoint*> *points,
89                 double *envelope);
90         void insert_point(GraphicPoint *point);
91         GraphicEQ *plugin;
92         GraphicGUI *gui;
93
94 // Temporary envelope when editing
95         void new_temps();
96         void save_temps();
97
98         ArrayList<GraphicPoint*> temp_points;
99         double temp_envelope[MAX_WINDOW / 2];
100
101
102
103
104         int state;
105         enum
106         {
107                 NONE,
108                 DRAG_POINT
109         };
110         int x_diff, y_diff;
111 };
112
113 class FreqTextBox : public BC_TextBox
114 {
115 public:
116         FreqTextBox(GraphicEQ *plugin,
117                 GraphicGUI *gui,
118                 int x,
119                 int y,
120                 int w);
121         int handle_event();
122         void update(int freq);
123         GraphicEQ *plugin;
124         GraphicGUI *gui;
125 };
126
127 class ValueTextBox : public BC_TextBox
128 {
129 public:
130         ValueTextBox(GraphicEQ *plugin,
131                 GraphicGUI *gui,
132                 int x,
133                 int y,
134                 int w);
135         int handle_event();
136         void update(float value);
137         GraphicEQ *plugin;
138         GraphicGUI *gui;
139 };
140
141 class GraphicReset : public BC_GenericButton
142 {
143 public:
144         GraphicReset(GraphicEQ *plugin,
145                 GraphicGUI *gui,
146                 int x,
147                 int y);
148         int handle_event();
149         GraphicEQ *plugin;
150         GraphicGUI *gui;
151 };
152
153
154 class GraphicSize : public BC_PopupMenu
155 {
156 public:
157         GraphicSize(GraphicGUI *window, GraphicEQ *plugin, int x, int y);
158
159         int handle_event();
160         void create_objects();         // add initial items
161         void update(int size);
162
163         GraphicGUI *window;
164         GraphicEQ *plugin;
165 };
166
167
168 class GraphicWetness : public BC_FPot
169 {
170 public:
171         GraphicWetness(GraphicGUI *window, GraphicEQ *plugin, int x, int y);
172         int handle_event();
173         GraphicGUI *window;
174         GraphicEQ *plugin;
175 };
176
177
178 class GraphicGUI : public PluginClientWindow
179 {
180 public:
181         GraphicGUI(GraphicEQ *plugin);
182         ~GraphicGUI();
183
184         void create_objects();
185         int keypress_event();
186         void update_canvas();
187         int resize_event(int w, int h);
188         void draw_ticks();
189         void update_textboxes();
190
191         FreqTextBox *freq_text;
192         ValueTextBox *value_text;
193         BC_Title *freq_title;
194         BC_Title *level_title;
195         BC_Title *size_title;
196
197         GraphicCanvas *canvas;
198         GraphicReset *reset;
199         GraphicSize *size;
200 //      GraphicWetness *wetness;
201         GraphicEQ *plugin;
202 };
203
204
205
206
207
208 class GraphicGUIFrame : public PluginClientFrame
209 {
210 public:
211         GraphicGUIFrame(int window_size, int sample_rate);
212         virtual ~GraphicGUIFrame();
213         double *data;
214 // Maximum of window in frequency domain
215         double freq_max;
216 // Maximum of window in time domain
217         double time_max;
218         int window_size;
219 };
220
221
222
223 class GraphicFFT : public CrossfadeFFT
224 {
225 public:
226         GraphicFFT(GraphicEQ *plugin);
227         ~GraphicFFT();
228
229         int post_process();
230         int signal_process();
231         int read_samples(int64_t output_sample,
232                 int samples,
233                 Samples *buffer);
234 // Current GUI frame being filled
235         GraphicGUIFrame *frame;
236
237         GraphicEQ *plugin;
238 };
239
240
241
242 class GraphicEQ : public PluginAClient
243 {
244 public:
245         GraphicEQ(PluginServer *server);
246         ~GraphicEQ();
247
248         int is_realtime();
249         void read_data(KeyFrame *keyframe);
250         void save_data(KeyFrame *keyframe);
251         int process_buffer(int64_t size,
252                 Samples *buffer,
253                 int64_t start_position,
254                 int sample_rate);
255         void update_gui();
256         double freq_to_magnitude(double frequency,
257                 ArrayList<GraphicPoint*> *points,
258                 double *envelope);
259         void calculate_envelope(ArrayList<GraphicPoint*> *points,
260                 double *envelope);
261         int active_point_exists();
262         void reconfigure();
263
264
265         PLUGIN_CLASS_MEMBERS(GraphicConfig)
266
267
268
269         double envelope[MAX_WINDOW / 2];
270         int active_point;
271 // For refreshing the canvas
272         GraphicGUIFrame *last_frame;
273         GraphicFFT *fft;
274         int need_reconfigure;
275         int w, h;
276 };
277
278
279
280 #endif // GRAPHIC_H