remove whitespace at eol
[goodguy/history.git] / cinelerra-5.1 / plugins / compressor / compressor.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 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 COMPRESSOR_H
23 #define COMPRESSOR_H
24
25
26
27 #include "bchash.inc"
28 #include "guicast.h"
29 #include "mutex.h"
30 #include "pluginaclient.h"
31 #include "samples.inc"
32 #include "vframe.inc"
33
34 class CompressorEffect;
35
36
37
38
39
40 class CompressorCanvas : public BC_SubWindow
41 {
42 public:
43         CompressorCanvas(CompressorEffect *plugin, int x, int y, int w, int h);
44         int button_press_event();
45         int button_release_event();
46         int cursor_motion_event();
47
48
49         enum
50         {
51                 NONE,
52                 DRAG
53         };
54
55         int current_point;
56         int current_operation;
57         CompressorEffect *plugin;
58 };
59
60
61 class CompressorReaction : public BC_TextBox
62 {
63 public:
64         CompressorReaction(CompressorEffect *plugin, int x, int y);
65         int handle_event();
66         int button_press_event();
67         CompressorEffect *plugin;
68 };
69
70 class CompressorClear : public BC_GenericButton
71 {
72 public:
73         CompressorClear(CompressorEffect *plugin, int x, int y);
74         int handle_event();
75         CompressorEffect *plugin;
76 };
77
78 class CompressorX : public BC_TextBox
79 {
80 public:
81         CompressorX(CompressorEffect *plugin, int x, int y);
82         int handle_event();
83         CompressorEffect *plugin;
84 };
85
86 class CompressorY : public BC_TextBox
87 {
88 public:
89         CompressorY(CompressorEffect *plugin, int x, int y);
90         int handle_event();
91         CompressorEffect *plugin;
92 };
93
94 class CompressorTrigger : public BC_TextBox
95 {
96 public:
97         CompressorTrigger(CompressorEffect *plugin, int x, int y);
98         int handle_event();
99         int button_press_event();
100         CompressorEffect *plugin;
101 };
102
103 class CompressorDecay : public BC_TextBox
104 {
105 public:
106         CompressorDecay(CompressorEffect *plugin, int x, int y);
107         int handle_event();
108         int button_press_event();
109         CompressorEffect *plugin;
110 };
111
112 class CompressorSmooth : public BC_CheckBox
113 {
114 public:
115         CompressorSmooth(CompressorEffect *plugin, int x, int y);
116         int handle_event();
117         CompressorEffect *plugin;
118 };
119
120 class CompressorInput : public BC_PopupMenu
121 {
122 public:
123         CompressorInput(CompressorEffect *plugin, int x, int y);
124         void create_objects();
125         int handle_event();
126         static const char* value_to_text(int value);
127         static int text_to_value(char *text);
128         CompressorEffect *plugin;
129 };
130
131
132
133 class CompressorWindow : public PluginClientWindow
134 {
135 public:
136         CompressorWindow(CompressorEffect *plugin);
137         void create_objects();
138         void update();
139         void update_textboxes();
140         void update_canvas();
141         void draw_scales();
142         int resize_event(int w, int h);
143
144         CompressorCanvas *canvas;
145         CompressorReaction *reaction;
146         CompressorClear *clear;
147         CompressorX *x_text;
148         CompressorY *y_text;
149         CompressorTrigger *trigger;
150         CompressorDecay *decay;
151         CompressorSmooth *smooth;
152         CompressorInput *input;
153         CompressorEffect *plugin;
154 };
155
156
157
158 typedef struct
159 {
160 // DB from min_db - 0
161         double x, y;
162 } compressor_point_t;
163
164 class CompressorConfig
165 {
166 public:
167         CompressorConfig();
168
169         void copy_from(CompressorConfig &that);
170         int equivalent(CompressorConfig &that);
171         void interpolate(CompressorConfig &prev,
172                 CompressorConfig &next,
173                 int64_t prev_frame,
174                 int64_t next_frame,
175                 int64_t current_frame);
176
177         int total_points();
178         void remove_point(int number);
179         void optimize();
180 // Return values of a specific point
181         double get_y(int number);
182         double get_x(int number);
183 // Returns db output from db input
184         double calculate_db(double x);
185         int set_point(double x, double y);
186         void dump();
187
188         int trigger;
189         int input;
190         enum
191         {
192                 TRIGGER,
193                 MAX,
194                 SUM
195         };
196         double min_db;
197         double reaction_len;
198         double decay_len;
199         double min_x, min_y;
200         double max_x, max_y;
201         int smoothing_only;
202         ArrayList<compressor_point_t> levels;
203 };
204
205 class CompressorEffect : public PluginAClient
206 {
207 public:
208         CompressorEffect(PluginServer *server);
209         ~CompressorEffect();
210
211         int is_multichannel();
212         int is_realtime();
213         void read_data(KeyFrame *keyframe);
214         void save_data(KeyFrame *keyframe);
215         int process_buffer(int64_t size,
216                 Samples **buffer,
217                 int64_t start_position,
218                 int sample_rate);
219         double calculate_gain(double input);
220
221 // Calculate linear output from linear input
222         double calculate_output(double x);
223
224
225         void reset();
226         void update_gui();
227         void delete_dsp();
228
229         PLUGIN_CLASS_MEMBERS(CompressorConfig)
230
231 // The raw input data for each channel with readahead
232         Samples **input_buffer;
233 // Number of samples in the input buffer
234         int64_t input_size;
235 // Number of samples allocated in the input buffer
236         int64_t input_allocated;
237 // Starting sample of input buffer relative to project in requested rate.
238         int64_t input_start;
239
240 // ending input value of smoothed input
241         double next_target;
242 // starting input value of smoothed input
243         double previous_target;
244 // samples between previous and next target value for readahead
245         int target_samples;
246 // current sample from 0 to target_samples
247         int target_current_sample;
248 // current smoothed input value
249         double current_value;
250 // Temporaries for linear transfer
251         ArrayList<compressor_point_t> levels;
252         double min_x, min_y;
253         double max_x, max_y;
254 };
255
256
257 #endif