r820: Move from x-devb to xorg-dev
[cinelerra_cv/mob.git] / cinelerra / automation.C
blob57ab5a462042ff3ed7b33041eae175bc6b817155
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();
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::paste_silence(int64_t start, int64_t end)
170 // Unit conversion done in calling routine
171         for(int i = 0; i < AUTOMATION_TOTAL; i++)
172         {
173                 if(autos[i])
174                         autos[i]->paste_silence(start, end);
175         }
178 // We don't replace it in pasting but
179 // when inserting the first EDL of a load operation we need to replace
180 // the default keyframe.
181 void Automation::insert_track(Automation *automation, 
182         int64_t start_unit, 
183         int64_t length_units,
184         int replace_default)
186         for(int i = 0; i < AUTOMATION_TOTAL; i++)
187         {
188                 if(autos[i] && automation->autos[i])
189                 {
190                         autos[i]->insert_track(automation->autos[i], 
191                                 start_unit, 
192                                 length_units, 
193                                 replace_default);
194                 }
195         }
200 void Automation::resample(double old_rate, double new_rate)
202 // Run resample for all the autos structures and all the keyframes
203         for(int i = 0; i < AUTOMATION_TOTAL; i++)
204         {
205                 if(autos[i]) autos[i]->resample(old_rate, new_rate);
206         }
211 int Automation::direct_copy_possible(int64_t start, int direction)
213         return 1;
219 void Automation::get_projector(float *x, 
220         float *y, 
221         float *z, 
222         int64_t position,
223         int direction)
227 void Automation::get_camera(float *x, 
228         float *y, 
229         float *z, 
230         int64_t position,
231         int direction)
238 int64_t Automation::get_length()
240         int64_t length = 0;
241         int64_t total_length = 0;
243         for(int i = 0; i < AUTOMATION_TOTAL; i++)
244         {
245                 if(autos[i])
246                 {
247                         length = autos[i]->get_length();
248                         if(length > total_length) total_length = length;
249                 }
250         }
253         return total_length;
256 void Automation::get_extents(float *min, 
257         float *max,
258         int *coords_undefined,
259         int64_t unit_start,
260         int64_t unit_end)
262         for(int i = 0; i < AUTOMATION_TOTAL; i++)
263         {
264                 if(autos[i] && edl->session->auto_conf->autos[i])
265                 {
266                         autos[i]->get_extents(min, max, coords_undefined, unit_start, unit_end);
267                 }
268         }
272 void Automation::dump()
274         printf("   Automation: %p\n", this);
277         for(int i = 0; i < AUTOMATION_TOTAL; i++)
278         {
279                 if(autos[i])
280                 {
281                         printf("    %s %p\n", xml_titles[i], autos[i]);
282                         autos[i]->dump();
283                 }
284         }