1 #include "bcdisplayinfo.h"
4 #include "delayaudio.h"
12 #define _(String) gettext(String)
13 #define gettext_noop(String) String
14 #define N_(String) gettext_noop (String)
17 PluginClient* new_plugin(PluginServer *server)
19 return new DelayAudio(server);
23 DelayAudio::DelayAudio(PluginServer *server)
24 : PluginAClient(server)
30 DelayAudio::~DelayAudio()
34 thread->window->set_done(0);
35 thread->completion.lock();
42 if(buffer) delete [] buffer;
47 VFrame* DelayAudio::new_picon()
49 return new VFrame(picon_png);
52 char* DelayAudio::plugin_title()
54 return _("Delay audio");
57 void DelayAudio::reset()
64 int DelayAudio::is_realtime()
69 void DelayAudio::load_configuration()
71 KeyFrame *prev_keyframe;
72 prev_keyframe = get_prev_keyframe(get_source_position());
74 DelayAudioConfig old_config;
75 old_config.copy_from(config);
76 read_data(prev_keyframe);
78 if(!old_config.equivalent(config))
85 int DelayAudio::load_defaults()
87 char directory[BCTEXTLEN];
89 sprintf(directory, "%sdelayaudio.rc", BCASTDIR);
90 defaults = new Defaults(directory);
92 config.length = defaults->get("LENGTH", (double)1);
98 int DelayAudio::save_defaults()
100 defaults->update("LENGTH", config.length);
105 void DelayAudio::read_data(KeyFrame *keyframe)
108 input.set_shared_string(keyframe->data, strlen(keyframe->data));
113 result = input.read_tag();
117 if(input.tag.title_is("DELAYAUDIO"))
119 config.length = input.tag.get_property("LENGTH", (double)config.length);
126 void DelayAudio::save_data(KeyFrame *keyframe)
129 output.set_shared_string(keyframe->data, MESSAGESIZE);
131 output.tag.set_title("DELAYAUDIO");
132 output.tag.set_property("LENGTH", (double)config.length);
134 output.append_newline();
135 output.terminate_string();
138 void DelayAudio::reconfigure()
140 input_start = (int64_t)(config.length * PluginAClient::project_sample_rate + 0.5);
141 int64_t new_allocation = input_start + PluginClient::in_buffer_size;
142 double *new_buffer = new double[new_allocation];
143 bzero(new_buffer, sizeof(double) * new_allocation);
145 // printf("DelayAudio::reconfigure %f %d %d %d\n",
147 // PluginAClient::project_sample_rate,
148 // PluginClient::in_buffer_size,
155 int size = MIN(new_allocation, allocation);
159 (size - PluginClient::in_buffer_size) * sizeof(double));
163 allocation = new_allocation;
165 allocation = new_allocation;
166 need_reconfigure = 0;
169 int DelayAudio::process_realtime(int64_t size, double *input_ptr, double *output_ptr)
171 load_configuration();
172 if(need_reconfigure) reconfigure();
174 // printf("DelayAudio::process_realtime %d %d\n",
175 // input_start, size);
179 memcpy(buffer + input_start, input_ptr, size * sizeof(double));
180 memcpy(output_ptr, buffer, size * sizeof(double));
182 for(int i = size, j = 0; i < allocation; i++, j++)
184 buffer[j] = buffer[i];
190 int DelayAudio::show_gui()
192 load_configuration();
194 thread = new DelayAudioThread(this);
199 int DelayAudio::set_string()
201 if(thread) thread->window->set_title(gui_string);
205 void DelayAudio::raise_window()
209 thread->window->raise_window();
210 thread->window->flush();
214 void DelayAudio::update_gui()
218 load_configuration();
219 thread->window->lock_window();
220 thread->window->update_gui();
221 thread->window->unlock_window();
236 DelayAudioThread::DelayAudioThread(DelayAudio *plugin)
239 this->plugin = plugin;
247 DelayAudioThread::~DelayAudioThread()
253 void DelayAudioThread::run()
257 window = new DelayAudioWindow(plugin,
258 info.get_abs_cursor_x() - 125,
259 info.get_abs_cursor_y() - 115);
261 window->create_objects();
262 int result = window->run_window();
264 // Last command executed in thread
265 if(result) plugin->client_side_close();
277 DelayAudioWindow::DelayAudioWindow(DelayAudio *plugin, int x, int y)
278 : BC_Window(plugin->gui_string,
289 this->plugin = plugin;
292 DelayAudioWindow::~DelayAudioWindow()
296 int DelayAudioWindow::create_objects()
298 add_subwindow(new BC_Title(10, 10, _("Delay seconds:")));
299 add_subwindow(length = new DelayAudioTextBox(plugin, 10, 40));
306 int DelayAudioWindow::close_event()
308 // Set result to 1 to indicate a client side close
313 void DelayAudioWindow::update_gui()
315 char string[BCTEXTLEN];
316 sprintf(string, "%.04f", plugin->config.length);
317 length->update(string);
331 DelayAudioTextBox::DelayAudioTextBox(DelayAudio *plugin, int x, int y)
332 : BC_TextBox(x, y, 150, 1, "")
334 this->plugin = plugin;
337 DelayAudioTextBox::~DelayAudioTextBox()
341 int DelayAudioTextBox::handle_event()
343 plugin->config.length = atof(get_text());
344 if(plugin->config.length < 0) plugin->config.length = 0;
345 plugin->send_configure_change();
356 DelayAudioConfig::DelayAudioConfig()
361 int DelayAudioConfig::equivalent(DelayAudioConfig &that)
363 return(EQUIV(this->length, that.length));
366 void DelayAudioConfig::copy_from(DelayAudioConfig &that)
368 this->length = that.length;