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[] =
50 Automation::Automation(EDL *edl, Track *track)
54 bzero(autos, sizeof(Autos*) * AUTOMATION_TOTAL);
57 Automation::~Automation()
59 for(int i = 0; i < AUTOMATION_TOTAL; i++)
65 int Automation::autogrouptype(int autoidx, Track *track)
67 int autogrouptype = -1;
70 case AUTOMATION_CAMERA_X:
71 case AUTOMATION_PROJECTOR_X:
72 autogrouptype = AUTOGROUPTYPE_X;
74 case AUTOMATION_CAMERA_Y:
75 case AUTOMATION_PROJECTOR_Y:
76 autogrouptype = AUTOGROUPTYPE_Y;
78 case AUTOMATION_CAMERA_Z:
79 case AUTOMATION_PROJECTOR_Z:
80 autogrouptype = AUTOGROUPTYPE_ZOOM;
82 case AUTOMATION_SPEED:
83 autogrouptype = AUTOGROUPTYPE_SPEED;
86 if (track->data_type == TRACK_AUDIO)
87 autogrouptype = AUTOGROUPTYPE_AUDIO_FADE;
89 autogrouptype = AUTOGROUPTYPE_VIDEO_FADE;
92 autogrouptype = AUTOGROUPTYPE_INT255;
95 return (autogrouptype);
98 void Automation::create_objects()
100 autos[AUTOMATION_MUTE] = new IntAutos(edl, track, 0);
101 autos[AUTOMATION_MUTE]->create_objects();
102 autos[AUTOMATION_MUTE]->autoidx = AUTOMATION_MUTE;
103 autos[AUTOMATION_MUTE]->autogrouptype = AUTOGROUPTYPE_INT255;
106 Automation& Automation::operator=(Automation& automation)
108 //printf("Automation::operator= 1\n");
109 copy_from(&automation);
113 void Automation::equivalent_output(Automation *automation, int64_t *result)
115 for(int i = 0; i < AUTOMATION_TOTAL; i++)
117 if(autos[i] && automation->autos[i])
118 autos[i]->equivalent_output(automation->autos[i], 0, result);
122 void Automation::copy_from(Automation *automation)
124 for(int i = 0; i < AUTOMATION_TOTAL; i++)
126 if(autos[i] && automation->autos[i])
127 autos[i]->copy_from(automation->autos[i]);
131 // These must match the enumerations
132 static const char *xml_titles[] =
148 int Automation::load(FileXML *file)
150 for(int i = 0; i < AUTOMATION_TOTAL; i++)
152 if(file->tag.title_is(xml_titles[i]) && autos[i])
154 autos[i]->load(file);
161 int Automation::paste(int64_t start,
169 if(!autoconf) autoconf = edl->session->auto_conf;
171 for(int i = 0; i < AUTOMATION_TOTAL; i++)
173 if(file->tag.title_is(xml_titles[i]) && autos[i] && autoconf->autos[i])
175 autos[i]->paste(start,
187 int Automation::copy(int64_t start,
193 // Copy regardless of what's visible.
194 for(int i = 0; i < AUTOMATION_TOTAL; i++)
198 file->tag.set_title(xml_titles[i]);
200 file->append_newline();
201 autos[i]->copy(start,
206 char string[BCTEXTLEN];
207 sprintf(string, "/%s", xml_titles[i]);
208 file->tag.set_title(string);
210 file->append_newline();
218 void Automation::clear(int64_t start,
223 AutoConf *temp_autoconf = 0;
227 temp_autoconf = new AutoConf;
228 temp_autoconf->set_all(1);
229 autoconf = temp_autoconf;
232 for(int i = 0; i < AUTOMATION_TOTAL; i++)
234 if(autos[i] && autoconf->autos[i])
236 autos[i]->clear(start, end, shift_autos);
240 if(temp_autoconf) delete temp_autoconf;
243 void Automation::set_automation_mode(int64_t start,
248 AutoConf *temp_autoconf = 0;
252 temp_autoconf = new AutoConf;
253 temp_autoconf->set_all(1);
254 autoconf = temp_autoconf;
257 for(int i = 0; i < AUTOMATION_TOTAL; i++)
259 if(autos[i] && autoconf->autos[i])
261 autos[i]->set_automation_mode(start, end, mode);
265 if(temp_autoconf) delete temp_autoconf;
269 void Automation::paste_silence(int64_t start, int64_t end)
271 // Unit conversion done in calling routine
272 for(int i = 0; i < AUTOMATION_TOTAL; i++)
275 autos[i]->paste_silence(start, end);
279 // We don't replace it in pasting but
280 // when inserting the first EDL of a load operation we need to replace
281 // the default keyframe.
282 void Automation::insert_track(Automation *automation,
284 int64_t length_units,
287 for(int i = 0; i < AUTOMATION_TOTAL; i++)
289 if(autos[i] && automation->autos[i])
291 autos[i]->insert_track(automation->autos[i],
301 void Automation::resample(double old_rate, double new_rate)
303 // Run resample for all the autos structures and all the keyframes
304 for(int i = 0; i < AUTOMATION_TOTAL; i++)
306 if(autos[i]) autos[i]->resample(old_rate, new_rate);
312 int Automation::direct_copy_possible(int64_t start, int direction)
320 void Automation::get_projector(float *x,
328 void Automation::get_camera(float *x,
339 int64_t Automation::get_length()
342 int64_t total_length = 0;
344 for(int i = 0; i < AUTOMATION_TOTAL; i++)
348 length = autos[i]->get_length();
349 if(length > total_length) total_length = length;
357 void Automation::get_extents(float *min,
359 int *coords_undefined,
364 for(int i = 0; i < AUTOMATION_TOTAL; i++)
366 if(autos[i] && edl->session->auto_conf->autos[i])
368 if (autos[i]->autogrouptype == autogrouptype)
369 autos[i]->get_extents(min, max, coords_undefined, unit_start, unit_end);
375 void Automation::dump(FILE *fp)
377 fprintf(fp," Automation: %p\n", this);
380 for(int i = 0; i < AUTOMATION_TOTAL; i++)
384 fprintf(fp," %s %p\n", xml_titles[i], autos[i]);