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