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"
40 KeyFrame::KeyFrame(EDL *edl, KeyFrames *autos)
41 : Auto(edl, (Autos*)autos)
50 void KeyFrame::load(FileXML *file)
52 //printf("KeyFrame::load 1\n");
53 // Shouldn't be necessary
54 // position = file->tag.get_property((char*)"POSITION", position);
55 //printf("KeyFrame::load 1\n");
57 int len = file->read_data_until((char*)"/KEYFRAME", data, MESSAGESIZE-1, 1);
59 //printf("KeyFrame::load 2 data=\n%s\nend of data\n", data);
62 void KeyFrame::copy(int64_t start, int64_t end, FileXML *file, int default_auto)
64 //printf("KeyFrame::copy 1 %d\n%s\n", position - start, data);
65 file->tag.set_title((char*)"KEYFRAME");
67 file->tag.set_property((char*)"POSITION", 0);
69 file->tag.set_property((char*)"POSITION", position - start);
70 // default_auto converts a default auto to a normal auto
71 if(is_default && !default_auto)
72 file->tag.set_property((char*)"DEFAULT", 1);
74 // Can't put newlines in because these would be reimported and resaved along
76 // file->append_newline();
78 file->append_data(data, strlen(data));
79 // file->append_newline();
81 file->tag.set_title((char*)"/KEYFRAME");
83 file->append_newline();
87 void KeyFrame::copy_from(Auto *that)
89 copy_from((KeyFrame*)that);
92 void KeyFrame::copy_from(KeyFrame *that)
94 Auto::copy_from(that);
95 KeyFrame *keyframe = (KeyFrame*)that;
96 strcpy(data, keyframe->data);
97 position = keyframe->position;
100 void KeyFrame::copy_data(KeyFrame *src)
102 strcpy(data, src->data);
105 int KeyFrame::identical(KeyFrame *src)
107 return !strcasecmp(src->data, data);
110 void KeyFrame::get_contents(BC_Hash *ptr, char **text, char **extra)
113 input.set_shared_input(data, strlen(data));
116 char *this_extra = 0;
119 result = input.read_tag();
122 for(int i = 0; i < input.tag.properties.size(); i++)
124 const char *key = input.tag.get_property_text(i);
125 const char *value = input.tag.get_property(key);
126 ptr->update(key, value);
129 // Read any text after tag
130 this_text = input.read_text();
131 (*text) = cstrdup(this_text);
133 // Read remaining data
134 this_extra = input.get_data();
135 (*extra) = cstrdup(this_extra);
141 void KeyFrame::update_parameter(BC_Hash *params,
142 const char *text, const char *extra)
146 input.set_shared_input(get_data(), strlen(get_data()));
150 char *this_extra = 0;
153 // printf("KeyFrame::update_parameter %d %p %p %p \n",
160 get_contents(&this_params, &this_text, &this_extra);
163 // printf("KeyFrame::update_parameter %d params=%p\n", __LINE__, params);
164 // if(params) params->dump();
165 // printf("KeyFrame::update_parameter %d\n", __LINE__);
166 // this_params.dump();
171 result = input.read_tag();
174 // Replicate first tag
175 output.tag.set_title(input.tag.get_title());
177 // Get each parameter from this keyframe
178 for(int i = 0; i < this_params.size(); i++)
180 const char *key = this_params.get_key(i);
181 const char *value = this_params.get_value(i);
183 // Get new value from the params argument
188 for(int j = 0; j < params->size(); j++)
190 if(!strcmp(params->get_key(j), key))
193 value = params->get_value(j);
199 // Set parameter in output.
200 output.tag.set_property(key, value);
203 // Get each parameter from params argument
206 for(int i = 0; i < params->size(); i++)
208 const char *key = params->get_key(i);
209 //printf("KeyFrame::update_parameter %d %s\n", __LINE__, key);
212 for(int j = 0; j < this_params.size(); j++)
214 if(!strcmp(this_params.get_key(j), key))
220 //printf("KeyFrame::update_parameter %d %s\n", __LINE__, key);
222 // If it wasn't found in output, set new parameter in output.
225 output.tag.set_property(key, params->get_value(i));
226 //printf("KeyFrame::update_parameter %d %s\n", __LINE__, key);
231 // Append parameters to output
233 // Write anonymous text & duplicate the rest
234 output.append_text(text ? text : this_text);
235 // Append remaining previous data
236 output.append_data(extra ? extra : this_extra);
237 // Move output to input
238 output.terminate_string();
239 strcpy(this->data, output.string());
245 delete [] this_extra;
249 void KeyFrame::get_diff(KeyFrame *src,
256 input.set_shared_input(data, strlen(data));
259 char *this_extra = 0;
260 BC_Hash src_parameters;
264 get_contents(&this_params, &this_text, &this_extra);
265 src->get_contents(&src_parameters, &src_text, &src_extra);
267 if(debug) printf("KeyFrame::get_diff %d %d %d\n",
270 src_parameters.size());
272 // Capture changed parameters
273 char this_value[BCTEXTLEN];
274 for(int i = 0; i < MIN(this_params.size(), src_parameters.size()); i++)
276 const char *src_key = src_parameters.get_key(i);
277 const char *src_value = src_parameters.get_value(i);
279 this_params.get(src_key, this_value);
280 if(debug) printf("KeyFrame::get_diff %d %s %s %s\n",
285 // Capture values which differ
286 if(strcmp(src_value, this_value))
288 if(!(*params)) (*params) = new BC_Hash;
289 (*params)->update(src_key, src_value);
294 // Capture text which differs
295 if( !this_text || strcmp(this_text, src_text))
296 (*text) = cstrdup(src_text);
298 if( !this_extra || strcmp(this_extra, src_extra))
299 (*extra) = cstrdup(src_extra);
303 delete [] this_extra;
308 int KeyFrame::operator==(Auto &that)
310 return identical((KeyFrame*)&that);
313 int KeyFrame::operator==(KeyFrame &that)
315 return identical(&that);
318 char* KeyFrame::get_data()
323 void KeyFrame::set_data(char *data)
325 strcpy(this->data, data);
328 void KeyFrame::dump(FILE *fp)
330 fprintf(fp," position: %jd\n", position);
331 fprintf(fp," data: %s\n", data);