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