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"
28 #include "pluginvclient.h"
29 #include "transportque.h"
43 class LoopVideoFrames : public BC_TextBox
46 LoopVideoFrames(LoopVideo *plugin,
53 class LoopVideoWindow : public PluginClientWindow
56 LoopVideoWindow(LoopVideo *plugin);
58 void create_objects();
60 LoopVideoFrames *frames;
64 class LoopVideo : public PluginVClient
67 LoopVideo(PluginServer *server);
70 PLUGIN_CLASS_MEMBERS(LoopVideoConfig)
72 void save_data(KeyFrame *keyframe);
73 void read_data(KeyFrame *keyframe);
77 int process_buffer(VFrame *frame,
78 int64_t start_position,
88 REGISTER_PLUGIN(LoopVideo);
92 LoopVideoConfig::LoopVideoConfig()
101 LoopVideoWindow::LoopVideoWindow(LoopVideo *plugin)
102 : PluginClientWindow(plugin,
109 this->plugin = plugin;
112 LoopVideoWindow::~LoopVideoWindow()
116 void LoopVideoWindow::create_objects()
119 int ys10 = yS(10), ys20 = yS(20);
120 int x = xs10, y = ys10;
122 add_subwindow(new BC_Title(x, y, _("Frames to loop:")));
124 add_subwindow(frames = new LoopVideoFrames(plugin,
141 LoopVideoFrames::LoopVideoFrames(LoopVideo *plugin,
148 plugin->config.frames)
150 this->plugin = plugin;
153 int LoopVideoFrames::handle_event()
155 plugin->config.frames = atol(get_text());
156 plugin->config.frames = MAX(1, plugin->config.frames);
157 plugin->send_configure_change();
169 LoopVideo::LoopVideo(PluginServer *server)
170 : PluginVClient(server)
176 LoopVideo::~LoopVideo()
181 const char* LoopVideo::plugin_title() { return N_("Loop video"); }
182 int LoopVideo::is_realtime() { return 1; }
183 int LoopVideo::is_synthesis() { return 1; }
186 NEW_WINDOW_MACRO(LoopVideo, LoopVideoWindow)
190 int LoopVideo::process_buffer(VFrame *frame,
191 int64_t start_position,
194 int64_t current_loop_position;
196 // Truncate to next keyframe
197 if(get_direction() == PLAY_FORWARD)
199 // Get start of current loop
200 KeyFrame *prev_keyframe = get_prev_keyframe(start_position);
201 int64_t prev_position = edl_to_local(prev_keyframe->position);
202 if(prev_position == 0)
203 prev_position = get_source_start();
204 read_data(prev_keyframe);
206 // Get start of fragment in current loop
207 current_loop_position = prev_position +
208 ((start_position - prev_position) %
210 while(current_loop_position < prev_position) current_loop_position += config.frames;
211 while(current_loop_position >= prev_position + config.frames) current_loop_position -= config.frames;
215 KeyFrame *prev_keyframe = get_next_keyframe(start_position);
216 int64_t prev_position = edl_to_local(prev_keyframe->position);
217 if(prev_position == 0)
218 prev_position = get_source_start() + get_total_len();
219 read_data(prev_keyframe);
221 current_loop_position = prev_position -
222 ((prev_position - start_position) %
224 while(current_loop_position <= prev_position - config.frames) current_loop_position += config.frames;
225 while(current_loop_position > prev_position) current_loop_position -= config.frames;
229 // printf("LoopVideo::process_buffer 100 %lld %lld %lld %d\n",
230 // current_position, current_loop_position, current_loop_end, fragment_size);
233 current_loop_position,
243 int LoopVideo::load_configuration()
245 KeyFrame *prev_keyframe;
246 int64_t old_frames = config.frames;
247 prev_keyframe = get_prev_keyframe(get_source_position());
248 read_data(prev_keyframe);
249 config.frames = MAX(config.frames, 1);
250 return old_frames != config.frames;
254 void LoopVideo::save_data(KeyFrame *keyframe)
258 // cause data to be stored directly in text
259 output.set_shared_output(keyframe->xbuf);
260 output.tag.set_title("LOOPVIDEO");
261 output.tag.set_property("FRAMES", config.frames);
263 output.tag.set_title("/LOOPVIDEO");
265 output.append_newline();
266 output.terminate_string();
269 void LoopVideo::read_data(KeyFrame *keyframe)
273 input.set_shared_input(keyframe->xbuf);
275 while(!input.read_tag())
277 if(input.tag.title_is("LOOPVIDEO"))
279 config.frames = input.tag.get_property("FRAMES", config.frames);
284 void LoopVideo::update_gui()
288 load_configuration();
289 thread->window->lock_window();
290 ((LoopVideoWindow*)thread->window)->frames->update(config.frames);
291 thread->window->unlock_window();