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() { return N_("Interpolate"); }
325 int InterpolateEffect::is_realtime() { return 1;}
326 int InterpolateEffect::is_multichannel() { return 1; }
330 void InterpolateEffect::read_data(KeyFrame *keyframe)
333 input.set_shared_string(keyframe->data, strlen(keyframe->data));
338 result = input.read_tag();
342 if(input.tag.title_is("FREEVERB"))
344 config.gain = input.tag.get_property("GAIN", config.gain);
345 config.roomsize = input.tag.get_property("ROOMSIZE", config.roomsize);
346 config.damp = input.tag.get_property("DAMP", config.damp);
347 config.wet = input.tag.get_property("WET", config.wet);
348 config.dry = input.tag.get_property("DRY", config.dry);
349 config.width = input.tag.get_property("WIDTH", config.width);
350 config.mode = input.tag.get_property("MODE", config.mode);
356 void InterpolateEffect::save_data(KeyFrame *keyframe)
359 output.set_shared_string(keyframe->data, MESSAGESIZE);
361 output.tag.set_title("FREEVERB");
362 output.tag.set_property("GAIN", config.gain);
363 output.tag.set_property("ROOMSIZE", config.roomsize);
364 output.tag.set_property("DAMP", config.damp);
365 output.tag.set_property("WET", config.wet);
366 output.tag.set_property("DRY", config.dry);
367 output.tag.set_property("WIDTH", config.width);
368 output.tag.set_property("MODE", config.mode);
370 output.append_newline();
372 output.terminate_string();
375 int InterpolateEffect::load_defaults()
377 char directory[BCTEXTLEN], string[BCTEXTLEN];
378 sprintf(directory, "%sfreeverb.rc", BCASTDIR);
379 defaults = new Defaults(directory);
382 config.gain = defaults->get("GAIN", config.gain);
383 config.roomsize = defaults->get("ROOMSIZE", config.roomsize);
384 config.damp = defaults->get("DAMP", config.damp);
385 config.wet = defaults->get("WET", config.wet);
386 config.dry = defaults->get("DRY", config.dry);
387 config.width = defaults->get("WIDTH", config.width);
388 config.mode = defaults->get("MODE", config.mode);
392 int InterpolateEffect::save_defaults()
394 char string[BCTEXTLEN];
396 defaults->update("GAIN", config.gain);
397 defaults->update("ROOMSIZE", config.roomsize);
398 defaults->update("DAMP", config.damp);
399 defaults->update("WET", config.wet);
400 defaults->update("DRY", config.dry);
401 defaults->update("WIDTH", config.width);
402 defaults->update("MODE", config.mode);
409 void InterpolateEffect::update_gui()
413 load_configuration();
414 thread->window->lock_window();
415 thread->window->gain->update(config.gain);
416 thread->window->roomsize->update(config.roomsize);
417 thread->window->damp->update(config.damp);
418 thread->window->wet->update(config.wet);
419 thread->window->dry->update(config.dry);
420 thread->window->width->update(config.width);
421 thread->window->mode->update((int)config.mode);
422 thread->window->unlock_window();
426 int InterpolateEffect::process_realtime(long size, double **input_ptr, double **output_ptr)
428 load_configuration();
429 if(!engine) engine = new revmodel;
431 engine->setroomsize(DB::fromdb(config.roomsize));
432 engine->setdamp(DB::fromdb(config.damp));
433 engine->setwet(DB::fromdb(config.wet));
434 engine->setdry(DB::fromdb(config.dry));
435 engine->setwidth(DB::fromdb(config.width));
436 engine->setmode(config.mode);
438 float gain_f = DB::fromdb(config.gain);
440 if(size > temp_allocated)
444 for(int i = 0; i < total_in_buffers; i++)
447 delete [] temp_out[i];
457 temp_allocated = size * 2;
458 temp = new float*[total_in_buffers];
459 temp_out = new float*[total_in_buffers];
460 for(int i = 0; i < total_in_buffers; i++)
462 temp[i] = new float[temp_allocated];
463 temp_out[i] = new float[temp_allocated];
467 for(int i = 0; i < 2 && i < total_in_buffers; i++)
469 float *out = temp[i];
470 double *in = input_ptr[i];
471 for(int j = 0; j < size; j++)
477 if(total_in_buffers < 2)
479 engine->processreplace(temp[0],
488 engine->processreplace(temp[0],
496 for(int i = 0; i < 2 && i < total_in_buffers; i++)
498 double *out = output_ptr[i];
499 float *in = temp_out[i];
500 for(int j = 0; j < size; j++)
502 out[j] = gain_f * in[j];