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