1 #include "bcdisplayinfo.h"
6 #include "pluginaclient.h"
11 #define _(String) gettext(String)
12 #define gettext_noop(String) String
13 #define N_(String) gettext_noop (String)
19 class InterpolateEffect;
21 class InterpolateConfig
27 #define INTERPOLATE_ALL 0
33 class InterpolateLength : public BC_TumbleTextBox
36 InterpolateLength(InterpolateEffect *plugin, InterpolateWindow *gui, int x, int y);
38 InterpolateEffect *plugin;
39 InterpolateWindow *gui;
42 class InterpolateAll : public BC_CheckBox
45 InterpolateAll(InterpolateEffect *plugin, InterpolateWindow *gui, int x, int y);
47 InterpolateEffect *plugin;
48 InterpolateWindow *gui;
53 class InterpolateWindow : public BC_Window
56 InterpolateWindow(InterpolateEffect *plugin, int x, int y);
57 void create_objects();
60 InterpolateEffect *plugin;
61 InterpolateLength *length;
68 class InterpolateEffect : public PluginAClient
71 InterpolateEffect(PluginServer *server);
76 int is_multichannel();
79 int process_loop(double **buffer, long &output_lenght);
89 MainProgressBar *progress;
90 InterpolateConfig config;
96 REGISTER_PLUGIN(InterpolateEffect)
109 InterpolateLength::InterpolateLength(InterpolateEffect *plugin,
110 InterpolateWindow *gui,
113 : BC_TumbleTextBox(gui,
114 plugin->config.length,
121 this->plugin = plugin;
126 int InterpolateLength::handle_event()
128 gui->length->update(0);
129 plugin->config.length = atol(get_text());
134 InterpolateAll::InterpolateAll(InterpolateEffect *plugin,
135 InterpolateWindow *gui,
138 plugin->config.length == INTERPOLATE_ALL)
140 this->plugin = plugin;
144 int InterpolateAll::handle_event()
146 gui->all->update(INTERPOLATE_ALL);
147 plugin->config.length = INTERPOLATE_ALL;
163 InterpolateWindow::InterpolateWindow(InterpolateEffect *plugin, int x, int y)
164 : BC_Window(plugin->gui_string,
175 this->plugin = plugin;
178 void InterpolateWindow::create_objects()
183 add_subwindow(new BC_OKButton(this));
184 add_subwindow(new BC_CancelButton(this));
189 int InterpolateWindow::close_event()
191 // Set result to 1 to indicate a client side close
207 InterpolateConfig::InterpolateConfig()
218 int InterpolateConfig::equivalent(InterpolateConfig &that)
220 return EQUIV(gain, that.gain) &&
221 EQUIV(wet, that.wet) &&
222 EQUIV(roomsize, that.roomsize) &&
223 EQUIV(dry, that.dry) &&
224 EQUIV(damp, that.damp) &&
225 EQUIV(width, that.width) &&
226 EQUIV(mode, that.mode);
229 void InterpolateConfig::copy_from(InterpolateConfig &that)
233 roomsize = that.roomsize;
240 void InterpolateConfig::interpolate(InterpolateConfig &prev,
241 InterpolateConfig &next,
246 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
247 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
249 gain = prev.gain * prev_scale + next.gain * next_scale;
250 wet = prev.wet * prev_scale + next.wet * next_scale;
251 roomsize = prev.roomsize * prev_scale + next.roomsize * next_scale;
252 dry = prev.dry * prev_scale + next.dry * next_scale;
253 damp = prev.damp * prev_scale + next.damp * next_scale;
254 width = prev.width * prev_scale + next.width * next_scale;
281 PLUGIN_THREAD_OBJECT(InterpolateEffect, InterpolateThread, InterpolateWindow)
287 InterpolateEffect::InterpolateEffect(PluginServer *server)
288 : PluginAClient(server)
294 PLUGIN_CONSTRUCTOR_MACRO
297 InterpolateEffect::~InterpolateEffect()
299 if(engine) delete engine;
302 for(int i = 0; i < total_in_buffers; i++)
305 delete [] temp_out[i];
310 PLUGIN_DESTRUCTOR_MACRO
313 NEW_PICON_MACRO(InterpolateEffect)
315 LOAD_CONFIGURATION_MACRO(InterpolateEffect, InterpolateConfig)
317 SHOW_GUI_MACRO(InterpolateEffect, InterpolateThread)
319 RAISE_WINDOW_MACRO(InterpolateEffect)
321 SET_STRING_MACRO(InterpolateEffect)
324 char* InterpolateEffect::plugin_title()
326 return _("Interpolate");
330 int InterpolateEffect::is_realtime()
335 int InterpolateEffect::is_multichannel()
342 void InterpolateEffect::read_data(KeyFrame *keyframe)
345 input.set_shared_string(keyframe->data, strlen(keyframe->data));
350 result = input.read_tag();
354 if(input.tag.title_is("FREEVERB"))
356 config.gain = input.tag.get_property("GAIN", config.gain);
357 config.roomsize = input.tag.get_property("ROOMSIZE", config.roomsize);
358 config.damp = input.tag.get_property("DAMP", config.damp);
359 config.wet = input.tag.get_property("WET", config.wet);
360 config.dry = input.tag.get_property("DRY", config.dry);
361 config.width = input.tag.get_property("WIDTH", config.width);
362 config.mode = input.tag.get_property("MODE", config.mode);
368 void InterpolateEffect::save_data(KeyFrame *keyframe)
371 output.set_shared_string(keyframe->data, MESSAGESIZE);
373 output.tag.set_title("FREEVERB");
374 output.tag.set_property("GAIN", config.gain);
375 output.tag.set_property("ROOMSIZE", config.roomsize);
376 output.tag.set_property("DAMP", config.damp);
377 output.tag.set_property("WET", config.wet);
378 output.tag.set_property("DRY", config.dry);
379 output.tag.set_property("WIDTH", config.width);
380 output.tag.set_property("MODE", config.mode);
382 output.append_newline();
384 output.terminate_string();
387 int InterpolateEffect::load_defaults()
389 char directory[BCTEXTLEN], string[BCTEXTLEN];
390 sprintf(directory, "%sfreeverb.rc", BCASTDIR);
391 defaults = new Defaults(directory);
394 config.gain = defaults->get("GAIN", config.gain);
395 config.roomsize = defaults->get("ROOMSIZE", config.roomsize);
396 config.damp = defaults->get("DAMP", config.damp);
397 config.wet = defaults->get("WET", config.wet);
398 config.dry = defaults->get("DRY", config.dry);
399 config.width = defaults->get("WIDTH", config.width);
400 config.mode = defaults->get("MODE", config.mode);
404 int InterpolateEffect::save_defaults()
406 char string[BCTEXTLEN];
408 defaults->update("GAIN", config.gain);
409 defaults->update("ROOMSIZE", config.roomsize);
410 defaults->update("DAMP", config.damp);
411 defaults->update("WET", config.wet);
412 defaults->update("DRY", config.dry);
413 defaults->update("WIDTH", config.width);
414 defaults->update("MODE", config.mode);
421 void InterpolateEffect::update_gui()
425 load_configuration();
426 thread->window->lock_window();
427 thread->window->gain->update(config.gain);
428 thread->window->roomsize->update(config.roomsize);
429 thread->window->damp->update(config.damp);
430 thread->window->wet->update(config.wet);
431 thread->window->dry->update(config.dry);
432 thread->window->width->update(config.width);
433 thread->window->mode->update((int)config.mode);
434 thread->window->unlock_window();
438 int InterpolateEffect::process_realtime(long size, double **input_ptr, double **output_ptr)
440 load_configuration();
441 if(!engine) engine = new revmodel;
443 engine->setroomsize(DB::fromdb(config.roomsize));
444 engine->setdamp(DB::fromdb(config.damp));
445 engine->setwet(DB::fromdb(config.wet));
446 engine->setdry(DB::fromdb(config.dry));
447 engine->setwidth(DB::fromdb(config.width));
448 engine->setmode(config.mode);
450 float gain_f = DB::fromdb(config.gain);
452 if(size > temp_allocated)
456 for(int i = 0; i < total_in_buffers; i++)
459 delete [] temp_out[i];
469 temp_allocated = size * 2;
470 temp = new float*[total_in_buffers];
471 temp_out = new float*[total_in_buffers];
472 for(int i = 0; i < total_in_buffers; i++)
474 temp[i] = new float[temp_allocated];
475 temp_out[i] = new float[temp_allocated];
479 for(int i = 0; i < 2 && i < total_in_buffers; i++)
481 float *out = temp[i];
482 double *in = input_ptr[i];
483 for(int j = 0; j < size; j++)
489 if(total_in_buffers < 2)
491 engine->processreplace(temp[0],
500 engine->processreplace(temp[0],
508 for(int i = 0; i < 2 && i < total_in_buffers; i++)
510 double *out = output_ptr[i];
511 float *in = temp_out[i];
512 for(int j = 0; j < size; j++)
514 out[j] = gain_f * in[j];