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 Automation::Automation(EDL *edl, Track *track)
41 bzero(autos, sizeof(Autos*) * AUTOMATION_TOTAL);
44 Automation::~Automation()
46 for(int i = 0; i < AUTOMATION_TOTAL; i++)
52 void Automation::create_objects()
54 autos[AUTOMATION_MUTE] = new IntAutos(edl, track, 0);
55 autos[AUTOMATION_MUTE]->create_objects();
57 autos[AUTOMATION_SPEED] = new FloatAutos(edl, track, 1.0);
58 autos[AUTOMATION_SPEED]->create_objects();
61 Automation& Automation::operator=(Automation& automation)
63 printf("Automation::operator= 1\n");
64 copy_from(&automation);
68 void Automation::equivalent_output(Automation *automation, int64_t *result)
70 for(int i = 0; i < AUTOMATION_TOTAL; i++)
72 if(autos[i] && automation->autos[i])
73 autos[i]->equivalent_output(automation->autos[i], 0, result);
77 void Automation::copy_from(Automation *automation)
79 for(int i = 0; i < AUTOMATION_TOTAL; i++)
81 if(autos[i] && automation->autos[i])
82 autos[i]->copy_from(automation->autos[i]);
86 // These must match the enumerations
87 static const char *xml_titles[] =
104 int Automation::load(FileXML *file)
106 for(int i = 0; i < AUTOMATION_TOTAL; i++)
108 if(file->tag.title_is(xml_titles[i]) && autos[i])
110 autos[i]->load(file);
117 int Automation::paste(int64_t start,
125 if(!autoconf) autoconf = edl->session->auto_conf;
127 for(int i = 0; i < AUTOMATION_TOTAL; i++)
129 if(file->tag.title_is(xml_titles[i]) && autos[i] && autoconf->autos[i])
131 autos[i]->paste(start,
143 int Automation::copy(int64_t start,
149 // Copy regardless of what's visible.
150 for(int i = 0; i < AUTOMATION_TOTAL; i++)
154 file->tag.set_title(xml_titles[i]);
156 file->append_newline();
157 autos[i]->copy(start,
162 char string[BCTEXTLEN];
163 sprintf(string, "/%s", xml_titles[i]);
164 file->tag.set_title(string);
166 file->append_newline();
174 void Automation::clear(int64_t start,
179 AutoConf *temp_autoconf = 0;
183 temp_autoconf = new AutoConf;
184 temp_autoconf->set_all(1);
185 autoconf = temp_autoconf;
188 for(int i = 0; i < AUTOMATION_TOTAL; i++)
190 if(autos[i] && autoconf->autos[i])
192 autos[i]->clear(start, end, shift_autos);
196 if(temp_autoconf) delete temp_autoconf;
199 void Automation::set_automation_mode(int64_t start,
204 AutoConf *temp_autoconf = 0;
208 temp_autoconf = new AutoConf;
209 temp_autoconf->set_all(1);
210 autoconf = temp_autoconf;
213 for(int i = 0; i < AUTOMATION_TOTAL; i++)
215 if(autos[i] && autoconf->autos[i])
217 autos[i]->set_automation_mode(start, end, mode);
221 if(temp_autoconf) delete temp_autoconf;
225 void Automation::paste_silence(int64_t start, int64_t end)
227 // Unit conversion done in calling routine
228 for(int i = 0; i < AUTOMATION_TOTAL; i++)
231 autos[i]->paste_silence(start, end);
235 // We don't replace it in pasting but
236 // when inserting the first EDL of a load operation we need to replace
237 // the default keyframe.
238 void Automation::insert_track(Automation *automation,
240 int64_t length_units,
243 for(int i = 0; i < AUTOMATION_TOTAL; i++)
245 if(autos[i] && automation->autos[i])
247 autos[i]->insert_track(automation->autos[i],
257 void Automation::resample(double old_rate, double new_rate)
259 // Run resample for all the autos structures and all the keyframes
260 for(int i = 0; i < AUTOMATION_TOTAL; i++)
262 if(autos[i]) autos[i]->resample(old_rate, new_rate);
268 int Automation::direct_copy_possible(int64_t start, int direction)
276 void Automation::get_projector(float *x,
284 void Automation::get_camera(float *x,
295 int64_t Automation::get_length()
298 int64_t total_length = 0;
300 for(int i = 0; i < AUTOMATION_TOTAL; i++)
304 length = autos[i]->get_length();
305 if(length > total_length) total_length = length;
313 void Automation::get_extents(float *min,
315 int *coords_undefined,
319 for(int i = 0; i < AUTOMATION_TOTAL; i++)
321 if(autos[i] && edl->session->auto_conf->autos[i])
323 autos[i]->get_extents(min, max, coords_undefined, unit_start, unit_end);
329 void Automation::dump(FILE *fp)
331 fprintf(fp," Automation: %p\n", this);
334 for(int i = 0; i < AUTOMATION_TOTAL; i++)
338 fprintf(fp," %s %p\n", xml_titles[i], autos[i]);