4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
22 #include "bcdisplayinfo.h"
23 #include "bcsignals.h"
25 #include "compressor.h"
42 REGISTER_PLUGIN(CompressorEffect)
49 // More potential compressor algorithms:
50 // Use single reaction time parameter. Negative reaction time uses
51 // readahead. Positive reaction time uses slope.
53 // Smooth input stage if readahead.
54 // Determine slope from current smoothed sample to every sample in readahead area.
55 // Once highest slope is found, count of number of samples remaining until it is
56 // reached. Only search after this count for the next highest slope.
57 // Use highest slope to determine smoothed value.
59 // Smooth input stage if not readahead.
60 // For every sample, calculate slope needed to reach current sample from
61 // current smoothed value in the reaction time. If higher than current slope,
62 // make it the current slope and count number of samples remaining until it is
63 // reached. If this count is met and no higher slopes are found, base slope
64 // on current sample when count is met.
67 // For every sample, calculate gain from smoothed input value.
73 CompressorEffect::CompressorEffect(PluginServer *server)
74 : PluginAClient(server)
80 CompressorEffect::~CompressorEffect()
87 void CompressorEffect::delete_dsp()
91 for(int i = 0; i < PluginClient::total_in_buffers; i++)
92 delete input_buffer[i];
93 delete [] input_buffer;
103 void CompressorEffect::reset()
111 previous_target = 1.0;
113 target_current_sample = -1;
117 const char* CompressorEffect::plugin_title() { return _("Compressor"); }
118 int CompressorEffect::is_realtime() { return 1; }
119 int CompressorEffect::is_multichannel() { return 1; }
123 void CompressorEffect::read_data(KeyFrame *keyframe)
126 input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
129 config.levels.remove_all();
132 result = input.read_tag();
136 if(input.tag.title_is("COMPRESSOR"))
138 config.reaction_len = input.tag.get_property("REACTION_LEN", config.reaction_len);
139 config.decay_len = input.tag.get_property("DECAY_LEN", config.decay_len);
140 config.trigger = input.tag.get_property("TRIGGER", config.trigger);
141 config.smoothing_only = input.tag.get_property("SMOOTHING_ONLY", config.smoothing_only);
142 config.input = input.tag.get_property("INPUT", config.input);
145 if(input.tag.title_is("LEVEL"))
147 double x = input.tag.get_property("X", (double)0);
148 double y = input.tag.get_property("Y", (double)0);
149 compressor_point_t point = { x, y };
151 config.levels.append(point);
157 void CompressorEffect::save_data(KeyFrame *keyframe)
160 output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
162 output.tag.set_title("COMPRESSOR");
163 output.tag.set_property("TRIGGER", config.trigger);
164 output.tag.set_property("REACTION_LEN", config.reaction_len);
165 output.tag.set_property("DECAY_LEN", config.decay_len);
166 output.tag.set_property("SMOOTHING_ONLY", config.smoothing_only);
167 output.tag.set_property("INPUT", config.input);
169 output.append_newline();
172 for(int i = 0; i < config.levels.total; i++)
174 output.tag.set_title("LEVEL");
175 output.tag.set_property("X", config.levels.values[i].x);
176 output.tag.set_property("Y", config.levels.values[i].y);
179 output.append_newline();
182 output.terminate_string();
186 void CompressorEffect::update_gui()
190 if(load_configuration())
192 thread->window->lock_window("CompressorEffect::update_gui");
193 ((CompressorWindow*)thread->window)->update();
194 thread->window->unlock_window();
200 LOAD_CONFIGURATION_MACRO(CompressorEffect, CompressorConfig)
201 NEW_WINDOW_MACRO(CompressorEffect, CompressorWindow)
206 int CompressorEffect::process_buffer(int64_t size,
208 int64_t start_position,
211 load_configuration();
213 // Calculate linear transfer from db
215 for(int i = 0; i < config.levels.total; i++)
218 levels.values[i].x = DB::fromdb(config.levels.values[i].x);
219 levels.values[i].y = DB::fromdb(config.levels.values[i].y);
221 min_x = DB::fromdb(config.min_db);
222 min_y = DB::fromdb(config.min_db);
227 int reaction_samples = (int)(config.reaction_len * sample_rate + 0.5);
228 int decay_samples = (int)(config.decay_len * sample_rate + 0.5);
229 int trigger = CLIP(config.trigger, 0, PluginAClient::total_in_buffers - 1);
231 CLAMP(reaction_samples, -1000000, 1000000);
232 CLAMP(decay_samples, reaction_samples, 1000000);
233 CLAMP(decay_samples, 1, 1000000);
234 if(labs(reaction_samples) < 1) reaction_samples = 1;
235 if(labs(decay_samples) < 1) decay_samples = 1;
237 int total_buffers = get_total_buffers();
238 if(reaction_samples >= 0)
240 if(target_current_sample < 0) target_current_sample = reaction_samples;
241 for(int i = 0; i < total_buffers; i++)
243 read_samples(buffer[i],
250 double current_slope = (next_target - previous_target) /
252 double *trigger_buffer = buffer[trigger]->get_data();
253 for(int i = 0; i < size; i++)
255 // Get slope required to reach current sample from smoothed sample over reaction
260 case CompressorConfig::MAX:
263 for(int j = 0; j < total_buffers; j++)
265 sample = fabs(buffer[j]->get_data()[i]);
266 if(sample > max) max = sample;
272 case CompressorConfig::TRIGGER:
273 sample = fabs(trigger_buffer[i]);
276 case CompressorConfig::SUM:
279 for(int j = 0; j < total_buffers; j++)
281 sample = fabs(buffer[j]->get_data()[i]);
289 double new_slope = (sample - current_value) /
292 // Slope greater than current slope
293 if(new_slope >= current_slope &&
294 (current_slope >= 0 ||
297 next_target = sample;
298 previous_target = current_value;
299 target_current_sample = 0;
300 target_samples = reaction_samples;
301 current_slope = new_slope;
304 if(sample > next_target && current_slope < 0)
306 next_target = sample;
307 previous_target = current_value;
308 target_current_sample = 0;
309 target_samples = decay_samples;
310 current_slope = (sample - current_value) / decay_samples;
312 // Current smoothed sample came up without finding higher slope
313 if(target_current_sample >= target_samples)
315 next_target = sample;
316 previous_target = current_value;
317 target_current_sample = 0;
318 target_samples = decay_samples;
319 current_slope = (sample - current_value) / decay_samples;
322 // Update current value and store gain
323 current_value = (next_target * target_current_sample +
324 previous_target * (target_samples - target_current_sample)) /
327 target_current_sample++;
329 if(config.smoothing_only)
331 for(int j = 0; j < total_buffers; j++)
332 buffer[j]->get_data()[i] = current_value;
336 double gain = calculate_gain(current_value);
337 for(int j = 0; j < total_buffers; j++)
339 buffer[j]->get_data()[i] *= gain;
346 if(target_current_sample < 0) target_current_sample = target_samples;
347 int64_t preview_samples = -reaction_samples;
349 // Start of new buffer is outside the current buffer. Start buffer over.
350 if(start_position < input_start ||
351 start_position >= input_start + input_size)
354 input_start = start_position;
357 // Shift current buffer so the buffer starts on start_position
358 if(start_position > input_start &&
359 start_position < input_start + input_size)
363 int len = input_start + input_size - start_position;
364 for(int i = 0; i < total_buffers; i++)
366 memcpy(input_buffer[i]->get_data(),
367 input_buffer[i]->get_data() + (start_position - input_start),
368 len * sizeof(double));
371 input_start = start_position;
375 // Expand buffer to handle preview size
376 if(size + preview_samples > input_allocated)
378 Samples **new_input_buffer = new Samples*[total_buffers];
379 for(int i = 0; i < total_buffers; i++)
381 new_input_buffer[i] = new Samples(size + preview_samples);
384 memcpy(new_input_buffer[i]->get_data(),
385 input_buffer[i]->get_data(),
386 input_size * sizeof(double));
387 delete input_buffer[i];
390 if(input_buffer) delete [] input_buffer;
392 input_allocated = size + preview_samples;
393 input_buffer = new_input_buffer;
396 // Append data to input buffer to construct readahead area.
397 #define MAX_FRAGMENT_SIZE 131072
398 while(input_size < size + preview_samples)
400 int fragment_size = MAX_FRAGMENT_SIZE;
401 if(fragment_size + input_size > size + preview_samples)
402 fragment_size = size + preview_samples - input_size;
403 for(int i = 0; i < total_buffers; i++)
405 input_buffer[i]->set_offset(input_size);
406 //printf("CompressorEffect::process_buffer %d %p %d\n", __LINE__, input_buffer[i], input_size);
407 read_samples(input_buffer[i],
410 input_start + input_size,
412 input_buffer[i]->set_offset(0);
414 input_size += fragment_size;
418 double current_slope = (next_target - previous_target) /
420 double *trigger_buffer = input_buffer[trigger]->get_data();
421 for(int i = 0; i < size; i++)
423 // Get slope from current sample to every sample in preview_samples.
424 // Take highest one or first one after target_samples are up.
426 // For optimization, calculate the first slope we really need.
427 // Assume every slope up to the end of preview_samples has been calculated and
428 // found <= to current slope.
429 int first_slope = preview_samples - 1;
430 // Need new slope immediately
431 if(target_current_sample >= target_samples)
433 for(int j = first_slope;
440 case CompressorConfig::MAX:
443 for(int k = 0; k < total_buffers; k++)
445 sample = fabs(input_buffer[k]->get_data()[i + j]);
446 if(sample > max) max = sample;
452 case CompressorConfig::TRIGGER:
453 sample = fabs(trigger_buffer[i + j]);
456 case CompressorConfig::SUM:
459 for(int k = 0; k < total_buffers; k++)
461 sample = fabs(input_buffer[k]->get_data()[i + j]);
474 double new_slope = (sample - current_value) /
476 // Got equal or higher slope
477 if(new_slope >= current_slope &&
478 (current_slope >= 0 ||
481 target_current_sample = 0;
483 current_slope = new_slope;
484 next_target = sample;
485 previous_target = current_value;
488 if(sample > next_target && current_slope < 0)
490 target_current_sample = 0;
491 target_samples = decay_samples;
492 current_slope = (sample - current_value) /
494 next_target = sample;
495 previous_target = current_value;
498 // Hit end of current slope range without finding higher slope
499 if(target_current_sample >= target_samples)
501 target_current_sample = 0;
502 target_samples = decay_samples;
503 current_slope = (sample - current_value) / decay_samples;
504 next_target = sample;
505 previous_target = current_value;
509 // Update current value and multiply gain
510 current_value = (next_target * target_current_sample +
511 previous_target * (target_samples - target_current_sample)) /
513 //buffer[0][i] = current_value;
514 target_current_sample++;
516 if(config.smoothing_only)
518 for(int j = 0; j < total_buffers; j++)
520 buffer[j]->get_data()[i] = current_value;
525 double gain = calculate_gain(current_value);
526 for(int j = 0; j < total_buffers; j++)
528 buffer[j]->get_data()[i] = input_buffer[j]->get_data()[i] * gain;
544 double CompressorEffect::calculate_output(double x)
546 if(x > 0.999) return 1.0;
548 for(int i = levels.total - 1; i >= 0; i--)
550 if(levels.values[i].x <= x)
552 if(i < levels.total - 1)
554 return levels.values[i].y +
555 (x - levels.values[i].x) *
556 (levels.values[i + 1].y - levels.values[i].y) /
557 (levels.values[i + 1].x - levels.values[i].x);
561 return levels.values[i].y +
562 (x - levels.values[i].x) *
563 (max_y - levels.values[i].y) /
564 (max_x - levels.values[i].x);
573 (levels.values[0].y - min_y) /
574 (levels.values[0].x - min_x);
581 double CompressorEffect::calculate_gain(double input)
583 // double x_db = DB::todb(input);
584 // double y_db = config.calculate_db(x_db);
585 // double y_linear = DB::fromdb(y_db);
586 double y_linear = calculate_output(input);
589 gain = y_linear / input;
604 CompressorConfig::CompressorConfig()
613 input = CompressorConfig::TRIGGER;
618 void CompressorConfig::copy_from(CompressorConfig &that)
620 this->reaction_len = that.reaction_len;
621 this->decay_len = that.decay_len;
622 this->min_db = that.min_db;
623 this->min_x = that.min_x;
624 this->min_y = that.min_y;
625 this->max_x = that.max_x;
626 this->max_y = that.max_y;
627 this->trigger = that.trigger;
628 this->input = that.input;
629 this->smoothing_only = that.smoothing_only;
631 for(int i = 0; i < that.levels.total; i++)
632 this->levels.append(that.levels.values[i]);
635 int CompressorConfig::equivalent(CompressorConfig &that)
637 if(!EQUIV(this->reaction_len, that.reaction_len) ||
638 !EQUIV(this->decay_len, that.decay_len) ||
639 this->trigger != that.trigger ||
640 this->input != that.input ||
641 this->smoothing_only != that.smoothing_only)
643 if(this->levels.total != that.levels.total) return 0;
645 i < this->levels.total && i < that.levels.total;
648 compressor_point_t *this_level = &this->levels.values[i];
649 compressor_point_t *that_level = &that.levels.values[i];
650 if(!EQUIV(this_level->x, that_level->x) ||
651 !EQUIV(this_level->y, that_level->y))
657 void CompressorConfig::interpolate(CompressorConfig &prev,
658 CompressorConfig &next,
661 int64_t current_frame)
666 int CompressorConfig::total_points()
674 void CompressorConfig::dump()
676 printf("CompressorConfig::dump\n");
677 for(int i = 0; i < levels.total; i++)
679 printf(" %f %f\n", levels.values[i].x, levels.values[i].y);
684 double CompressorConfig::get_y(int number)
689 if(number >= levels.total)
690 return levels.values[levels.total - 1].y;
692 return levels.values[number].y;
695 double CompressorConfig::get_x(int number)
700 if(number >= levels.total)
701 return levels.values[levels.total - 1].x;
703 return levels.values[number].x;
706 double CompressorConfig::calculate_db(double x)
708 if(x > -0.001) return 0.0;
710 for(int i = levels.total - 1; i >= 0; i--)
712 if(levels.values[i].x <= x)
714 if(i < levels.total - 1)
716 return levels.values[i].y +
717 (x - levels.values[i].x) *
718 (levels.values[i + 1].y - levels.values[i].y) /
719 (levels.values[i + 1].x - levels.values[i].x);
723 return levels.values[i].y +
724 (x - levels.values[i].x) *
725 (max_y - levels.values[i].y) /
726 (max_x - levels.values[i].x);
735 (levels.values[0].y - min_y) /
736 (levels.values[0].x - min_x);
743 int CompressorConfig::set_point(double x, double y)
745 for(int i = levels.total - 1; i >= 0; i--)
747 if(levels.values[i].x < x)
751 for(int j = levels.total - 2; j >= i; j--)
753 levels.values[j + 1] = levels.values[j];
755 levels.values[i].x = x;
756 levels.values[i].y = y;
763 for(int j = levels.total - 2; j >= 0; j--)
765 levels.values[j + 1] = levels.values[j];
767 levels.values[0].x = x;
768 levels.values[0].y = y;
772 void CompressorConfig::remove_point(int number)
774 for(int j = number; j < levels.total - 1; j++)
776 levels.values[j] = levels.values[j + 1];
781 void CompressorConfig::optimize()
790 for(int i = 0; i < levels.total - 1; i++)
792 if(levels.values[i].x >= levels.values[i + 1].x)
795 for(int j = i + 1; j < levels.total - 1; j++)
797 levels.values[j] = levels.values[j + 1];
832 CompressorWindow::CompressorWindow(CompressorEffect *plugin)
833 : PluginClientWindow(plugin,
840 this->plugin = plugin;
843 void CompressorWindow::create_objects()
846 int control_margin = 130;
848 add_subwindow(canvas = new CompressorCanvas(plugin,
851 get_w() - x - control_margin - 10,
853 canvas->set_cursor(CROSS_CURSOR, 0, 0);
854 x = get_w() - control_margin;
855 add_subwindow(new BC_Title(x, y, _("Reaction secs:")));
857 add_subwindow(reaction = new CompressorReaction(plugin, x, y));
859 add_subwindow(new BC_Title(x, y, _("Decay secs:")));
861 add_subwindow(decay = new CompressorDecay(plugin, x, y));
863 add_subwindow(new BC_Title(x, y, _("Trigger Type:")));
865 add_subwindow(input = new CompressorInput(plugin, x, y));
866 input->create_objects();
868 add_subwindow(new BC_Title(x, y, _("Trigger:")));
870 add_subwindow(trigger = new CompressorTrigger(plugin, x, y));
871 if(plugin->config.input != CompressorConfig::TRIGGER) trigger->disable();
873 add_subwindow(smooth = new CompressorSmooth(plugin, x, y));
875 add_subwindow(clear = new CompressorClear(plugin, x, y));
878 add_subwindow(new BC_Title(x, y, _("Point:")));
880 add_subwindow(x_text = new CompressorX(plugin, x, y));
882 add_subwindow(new BC_Title(x, y, _("x")));
884 add_subwindow(y_text = new CompressorY(plugin, x, y));
891 void CompressorWindow::draw_scales()
893 draw_3d_border(canvas->get_x() - 2,
904 set_color(get_resources()->default_text_color);
907 for(int i = 0; i <= DIVISIONS; i++)
909 int y = canvas->get_y() + 10 + canvas->get_h() / DIVISIONS * i;
910 int x = canvas->get_x() - 30;
911 char string[BCTEXTLEN];
913 sprintf(string, "%.0f", (float)i / DIVISIONS * plugin->config.min_db);
914 draw_text(x, y, string);
916 int y1 = canvas->get_y() + canvas->get_h() / DIVISIONS * i;
917 int y2 = canvas->get_y() + canvas->get_h() / DIVISIONS * (i + 1);
918 for(int j = 0; j < 10; j++)
920 y = y1 + (y2 - y1) * j / 10;
923 draw_line(canvas->get_x() - 10, y, canvas->get_x(), y);
928 draw_line(canvas->get_x() - 5, y, canvas->get_x(), y);
934 for(int i = 0; i <= DIVISIONS; i++)
936 int y = canvas->get_h() + 30;
937 int x = canvas->get_x() + (canvas->get_w() - 10) / DIVISIONS * i;
938 char string[BCTEXTLEN];
940 sprintf(string, "%.0f", (1.0 - (float)i / DIVISIONS) * plugin->config.min_db);
941 draw_text(x, y, string);
943 int x1 = canvas->get_x() + canvas->get_w() / DIVISIONS * i;
944 int x2 = canvas->get_x() + canvas->get_w() / DIVISIONS * (i + 1);
945 for(int j = 0; j < 10; j++)
947 x = x1 + (x2 - x1) * j / 10;
950 draw_line(x, canvas->get_y() + canvas->get_h(), x, canvas->get_y() + canvas->get_h() + 10);
955 draw_line(x, canvas->get_y() + canvas->get_h(), x, canvas->get_y() + canvas->get_h() + 5);
965 void CompressorWindow::update()
971 void CompressorWindow::update_textboxes()
973 if(atol(trigger->get_text()) != plugin->config.trigger)
974 trigger->update((int64_t)plugin->config.trigger);
975 if(strcmp(input->get_text(), CompressorInput::value_to_text(plugin->config.input)))
976 input->set_text(CompressorInput::value_to_text(plugin->config.input));
978 if(plugin->config.input != CompressorConfig::TRIGGER && trigger->get_enabled())
981 if(plugin->config.input == CompressorConfig::TRIGGER && !trigger->get_enabled())
984 if(!EQUIV(atof(reaction->get_text()), plugin->config.reaction_len))
985 reaction->update((float)plugin->config.reaction_len);
986 if(!EQUIV(atof(decay->get_text()), plugin->config.decay_len))
987 decay->update((float)plugin->config.decay_len);
988 smooth->update(plugin->config.smoothing_only);
989 if(canvas->current_operation == CompressorCanvas::DRAG)
991 x_text->update((float)plugin->config.levels.values[canvas->current_point].x);
992 y_text->update((float)plugin->config.levels.values[canvas->current_point].y);
997 void CompressorWindow::update_canvas()
999 canvas->clear_box(0, 0, canvas->get_w(), canvas->get_h());
1000 canvas->set_line_dashes(1);
1001 canvas->set_color(GREEN);
1003 for(int i = 1; i < DIVISIONS; i++)
1005 int y = canvas->get_h() * i / DIVISIONS;
1006 canvas->draw_line(0, y, canvas->get_w(), y);
1008 int x = canvas->get_w() * i / DIVISIONS;
1009 canvas->draw_line(x, 0, x, canvas->get_h());
1011 canvas->set_line_dashes(0);
1014 canvas->set_font(MEDIUMFONT);
1015 canvas->draw_text(plugin->get_theme()->widget_border,
1016 canvas->get_h() / 2,
1018 canvas->draw_text(canvas->get_w() / 2 - canvas->get_text_width(MEDIUMFONT, _("Input")) / 2,
1019 canvas->get_h() - plugin->get_theme()->widget_border,
1023 canvas->set_color(WHITE);
1024 canvas->set_line_width(2);
1026 double x_db = plugin->config.min_db;
1027 double y_db = plugin->config.calculate_db(x_db);
1028 int y1 = (int)(y_db / plugin->config.min_db * canvas->get_h());
1030 for(int i=1; i<canvas->get_w(); i++)
1032 x_db = (1. - (double)i / canvas->get_w()) * plugin->config.min_db;
1033 y_db = plugin->config.calculate_db(x_db);
1034 int y2 = (int)(y_db / plugin->config.min_db * canvas->get_h());
1035 canvas->draw_line(i-1, y1, i, y2);
1038 canvas->set_line_width(1);
1040 int total = plugin->config.levels.total ? plugin->config.levels.total : 1;
1041 for(int i=0; i < total; i++)
1043 x_db = plugin->config.get_x(i);
1044 y_db = plugin->config.get_y(i);
1046 int x = (int)((1. - x_db / plugin->config.min_db) * canvas->get_w());
1047 int y = (int)(y_db / plugin->config.min_db * canvas->get_h());
1049 canvas->draw_box(x - POINT_W / 2, y - POINT_W / 2, POINT_W, POINT_W);
1055 int CompressorWindow::resize_event(int w, int h)
1067 CompressorCanvas::CompressorCanvas(CompressorEffect *plugin, int x, int y, int w, int h)
1068 : BC_SubWindow(x, y, w, h, BLACK)
1070 this->plugin = plugin;
1071 current_operation = NONE;
1074 int CompressorCanvas::button_press_event()
1076 // Check existing points
1077 if(is_event_win() && cursor_inside())
1079 for(int i = 0; i < plugin->config.levels.total; i++)
1081 double x_db = plugin->config.get_x(i);
1082 double y_db = plugin->config.get_y(i);
1084 int x = (int)(((double)1 - x_db / plugin->config.min_db) * get_w());
1085 int y = (int)(y_db / plugin->config.min_db * get_h());
1087 if(get_cursor_x() < x + POINT_W / 2 && get_cursor_x() >= x - POINT_W / 2 &&
1088 get_cursor_y() < y + POINT_W / 2 && get_cursor_y() >= y - POINT_W / 2)
1090 current_operation = DRAG;
1099 double x_db = (double)(1 - (double)get_cursor_x() / get_w()) * plugin->config.min_db;
1100 double y_db = (double)get_cursor_y() / get_h() * plugin->config.min_db;
1102 current_point = plugin->config.set_point(x_db, y_db);
1103 current_operation = DRAG;
1104 ((CompressorWindow*)plugin->thread->window)->update();
1105 plugin->send_configure_change();
1109 //plugin->config.dump();
1112 int CompressorCanvas::button_release_event()
1114 if(current_operation == DRAG)
1116 if(current_point > 0)
1118 if(plugin->config.levels.values[current_point].x <
1119 plugin->config.levels.values[current_point - 1].x)
1120 plugin->config.remove_point(current_point);
1123 if(current_point < plugin->config.levels.total - 1)
1125 if(plugin->config.levels.values[current_point].x >=
1126 plugin->config.levels.values[current_point + 1].x)
1127 plugin->config.remove_point(current_point);
1130 ((CompressorWindow*)plugin->thread->window)->update();
1131 plugin->send_configure_change();
1132 current_operation = NONE;
1139 int CompressorCanvas::cursor_motion_event()
1141 if(current_operation == DRAG)
1143 int x = get_cursor_x();
1144 int y = get_cursor_y();
1145 CLAMP(x, 0, get_w());
1146 CLAMP(y, 0, get_h());
1147 double x_db = (double)(1 - (double)x / get_w()) * plugin->config.min_db;
1148 double y_db = (double)y / get_h() * plugin->config.min_db;
1149 plugin->config.levels.values[current_point].x = x_db;
1150 plugin->config.levels.values[current_point].y = y_db;
1151 ((CompressorWindow*)plugin->thread->window)->update();
1152 plugin->send_configure_change();
1154 //plugin->config.dump();
1157 // Change cursor over points
1158 if(is_event_win() && cursor_inside())
1160 int new_cursor = CROSS_CURSOR;
1162 for(int i = 0; i < plugin->config.levels.total; i++)
1164 double x_db = plugin->config.get_x(i);
1165 double y_db = plugin->config.get_y(i);
1167 int x = (int)(((double)1 - x_db / plugin->config.min_db) * get_w());
1168 int y = (int)(y_db / plugin->config.min_db * get_h());
1170 if(get_cursor_x() < x + POINT_W / 2 && get_cursor_x() >= x - POINT_W / 2 &&
1171 get_cursor_y() < y + POINT_W / 2 && get_cursor_y() >= y - POINT_W / 2)
1173 new_cursor = UPRIGHT_ARROW_CURSOR;
1179 if(new_cursor != get_cursor())
1181 set_cursor(new_cursor, 0, 1);
1191 CompressorReaction::CompressorReaction(CompressorEffect *plugin, int x, int y)
1192 : BC_TextBox(x, y, 100, 1, (float)plugin->config.reaction_len)
1194 this->plugin = plugin;
1197 int CompressorReaction::handle_event()
1199 plugin->config.reaction_len = atof(get_text());
1200 plugin->send_configure_change();
1204 int CompressorReaction::button_press_event()
1208 if(get_buttonpress() < 4) return BC_TextBox::button_press_event();
1209 if(get_buttonpress() == 4)
1211 plugin->config.reaction_len += 0.1;
1214 if(get_buttonpress() == 5)
1216 plugin->config.reaction_len -= 0.1;
1218 update((float)plugin->config.reaction_len);
1219 plugin->send_configure_change();
1225 CompressorDecay::CompressorDecay(CompressorEffect *plugin, int x, int y)
1226 : BC_TextBox(x, y, 100, 1, (float)plugin->config.decay_len)
1228 this->plugin = plugin;
1230 int CompressorDecay::handle_event()
1232 plugin->config.decay_len = atof(get_text());
1233 plugin->send_configure_change();
1237 int CompressorDecay::button_press_event()
1241 if(get_buttonpress() < 4) return BC_TextBox::button_press_event();
1242 if(get_buttonpress() == 4)
1244 plugin->config.decay_len += 0.1;
1247 if(get_buttonpress() == 5)
1249 plugin->config.decay_len -= 0.1;
1251 update((float)plugin->config.decay_len);
1252 plugin->send_configure_change();
1260 CompressorX::CompressorX(CompressorEffect *plugin, int x, int y)
1261 : BC_TextBox(x, y, 100, 1, "")
1263 this->plugin = plugin;
1265 int CompressorX::handle_event()
1267 int current_point = ((CompressorWindow*)plugin->thread->window)->canvas->current_point;
1268 if(current_point < plugin->config.levels.total)
1270 plugin->config.levels.values[current_point].x = atof(get_text());
1271 ((CompressorWindow*)plugin->thread->window)->update_canvas();
1272 plugin->send_configure_change();
1279 CompressorY::CompressorY(CompressorEffect *plugin, int x, int y)
1280 : BC_TextBox(x, y, 100, 1, "")
1282 this->plugin = plugin;
1284 int CompressorY::handle_event()
1286 int current_point = ((CompressorWindow*)plugin->thread->window)->canvas->current_point;
1287 if(current_point < plugin->config.levels.total)
1289 plugin->config.levels.values[current_point].y = atof(get_text());
1290 ((CompressorWindow*)plugin->thread->window)->update_canvas();
1291 plugin->send_configure_change();
1300 CompressorTrigger::CompressorTrigger(CompressorEffect *plugin, int x, int y)
1301 : BC_TextBox(x, y, (int64_t)100, (int64_t)1, (int64_t)plugin->config.trigger)
1303 this->plugin = plugin;
1305 int CompressorTrigger::handle_event()
1307 plugin->config.trigger = atol(get_text());
1308 plugin->send_configure_change();
1312 int CompressorTrigger::button_press_event()
1316 if(get_buttonpress() < 4) return BC_TextBox::button_press_event();
1317 if(get_buttonpress() == 4)
1319 plugin->config.trigger++;
1322 if(get_buttonpress() == 5)
1324 plugin->config.trigger--;
1326 update((int64_t)plugin->config.trigger);
1327 plugin->send_configure_change();
1337 CompressorInput::CompressorInput(CompressorEffect *plugin, int x, int y)
1341 CompressorInput::value_to_text(plugin->config.input),
1344 this->plugin = plugin;
1346 int CompressorInput::handle_event()
1348 plugin->config.input = text_to_value(get_text());
1349 ((CompressorWindow*)plugin->thread->window)->update();
1350 plugin->send_configure_change();
1354 void CompressorInput::create_objects()
1356 for(int i = 0; i < 3; i++)
1358 add_item(new BC_MenuItem(value_to_text(i)));
1362 const char* CompressorInput::value_to_text(int value)
1366 case CompressorConfig::TRIGGER: return _("Trigger");
1367 case CompressorConfig::MAX: return _("Maximum");
1368 case CompressorConfig::SUM: return _("Total");
1371 return _("Trigger");
1374 int CompressorInput::text_to_value(char *text)
1376 for(int i = 0; i < 3; i++)
1378 if(!strcmp(value_to_text(i), text)) return i;
1381 return CompressorConfig::TRIGGER;
1389 CompressorClear::CompressorClear(CompressorEffect *plugin, int x, int y)
1390 : BC_GenericButton(x, y, _("Clear"))
1392 this->plugin = plugin;
1395 int CompressorClear::handle_event()
1397 plugin->config.levels.remove_all();
1398 //plugin->config.dump();
1399 ((CompressorWindow*)plugin->thread->window)->update();
1400 plugin->send_configure_change();
1406 CompressorSmooth::CompressorSmooth(CompressorEffect *plugin, int x, int y)
1407 : BC_CheckBox(x, y, plugin->config.smoothing_only, _("Smooth only"))
1409 this->plugin = plugin;
1412 int CompressorSmooth::handle_event()
1414 plugin->config.smoothing_only = get_value();
1415 plugin->send_configure_change();