4 * Copyright (C) 2008-2013 Adam Williams <broadcast at earthling dot net>
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.
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.
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
23 #include "automation.h"
26 #include "bcsignals.h"
29 #include "edlsession.h"
31 #include "floatautos.h"
34 #include "transportque.inc"
37 int Automation::autogrouptypes_fixedrange[] =
49 Automation::Automation(EDL *edl, Track *track)
53 bzero(autos, sizeof(Autos*) * AUTOMATION_TOTAL);
56 Automation::~Automation()
58 for(int i = 0; i < AUTOMATION_TOTAL; i++)
64 int Automation::autogrouptype(int autoidx, Track *track)
66 int autogrouptype = -1;
69 case AUTOMATION_CAMERA_X:
70 case AUTOMATION_PROJECTOR_X:
71 autogrouptype = AUTOGROUPTYPE_X;
73 case AUTOMATION_CAMERA_Y:
74 case AUTOMATION_PROJECTOR_Y:
75 autogrouptype = AUTOGROUPTYPE_Y;
77 case AUTOMATION_CAMERA_Z:
78 case AUTOMATION_PROJECTOR_Z:
79 autogrouptype = AUTOGROUPTYPE_ZOOM;
81 case AUTOMATION_SPEED:
82 autogrouptype = AUTOGROUPTYPE_SPEED;
85 if (track->data_type == TRACK_AUDIO)
86 autogrouptype = AUTOGROUPTYPE_AUDIO_FADE;
88 autogrouptype = AUTOGROUPTYPE_VIDEO_FADE;
91 autogrouptype = AUTOGROUPTYPE_INT255;
94 return (autogrouptype);
97 void Automation::create_objects()
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;
105 Automation& Automation::operator=(Automation& automation)
107 //printf("Automation::operator= 1\n");
108 copy_from(&automation);
112 void Automation::equivalent_output(Automation *automation, int64_t *result)
114 for(int i = 0; i < AUTOMATION_TOTAL; i++)
116 if(autos[i] && automation->autos[i])
117 autos[i]->equivalent_output(automation->autos[i], 0, result);
121 void Automation::copy_from(Automation *automation)
123 for(int i = 0; i < AUTOMATION_TOTAL; i++)
125 if(autos[i] && automation->autos[i])
126 autos[i]->copy_from(automation->autos[i]);
130 // These must match the enumerations
131 static const char *xml_titles[] =
147 int Automation::load(FileXML *file)
149 for(int i = 0; i < AUTOMATION_TOTAL; i++)
151 if(file->tag.title_is(xml_titles[i]) && autos[i])
153 autos[i]->load(file);
160 int Automation::paste(int64_t start,
168 if(!autoconf) autoconf = edl->session->auto_conf;
170 for(int i = 0; i < AUTOMATION_TOTAL; i++)
172 if(file->tag.title_is(xml_titles[i]) && autos[i] && autoconf->autos[i])
174 autos[i]->paste(start,
186 int Automation::copy(int64_t start,
192 // Copy regardless of what's visible.
193 for(int i = 0; i < AUTOMATION_TOTAL; i++)
197 file->tag.set_title(xml_titles[i]);
199 file->append_newline();
200 autos[i]->copy(start,
205 char string[BCTEXTLEN];
206 sprintf(string, "/%s", xml_titles[i]);
207 file->tag.set_title(string);
209 file->append_newline();
217 void Automation::clear(int64_t start,
222 AutoConf *temp_autoconf = 0;
226 temp_autoconf = new AutoConf;
227 temp_autoconf->set_all(1);
228 autoconf = temp_autoconf;
231 for(int i = 0; i < AUTOMATION_TOTAL; i++)
233 if(autos[i] && autoconf->autos[i])
235 autos[i]->clear(start, end, shift_autos);
239 if(temp_autoconf) delete temp_autoconf;
242 void Automation::set_automation_mode(int64_t start,
247 AutoConf *temp_autoconf = 0;
251 temp_autoconf = new AutoConf;
252 temp_autoconf->set_all(1);
253 autoconf = temp_autoconf;
256 for(int i = 0; i < AUTOMATION_TOTAL; i++)
258 if(autos[i] && autoconf->autos[i])
260 autos[i]->set_automation_mode(start, end, mode);
264 if(temp_autoconf) delete temp_autoconf;
268 void Automation::paste_silence(int64_t start, int64_t end)
270 // Unit conversion done in calling routine
271 for(int i = 0; i < AUTOMATION_TOTAL; i++)
274 autos[i]->paste_silence(start, end);
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,
283 int64_t length_units,
286 for(int i = 0; i < AUTOMATION_TOTAL; i++)
288 if(autos[i] && automation->autos[i])
290 autos[i]->insert_track(automation->autos[i],
300 void Automation::resample(double old_rate, double new_rate)
302 // Run resample for all the autos structures and all the keyframes
303 for(int i = 0; i < AUTOMATION_TOTAL; i++)
305 if(autos[i]) autos[i]->resample(old_rate, new_rate);
311 int Automation::direct_copy_possible(int64_t start, int direction)
319 void Automation::get_projector(float *x,
327 void Automation::get_camera(float *x,
338 int64_t Automation::get_length()
341 int64_t total_length = 0;
343 for(int i = 0; i < AUTOMATION_TOTAL; i++)
347 length = autos[i]->get_length();
348 if(length > total_length) total_length = length;
356 void Automation::get_extents(float *min,
358 int *coords_undefined,
363 for(int i = 0; i < AUTOMATION_TOTAL; i++)
365 if(autos[i] && edl->session->auto_conf->autos[i])
367 if (autos[i]->autogrouptype == autogrouptype)
368 autos[i]->get_extents(min, max, coords_undefined, unit_start, unit_end);
374 void Automation::dump(FILE *fp)
376 fprintf(fp," Automation: %p\n", this);
379 for(int i = 0; i < AUTOMATION_TOTAL; i++)
383 fprintf(fp," %s %p\n", xml_titles[i], autos[i]);