merge: added speed auto gang/ranges, fix overlayframe norm alpha
[goodguy/history.git] / cinelerra-5.1 / cinelerra / automation.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008-2013 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 "autoconf.h"
23 #include "automation.h"
24 #include "autos.h"
25 #include "atrack.inc"
26 #include "bcsignals.h"
27 #include "colors.h"
28 #include "edl.h"
29 #include "edlsession.h"
30 #include "filexml.h"
31 #include "floatautos.h"
32 #include "intautos.h"
33 #include "track.h"
34 #include "transportque.inc"
35
36
37 int Automation::autogrouptypes_fixedrange[] =
38 {
39         0,
40         0,
41         0,
42         0,
43         0,
44         1
45 };
46
47
48
49 Automation::Automation(EDL *edl, Track *track)
50 {
51         this->edl = edl;
52         this->track = track;
53         bzero(autos, sizeof(Autos*) * AUTOMATION_TOTAL);
54 }
55
56 Automation::~Automation()
57 {
58         for(int i = 0; i < AUTOMATION_TOTAL; i++)
59         {
60                 delete autos[i];
61         }
62 }
63
64 int Automation::autogrouptype(int autoidx, Track *track)
65 {
66         int autogrouptype = -1;
67         switch (autoidx)
68         {
69                 case AUTOMATION_CAMERA_X:
70                 case AUTOMATION_PROJECTOR_X:
71                         autogrouptype = AUTOGROUPTYPE_X;
72                         break;
73                 case AUTOMATION_CAMERA_Y:
74                 case AUTOMATION_PROJECTOR_Y:
75                         autogrouptype = AUTOGROUPTYPE_Y;
76                         break;
77                 case AUTOMATION_CAMERA_Z:
78                 case AUTOMATION_PROJECTOR_Z:
79                         autogrouptype = AUTOGROUPTYPE_ZOOM;
80                         break;
81                 case AUTOMATION_SPEED:
82                         autogrouptype = AUTOGROUPTYPE_SPEED;
83                         break;
84                 case AUTOMATION_FADE:
85                         if (track->data_type == TRACK_AUDIO)
86                                 autogrouptype = AUTOGROUPTYPE_AUDIO_FADE;
87                         else
88                                 autogrouptype = AUTOGROUPTYPE_VIDEO_FADE;
89                         break;
90                 case AUTOMATION_MUTE:
91                         autogrouptype = AUTOGROUPTYPE_INT255;
92                         break;
93         }
94         return (autogrouptype);
95 }
96
97 void Automation::create_objects()
98 {
99         autos[AUTOMATION_MUTE] = new IntAutos(edl, track, 0);
100         autos[AUTOMATION_MUTE]->create_objects();
101         autos[AUTOMATION_MUTE]->autoidx = AUTOMATION_MUTE;
102         autos[AUTOMATION_MUTE]->autogrouptype = AUTOGROUPTYPE_INT255;
103         autos[AUTOMATION_SPEED] = new FloatAutos(edl, track, 1.0);
104         autos[AUTOMATION_SPEED]->create_objects();
105         autos[AUTOMATION_SPEED]->autogrouptype = AUTOGROUPTYPE_SPEED;
106 }
107
108 Automation& Automation::operator=(Automation& automation)
109 {
110 //printf("Automation::operator= 1\n");
111         copy_from(&automation);
112         return *this;
113 }
114
115 void Automation::equivalent_output(Automation *automation, int64_t *result)
116 {
117         for(int i = 0; i < AUTOMATION_TOTAL; i++)
118         {
119                 if(autos[i] && automation->autos[i])
120                         autos[i]->equivalent_output(automation->autos[i], 0, result);
121         }
122 }
123
124 void Automation::copy_from(Automation *automation)
125 {
126         for(int i = 0; i < AUTOMATION_TOTAL; i++)
127         {
128                 if(autos[i] && automation->autos[i])
129                         autos[i]->copy_from(automation->autos[i]);
130         }
131 }
132
133 // These must match the enumerations
134 static const char *xml_titles[] =
135 {
136         "MUTEAUTOS",
137         "CAMERA_X",
138         "CAMERA_Y",
139         "CAMERA_Z",
140         "PROJECTOR_X",
141         "PROJECTOR_Y",
142         "PROJECTOR_Z",
143         "FADEAUTOS",
144         "PANAUTOS",
145         "MODEAUTOS",
146         "MASKAUTOS",
147         "SPEEDAUTOS",
148 };
149
150 int Automation::load(FileXML *file)
151 {
152         for(int i = 0; i < AUTOMATION_TOTAL; i++)
153         {
154                 if(file->tag.title_is(xml_titles[i]) && autos[i])
155                 {
156                         autos[i]->load(file);
157                         return 1;
158                 }
159         }
160         return 0;
161 }
162
163 int Automation::paste(int64_t start,
164         int64_t length,
165         double scale,
166         FileXML *file,
167         int default_only,
168         int active_only,
169         AutoConf *autoconf)
170 {
171         if(!autoconf) autoconf = edl->session->auto_conf;
172
173         for(int i = 0; i < AUTOMATION_TOTAL; i++)
174         {
175                 if(file->tag.title_is(xml_titles[i]) && autos[i] && autoconf->autos[i])
176                 {
177                         autos[i]->paste(start,
178                                 length,
179                                 scale,
180                                 file,
181                                 default_only,
182                                 active_only);
183                         return 1;
184                 }
185         }
186         return 0;
187 }
188
189 int Automation::copy(int64_t start,
190         int64_t end,
191         FileXML *file,
192         int default_only,
193         int active_only)
194 {
195 // Copy regardless of what's visible.
196         for(int i = 0; i < AUTOMATION_TOTAL; i++)
197         {
198                 if(autos[i])
199                 {
200                         file->tag.set_title(xml_titles[i]);
201                         file->append_tag();
202                         file->append_newline();
203                         autos[i]->copy(start,
204                                                         end,
205                                                         file,
206                                                         default_only,
207                                                         active_only);
208                         char string[BCTEXTLEN];
209                         sprintf(string, "/%s", xml_titles[i]);
210                         file->tag.set_title(string);
211                         file->append_tag();
212                         file->append_newline();
213                 }
214         }
215
216         return 0;
217 }
218
219
220 void Automation::clear(int64_t start,
221         int64_t end,
222         AutoConf *autoconf,
223         int shift_autos)
224 {
225         AutoConf *temp_autoconf = 0;
226
227         if(!autoconf)
228         {
229                 temp_autoconf = new AutoConf;
230                 temp_autoconf->set_all(1);
231                 autoconf = temp_autoconf;
232         }
233
234         for(int i = 0; i < AUTOMATION_TOTAL; i++)
235         {
236                 if(autos[i] && autoconf->autos[i])
237                 {
238                         autos[i]->clear(start, end, shift_autos);
239                 }
240         }
241
242         if(temp_autoconf) delete temp_autoconf;
243 }
244
245 void Automation::set_automation_mode(int64_t start,
246         int64_t end,
247         int mode,
248         AutoConf *autoconf)
249 {
250         AutoConf *temp_autoconf = 0;
251
252         if(!autoconf)
253         {
254                 temp_autoconf = new AutoConf;
255                 temp_autoconf->set_all(1);
256                 autoconf = temp_autoconf;
257         }
258
259         for(int i = 0; i < AUTOMATION_TOTAL; i++)
260         {
261                 if(autos[i] && autoconf->autos[i])
262                 {
263                         autos[i]->set_automation_mode(start, end, mode);
264                 }
265         }
266
267         if(temp_autoconf) delete temp_autoconf;
268 }
269
270
271 void Automation::paste_silence(int64_t start, int64_t end)
272 {
273 // Unit conversion done in calling routine
274         for(int i = 0; i < AUTOMATION_TOTAL; i++)
275         {
276                 if(autos[i])
277                         autos[i]->paste_silence(start, end);
278         }
279 }
280
281 // We don't replace it in pasting but
282 // when inserting the first EDL of a load operation we need to replace
283 // the default keyframe.
284 void Automation::insert_track(Automation *automation,
285         int64_t start_unit,
286         int64_t length_units,
287         int replace_default)
288 {
289         for(int i = 0; i < AUTOMATION_TOTAL; i++)
290         {
291                 if(autos[i] && automation->autos[i])
292                 {
293                         autos[i]->insert_track(automation->autos[i],
294                                 start_unit,
295                                 length_units,
296                                 replace_default);
297                 }
298         }
299
300
301 }
302
303 void Automation::resample(double old_rate, double new_rate)
304 {
305 // Run resample for all the autos structures and all the keyframes
306         for(int i = 0; i < AUTOMATION_TOTAL; i++)
307         {
308                 if(autos[i]) autos[i]->resample(old_rate, new_rate);
309         }
310 }
311
312
313
314 int Automation::direct_copy_possible(int64_t start, int direction)
315 {
316         return 1;
317 }
318
319
320
321
322 void Automation::get_projector(float *x,
323         float *y,
324         float *z,
325         int64_t position,
326         int direction)
327 {
328 }
329
330 void Automation::get_camera(float *x,
331         float *y,
332         float *z,
333         int64_t position,
334         int direction)
335 {
336 }
337
338
339
340
341 int64_t Automation::get_length()
342 {
343         int64_t length = 0;
344         int64_t total_length = 0;
345
346         for(int i = 0; i < AUTOMATION_TOTAL; i++)
347         {
348                 if(autos[i])
349                 {
350                         length = autos[i]->get_length();
351                         if(length > total_length) total_length = length;
352                 }
353         }
354
355
356         return total_length;
357 }
358
359 void Automation::get_extents(float *min,
360         float *max,
361         int *coords_undefined,
362         int64_t unit_start,
363         int64_t unit_end,
364         int autogrouptype)
365 {
366         for(int i = 0; i < AUTOMATION_TOTAL; i++)
367         {
368                 if(autos[i] && edl->session->auto_conf->autos[i])
369                 {
370                         if (autos[i]->autogrouptype == autogrouptype)
371                                 autos[i]->get_extents(min, max, coords_undefined, unit_start, unit_end);
372                 }
373         }
374 }
375
376
377 void Automation::dump(FILE *fp)
378 {
379         fprintf(fp,"   Automation: %p\n", this);
380
381
382         for(int i = 0; i < AUTOMATION_TOTAL; i++)
383         {
384                 if(autos[i])
385                 {
386                         fprintf(fp,"    %s %p\n", xml_titles[i], autos[i]);
387                         autos[i]->dump(fp);
388                 }
389         }
390
391 }