3 * Copyright (C) 2008-2019 Adam Williams <broadcast at earthling dot net>
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.
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.
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
22 // Base classes for compressors
24 #ifndef COMPRESSORTOOLS_H
25 #define COMPRESSORTOOLS_H
29 #include "pluginaclient.h"
30 #include "samples.inc"
33 #define MIN_ATTACK -10
38 #define MAX_TRIGGER 255
40 #define MIN_GAIN_CHANGE -20
41 #define MAX_GAIN_CHANGE 20
44 class CompressorConfigBase;
45 class CompressorPopup;
48 // get sample from trigger buffer
49 #define GET_TRIGGER(buffer, offset) \
51 switch(config->input) \
53 case CompressorConfigBase::MAX: \
56 for(int channel = 0; channel < channels; channel++) \
58 sample = fabs((buffer)[offset]); \
59 if(sample > max) max = sample; \
65 case CompressorConfigBase::TRIGGER: \
66 sample = fabs(trigger_buffer[offset]); \
69 case CompressorConfigBase::SUM: \
72 for(int channel = 0; channel < channels; channel++) \
74 sample = fabs((buffer)[offset]); \
96 virtual ~BandConfig();
98 void copy_from(BandConfig *src);
99 int equiv(BandConfig *src);
100 void boundaries(CompressorConfigBase *base);
101 void save_data(FileXML *xml, int number, int do_multiband);
102 void read_data(FileXML *xml, int do_multiband);
105 ArrayList<compressor_point_t> levels;
109 // double readahead_len;
114 // upper frequency in Hz
118 class CompressorConfigBase
121 CompressorConfigBase(int total_bands);
122 virtual ~CompressorConfigBase();
124 virtual void copy_from(CompressorConfigBase &that);
125 virtual int equivalent(CompressorConfigBase &that);
130 void remove_point(int band, int number);
131 int set_point(int band, double x, double y);
132 double calculate_db(int band, double x);
133 double get_x(int band, int number);
134 double get_y(int band, int number);
135 double calculate_gain(int band, double input);
137 // Calculate linear output from linear input
138 double calculate_output(int band, double x);
140 // min DB of the graph
142 // max DB of the graph
158 // double min_x, min_y;
159 // double max_x, max_y;
164 class CompressorCanvasBase : public BC_SubWindow
167 CompressorCanvasBase(CompressorConfigBase *config, PluginClient *plugin,
168 PluginClientWindow *window, int x, int y, int w, int h);
169 virtual ~CompressorCanvasBase();
171 int button_press_event();
172 int button_release_event();
173 int cursor_motion_event();
174 void create_objects();
177 int x_to_y(int band, int x);
178 int db_to_x(double db);
179 int db_to_y(double db);
180 double x_to_db(int x);
181 double y_to_db(int y);
183 virtual void update_window();
187 // clickable area of canvas
188 int graph_x, graph_y;
189 int graph_w, graph_h;
191 int current_operation;
194 CompressorConfigBase *config;
195 CompressorPopup *menu;
196 PluginClient *plugin;
197 PluginClientWindow *window;
201 #define FREQ_COMPRESSORFRAME 0
202 #define GAIN_COMPRESSORFRAME 1
203 // used in eqcanvas, compressortools,
204 // plugins: compressor, compressormulti
205 class CompressorClientFrame : public PluginClientFrame
208 CompressorClientFrame();
209 ~CompressorClientFrame();
213 class CompressorFreqFrame : public CompressorClientFrame
216 CompressorFreqFrame();
217 ~CompressorFreqFrame();
219 double freq_max, time_max;
225 class CompressorGainFrame : public CompressorClientFrame
228 CompressorGainFrame();
229 ~CompressorGainFrame();
234 class CompressorEngine
237 CompressorEngine(CompressorConfigBase *config,
242 void calculate_ranges(int *attack_samples,
243 int *release_samples,
244 int *preview_samples,
246 void process(Samples **output_buffer,
247 Samples **input_buffer,
251 int64_t start_position);
253 CompressorConfigBase *config;
255 // the current line segment defining the smooth signal level
256 // starting input value of line segment
258 // ending input value of line segment
260 // samples comprising the line segment
262 // samples from the start of the line to the peak that determined the slope
264 // current sample from 0 to slope_samples
265 int slope_current_sample;
266 // current value in the line segment
267 double current_value;
268 // gain change values to draw on the GUI
269 ArrayList<double> gui_gains;
270 // input levels to draw on the GUI
271 ArrayList<double> gui_levels;
272 // which second in process() the gui_values came from
273 ArrayList<double> gui_offsets;
274 // samples between gui_values. Set by the user.
275 int gui_frame_samples;
277 int gui_frame_counter;
279 double gui_max_level;
283 class CompressorCopy : public BC_MenuItem
286 CompressorCopy(CompressorPopup *popup);
289 CompressorPopup *popup;
292 class CompressorPaste : public BC_MenuItem
295 CompressorPaste(CompressorPopup *popup);
298 CompressorPopup *popup;
301 class CompressorClearGraph : public BC_MenuItem
304 CompressorClearGraph(CompressorPopup *popup);
305 ~CompressorClearGraph();
307 CompressorPopup *popup;
310 class CompressorPopup : public BC_PopupMenu
313 CompressorPopup(CompressorCanvasBase *canvas);
316 void create_objects();
319 CompressorCanvasBase *canvas;