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()
91 int ys10 = yS(10), ys20 = yS(20);
92 int x = xs10, y = ys10;
94 add_subwindow(new BC_Title(x, y, _("Delay seconds:")));
96 slider = new DelayVideoSlider(this, plugin, x, y);
97 slider->create_objects();
102 void DelayVideoWindow::update_gui()
104 char string[BCTEXTLEN];
105 sprintf(string, "%.04f", plugin->config.length);
106 slider->update(string);
120 DelayVideoSlider::DelayVideoSlider(DelayVideoWindow *window,
124 : BC_TumbleTextBox(window,
125 (float)plugin->config.length,
132 this->plugin = plugin;
136 int DelayVideoSlider::handle_event()
138 plugin->config.length = atof(get_text());
139 plugin->send_configure_change();
159 DelayVideo::DelayVideo(PluginServer *server)
160 : PluginVClient(server)
165 DelayVideo::~DelayVideo()
169 //printf("DelayVideo::~DelayVideo 1\n");
170 for(int i = 0; i < allocation; i++)
172 //printf("DelayVideo::~DelayVideo 1\n");
175 //printf("DelayVideo::~DelayVideo 1\n");
179 void DelayVideo::reset()
182 need_reconfigure = 1;
187 void DelayVideo::reconfigure()
189 int new_allocation = 1 + (int)(config.length * PluginVClient::project_frame_rate);
190 VFrame **new_buffer = new VFrame*[new_allocation];
191 int reuse = MIN(new_allocation, allocation);
193 for(int i = 0; i < reuse; i++)
195 new_buffer[i] = buffer[i];
198 for(int i = reuse; i < new_allocation; i++)
200 new_buffer[i] = new VFrame(input->get_w(), input->get_h(),
201 PluginVClient::project_color_model, 0);
204 for(int i = reuse; i < allocation; i++)
209 if(buffer) delete [] buffer;
213 allocation = new_allocation;
215 need_reconfigure = 0;
218 int DelayVideo::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
220 //printf("DelayVideo::process_realtime 1 %d\n", config.length);
221 this->input = input_ptr;
222 this->output = output_ptr;
223 need_reconfigure += load_configuration();
224 CLAMP(config.length, 0, 10);
226 //printf("DelayVideo::process_realtime 2 %d\n", config.length);
227 if(need_reconfigure) reconfigure();
228 //printf("DelayVideo::process_realtime 3 %d %d\n", config.length, allocation);
230 buffer[allocation - 1]->copy_from(input_ptr);
231 output_ptr->copy_from(buffer[0]);
233 VFrame *temp = buffer[0];
234 for(int i = 0; i < allocation - 1; i++)
236 buffer[i] = buffer[i + 1];
239 buffer[allocation - 1] = temp;
240 //printf("DelayVideo::process_realtime 4\n");
246 int DelayVideo::is_realtime()
251 const char* DelayVideo::plugin_title() { return N_("Delay Video"); }
253 LOAD_CONFIGURATION_MACRO(DelayVideo, DelayVideoConfig)
254 NEW_WINDOW_MACRO(DelayVideo, DelayVideoWindow)
257 void DelayVideo::save_data(KeyFrame *keyframe)
260 output.set_shared_output(keyframe->xbuf);
262 output.tag.set_title("DELAYVIDEO");
263 output.tag.set_property("LENGTH", (double)config.length);
265 output.tag.set_title("/DELAYVIDEO");
267 output.append_newline();
268 output.terminate_string();
271 void DelayVideo::read_data(KeyFrame *keyframe)
274 input.set_shared_input(keyframe->xbuf);
279 result = input.read_tag();
283 if(input.tag.title_is("DELAYVIDEO"))
285 config.length = input.tag.get_property("LENGTH", (double)config.length);
291 void DelayVideo::update_gui()
295 load_configuration();
296 ((DelayVideoWindow*)thread->window)->lock_window();
297 ((DelayVideoWindow*)thread->window)->slider->update(config.length);
298 ((DelayVideoWindow*)thread->window)->unlock_window();