r901: Automation::fit_autos() now works and automation_{min,max} variable removed
[cinelerra_cv/pmdumuid.git] / cinelerra / automation.C
blob8255e04dd30559d11d22423294c91e36357c526b
1 #include "autoconf.h"
2 #include "automation.h"
3 #include "autos.h"
4 #include "atrack.inc"
5 #include "bcsignals.h"
6 #include "colors.h"
7 #include "edl.h"
8 #include "edlsession.h"
9 #include "filexml.h"
10 #include "intautos.h"
11 #include "track.h"
12 #include "transportque.inc"
15 int Automation::autogrouptypes_fixedrange[] =
17         0,
18         0,
19         0,
20         0,
21         0,
22         1
27 Automation::Automation(EDL *edl, Track *track)
29         this->edl = edl;
30         this->track = track;
31         bzero(autos, sizeof(Autos*) * AUTOMATION_TOTAL);
34 Automation::~Automation()
36         for(int i = 0; i < AUTOMATION_TOTAL; i++)
37         {
38                 delete autos[i];
39         }
42 int Automation::autogrouptype(int autoidx, Track *track)
44         int autogrouptype = -1;
45         switch (autoidx) 
46         {
47                 case AUTOMATION_CAMERA_X:
48                 case AUTOMATION_PROJECTOR_X:
49                         autogrouptype = AUTOGROUPTYPE_X;
50                         break;
51                 case AUTOMATION_CAMERA_Y:
52                 case AUTOMATION_PROJECTOR_Y:
53                         autogrouptype = AUTOGROUPTYPE_Y;
54                         break;
55                 case AUTOMATION_CAMERA_Z:
56                 case AUTOMATION_PROJECTOR_Z:
57                         autogrouptype = AUTOGROUPTYPE_ZOOM;
58                         break;
59                 case AUTOMATION_FADE:
60                         if (track->data_type == TRACK_AUDIO)
61                                 autogrouptype = AUTOGROUPTYPE_AUDIO_FADE;
62                         else
63                                 autogrouptype = AUTOGROUPTYPE_VIDEO_FADE;
64                         break;
65                 case AUTOMATION_MUTE:
66                         autogrouptype = AUTOGROUPTYPE_INT255;
67                         break;
68         }
69         return (autogrouptype);
72 int Automation::create_objects()
74         autos[AUTOMATION_MUTE] = new IntAutos(edl, track, 0);
75         autos[AUTOMATION_MUTE]->create_objects();
76         autos[AUTOMATION_MUTE]->autoidx = AUTOMATION_MUTE; 
77         autos[AUTOMATION_MUTE]->autogrouptype = AUTOGROUPTYPE_INT255;
78         return 0;
81 Automation& Automation::operator=(Automation& automation)
83 printf("Automation::operator= 1\n");
84         copy_from(&automation);
85         return *this;
88 void Automation::equivalent_output(Automation *automation, int64_t *result)
90         for(int i = 0; i < AUTOMATION_TOTAL; i++)
91         {
92                 if(autos[i] && automation->autos[i])
93                         autos[i]->equivalent_output(automation->autos[i], 0, result);
94         }
97 void Automation::copy_from(Automation *automation)
99         for(int i = 0; i < AUTOMATION_TOTAL; i++)
100         {
101                 if(autos[i] && automation->autos[i])
102                         autos[i]->copy_from(automation->autos[i]);
103         }
106 // These must match the enumerations
107 static char *xml_titles[] = 
109         "MUTEAUTOS",
110         "CAMERA_X",
111         "CAMERA_Y",
112         "CAMERA_Z",
113         "PROJECTOR_X",
114         "PROJECTOR_Y",
115         "PROJECTOR_Z",
116         "FADEAUTOS",
117         "PANAUTOS",
118         "MODEAUTOS",
119         "MASKAUTOS",
120         "NUDGEAUTOS"
123 int Automation::load(FileXML *file)
125         for(int i = 0; i < AUTOMATION_TOTAL; i++)
126         {
127                 if(file->tag.title_is(xml_titles[i]) && autos[i])
128                 {
129                         autos[i]->load(file);
130                         return 1;
131                 }
132         }
133         return 0;
136 int Automation::paste(int64_t start, 
137         int64_t length, 
138         double scale,
139         FileXML *file, 
140         int default_only,
141         AutoConf *autoconf)
143         if(!autoconf) autoconf = edl->session->auto_conf;
145         for(int i = 0; i < AUTOMATION_TOTAL; i++)
146         {
147                 if(file->tag.title_is(xml_titles[i]) && autos[i] && autoconf->autos[i])
148                 {
149                         autos[i]->paste(start, length, scale, file, default_only);
150                         return 1;
151                 }
152         }
153         return 0;
156 int Automation::copy(int64_t start, 
157         int64_t end, 
158         FileXML *file, 
159         int default_only,
160         int autos_only)
162 // Copy regardless of what's visible.
163         for(int i = 0; i < AUTOMATION_TOTAL; i++)
164         {
165                 if(autos[i])
166                 {
167                         file->tag.set_title(xml_titles[i]);
168                         file->append_tag();
169                         file->append_newline();
170                         autos[i]->copy(start, 
171                                                         end, 
172                                                         file, 
173                                                         default_only,
174                                                         autos_only);
175                         char string[BCTEXTLEN];
176                         sprintf(string, "/%s", xml_titles[i]);
177                         file->tag.set_title(string);
178                         file->append_tag();
179                         file->append_newline();
180                 }
181         }
183         return 0;
187 void Automation::clear(int64_t start, 
188         int64_t end, 
189         AutoConf *autoconf, 
190         int shift_autos)
192         AutoConf *temp_autoconf = 0;
194         if(!autoconf)
195         {
196                 temp_autoconf = new AutoConf;
197                 temp_autoconf->set_all(1);
198                 autoconf = temp_autoconf;
199         }
201         for(int i = 0; i < AUTOMATION_TOTAL; i++)
202         {
203                 if(autos[i] && autoconf->autos[i])
204                 {
205                         autos[i]->clear(start, end, shift_autos);
206                 }
207         }
209         if(temp_autoconf) delete temp_autoconf;
212 void Automation::straighten(int64_t start, 
213         int64_t end, 
214         AutoConf *autoconf)
216         AutoConf *temp_autoconf = 0;
218         if(!autoconf)
219         {
220                 temp_autoconf = new AutoConf;
221                 temp_autoconf->set_all(1);
222                 autoconf = temp_autoconf;
223         }
225         for(int i = 0; i < AUTOMATION_TOTAL; i++)
226         {
227                 if(autos[i] && autoconf->autos[i])
228                 {
229                         autos[i]->straighten(start, end);
230                 }
231         }
233         if(temp_autoconf) delete temp_autoconf;
237 void Automation::paste_silence(int64_t start, int64_t end)
239 // Unit conversion done in calling routine
240         for(int i = 0; i < AUTOMATION_TOTAL; i++)
241         {
242                 if(autos[i])
243                         autos[i]->paste_silence(start, end);
244         }
247 // We don't replace it in pasting but
248 // when inserting the first EDL of a load operation we need to replace
249 // the default keyframe.
250 void Automation::insert_track(Automation *automation, 
251         int64_t start_unit, 
252         int64_t length_units,
253         int replace_default)
255         for(int i = 0; i < AUTOMATION_TOTAL; i++)
256         {
257                 if(autos[i] && automation->autos[i])
258                 {
259                         autos[i]->insert_track(automation->autos[i], 
260                                 start_unit, 
261                                 length_units, 
262                                 replace_default);
263                 }
264         }
269 void Automation::resample(double old_rate, double new_rate)
271 // Run resample for all the autos structures and all the keyframes
272         for(int i = 0; i < AUTOMATION_TOTAL; i++)
273         {
274                 if(autos[i]) autos[i]->resample(old_rate, new_rate);
275         }
280 int Automation::direct_copy_possible(int64_t start, int direction)
282         return 1;
288 void Automation::get_projector(float *x, 
289         float *y, 
290         float *z, 
291         int64_t position,
292         int direction)
296 void Automation::get_camera(float *x, 
297         float *y, 
298         float *z, 
299         int64_t position,
300         int direction)
307 int64_t Automation::get_length()
309         int64_t length = 0;
310         int64_t total_length = 0;
312         for(int i = 0; i < AUTOMATION_TOTAL; i++)
313         {
314                 if(autos[i])
315                 {
316                         length = autos[i]->get_length();
317                         if(length > total_length) total_length = length;
318                 }
319         }
322         return total_length;
325 void Automation::get_extents(float *min, 
326         float *max,
327         int *coords_undefined,
328         int64_t unit_start,
329         int64_t unit_end,
330         int autogrouptype)
332         for(int i = 0; i < AUTOMATION_TOTAL; i++)
333         {
334                 if(autos[i] && edl->session->auto_conf->autos[i])
335                 {
336                         if (autos[i]->autogrouptype == autogrouptype)
337                                 autos[i]->get_extents(min, max, coords_undefined, unit_start, unit_end);
338                 }
339         }
343 void Automation::dump()
345         printf("   Automation: %p\n", this);
348         for(int i = 0; i < AUTOMATION_TOTAL; i++)
349         {
350                 if(autos[i])
351                 {
352                         printf("    %s %p\n", xml_titles[i], autos[i]);
353                         autos[i]->dump();
354                 }
355         }