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 int ys5 = yS(5), ys10 = yS(10), ys35 = yS(35);
200 int x = xs10, y = ys10;
201 add_subwindow(on = new SwapFramesOn(plugin, x, y));
202 y += on->get_h() + ys5;
204 add_subwindow(bar = new BC_Bar(x, y, get_w() - x * xS(2)));
205 y += bar->get_h() + ys5;
206 add_subwindow(swap_even = new SwapFramesEven(plugin,
210 y += swap_even->get_h() + ys5;
211 add_subwindow(swap_odd = new SwapFramesOdd(plugin,
217 add_subwindow(reset = new SwapFramesReset(plugin, this, x, y));
223 void SwapFramesWindow::update()
225 on->update(plugin->config.swap_even);
226 swap_even->update(plugin->config.swap_even);
227 swap_odd->update(!plugin->config.swap_even);
240 SwapFrames::SwapFrames(PluginServer *server)
241 : PluginVClient(server)
245 buffer_position = -1;
249 SwapFrames::~SwapFrames()
255 const char* SwapFrames::plugin_title() { return N_("Swap Frames"); }
256 int SwapFrames::is_realtime() { return 1; }
258 NEW_WINDOW_MACRO(SwapFrames, SwapFramesWindow)
259 LOAD_CONFIGURATION_MACRO(SwapFrames, SwapFramesConfig)
261 void SwapFrames::update_gui()
265 thread->window->lock_window();
266 if(load_configuration())
268 ((SwapFramesWindow*)thread->window)->on->update(config.on);
269 ((SwapFramesWindow*)thread->window)->swap_even->update(config.swap_even);
270 ((SwapFramesWindow*)thread->window)->swap_odd->update(!config.swap_even);
272 thread->window->unlock_window();
277 void SwapFrames::save_data(KeyFrame *keyframe)
280 output.set_shared_output(keyframe->xbuf);
281 output.tag.set_title("SWAPFRAMES");
282 output.tag.set_property("ON", config.on);
283 output.tag.set_property("SWAP_EVEN", config.swap_even);
285 output.tag.set_title("/SWAPFRAMES");
287 output.append_newline();
288 output.terminate_string();
291 void SwapFrames::read_data(KeyFrame *keyframe)
294 input.set_shared_input(keyframe->xbuf);
295 while(!input.read_tag())
297 if(input.tag.title_is("SWAPFRAMES"))
299 config.on = input.tag.get_property("ON", config.on);
300 config.swap_even = input.tag.get_property("SWAP_EVEN", config.swap_even);
306 int SwapFrames::process_buffer(VFrame *frame,
307 int64_t start_position,
310 load_configuration();
311 int64_t new_position = start_position;
332 //printf("SwapFrames::process_buffer %d new_position=%lld\n", __LINE__, new_position);
333 if(buffer && buffer_position == new_position)
335 //printf("SwapFrames::process_buffer %d\n", __LINE__);
336 frame->copy_from(buffer);
340 if(new_position > prev_frame + 1)
342 //printf("SwapFrames::process_buffer %d\n", __LINE__);
344 buffer = new VFrame(frame->get_w(), frame->get_h(),
345 frame->get_color_model(), 0);
346 buffer_position = new_position - 1;
357 prev_frame = new_position;
362 //printf("SwapFrames::process_buffer %d\n", __LINE__);
368 prev_frame = new_position;