X-Git-Url: http://git.cinelerra-gg.org/git/?a=blobdiff_plain;f=cinelerra-5.1%2Fcinelerra%2Fkeyframe.C;h=faad855bec12fe610f6985c996ad930ff105b2fb;hb=340840559db419a217ccb6adc7de1f96518d2906;hp=cdeebd642cf6bce2fcb6d07dcb920a41e53afba3;hpb=270d86e71b318578d56d0e8a245cf14f32cf09ac;p=goodguy%2Fhistory.git diff --git a/cinelerra-5.1/cinelerra/keyframe.C b/cinelerra-5.1/cinelerra/keyframe.C index cdeebd64..faad855b 100644 --- a/cinelerra-5.1/cinelerra/keyframe.C +++ b/cinelerra-5.1/cinelerra/keyframe.C @@ -34,17 +34,18 @@ KeyFrame::KeyFrame() : Auto() { - data[0] = 0; + xbuf = new XMLBuffer(); } KeyFrame::KeyFrame(EDL *edl, KeyFrames *autos) : Auto(edl, (Autos*)autos) { - data[0] = 0; + xbuf = new XMLBuffer(); } KeyFrame::~KeyFrame() { + delete xbuf; } void KeyFrame::load(FileXML *file) @@ -53,15 +54,12 @@ void KeyFrame::load(FileXML *file) // Shouldn't be necessary // position = file->tag.get_property((char*)"POSITION", position); //printf("KeyFrame::load 1\n"); - - int len = file->read_data_until((char*)"/KEYFRAME", data, MESSAGESIZE-1, 1); - data[len] = 0; -//printf("KeyFrame::load 2 data=\n%s\nend of data\n", data); + xbuf->iseek(0); xbuf->oseek(0); + file->read_data_until((char*)"/KEYFRAME", xbuf, 1); } void KeyFrame::copy(int64_t start, int64_t end, FileXML *file, int default_auto) { -//printf("KeyFrame::copy 1 %d\n%s\n", position - start, data); file->tag.set_title((char*)"KEYFRAME"); if(default_auto) file->tag.set_property((char*)"POSITION", 0); @@ -73,10 +71,8 @@ void KeyFrame::copy(int64_t start, int64_t end, FileXML *file, int default_auto) file->append_tag(); // Can't put newlines in because these would be reimported and resaved along // with new newlines. -// file->append_newline(); - + char *data = (char*)xbuf->cstr(); file->append_data(data, strlen(data)); -// file->append_newline(); file->tag.set_title((char*)"/KEYFRAME"); file->append_tag(); @@ -89,156 +85,102 @@ void KeyFrame::copy_from(Auto *that) copy_from((KeyFrame*)that); } -void KeyFrame::copy_from(KeyFrame *that) +void KeyFrame::copy_data(KeyFrame *src) { - Auto::copy_from(that); - KeyFrame *keyframe = (KeyFrame*)that; - strcpy(data, keyframe->data); - position = keyframe->position; + xbuf->copy_from(src->xbuf); } -void KeyFrame::copy_data(KeyFrame *src) +void KeyFrame::copy_from(KeyFrame *that) { - strcpy(data, src->data); + Auto::copy_from(that); + copy_data(that); + position = that->position; } int KeyFrame::identical(KeyFrame *src) { - return !strcasecmp(src->data, data); + return !strcasecmp(xbuf->cstr(), src->xbuf->cstr()); } void KeyFrame::get_contents(BC_Hash *ptr, char **text, char **extra) { FileXML input; - input.set_shared_input(data, strlen(data)); - int result = 0; - char *this_text = 0; - char *this_extra = 0; - while(!result) - { - result = input.read_tag(); - if(!result) - { - for(int i = 0; i < input.tag.properties.size(); i++) - { - const char *key = input.tag.get_property_text(i); - const char *value = input.tag.get_property(key); - ptr->update(key, value); - } + input.set_shared_input(xbuf); + char *this_text = 0, *this_extra = 0; + if( !input.read_tag() ) { + for( int i=0; iupdate(key, value); + } // Read any text after tag - this_text = input.read_text(); - (*text) = cstrdup(this_text); + this_text = input.read_text(); + (*text) = cstrdup(this_text); // Read remaining data - this_extra = input.get_data(); - (*extra) = cstrdup(this_extra); - break; - } + this_extra = input.get_data(); + (*extra) = cstrdup(this_extra); } } void KeyFrame::update_parameter(BC_Hash *params, const char *text, const char *extra) { - FileXML output; - FileXML input; - input.set_shared_input(get_data(), strlen(get_data())); - int result = 0; BC_Hash this_params; - char *this_text = 0; - char *this_extra = 0; - int got_it = 0; - -// printf("KeyFrame::update_parameter %d %p %p %p \n", -// __LINE__, -// params, -// text, -// extra); - - + char *this_text = 0, *this_extra = 0; get_contents(&this_params, &this_text, &this_extra); - -// printf("KeyFrame::update_parameter %d params=%p\n", __LINE__, params); -// if(params) params->dump(); -// printf("KeyFrame::update_parameter %d\n", __LINE__); -// this_params.dump(); - -// Get first tag - while(!result) - { - result = input.read_tag(); - if(!result) - { -// Replicate first tag - output.tag.set_title(input.tag.get_title()); + FileXML input, output; + input.set_shared_input(xbuf); + if( !input.read_tag() ) { +// Replicate tag + output.tag.set_title(input.tag.get_title()); // Get each parameter from this keyframe - for(int i = 0; i < this_params.size(); i++) - { - const char *key = this_params.get_key(i); - const char *value = this_params.get_value(i); - + for( int i=0; isize(); j++) - { - if(!strcmp(params->get_key(j), key)) - { - got_it = 1; - value = params->get_value(j); - break; - } + if( params ) { + for( int j=0; jsize(); ++j ) { + if( !strcmp(params->get_key(j), key) ) { + value = params->get_value(j); + break; } } - -// Set parameter in output. - output.tag.set_property(key, value); } + output.tag.set_property(key, value); + } + // Get each parameter from params argument - if(params) - { - for(int i = 0; i < params->size(); i++) - { - const char *key = params->get_key(i); -//printf("KeyFrame::update_parameter %d %s\n", __LINE__, key); - - got_it = 0; - for(int j = 0; j < this_params.size(); j++) - { - if(!strcmp(this_params.get_key(j), key)) - { - got_it = 1; - break; - } + if( params ) { + for( int i=0; isize(); ++i ) { + const char *key = params->get_key(i); + int got_it = 0; + for( int j=0; jget_value(i)); -//printf("KeyFrame::update_parameter %d %s\n", __LINE__, key); - } + if( !got_it ) { + output.tag.set_property(key, params->get_value(i)); } } + } -// Append parameters to output - output.append_tag(); + output.append_tag(); // Write anonymous text & duplicate the rest - output.append_text(text ? text : this_text); -// Append remaining previous data - output.append_data(extra ? extra : this_extra); + output.append_text(text ? text : this_text); + output.append_data(extra ? extra : this_extra); + output.terminate_string(); // Move output to input - output.terminate_string(); - strcpy(this->data, output.string()); - break; - } + xbuf->oseek(0); + xbuf->write(output.string(), output.length()); } delete [] this_text; @@ -294,19 +236,21 @@ int KeyFrame::operator==(KeyFrame &that) return identical(&that); } -char* KeyFrame::get_data() +char *KeyFrame::get_data(int64_t sz) { - return data; + if( sz >= 0 ) xbuf->demand(sz); + return xbuf->cstr(); } void KeyFrame::set_data(char *data) { - strcpy(this->data, data); + xbuf->oseek(0); + xbuf->write(data, strlen(data)); } void KeyFrame::dump(FILE *fp) { fprintf(fp," position: %jd\n", position); - fprintf(fp," data: %s\n", data); + fprintf(fp," data: %s\n", xbuf->cstr()); }