4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5 * Copyright (C) 2003-2016 Cinelerra CV contributors
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "bcdisplayinfo.h"
29 #include "pluginvclient.h"
30 #include "transportque.h"
44 class LoopVideoFrames : public BC_TextBox
47 LoopVideoFrames(LoopVideo *plugin,
54 class LoopVideoWindow : public PluginClientWindow
57 LoopVideoWindow(LoopVideo *plugin);
59 void create_objects();
61 LoopVideoFrames *frames;
65 class LoopVideo : public PluginVClient
68 LoopVideo(PluginServer *server);
71 PLUGIN_CLASS_MEMBERS(LoopVideoConfig)
73 void save_data(KeyFrame *keyframe);
74 void read_data(KeyFrame *keyframe);
78 int process_buffer(VFrame *frame,
79 int64_t start_position,
89 REGISTER_PLUGIN(LoopVideo);
93 LoopVideoConfig::LoopVideoConfig()
102 LoopVideoWindow::LoopVideoWindow(LoopVideo *plugin)
103 : PluginClientWindow(plugin,
110 this->plugin = plugin;
113 LoopVideoWindow::~LoopVideoWindow()
117 void LoopVideoWindow::create_objects()
120 int ys10 = yS(10), ys20 = yS(20);
121 int x = xs10, y = ys10;
123 add_subwindow(new BC_Title(x, y, _("Frames to loop:")));
125 add_subwindow(frames = new LoopVideoFrames(plugin,
142 LoopVideoFrames::LoopVideoFrames(LoopVideo *plugin,
149 plugin->config.frames)
151 this->plugin = plugin;
154 int LoopVideoFrames::handle_event()
156 plugin->config.frames = atol(get_text());
157 plugin->config.frames = MAX(1, plugin->config.frames);
158 plugin->send_configure_change();
170 LoopVideo::LoopVideo(PluginServer *server)
171 : PluginVClient(server)
177 LoopVideo::~LoopVideo()
182 const char* LoopVideo::plugin_title() { return N_("Loop video"); }
183 int LoopVideo::is_realtime() { return 1; }
184 int LoopVideo::is_synthesis() { return 1; }
187 NEW_WINDOW_MACRO(LoopVideo, LoopVideoWindow)
191 int LoopVideo::process_buffer(VFrame *frame,
192 int64_t start_position,
195 int64_t current_loop_position;
197 // Truncate to next keyframe
198 if(get_direction() == PLAY_FORWARD)
200 // Get start of current loop
201 KeyFrame *prev_keyframe = get_prev_keyframe(start_position);
202 int64_t prev_position = edl_to_local(prev_keyframe->position);
203 if(prev_position == 0)
204 prev_position = get_source_start();
205 read_data(prev_keyframe);
207 // Get start of fragment in current loop
208 current_loop_position = prev_position +
209 ((start_position - prev_position) %
211 while(current_loop_position < prev_position) current_loop_position += config.frames;
212 while(current_loop_position >= prev_position + config.frames) current_loop_position -= config.frames;
216 KeyFrame *prev_keyframe = get_next_keyframe(start_position);
217 int64_t prev_position = edl_to_local(prev_keyframe->position);
218 if(prev_position == 0)
219 prev_position = get_source_start() + get_total_len();
220 read_data(prev_keyframe);
222 current_loop_position = prev_position -
223 ((prev_position - start_position) %
225 while(current_loop_position <= prev_position - config.frames) current_loop_position += config.frames;
226 while(current_loop_position > prev_position) current_loop_position -= config.frames;
230 // printf("LoopVideo::process_buffer 100 %lld %lld %lld %d\n",
231 // current_position, current_loop_position, current_loop_end, fragment_size);
234 current_loop_position,
244 int LoopVideo::load_configuration()
246 KeyFrame *prev_keyframe;
247 int64_t old_frames = config.frames;
248 prev_keyframe = get_prev_keyframe(get_source_position());
249 read_data(prev_keyframe);
250 config.frames = MAX(config.frames, 1);
251 return old_frames != config.frames;
255 void LoopVideo::save_data(KeyFrame *keyframe)
259 // cause data to be stored directly in text
260 output.set_shared_output(keyframe->xbuf);
261 output.tag.set_title("LOOPVIDEO");
262 output.tag.set_property("FRAMES", config.frames);
264 output.tag.set_title("/LOOPVIDEO");
266 output.append_newline();
267 output.terminate_string();
270 void LoopVideo::read_data(KeyFrame *keyframe)
274 input.set_shared_input(keyframe->xbuf);
276 while(!input.read_tag())
278 if(input.tag.title_is("LOOPVIDEO"))
280 config.frames = input.tag.get_property("FRAMES", config.frames);
285 void LoopVideo::update_gui()
289 load_configuration();
290 thread->window->lock_window();
291 ((LoopVideoWindow*)thread->window)->frames->update(config.frames);
292 thread->window->unlock_window();