1 #include "bcdisplayinfo.h"
7 #include "pluginaclient.h"
15 class InterpolateEffect;
17 class InterpolateConfig
23 #define INTERPOLATE_ALL 0
29 class InterpolateLength : public BC_TumbleTextBox
32 InterpolateLength(InterpolateEffect *plugin, InterpolateWindow *gui, int x, int y);
34 InterpolateEffect *plugin;
35 InterpolateWindow *gui;
38 class InterpolateAll : public BC_CheckBox
41 InterpolateAll(InterpolateEffect *plugin, InterpolateWindow *gui, int x, int y);
43 InterpolateEffect *plugin;
44 InterpolateWindow *gui;
49 class InterpolateWindow : public BC_Window
52 InterpolateWindow(InterpolateEffect *plugin, int x, int y);
53 void create_objects();
56 InterpolateEffect *plugin;
57 InterpolateLength *length;
64 class InterpolateEffect : public PluginAClient
67 InterpolateEffect(PluginServer *server);
72 int is_multichannel();
75 int process_loop(double **buffer, long &output_lenght);
85 MainProgressBar *progress;
86 InterpolateConfig config;
92 REGISTER_PLUGIN(InterpolateEffect)
105 InterpolateLength::InterpolateLength(InterpolateEffect *plugin,
106 InterpolateWindow *gui,
109 : BC_TumbleTextBox(gui,
110 plugin->config.length,
117 this->plugin = plugin;
122 int InterpolateLength::handle_event()
124 gui->length->update(0);
125 plugin->config.length = atol(get_text());
130 InterpolateAll::InterpolateAll(InterpolateEffect *plugin,
131 InterpolateWindow *gui,
134 plugin->config.length == INTERPOLATE_ALL)
136 this->plugin = plugin;
140 int InterpolateAll::handle_event()
142 gui->all->update(INTERPOLATE_ALL);
143 plugin->config.length = INTERPOLATE_ALL;
159 InterpolateWindow::InterpolateWindow(InterpolateEffect *plugin, int x, int y)
160 : BC_Window(plugin->gui_string,
171 this->plugin = plugin;
174 void InterpolateWindow::create_objects()
179 add_subwindow(new BC_OKButton(this));
180 add_subwindow(new BC_CancelButton(this));
185 WINDOW_CLOSE_EVENT(InterpolateWindow)
197 InterpolateConfig::InterpolateConfig()
208 int InterpolateConfig::equivalent(InterpolateConfig &that)
210 return EQUIV(gain, that.gain) &&
211 EQUIV(wet, that.wet) &&
212 EQUIV(roomsize, that.roomsize) &&
213 EQUIV(dry, that.dry) &&
214 EQUIV(damp, that.damp) &&
215 EQUIV(width, that.width) &&
216 EQUIV(mode, that.mode);
219 void InterpolateConfig::copy_from(InterpolateConfig &that)
223 roomsize = that.roomsize;
230 void InterpolateConfig::interpolate(InterpolateConfig &prev,
231 InterpolateConfig &next,
236 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
237 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
239 gain = prev.gain * prev_scale + next.gain * next_scale;
240 wet = prev.wet * prev_scale + next.wet * next_scale;
241 roomsize = prev.roomsize * prev_scale + next.roomsize * next_scale;
242 dry = prev.dry * prev_scale + next.dry * next_scale;
243 damp = prev.damp * prev_scale + next.damp * next_scale;
244 width = prev.width * prev_scale + next.width * next_scale;
271 PLUGIN_THREAD_OBJECT(InterpolateEffect, InterpolateThread, InterpolateWindow)
277 InterpolateEffect::InterpolateEffect(PluginServer *server)
278 : PluginAClient(server)
284 PLUGIN_CONSTRUCTOR_MACRO
287 InterpolateEffect::~InterpolateEffect()
289 if(engine) delete engine;
292 for(int i = 0; i < total_in_buffers; i++)
295 delete [] temp_out[i];
300 PLUGIN_DESTRUCTOR_MACRO
303 NEW_PICON_MACRO(InterpolateEffect)
305 LOAD_CONFIGURATION_MACRO(InterpolateEffect, InterpolateConfig)
307 SHOW_GUI_MACRO(InterpolateEffect, InterpolateThread)
309 RAISE_WINDOW_MACRO(InterpolateEffect)
311 SET_STRING_MACRO(InterpolateEffect)
314 char* InterpolateEffect::plugin_title() { return N_("Interpolate"); }
315 int InterpolateEffect::is_realtime() { return 1;}
316 int InterpolateEffect::is_multichannel() { return 1; }
320 void InterpolateEffect::read_data(KeyFrame *keyframe)
323 input.set_shared_string(keyframe->data, strlen(keyframe->data));
328 result = input.read_tag();
332 if(input.tag.title_is("FREEVERB"))
334 config.gain = input.tag.get_property("GAIN", config.gain);
335 config.roomsize = input.tag.get_property("ROOMSIZE", config.roomsize);
336 config.damp = input.tag.get_property("DAMP", config.damp);
337 config.wet = input.tag.get_property("WET", config.wet);
338 config.dry = input.tag.get_property("DRY", config.dry);
339 config.width = input.tag.get_property("WIDTH", config.width);
340 config.mode = input.tag.get_property("MODE", config.mode);
346 void InterpolateEffect::save_data(KeyFrame *keyframe)
349 output.set_shared_string(keyframe->data, MESSAGESIZE);
351 output.tag.set_title("FREEVERB");
352 output.tag.set_property("GAIN", config.gain);
353 output.tag.set_property("ROOMSIZE", config.roomsize);
354 output.tag.set_property("DAMP", config.damp);
355 output.tag.set_property("WET", config.wet);
356 output.tag.set_property("DRY", config.dry);
357 output.tag.set_property("WIDTH", config.width);
358 output.tag.set_property("MODE", config.mode);
360 output.append_newline();
362 output.terminate_string();
365 int InterpolateEffect::load_defaults()
367 char directory[BCTEXTLEN], string[BCTEXTLEN];
368 sprintf(directory, "%sfreeverb.rc", BCASTDIR);
369 defaults = new Defaults(directory);
372 config.gain = defaults->get("GAIN", config.gain);
373 config.roomsize = defaults->get("ROOMSIZE", config.roomsize);
374 config.damp = defaults->get("DAMP", config.damp);
375 config.wet = defaults->get("WET", config.wet);
376 config.dry = defaults->get("DRY", config.dry);
377 config.width = defaults->get("WIDTH", config.width);
378 config.mode = defaults->get("MODE", config.mode);
382 int InterpolateEffect::save_defaults()
384 char string[BCTEXTLEN];
386 defaults->update("GAIN", config.gain);
387 defaults->update("ROOMSIZE", config.roomsize);
388 defaults->update("DAMP", config.damp);
389 defaults->update("WET", config.wet);
390 defaults->update("DRY", config.dry);
391 defaults->update("WIDTH", config.width);
392 defaults->update("MODE", config.mode);
399 void InterpolateEffect::update_gui()
403 load_configuration();
404 thread->window->lock_window();
405 thread->window->gain->update(config.gain);
406 thread->window->roomsize->update(config.roomsize);
407 thread->window->damp->update(config.damp);
408 thread->window->wet->update(config.wet);
409 thread->window->dry->update(config.dry);
410 thread->window->width->update(config.width);
411 thread->window->mode->update((int)config.mode);
412 thread->window->unlock_window();
416 int InterpolateEffect::process_realtime(long size,
420 load_configuration();
421 if(!engine) engine = new revmodel;
423 engine->setroomsize(DB::fromdb(config.roomsize));
424 engine->setdamp(DB::fromdb(config.damp));
425 engine->setwet(DB::fromdb(config.wet));
426 engine->setdry(DB::fromdb(config.dry));
427 engine->setwidth(DB::fromdb(config.width));
428 engine->setmode(config.mode);
430 float gain_f = DB::fromdb(config.gain);
432 if(size > temp_allocated)
436 for(int i = 0; i < total_in_buffers; i++)
439 delete [] temp_out[i];
449 temp_allocated = size * 2;
450 temp = new float*[total_in_buffers];
451 temp_out = new float*[total_in_buffers];
452 for(int i = 0; i < total_in_buffers; i++)
454 temp[i] = new float[temp_allocated];
455 temp_out[i] = new float[temp_allocated];
459 for(int i = 0; i < 2 && i < total_in_buffers; i++)
461 float *out = temp[i];
462 double *in = input_ptr[i];
463 for(int j = 0; j < size; j++)
469 if(total_in_buffers < 2)
471 engine->processreplace(temp[0],
480 engine->processreplace(temp[0],
488 for(int i = 0; i < 2 && i < total_in_buffers; i++)
490 double *out = output_ptr[i];
491 float *in = temp_out[i];
492 for(int j = 0; j < size; j++)
494 out[j] = gain_f * in[j];