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);
104 ArrayList<compressor_point_t> levels;
108 // double readahead_len;
112 // upper frequency in Hz
116 class CompressorConfigBase
119 CompressorConfigBase(int total_bands);
120 virtual ~CompressorConfigBase();
122 virtual void copy_from(CompressorConfigBase &that);
123 virtual int equivalent(CompressorConfigBase &that);
126 void remove_point(int band, int number);
127 int set_point(int band, double x, double y);
128 double calculate_db(int band, double x);
129 double get_x(int band, int number);
130 double get_y(int band, int number);
131 double calculate_gain(int band, double input);
133 // Calculate linear output from linear input
134 double calculate_output(int band, double x);
136 // min DB of the graph
138 // max DB of the graph
154 // double min_x, min_y;
155 // double max_x, max_y;
160 class CompressorCanvasBase : public BC_SubWindow
163 CompressorCanvasBase(CompressorConfigBase *config, PluginClient *plugin,
164 PluginClientWindow *window, int x, int y, int w, int h);
165 virtual ~CompressorCanvasBase();
167 int button_press_event();
168 int button_release_event();
169 int cursor_motion_event();
170 void create_objects();
173 int x_to_y(int band, int x);
174 int db_to_x(double db);
175 int db_to_y(double db);
176 double x_to_db(int x);
177 double y_to_db(int y);
179 virtual void update_window();
183 // clickable area of canvas
184 int graph_x, graph_y;
185 int graph_w, graph_h;
187 int current_operation;
190 CompressorConfigBase *config;
191 CompressorPopup *menu;
192 PluginClient *plugin;
193 PluginClientWindow *window;
197 #define FREQ_COMPRESSORFRAME 0
198 #define GAIN_COMPRESSORFRAME 1
199 // used in eqcanvas, compressortools,
200 // plugins: compressor, compressormulti
201 class CompressorClientFrame : public PluginClientFrame
204 CompressorClientFrame();
205 ~CompressorClientFrame();
209 class CompressorFreqFrame : public CompressorClientFrame
212 CompressorFreqFrame();
213 ~CompressorFreqFrame();
215 double freq_max, time_max;
221 class CompressorGainFrame : public CompressorClientFrame
224 CompressorGainFrame();
225 ~CompressorGainFrame();
230 class CompressorEngine
233 CompressorEngine(CompressorConfigBase *config,
238 void calculate_ranges(int *attack_samples,
239 int *release_samples,
240 int *preview_samples,
242 void process(Samples **output_buffer,
243 Samples **input_buffer,
247 int64_t start_position);
249 CompressorConfigBase *config;
251 // the current line segment defining the smooth signal level
252 // starting input value of line segment
254 // ending input value of line segment
256 // samples comprising the line segment
258 // samples from the start of the line to the peak that determined the slope
260 // current sample from 0 to slope_samples
261 int slope_current_sample;
262 // current value in the line segment
263 double current_value;
264 // gain change values to draw on the GUI
265 ArrayList<double> gui_gains;
266 // input levels to draw on the GUI
267 ArrayList<double> gui_levels;
268 // which second in process() the gui_values came from
269 ArrayList<double> gui_offsets;
270 // samples between gui_values. Set by the user.
271 int gui_frame_samples;
273 int gui_frame_counter;
275 double gui_max_level;
279 class CompressorCopy : public BC_MenuItem
282 CompressorCopy(CompressorPopup *popup);
285 CompressorPopup *popup;
288 class CompressorPaste : public BC_MenuItem
291 CompressorPaste(CompressorPopup *popup);
294 CompressorPopup *popup;
297 class CompressorClearGraph : public BC_MenuItem
300 CompressorClearGraph(CompressorPopup *popup);
301 ~CompressorClearGraph();
303 CompressorPopup *popup;
306 class CompressorPopup : public BC_PopupMenu
309 CompressorPopup(CompressorCanvasBase *canvas);
312 void create_objects();
315 CompressorCanvasBase *canvas;
318 #define GRAPH_BG_COLOR 0x559977
319 #define GRAPH_BORDER1_COLOR 0xeeaa44
320 #define GRAPH_BORDER2_COLOR 0xeeaaff
321 #define GRAPH_GRID_COLOR 0xeeffcc
322 #define GRAPH_ACTIVE_COLOR 0x99cc77
323 #define GRAPH_INACTIVE_COLOR 0x666688