4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "bcdisplayinfo.h"
25 #include "delayvideo.h"
40 REGISTER_PLUGIN(DelayVideo)
46 DelayVideoConfig::DelayVideoConfig()
51 int DelayVideoConfig::equivalent(DelayVideoConfig &that)
53 return EQUIV(length, that.length);
56 void DelayVideoConfig::copy_from(DelayVideoConfig &that)
61 void DelayVideoConfig::interpolate(DelayVideoConfig &prev,
62 DelayVideoConfig &next,
65 int64_t current_frame)
67 this->length = prev.length;
72 DelayVideoWindow::DelayVideoWindow(DelayVideo *plugin)
73 : PluginClientWindow(plugin,
80 this->plugin = plugin;
83 DelayVideoWindow::~DelayVideoWindow()
88 void DelayVideoWindow::create_objects()
92 add_subwindow(new BC_Title(x, y, _("Delay seconds:")));
94 slider = new DelayVideoSlider(this, plugin, x, y);
95 slider->create_objects();
100 void DelayVideoWindow::update_gui()
102 char string[BCTEXTLEN];
103 sprintf(string, "%.04f", plugin->config.length);
104 slider->update(string);
118 DelayVideoSlider::DelayVideoSlider(DelayVideoWindow *window,
122 : BC_TumbleTextBox(window,
123 (float)plugin->config.length,
130 this->plugin = plugin;
134 int DelayVideoSlider::handle_event()
136 plugin->config.length = atof(get_text());
137 plugin->send_configure_change();
157 DelayVideo::DelayVideo(PluginServer *server)
158 : PluginVClient(server)
163 DelayVideo::~DelayVideo()
167 //printf("DelayVideo::~DelayVideo 1\n");
168 for(int i = 0; i < allocation; i++)
170 //printf("DelayVideo::~DelayVideo 1\n");
173 //printf("DelayVideo::~DelayVideo 1\n");
177 void DelayVideo::reset()
180 need_reconfigure = 1;
185 void DelayVideo::reconfigure()
187 int new_allocation = 1 + (int)(config.length * PluginVClient::project_frame_rate);
188 VFrame **new_buffer = new VFrame*[new_allocation];
189 int reuse = MIN(new_allocation, allocation);
191 for(int i = 0; i < reuse; i++)
193 new_buffer[i] = buffer[i];
196 for(int i = reuse; i < new_allocation; i++)
198 new_buffer[i] = new VFrame(input->get_w(), input->get_h(),
199 PluginVClient::project_color_model, 0);
202 for(int i = reuse; i < allocation; i++)
207 if(buffer) delete [] buffer;
211 allocation = new_allocation;
213 need_reconfigure = 0;
216 int DelayVideo::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
218 //printf("DelayVideo::process_realtime 1 %d\n", config.length);
219 this->input = input_ptr;
220 this->output = output_ptr;
221 need_reconfigure += load_configuration();
222 CLAMP(config.length, 0, 10);
224 //printf("DelayVideo::process_realtime 2 %d\n", config.length);
225 if(need_reconfigure) reconfigure();
226 //printf("DelayVideo::process_realtime 3 %d %d\n", config.length, allocation);
228 buffer[allocation - 1]->copy_from(input_ptr);
229 output_ptr->copy_from(buffer[0]);
231 VFrame *temp = buffer[0];
232 for(int i = 0; i < allocation - 1; i++)
234 buffer[i] = buffer[i + 1];
237 buffer[allocation - 1] = temp;
238 //printf("DelayVideo::process_realtime 4\n");
244 int DelayVideo::is_realtime()
249 const char* DelayVideo::plugin_title() { return N_("Delay Video"); }
251 LOAD_CONFIGURATION_MACRO(DelayVideo, DelayVideoConfig)
252 NEW_WINDOW_MACRO(DelayVideo, DelayVideoWindow)
255 void DelayVideo::save_data(KeyFrame *keyframe)
258 output.set_shared_output(keyframe->xbuf);
260 output.tag.set_title("DELAYVIDEO");
261 output.tag.set_property("LENGTH", (double)config.length);
263 output.tag.set_title("/DELAYVIDEO");
265 output.append_newline();
266 output.terminate_string();
269 void DelayVideo::read_data(KeyFrame *keyframe)
272 input.set_shared_input(keyframe->xbuf);
277 result = input.read_tag();
281 if(input.tag.title_is("DELAYVIDEO"))
283 config.length = input.tag.get_property("LENGTH", (double)config.length);
289 void DelayVideo::update_gui()
293 load_configuration();
294 ((DelayVideoWindow*)thread->window)->lock_window();
295 ((DelayVideoWindow*)thread->window)->slider->update(config.length);
296 ((DelayVideoWindow*)thread->window)->unlock_window();