font debug env var, drag fixes, cposer hide scrollbar, plugin tool tip
[goodguy/history.git] / cinelerra-5.1 / plugins / delayvideo / delayvideo.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 "clip.h"
24 #include "bchash.h"
25 #include "delayvideo.h"
26 #include "filexml.h"
27 #include "language.h"
28 #include "vframe.h"
29
30
31
32
33 #include <string.h>
34
35
36
37
38
39
40 REGISTER_PLUGIN(DelayVideo)
41
42
43
44
45
46 DelayVideoConfig::DelayVideoConfig()
47 {
48         length = 0;
49 }
50
51 int DelayVideoConfig::equivalent(DelayVideoConfig &that)
52 {
53         return EQUIV(length, that.length);
54 }
55
56 void DelayVideoConfig::copy_from(DelayVideoConfig &that)
57 {
58         length = that.length;
59 }
60
61 void DelayVideoConfig::interpolate(DelayVideoConfig &prev,
62                 DelayVideoConfig &next,
63                 int64_t prev_frame,
64                 int64_t next_frame,
65                 int64_t current_frame)
66 {
67         this->length = prev.length;
68 }
69
70
71
72 DelayVideoWindow::DelayVideoWindow(DelayVideo *plugin)
73  : PluginClientWindow(plugin,
74         210,
75         120,
76         210,
77         120,
78         0)
79 {
80         this->plugin = plugin;
81 }
82
83 DelayVideoWindow::~DelayVideoWindow()
84 {
85 }
86
87
88 void DelayVideoWindow::create_objects()
89 {
90         int x = 10, y = 10;
91
92         add_subwindow(new BC_Title(x, y, _("Delay seconds:")));
93         y += 20;
94         slider = new DelayVideoSlider(this, plugin, x, y);
95         slider->create_objects();
96         show_window();
97 }
98
99
100 void DelayVideoWindow::update_gui()
101 {
102         char string[BCTEXTLEN];
103         sprintf(string, "%.04f", plugin->config.length);
104         slider->update(string);
105 }
106
107
108
109
110
111
112
113
114
115
116
117
118 DelayVideoSlider::DelayVideoSlider(DelayVideoWindow *window,
119         DelayVideo *plugin,
120         int x,
121         int y)
122  : BC_TumbleTextBox(window,
123         (float)plugin->config.length,
124         (float)0,
125         (float)10,
126         x,
127         y,
128         150)
129 {
130         this->plugin = plugin;
131         set_increment(0.1);
132 }
133
134 int DelayVideoSlider::handle_event()
135 {
136         plugin->config.length = atof(get_text());
137         plugin->send_configure_change();
138         return 1;
139 }
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157 DelayVideo::DelayVideo(PluginServer *server)
158  : PluginVClient(server)
159 {
160         reset();
161 }
162
163 DelayVideo::~DelayVideo()
164 {
165         if(buffer)
166         {
167 //printf("DelayVideo::~DelayVideo 1\n");
168                 for(int i = 0; i < allocation; i++)
169                         delete buffer[i];
170 //printf("DelayVideo::~DelayVideo 1\n");
171
172                 delete [] buffer;
173 //printf("DelayVideo::~DelayVideo 1\n");
174         }
175 }
176
177 void DelayVideo::reset()
178 {
179         thread = 0;
180         need_reconfigure = 1;
181         buffer = 0;
182         allocation = 0;
183 }
184
185 void DelayVideo::reconfigure()
186 {
187         int new_allocation = 1 + (int)(config.length * PluginVClient::project_frame_rate);
188         VFrame **new_buffer = new VFrame*[new_allocation];
189         int reuse = MIN(new_allocation, allocation);
190
191         for(int i = 0; i < reuse; i++)
192         {
193                 new_buffer[i] = buffer[i];
194         }
195
196         for(int i = reuse; i < new_allocation; i++)
197         {
198                 new_buffer[i] = new VFrame(0,
199                         -1,
200                         input->get_w(),
201                         input->get_h(),
202                         PluginVClient::project_color_model,
203                         -1);
204         }
205
206         for(int i = reuse; i < allocation; i++)
207         {
208                 delete buffer[i];
209         }
210
211         if(buffer) delete [] buffer;
212
213
214         buffer = new_buffer;
215         allocation = new_allocation;
216
217         need_reconfigure = 0;
218 }
219
220 int DelayVideo::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
221 {
222 //printf("DelayVideo::process_realtime 1 %d\n", config.length);
223         this->input = input_ptr;
224         this->output = output_ptr;
225         need_reconfigure += load_configuration();
226         CLAMP(config.length, 0, 10);
227
228 //printf("DelayVideo::process_realtime 2 %d\n", config.length);
229         if(need_reconfigure) reconfigure();
230 //printf("DelayVideo::process_realtime 3 %d %d\n", config.length, allocation);
231
232         buffer[allocation - 1]->copy_from(input_ptr);
233         output_ptr->copy_from(buffer[0]);
234
235         VFrame *temp = buffer[0];
236         for(int i = 0; i < allocation - 1; i++)
237         {
238                 buffer[i] = buffer[i + 1];
239         }
240
241         buffer[allocation - 1] = temp;
242 //printf("DelayVideo::process_realtime 4\n");
243
244
245         return 0;
246 }
247
248 int DelayVideo::is_realtime()
249 {
250         return 1;
251 }
252
253 const char* DelayVideo::plugin_title() { return _("Delay Video"); }
254
255 LOAD_CONFIGURATION_MACRO(DelayVideo, DelayVideoConfig)
256 NEW_WINDOW_MACRO(DelayVideo, DelayVideoWindow)
257
258
259 void DelayVideo::save_data(KeyFrame *keyframe)
260 {
261         FileXML output;
262         output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
263
264         output.tag.set_title("DELAYVIDEO");
265         output.tag.set_property("LENGTH", (double)config.length);
266         output.append_tag();
267         output.tag.set_title("/DELAYVIDEO");
268         output.append_tag();
269         output.append_newline();
270         output.terminate_string();
271 }
272
273 void DelayVideo::read_data(KeyFrame *keyframe)
274 {
275         FileXML input;
276         input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
277
278         int result = 0;
279         while(!result)
280         {
281                 result = input.read_tag();
282
283                 if(!result)
284                 {
285                         if(input.tag.title_is("DELAYVIDEO"))
286                         {
287                                 config.length = input.tag.get_property("LENGTH", (double)config.length);
288                         }
289                 }
290         }
291 }
292
293 void DelayVideo::update_gui()
294 {
295         if(thread)
296         {
297                 load_configuration();
298                 ((DelayVideoWindow*)thread->window)->lock_window();
299                 ((DelayVideoWindow*)thread->window)->slider->update(config.length);
300                 ((DelayVideoWindow*)thread->window)->unlock_window();
301         }
302 }
303
304
305
306
307
308
309