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;
103 autos[AUTOMATION_SPEED] = new FloatAutos(edl, track, 1.0);
104 autos[AUTOMATION_SPEED]->create_objects();
105 autos[AUTOMATION_SPEED]->autogrouptype = AUTOGROUPTYPE_SPEED;
108 Automation& Automation::operator=(Automation& automation)
110 //printf("Automation::operator= 1\n");
111 copy_from(&automation);
115 void Automation::equivalent_output(Automation *automation, int64_t *result)
117 for(int i = 0; i < AUTOMATION_TOTAL; i++)
119 if(autos[i] && automation->autos[i])
120 autos[i]->equivalent_output(automation->autos[i], 0, result);
124 void Automation::copy_from(Automation *automation)
126 for(int i = 0; i < AUTOMATION_TOTAL; i++)
128 if(autos[i] && automation->autos[i])
129 autos[i]->copy_from(automation->autos[i]);
133 // These must match the enumerations
134 static const char *xml_titles[] =
150 int Automation::load(FileXML *file)
152 for(int i = 0; i < AUTOMATION_TOTAL; i++)
154 if(file->tag.title_is(xml_titles[i]) && autos[i])
156 autos[i]->load(file);
163 int Automation::paste(int64_t start,
171 if(!autoconf) autoconf = edl->session->auto_conf;
173 for(int i = 0; i < AUTOMATION_TOTAL; i++)
175 if(file->tag.title_is(xml_titles[i]) && autos[i] && autoconf->autos[i])
177 autos[i]->paste(start,
189 int Automation::copy(int64_t start,
195 // Copy regardless of what's visible.
196 for(int i = 0; i < AUTOMATION_TOTAL; i++)
200 file->tag.set_title(xml_titles[i]);
202 file->append_newline();
203 autos[i]->copy(start,
208 char string[BCTEXTLEN];
209 sprintf(string, "/%s", xml_titles[i]);
210 file->tag.set_title(string);
212 file->append_newline();
220 void Automation::clear(int64_t start,
225 AutoConf *temp_autoconf = 0;
229 temp_autoconf = new AutoConf;
230 temp_autoconf->set_all(1);
231 autoconf = temp_autoconf;
234 for(int i = 0; i < AUTOMATION_TOTAL; i++)
236 if(autos[i] && autoconf->autos[i])
238 autos[i]->clear(start, end, shift_autos);
242 if(temp_autoconf) delete temp_autoconf;
245 void Automation::set_automation_mode(int64_t start,
250 AutoConf *temp_autoconf = 0;
254 temp_autoconf = new AutoConf;
255 temp_autoconf->set_all(1);
256 autoconf = temp_autoconf;
259 for(int i = 0; i < AUTOMATION_TOTAL; i++)
261 if(autos[i] && autoconf->autos[i])
263 autos[i]->set_automation_mode(start, end, mode);
267 if(temp_autoconf) delete temp_autoconf;
271 void Automation::paste_silence(int64_t start, int64_t end)
273 // Unit conversion done in calling routine
274 for(int i = 0; i < AUTOMATION_TOTAL; i++)
277 autos[i]->paste_silence(start, end);
281 // We don't replace it in pasting but
282 // when inserting the first EDL of a load operation we need to replace
283 // the default keyframe.
284 void Automation::insert_track(Automation *automation,
286 int64_t length_units,
289 for(int i = 0; i < AUTOMATION_TOTAL; i++)
291 if(autos[i] && automation->autos[i])
293 autos[i]->insert_track(automation->autos[i],
303 void Automation::resample(double old_rate, double new_rate)
305 // Run resample for all the autos structures and all the keyframes
306 for(int i = 0; i < AUTOMATION_TOTAL; i++)
308 if(autos[i]) autos[i]->resample(old_rate, new_rate);
314 int Automation::direct_copy_possible(int64_t start, int direction)
322 void Automation::get_projector(float *x,
330 void Automation::get_camera(float *x,
341 int64_t Automation::get_length()
344 int64_t total_length = 0;
346 for(int i = 0; i < AUTOMATION_TOTAL; i++)
350 length = autos[i]->get_length();
351 if(length > total_length) total_length = length;
359 void Automation::get_extents(float *min,
361 int *coords_undefined,
366 for(int i = 0; i < AUTOMATION_TOTAL; i++)
368 if(autos[i] && edl->session->auto_conf->autos[i])
370 if (autos[i]->autogrouptype == autogrouptype)
371 autos[i]->get_extents(min, max, coords_undefined, unit_start, unit_end);
377 void Automation::dump(FILE *fp)
379 fprintf(fp," Automation: %p\n", this);
382 for(int i = 0; i < AUTOMATION_TOTAL; i++)
386 fprintf(fp," %s %p\n", xml_titles[i], autos[i]);