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"
29 #include "pluginvclient.h"
30 #include "swapframes.h"
39 REGISTER_PLUGIN(SwapFrames)
47 SwapFramesConfig::SwapFramesConfig()
52 void SwapFramesConfig::reset()
58 void SwapFramesConfig::copy_from(SwapFramesConfig &src)
61 swap_even = src.swap_even;
64 int SwapFramesConfig::equivalent(SwapFramesConfig &src)
66 return on == src.on &&
67 swap_even == src.swap_even;
70 void SwapFramesConfig::interpolate(SwapFramesConfig &prev,
71 SwapFramesConfig &next,
74 int64_t current_frame)
77 swap_even = prev.swap_even;
89 SwapFramesOn::SwapFramesOn(SwapFrames *plugin,
96 this->plugin = plugin;
99 int SwapFramesOn::handle_event()
101 plugin->config.on = get_value();
102 plugin->send_configure_change();
111 SwapFramesEven::SwapFramesEven(SwapFrames *plugin,
112 SwapFramesWindow *gui,
117 plugin->config.swap_even,
118 _("Swap 0-1, 2-3, 4-5..."))
120 this->plugin = plugin;
124 int SwapFramesEven::handle_event()
126 plugin->config.swap_even = 1;
127 gui->swap_odd->update(0);
128 plugin->send_configure_change();
137 SwapFramesOdd::SwapFramesOdd(SwapFrames *plugin,
138 SwapFramesWindow *gui,
143 !plugin->config.swap_even,
144 _("Swap 1-2, 3-4, 5-6..."))
146 this->plugin = plugin;
150 int SwapFramesOdd::handle_event()
152 plugin->config.swap_even = 0;
153 gui->swap_even->update(0);
154 plugin->send_configure_change();
164 SwapFramesReset::SwapFramesReset(SwapFrames *plugin, SwapFramesWindow *gui, int x, int y)
165 : BC_GenericButton(x, y, _("Reset"))
167 this->plugin = plugin;
170 SwapFramesReset::~SwapFramesReset()
173 int SwapFramesReset::handle_event()
175 plugin->config.reset();
177 plugin->send_configure_change();
185 SwapFramesWindow::SwapFramesWindow(SwapFrames *plugin)
186 : PluginClientWindow(plugin,
193 this->plugin = plugin;
196 void SwapFramesWindow::create_objects()
199 add_subwindow(on = new SwapFramesOn(plugin, x, y));
200 y += on->get_h() + 5;
202 add_subwindow(bar = new BC_Bar(x, y, get_w() - x * 2));
203 y += bar->get_h() + 5;
204 add_subwindow(swap_even = new SwapFramesEven(plugin,
208 y += swap_even->get_h() + 5;
209 add_subwindow(swap_odd = new SwapFramesOdd(plugin,
215 add_subwindow(reset = new SwapFramesReset(plugin, this, x, y));
221 void SwapFramesWindow::update()
223 on->update(plugin->config.swap_even);
224 swap_even->update(plugin->config.swap_even);
225 swap_odd->update(!plugin->config.swap_even);
238 SwapFrames::SwapFrames(PluginServer *server)
239 : PluginVClient(server)
243 buffer_position = -1;
247 SwapFrames::~SwapFrames()
253 const char* SwapFrames::plugin_title() { return N_("Swap Frames"); }
254 int SwapFrames::is_realtime() { return 1; }
256 NEW_WINDOW_MACRO(SwapFrames, SwapFramesWindow)
257 LOAD_CONFIGURATION_MACRO(SwapFrames, SwapFramesConfig)
259 void SwapFrames::update_gui()
263 thread->window->lock_window();
264 if(load_configuration())
266 ((SwapFramesWindow*)thread->window)->on->update(config.on);
267 ((SwapFramesWindow*)thread->window)->swap_even->update(config.swap_even);
268 ((SwapFramesWindow*)thread->window)->swap_odd->update(!config.swap_even);
270 thread->window->unlock_window();
275 void SwapFrames::save_data(KeyFrame *keyframe)
278 output.set_shared_output(keyframe->xbuf);
279 output.tag.set_title("SWAPFRAMES");
280 output.tag.set_property("ON", config.on);
281 output.tag.set_property("SWAP_EVEN", config.swap_even);
283 output.tag.set_title("/SWAPFRAMES");
285 output.append_newline();
286 output.terminate_string();
289 void SwapFrames::read_data(KeyFrame *keyframe)
292 input.set_shared_input(keyframe->xbuf);
293 while(!input.read_tag())
295 if(input.tag.title_is("SWAPFRAMES"))
297 config.on = input.tag.get_property("ON", config.on);
298 config.swap_even = input.tag.get_property("SWAP_EVEN", config.swap_even);
304 int SwapFrames::process_buffer(VFrame *frame,
305 int64_t start_position,
308 load_configuration();
309 int64_t new_position = start_position;
330 //printf("SwapFrames::process_buffer %d new_position=%lld\n", __LINE__, new_position);
331 if(buffer && buffer_position == new_position)
333 //printf("SwapFrames::process_buffer %d\n", __LINE__);
334 frame->copy_from(buffer);
338 if(new_position > prev_frame + 1)
340 //printf("SwapFrames::process_buffer %d\n", __LINE__);
342 buffer = new VFrame(frame->get_w(), frame->get_h(),
343 frame->get_color_model(), 0);
344 buffer_position = new_position - 1;
355 prev_frame = new_position;
360 //printf("SwapFrames::process_buffer %d\n", __LINE__);
366 prev_frame = new_position;