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;
82 if (track->data_type == TRACK_AUDIO)
83 autogrouptype = AUTOGROUPTYPE_AUDIO_FADE;
85 autogrouptype = AUTOGROUPTYPE_VIDEO_FADE;
88 autogrouptype = AUTOGROUPTYPE_INT255;
91 return (autogrouptype);
94 void Automation::create_objects()
96 autos[AUTOMATION_MUTE] = new IntAutos(edl, track, 0);
97 autos[AUTOMATION_MUTE]->create_objects();
98 autos[AUTOMATION_MUTE]->autoidx = AUTOMATION_MUTE;
99 autos[AUTOMATION_MUTE]->autogrouptype = AUTOGROUPTYPE_INT255;
100 autos[AUTOMATION_SPEED] = new FloatAutos(edl, track, 1.0);
101 autos[AUTOMATION_SPEED]->create_objects();
104 Automation& Automation::operator=(Automation& automation)
106 //printf("Automation::operator= 1\n");
107 copy_from(&automation);
111 void Automation::equivalent_output(Automation *automation, int64_t *result)
113 for(int i = 0; i < AUTOMATION_TOTAL; i++)
115 if(autos[i] && automation->autos[i])
116 autos[i]->equivalent_output(automation->autos[i], 0, result);
120 void Automation::copy_from(Automation *automation)
122 for(int i = 0; i < AUTOMATION_TOTAL; i++)
124 if(autos[i] && automation->autos[i])
125 autos[i]->copy_from(automation->autos[i]);
129 // These must match the enumerations
130 static const char *xml_titles[] =
146 int Automation::load(FileXML *file)
148 for(int i = 0; i < AUTOMATION_TOTAL; i++)
150 if(file->tag.title_is(xml_titles[i]) && autos[i])
152 autos[i]->load(file);
159 int Automation::paste(int64_t start,
167 if(!autoconf) autoconf = edl->session->auto_conf;
169 for(int i = 0; i < AUTOMATION_TOTAL; i++)
171 if(file->tag.title_is(xml_titles[i]) && autos[i] && autoconf->autos[i])
173 autos[i]->paste(start,
185 int Automation::copy(int64_t start,
191 // Copy regardless of what's visible.
192 for(int i = 0; i < AUTOMATION_TOTAL; i++)
196 file->tag.set_title(xml_titles[i]);
198 file->append_newline();
199 autos[i]->copy(start,
204 char string[BCTEXTLEN];
205 sprintf(string, "/%s", xml_titles[i]);
206 file->tag.set_title(string);
208 file->append_newline();
216 void Automation::clear(int64_t start,
221 AutoConf *temp_autoconf = 0;
225 temp_autoconf = new AutoConf;
226 temp_autoconf->set_all(1);
227 autoconf = temp_autoconf;
230 for(int i = 0; i < AUTOMATION_TOTAL; i++)
232 if(autos[i] && autoconf->autos[i])
234 autos[i]->clear(start, end, shift_autos);
238 if(temp_autoconf) delete temp_autoconf;
241 void Automation::set_automation_mode(int64_t start,
246 AutoConf *temp_autoconf = 0;
250 temp_autoconf = new AutoConf;
251 temp_autoconf->set_all(1);
252 autoconf = temp_autoconf;
255 for(int i = 0; i < AUTOMATION_TOTAL; i++)
257 if(autos[i] && autoconf->autos[i])
259 autos[i]->set_automation_mode(start, end, mode);
263 if(temp_autoconf) delete temp_autoconf;
267 void Automation::paste_silence(int64_t start, int64_t end)
269 // Unit conversion done in calling routine
270 for(int i = 0; i < AUTOMATION_TOTAL; i++)
273 autos[i]->paste_silence(start, end);
277 // We don't replace it in pasting but
278 // when inserting the first EDL of a load operation we need to replace
279 // the default keyframe.
280 void Automation::insert_track(Automation *automation,
282 int64_t length_units,
285 for(int i = 0; i < AUTOMATION_TOTAL; i++)
287 if(autos[i] && automation->autos[i])
289 autos[i]->insert_track(automation->autos[i],
299 void Automation::resample(double old_rate, double new_rate)
301 // Run resample for all the autos structures and all the keyframes
302 for(int i = 0; i < AUTOMATION_TOTAL; i++)
304 if(autos[i]) autos[i]->resample(old_rate, new_rate);
310 int Automation::direct_copy_possible(int64_t start, int direction)
318 void Automation::get_projector(float *x,
326 void Automation::get_camera(float *x,
337 int64_t Automation::get_length()
340 int64_t total_length = 0;
342 for(int i = 0; i < AUTOMATION_TOTAL; i++)
346 length = autos[i]->get_length();
347 if(length > total_length) total_length = length;
355 void Automation::get_extents(float *min,
357 int *coords_undefined,
362 for(int i = 0; i < AUTOMATION_TOTAL; i++)
364 if(autos[i] && edl->session->auto_conf->autos[i])
366 if (autos[i]->autogrouptype == autogrouptype)
367 autos[i]->get_extents(min, max, coords_undefined, unit_start, unit_end);
373 void Automation::dump(FILE *fp)
375 fprintf(fp," Automation: %p\n", this);
378 for(int i = 0; i < AUTOMATION_TOTAL; i++)
382 fprintf(fp," %s %p\n", xml_titles[i], autos[i]);