r870: Merge 2.1:
[cinelerra_cv.git] / cinelerra / automation.C
blobf4a63b0e3a37b3bc745bf609e56bd36d3d1fef44
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 Automation::Automation(EDL *edl, Track *track)
17         this->edl = edl;
18         this->track = track;
19         bzero(autos, sizeof(Autos*) * AUTOMATION_TOTAL);
22 Automation::~Automation()
24         for(int i = 0; i < AUTOMATION_TOTAL; i++)
25         {
26                 delete autos[i];
27         }
30 int Automation::create_objects()
32         autos[AUTOMATION_MUTE] = new IntAutos(edl, track, 0);
33         autos[AUTOMATION_MUTE]->create_objects();
34         return 0;
37 Automation& Automation::operator=(Automation& automation)
39 printf("Automation::operator= 1\n");
40         copy_from(&automation);
41         return *this;
44 void Automation::equivalent_output(Automation *automation, int64_t *result)
46         for(int i = 0; i < AUTOMATION_TOTAL; i++)
47         {
48                 if(autos[i] && automation->autos[i])
49                         autos[i]->equivalent_output(automation->autos[i], 0, result);
50         }
53 void Automation::copy_from(Automation *automation)
55         for(int i = 0; i < AUTOMATION_TOTAL; i++)
56         {
57                 if(autos[i] && automation->autos[i])
58                         autos[i]->copy_from(automation->autos[i]);
59         }
62 // These must match the enumerations
63 static char *xml_titles[] = 
65         "MUTEAUTOS",
66         "CAMERA_X",
67         "CAMERA_Y",
68         "CAMERA_Z",
69         "PROJECTOR_X",
70         "PROJECTOR_Y",
71         "PROJECTOR_Z",
72         "FADEAUTOS",
73         "PANAUTOS",
74         "MODEAUTOS",
75         "MASKAUTOS",
76         "NUDGEAUTOS"
79 int Automation::load(FileXML *file)
81         for(int i = 0; i < AUTOMATION_TOTAL; i++)
82         {
83                 if(file->tag.title_is(xml_titles[i]) && autos[i])
84                 {
85                         autos[i]->load(file);
86                         return 1;
87                 }
88         }
89         return 0;
92 int Automation::paste(int64_t start, 
93         int64_t length, 
94         double scale,
95         FileXML *file, 
96         int default_only,
97         AutoConf *autoconf)
99         if(!autoconf) autoconf = edl->session->auto_conf;
101         for(int i = 0; i < AUTOMATION_TOTAL; i++)
102         {
103                 if(file->tag.title_is(xml_titles[i]) && autos[i] && autoconf->autos[i])
104                 {
105                         autos[i]->paste(start, length, scale, file, default_only);
106                         return 1;
107                 }
108         }
109         return 0;
112 int Automation::copy(int64_t start, 
113         int64_t end, 
114         FileXML *file, 
115         int default_only,
116         int autos_only)
118 // Copy regardless of what's visible.
119         for(int i = 0; i < AUTOMATION_TOTAL; i++)
120         {
121                 if(autos[i])
122                 {
123                         file->tag.set_title(xml_titles[i]);
124                         file->append_tag();
125                         file->append_newline();
126                         autos[i]->copy(start, 
127                                                         end, 
128                                                         file, 
129                                                         default_only,
130                                                         autos_only);
131                         char string[BCTEXTLEN];
132                         sprintf(string, "/%s", xml_titles[i]);
133                         file->tag.set_title(string);
134                         file->append_tag();
135                         file->append_newline();
136                 }
137         }
139         return 0;
143 void Automation::clear(int64_t start, 
144         int64_t end, 
145         AutoConf *autoconf, 
146         int shift_autos)
148         AutoConf *temp_autoconf = 0;
150         if(!autoconf)
151         {
152                 temp_autoconf = new AutoConf;
153                 temp_autoconf->set_all(1);
154                 autoconf = temp_autoconf;
155         }
157         for(int i = 0; i < AUTOMATION_TOTAL; i++)
158         {
159                 if(autos[i] && autoconf->autos[i])
160                 {
161                         autos[i]->clear(start, end, shift_autos);
162                 }
163         }
165         if(temp_autoconf) delete temp_autoconf;
168 void Automation::straighten(int64_t start, 
169         int64_t end, 
170         AutoConf *autoconf)
172         AutoConf *temp_autoconf = 0;
174         if(!autoconf)
175         {
176                 temp_autoconf = new AutoConf;
177                 temp_autoconf->set_all(1);
178                 autoconf = temp_autoconf;
179         }
181         for(int i = 0; i < AUTOMATION_TOTAL; i++)
182         {
183                 if(autos[i] && autoconf->autos[i])
184                 {
185                         autos[i]->straighten(start, end);
186                 }
187         }
189         if(temp_autoconf) delete temp_autoconf;
193 void Automation::paste_silence(int64_t start, int64_t end)
195 // Unit conversion done in calling routine
196         for(int i = 0; i < AUTOMATION_TOTAL; i++)
197         {
198                 if(autos[i])
199                         autos[i]->paste_silence(start, end);
200         }
203 // We don't replace it in pasting but
204 // when inserting the first EDL of a load operation we need to replace
205 // the default keyframe.
206 void Automation::insert_track(Automation *automation, 
207         int64_t start_unit, 
208         int64_t length_units,
209         int replace_default)
211         for(int i = 0; i < AUTOMATION_TOTAL; i++)
212         {
213                 if(autos[i] && automation->autos[i])
214                 {
215                         autos[i]->insert_track(automation->autos[i], 
216                                 start_unit, 
217                                 length_units, 
218                                 replace_default);
219                 }
220         }
225 void Automation::resample(double old_rate, double new_rate)
227 // Run resample for all the autos structures and all the keyframes
228         for(int i = 0; i < AUTOMATION_TOTAL; i++)
229         {
230                 if(autos[i]) autos[i]->resample(old_rate, new_rate);
231         }
236 int Automation::direct_copy_possible(int64_t start, int direction)
238         return 1;
244 void Automation::get_projector(float *x, 
245         float *y, 
246         float *z, 
247         int64_t position,
248         int direction)
252 void Automation::get_camera(float *x, 
253         float *y, 
254         float *z, 
255         int64_t position,
256         int direction)
263 int64_t Automation::get_length()
265         int64_t length = 0;
266         int64_t total_length = 0;
268         for(int i = 0; i < AUTOMATION_TOTAL; i++)
269         {
270                 if(autos[i])
271                 {
272                         length = autos[i]->get_length();
273                         if(length > total_length) total_length = length;
274                 }
275         }
278         return total_length;
281 void Automation::get_extents(float *min, 
282         float *max,
283         int *coords_undefined,
284         int64_t unit_start,
285         int64_t unit_end)
287         for(int i = 0; i < AUTOMATION_TOTAL; i++)
288         {
289                 if(autos[i] && edl->session->auto_conf->autos[i])
290                 {
291                         autos[i]->get_extents(min, max, coords_undefined, unit_start, unit_end);
292                 }
293         }
297 void Automation::dump()
299         printf("   Automation: %p\n", this);
302         for(int i = 0; i < AUTOMATION_TOTAL; i++)
303         {
304                 if(autos[i])
305                 {
306                         printf("    %s %p\n", xml_titles[i], autos[i]);
307                         autos[i]->dump();
308                 }
309         }