Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / slide / slide.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "bcdisplayinfo.h"
23 #include "bchash.h"
24 #include "edl.inc"
25 #include "filexml.h"
26 #include "language.h"
27 #include "overlayframe.h"
28 #include "vframe.h"
29 #include "slide.h"
30
31
32 #include <stdint.h>
33 #include <string.h>
34
35
36
37 REGISTER_PLUGIN(SlideMain)
38
39
40
41
42
43 SlideLeft::SlideLeft(SlideMain *plugin,
44         SlideWindow *window,
45         int x,
46         int y)
47  : BC_Radial(x,
48                 y,
49                 plugin->motion_direction == 0,
50                 _("Left"))
51 {
52         this->plugin = plugin;
53         this->window = window;
54 }
55
56 int SlideLeft::handle_event()
57 {
58         update(1);
59         plugin->motion_direction = 0;
60         window->right->update(0);
61         plugin->send_configure_change();
62         return 0;
63 }
64
65 SlideRight::SlideRight(SlideMain *plugin,
66         SlideWindow *window,
67         int x,
68         int y)
69  : BC_Radial(x,
70                 y,
71                 plugin->motion_direction == 1,
72                 _("Right"))
73 {
74         this->plugin = plugin;
75         this->window = window;
76 }
77
78 int SlideRight::handle_event()
79 {
80         update(1);
81         plugin->motion_direction = 1;
82         window->left->update(0);
83         plugin->send_configure_change();
84         return 0;
85 }
86
87 SlideIn::SlideIn(SlideMain *plugin,
88         SlideWindow *window,
89         int x,
90         int y)
91  : BC_Radial(x,
92                 y,
93                 plugin->direction == 0,
94                 _("In"))
95 {
96         this->plugin = plugin;
97         this->window = window;
98 }
99
100 int SlideIn::handle_event()
101 {
102         update(1);
103         plugin->direction = 0;
104         window->out->update(0);
105         plugin->send_configure_change();
106         return 0;
107 }
108
109 SlideOut::SlideOut(SlideMain *plugin,
110         SlideWindow *window,
111         int x,
112         int y)
113  : BC_Radial(x,
114                 y,
115                 plugin->direction == 1,
116                 _("Out"))
117 {
118         this->plugin = plugin;
119         this->window = window;
120 }
121
122 int SlideOut::handle_event()
123 {
124         update(1);
125         plugin->direction = 1;
126         window->in->update(0);
127         plugin->send_configure_change();
128         return 0;
129 }
130
131
132
133
134
135
136
137
138 SlideWindow::SlideWindow(SlideMain *plugin)
139  : PluginClientWindow(plugin,
140         xS(320),
141         yS(100),
142         xS(320),
143         yS(100),
144         0)
145 {
146         this->plugin = plugin;
147 }
148
149
150
151
152
153
154 void SlideWindow::create_objects()
155 {
156         int xs10 = xS(10), xs100 = xS(100);
157         int ys10 = yS(10), ys30 = yS(30);
158         int x = xs10, y = ys10;
159         add_subwindow(new BC_Title(x, y, _("Direction:")));
160         x += xs100;
161         add_subwindow(left = new SlideLeft(plugin,
162                 this,
163                 x,
164                 y));
165         x += xs100;
166         add_subwindow(right = new SlideRight(plugin,
167                 this,
168                 x,
169                 y));
170
171         y += ys30;
172         x = xs10;
173         add_subwindow(new BC_Title(x, y, _("Direction:")));
174         x += xs100;
175         add_subwindow(in = new SlideIn(plugin,
176                 this,
177                 x,
178                 y));
179         x += xs100;
180         add_subwindow(out = new SlideOut(plugin,
181                 this,
182                 x,
183                 y));
184
185         show_window();
186         flush();
187 }
188
189
190
191
192
193
194
195
196
197
198
199 SlideMain::SlideMain(PluginServer *server)
200  : PluginVClient(server)
201 {
202         motion_direction = 0;
203         direction = 0;
204
205 }
206
207 SlideMain::~SlideMain()
208 {
209
210 }
211
212 const char* SlideMain::plugin_title() { return N_("Slide"); }
213 int SlideMain::is_video() { return 1; }
214 int SlideMain::is_transition() { return 1; }
215 int SlideMain::uses_gui() { return 1; }
216
217 NEW_WINDOW_MACRO(SlideMain, SlideWindow)
218
219
220 void SlideMain::save_data(KeyFrame *keyframe)
221 {
222         FileXML output;
223         output.set_shared_output(keyframe->xbuf);
224         output.tag.set_title("SLIDE");
225         output.tag.set_property("MOTION_DIRECTION", motion_direction);
226         output.tag.set_property("DIRECTION", direction);
227         output.append_tag();
228         output.tag.set_title("/SLIDE");
229         output.append_tag();
230         output.append_newline();
231         output.terminate_string();
232 }
233
234 void SlideMain::read_data(KeyFrame *keyframe)
235 {
236         FileXML input;
237
238         input.set_shared_input(keyframe->xbuf);
239
240         while(!input.read_tag())
241         {
242                 if(input.tag.title_is("SLIDE"))
243                 {
244                         motion_direction = input.tag.get_property("MOTION_DIRECTION", motion_direction);
245                         direction = input.tag.get_property("DIRECTION", direction);
246                 }
247         }
248 }
249
250 int SlideMain::load_configuration()
251 {
252         read_data(get_prev_keyframe(get_source_position()));
253         return 1;
254 }
255
256
257
258
259 #define SLIDE(type, components) \
260 { \
261         if(direction == 0) \
262         { \
263                 int in_add, out_add, cpy_len; \
264                 if(motion_direction == 0) \
265                 { \
266                         int x = w *  \
267                                 PluginClient::get_source_position() /  \
268                                 PluginClient::get_total_len(); \
269                         out_add = 0; \
270                         in_add = (w - x) * components * sizeof(type); \
271                         cpy_len = x * components * sizeof(type); \
272                 } \
273                 else \
274                 { \
275                         int x = w - w *  \
276                                 PluginClient::get_source_position() /  \
277                                 PluginClient::get_total_len(); \
278                         out_add = x * components * sizeof(type); \
279                         in_add = 0; \
280                         cpy_len = (w - x) * components * sizeof(type); \
281                 } \
282  \
283                 for(int j = 0; j < h; j++) \
284                 { \
285                         memcpy( ((char *)outgoing->get_rows()[j]) + out_add, \
286                                 ((char *)incoming->get_rows()[j]) + in_add, \
287                                 cpy_len); \
288                 } \
289         } \
290         else \
291         { \
292                 if(motion_direction == 0) \
293                 { \
294                         int x = w - w *  \
295                                 PluginClient::get_source_position() /  \
296                                 PluginClient::get_total_len(); \
297                         for(int j = 0; j < h; j++) \
298                         { \
299                                 char *in_row = (char*)incoming->get_rows()[j]; \
300                                 char *out_row = (char*)outgoing->get_rows()[j]; \
301                                 memmove(out_row + 0, out_row + ((w - x) * components * sizeof(type)), x * components * sizeof(type)); \
302                                 memcpy (out_row + x * components * sizeof(type), in_row + x * components * sizeof (type), (w - x) * components * sizeof(type)); \
303                         } \
304                 } \
305                 else \
306                 { \
307                         int x = w *  \
308                                 PluginClient::get_source_position() /  \
309                                 PluginClient::get_total_len(); \
310                         for(int j = 0; j < h; j++) \
311                         { \
312                                 char *in_row = (char*)incoming->get_rows()[j]; \
313                                 char *out_row = (char*)outgoing->get_rows()[j]; \
314          \
315                                 memmove(out_row + (x * components *sizeof(type)), out_row + 0, (w - x) * components * sizeof(type)); \
316                                 memcpy (out_row + 0, in_row + 0, (x) * components * sizeof(type)); \
317                         } \
318                 } \
319         } \
320 }
321
322
323
324
325
326 int SlideMain::process_realtime(VFrame *incoming, VFrame *outgoing)
327 {
328         load_configuration();
329
330         int w = incoming->get_w();
331         int h = incoming->get_h();
332
333 //      struct timeval start_time;
334 //      gettimeofday(&start_time, 0);
335
336         switch(incoming->get_color_model())
337         {
338                 case BC_RGB_FLOAT:
339                         SLIDE(float, 3)
340                         break;
341                 case BC_RGBA_FLOAT:
342                         SLIDE(float, 4)
343                         break;
344                 case BC_RGB888:
345                 case BC_YUV888:
346                         SLIDE(unsigned char, 3)
347                         break;
348                 case BC_RGBA8888:
349                 case BC_YUVA8888:
350                         SLIDE(unsigned char, 4)
351                         break;
352                 case BC_RGB161616:
353                 case BC_YUV161616:
354                         SLIDE(uint16_t, 3)
355                         break;
356                 case BC_RGBA16161616:
357                 case BC_YUVA16161616:
358                         SLIDE(uint16_t, 4)
359                         break;
360         }
361
362 //      int64_t dif= get_difference(&start_time);
363 //      printf("diff: %lli\n", dif);
364
365         return 0;
366 }