4 * Copyright (C) 2010 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 "bcsignals.h"
41 KeyFrame::KeyFrame(EDL *edl, KeyFrames *autos)
42 : Auto(edl, (Autos*)autos)
51 void KeyFrame::load(FileXML *file)
53 //printf("KeyFrame::load 1\n");
54 // Shouldn't be necessary
55 // position = file->tag.get_property((char*)"POSITION", position);
56 //printf("KeyFrame::load 1\n");
58 int len = file->read_data_until((char*)"/KEYFRAME", data, MESSAGESIZE-1);
60 //printf("KeyFrame::load 2 data=\n%s\nend of data\n", data);
63 void KeyFrame::copy(int64_t start, int64_t end, FileXML *file, int default_auto)
65 //printf("KeyFrame::copy 1 %d\n%s\n", position - start, data);
66 file->tag.set_title((char*)"KEYFRAME");
68 file->tag.set_property((char*)"POSITION", 0);
70 file->tag.set_property((char*)"POSITION", position - start);
71 // default_auto converts a default auto to a normal auto
72 if(is_default && !default_auto)
73 file->tag.set_property((char*)"DEFAULT", 1);
75 // Can't put newlines in because these would be reimported and resaved along
77 // file->append_newline();
79 file->append_data(data, strlen(data));
80 // file->append_newline();
82 file->tag.set_title((char*)"/KEYFRAME");
84 file->append_newline();
88 void KeyFrame::copy_from(Auto *that)
90 copy_from((KeyFrame*)that);
93 void KeyFrame::copy_from(KeyFrame *that)
95 Auto::copy_from(that);
96 KeyFrame *keyframe = (KeyFrame*)that;
97 strcpy(data, keyframe->data);
98 position = keyframe->position;
101 void KeyFrame::copy_data(KeyFrame *src)
103 strcpy(data, src->data);
106 int KeyFrame::identical(KeyFrame *src)
108 return !strcasecmp(src->data, data);
112 void KeyFrame::get_contents(BC_Hash *ptr, char **text, char **extra)
115 input.set_shared_input(data, strlen(data));
118 char *this_extra = 0;
121 result = input.read_tag();
124 for(int i = 0; i < input.tag.properties.size(); i++)
126 const char *key = input.tag.get_property_text(i);
127 const char *value = input.tag.get_property(key);
128 ptr->update(key, value);
131 // Read any text after tag
132 this_text = input.read_text();
133 (*text) = cstrdup(this_text);
135 // Read remaining data
136 this_extra = input.get_data();
137 (*extra) = cstrdup(this_extra);
143 void KeyFrame::update_parameter(BC_Hash *params,
149 input.set_shared_input(get_data(), strlen(get_data()));
153 char *this_extra = 0;
156 // printf("KeyFrame::update_parameter %d %p %p %p \n",
163 get_contents(&this_params, &this_text, &this_extra);
166 // printf("KeyFrame::update_parameter %d params=%p\n", __LINE__, params);
167 // if(params) params->dump();
168 // printf("KeyFrame::update_parameter %d\n", __LINE__);
169 // this_params.dump();
174 result = input.read_tag();
177 // Replicate first tag
178 output.tag.set_title(input.tag.get_title());
180 // Get each parameter from this keyframe
181 for(int i = 0; i < this_params.size(); i++)
183 const char *key = this_params.get_key(i);
184 const char *value = this_params.get_value(i);
186 // Get new value from the params argument
191 for(int j = 0; j < params->size(); j++)
193 if(!strcmp(params->get_key(j), key))
196 value = params->get_value(j);
202 // Set parameter in output.
203 output.tag.set_property(key, value);
206 // Get each parameter from params argument
209 for(int i = 0; i < params->size(); i++)
211 const char *key = params->get_key(i);
212 //printf("KeyFrame::update_parameter %d %s\n", __LINE__, key);
215 for(int j = 0; j < this_params.size(); j++)
217 if(!strcmp(this_params.get_key(j), key))
223 //printf("KeyFrame::update_parameter %d %s\n", __LINE__, key);
225 // If it wasn't found in output, set new parameter in output.
228 output.tag.set_property(key, params->get_value(i));
229 //printf("KeyFrame::update_parameter %d %s\n", __LINE__, key);
234 // Append parameters to output
236 // Write anonymous text & duplicate the rest
237 output.append_text(text ? text : this_text);
238 // Append remaining previous data
239 output.append_data(extra ? extra : this_extra);
240 // Move output to input
241 output.terminate_string();
242 strcpy(this->data, output.string());
248 delete [] this_extra;
252 void KeyFrame::get_diff(KeyFrame *src,
259 input.set_shared_input(data, strlen(data));
262 char *this_extra = 0;
263 BC_Hash src_parameters;
267 get_contents(&this_params, &this_text, &this_extra);
268 src->get_contents(&src_parameters, &src_text, &src_extra);
270 if(debug) printf("KeyFrame::get_diff %d %d %d\n",
273 src_parameters.size());
275 // Capture changed parameters
276 char this_value[BCTEXTLEN];
277 for(int i = 0; i < MIN(this_params.size(), src_parameters.size()); i++)
279 const char *src_key = src_parameters.get_key(i);
280 const char *src_value = src_parameters.get_value(i);
282 this_params.get(src_key, this_value);
283 if(debug) printf("KeyFrame::get_diff %d %s %s %s\n",
288 // Capture values which differ
289 if(strcmp(src_value, this_value))
291 if(!(*params)) (*params) = new BC_Hash;
292 (*params)->update(src_key, src_value);
297 // Capture text which differs
298 if( !this_text || strcmp(this_text, src_text))
299 (*text) = cstrdup(src_text);
301 if( !this_extra || strcmp(this_extra, src_extra))
302 (*extra) = cstrdup(src_extra);
306 delete [] this_extra;
311 int KeyFrame::operator==(Auto &that)
313 return identical((KeyFrame*)&that);
316 int KeyFrame::operator==(KeyFrame &that)
318 return identical(&that);
321 char* KeyFrame::get_data()
326 void KeyFrame::set_data(char *data)
328 strcpy(this->data, data);
332 void KeyFrame::dump(FILE *fp)
334 fprintf(fp," position: " _LD "\n", position);
335 fprintf(fp," data: %s\n", data);