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() { return N_("Delay audio"); }
53 int DelayAudio::is_realtime() { return 1; }
56 void DelayAudio::reset()
63 void DelayAudio::load_configuration()
65 KeyFrame *prev_keyframe;
66 prev_keyframe = get_prev_keyframe(get_source_position());
68 DelayAudioConfig old_config;
69 old_config.copy_from(config);
70 read_data(prev_keyframe);
72 if(!old_config.equivalent(config))
79 int DelayAudio::load_defaults()
81 char directory[BCTEXTLEN];
83 sprintf(directory, "%sdelayaudio.rc", BCASTDIR);
84 defaults = new BC_Hash(directory);
86 config.length = defaults->get("LENGTH", (double)1);
92 int DelayAudio::save_defaults()
94 defaults->update("LENGTH", config.length);
99 void DelayAudio::read_data(KeyFrame *keyframe)
102 input.set_shared_string(keyframe->data, strlen(keyframe->data));
107 result = input.read_tag();
111 if(input.tag.title_is("DELAYAUDIO"))
113 config.length = input.tag.get_property("LENGTH", (double)config.length);
120 void DelayAudio::save_data(KeyFrame *keyframe)
123 output.set_shared_string(keyframe->data, MESSAGESIZE);
125 output.tag.set_title("DELAYAUDIO");
126 output.tag.set_property("LENGTH", (double)config.length);
128 output.append_newline();
129 output.terminate_string();
132 void DelayAudio::reconfigure()
134 input_start = (int64_t)(config.length * PluginAClient::project_sample_rate + 0.5);
135 int64_t new_allocation = input_start + PluginClient::in_buffer_size;
136 double *new_buffer = new double[new_allocation];
137 bzero(new_buffer, sizeof(double) * new_allocation);
139 // printf("DelayAudio::reconfigure %f %d %d %d\n",
141 // PluginAClient::project_sample_rate,
142 // PluginClient::in_buffer_size,
149 int size = MIN(new_allocation, allocation);
153 (size - PluginClient::in_buffer_size) * sizeof(double));
157 allocation = new_allocation;
159 allocation = new_allocation;
160 need_reconfigure = 0;
163 int DelayAudio::process_realtime(int64_t size, double *input_ptr, double *output_ptr)
165 load_configuration();
166 if(need_reconfigure) reconfigure();
168 // printf("DelayAudio::process_realtime %d %d\n",
169 // input_start, size);
173 memcpy(buffer + input_start, input_ptr, size * sizeof(double));
174 memcpy(output_ptr, buffer, size * sizeof(double));
176 for(int i = size, j = 0; i < allocation; i++, j++)
178 buffer[j] = buffer[i];
184 int DelayAudio::show_gui()
186 load_configuration();
188 thread = new DelayAudioThread(this);
193 int DelayAudio::set_string()
195 if(thread) thread->window->set_title(gui_string);
199 void DelayAudio::raise_window()
203 thread->window->raise_window();
204 thread->window->flush();
208 void DelayAudio::update_gui()
212 load_configuration();
213 thread->window->lock_window();
214 thread->window->update_gui();
215 thread->window->unlock_window();
230 DelayAudioThread::DelayAudioThread(DelayAudio *plugin)
233 this->plugin = plugin;
241 DelayAudioThread::~DelayAudioThread()
247 void DelayAudioThread::run()
251 window = new DelayAudioWindow(plugin,
252 info.get_abs_cursor_x() - 125,
253 info.get_abs_cursor_y() - 115);
255 window->create_objects();
256 int result = window->run_window();
258 // Last command executed in thread
259 if(result) plugin->client_side_close();
271 DelayAudioWindow::DelayAudioWindow(DelayAudio *plugin, int x, int y)
272 : BC_Window(plugin->gui_string,
283 this->plugin = plugin;
286 DelayAudioWindow::~DelayAudioWindow()
290 int DelayAudioWindow::create_objects()
292 add_subwindow(new BC_Title(10, 10, _("Delay seconds:")));
293 add_subwindow(length = new DelayAudioTextBox(plugin, 10, 40));
300 int DelayAudioWindow::close_event()
302 // Set result to 1 to indicate a client side close
307 void DelayAudioWindow::update_gui()
309 char string[BCTEXTLEN];
310 sprintf(string, "%.04f", plugin->config.length);
311 length->update(string);
325 DelayAudioTextBox::DelayAudioTextBox(DelayAudio *plugin, int x, int y)
326 : BC_TextBox(x, y, 150, 1, "")
328 this->plugin = plugin;
331 DelayAudioTextBox::~DelayAudioTextBox()
335 int DelayAudioTextBox::handle_event()
337 plugin->config.length = atof(get_text());
338 if(plugin->config.length < 0) plugin->config.length = 0;
339 plugin->send_configure_change();
350 DelayAudioConfig::DelayAudioConfig()
355 int DelayAudioConfig::equivalent(DelayAudioConfig &that)
357 return(EQUIV(this->length, that.length));
360 void DelayAudioConfig::copy_from(DelayAudioConfig &that)
362 this->length = that.length;