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"
24 #include "bcsignals.h"
28 #include "pluginvclient.h"
29 #include "transportque.h"
35 class ReverseVideoConfig
43 class ReverseVideoEnabled : public BC_CheckBox
46 ReverseVideoEnabled(ReverseVideo *plugin,
53 class ReverseVideoWindow : public PluginClientWindow
56 ReverseVideoWindow(ReverseVideo *plugin);
57 ~ReverseVideoWindow();
58 void create_objects();
61 ReverseVideoEnabled *enabled;
65 class ReverseVideo : public PluginVClient
68 ReverseVideo(PluginServer *server);
71 PLUGIN_CLASS_MEMBERS(ReverseVideoConfig)
73 void save_data(KeyFrame *keyframe);
74 void read_data(KeyFrame *keyframe);
77 int process_buffer(VFrame *frame,
78 int64_t start_position,
81 int64_t input_position;
90 REGISTER_PLUGIN(ReverseVideo);
94 ReverseVideoConfig::ReverseVideoConfig()
103 ReverseVideoWindow::ReverseVideoWindow(ReverseVideo *plugin)
104 : PluginClientWindow(plugin,
111 this->plugin = plugin;
114 ReverseVideoWindow::~ReverseVideoWindow()
118 void ReverseVideoWindow::create_objects()
122 add_subwindow(enabled = new ReverseVideoEnabled(plugin,
140 ReverseVideoEnabled::ReverseVideoEnabled(ReverseVideo *plugin,
145 plugin->config.enabled,
148 this->plugin = plugin;
151 int ReverseVideoEnabled::handle_event()
153 plugin->config.enabled = get_value();
154 plugin->send_configure_change();
166 ReverseVideo::ReverseVideo(PluginServer *server)
167 : PluginVClient(server)
173 ReverseVideo::~ReverseVideo()
178 const char* ReverseVideo::plugin_title() { return N_("Reverse video"); }
179 int ReverseVideo::is_realtime() { return 1; }
182 NEW_WINDOW_MACRO(ReverseVideo, ReverseVideoWindow)
185 int ReverseVideo::process_buffer(VFrame *frame,
186 int64_t start_position,
189 load_configuration();
209 int ReverseVideo::load_configuration()
211 KeyFrame *prev_keyframe, *next_keyframe;
212 next_keyframe = get_next_keyframe(get_source_position());
213 prev_keyframe = get_prev_keyframe(get_source_position());
214 // Previous keyframe stays in config object.
215 read_data(prev_keyframe);
217 int64_t prev_position = edl_to_local(prev_keyframe->position);
218 int64_t next_position = edl_to_local(next_keyframe->position);
220 if(prev_position == 0 && next_position == 0)
222 next_position = prev_position = get_source_start();
225 // Get range to flip in requested rate
226 int64_t range_start = prev_position;
227 int64_t range_end = next_position;
229 // Between keyframe and edge of range or no keyframes
230 if(range_start == range_end)
232 // Between first keyframe and start of effect
233 if(get_source_position() >= get_source_start() &&
234 get_source_position() < range_start)
236 range_start = get_source_start();
239 // Between last keyframe and end of effect
240 if(get_source_position() >= range_start &&
241 get_source_position() < get_source_start() + get_total_len())
243 range_end = get_source_start() + get_total_len();
247 // Should never get here
253 // Convert start position to new direction
254 if(get_direction() == PLAY_FORWARD)
256 //printf("ReverseVideo::load_configuration %d %ld %ld %ld %ld %ld\n",
258 // get_source_position(),
259 // get_source_start(),
263 input_position = get_source_position() - range_start;
264 input_position = range_end - input_position - 1;
268 input_position = range_end - get_source_position();
269 input_position = range_start + input_position + 1;
271 // printf("ReverseVideo::load_configuration 2 start=%lld end=%lld current=%lld input=%lld\n",
274 // get_source_position(),
281 void ReverseVideo::save_data(KeyFrame *keyframe)
285 // cause data to be stored directly in text
286 output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
287 output.tag.set_title("REVERSEVIDEO");
288 output.tag.set_property("ENABLED", config.enabled);
290 output.tag.set_title("/REVERSEVIDEO");
292 output.append_newline();
293 output.terminate_string();
296 void ReverseVideo::read_data(KeyFrame *keyframe)
300 input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
302 while(!input.read_tag())
304 if(input.tag.title_is("REVERSEVIDEO"))
306 config.enabled = input.tag.get_property("ENABLED", config.enabled);
311 void ReverseVideo::update_gui()
315 load_configuration();
316 thread->window->lock_window();
317 ((ReverseVideoWindow*)thread->window)->enabled->update(config.enabled);
318 thread->window->unlock_window();