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(0,
202 PluginVClient::project_color_model,
206 for(int i = reuse; i < allocation; i++)
211 if(buffer) delete [] buffer;
215 allocation = new_allocation;
217 need_reconfigure = 0;
220 int DelayVideo::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
222 //printf("DelayVideo::process_realtime 1 %d\n", config.length);
223 this->input = input_ptr;
224 this->output = output_ptr;
225 need_reconfigure += load_configuration();
226 CLAMP(config.length, 0, 10);
228 //printf("DelayVideo::process_realtime 2 %d\n", config.length);
229 if(need_reconfigure) reconfigure();
230 //printf("DelayVideo::process_realtime 3 %d %d\n", config.length, allocation);
232 buffer[allocation - 1]->copy_from(input_ptr);
233 output_ptr->copy_from(buffer[0]);
235 VFrame *temp = buffer[0];
236 for(int i = 0; i < allocation - 1; i++)
238 buffer[i] = buffer[i + 1];
241 buffer[allocation - 1] = temp;
242 //printf("DelayVideo::process_realtime 4\n");
248 int DelayVideo::is_realtime()
253 const char* DelayVideo::plugin_title() { return _("Delay Video"); }
255 LOAD_CONFIGURATION_MACRO(DelayVideo, DelayVideoConfig)
256 NEW_WINDOW_MACRO(DelayVideo, DelayVideoWindow)
259 void DelayVideo::save_data(KeyFrame *keyframe)
262 output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
264 output.tag.set_title("DELAYVIDEO");
265 output.tag.set_property("LENGTH", (double)config.length);
267 output.tag.set_title("/DELAYVIDEO");
269 output.append_newline();
270 output.terminate_string();
273 void DelayVideo::read_data(KeyFrame *keyframe)
276 input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
281 result = input.read_tag();
285 if(input.tag.title_is("DELAYVIDEO"))
287 config.length = input.tag.get_property("LENGTH", (double)config.length);
293 void DelayVideo::update_gui()
297 load_configuration();
298 ((DelayVideoWindow*)thread->window)->lock_window();
299 ((DelayVideoWindow*)thread->window)->slider->update(config.length);
300 ((DelayVideoWindow*)thread->window)->unlock_window();