X-Git-Url: http://git.cinelerra-gg.org/git/?p=goodguy%2Fhistory.git;a=blobdiff_plain;f=cinelerra-5.1%2Fcinelerra%2Fedits.C;h=a79bb171d9ba2f4178f4d5a7b45b54506a4a9a44;hp=a8e668f844c3dedf15322cc0abc320e7600a2525;hb=d079f6253a75cc8cfedbab636ad0bc7f5dc9c5f5;hpb=101d92b4c50a831fb00edd65df57de41b408c7b6 diff --git a/cinelerra-5.1/cinelerra/edits.C b/cinelerra-5.1/cinelerra/edits.C index a8e668f8..a79bb171 100644 --- a/cinelerra-5.1/cinelerra/edits.C +++ b/cinelerra-5.1/cinelerra/edits.C @@ -1,7 +1,7 @@ /* * CINELERRA - * Copyright (C) 2008 Adam Williams + * Copyright (C) 2008-2017 Adam Williams * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,6 +26,7 @@ #include "bcsignals.h" #include "cache.h" #include "clip.h" +#include "clipedls.h" #include "edit.h" #include "edits.h" #include "edl.h" @@ -34,7 +35,6 @@ #include "filexml.h" #include "filesystem.h" #include "localsession.h" -#include "nestededls.h" #include "plugin.h" #include "strategies.inc" #include "track.h" @@ -111,11 +111,8 @@ printf("Edits::operator= 1\n"); } -void Edits::insert_asset(Asset *asset, - EDL *nested_edl, - int64_t length, - int64_t position, - int track_number) +void Edits::insert_asset(Asset *asset, EDL *nested_edl, + int64_t length, int64_t position, int track_number) { Edit *new_edit = insert_new_edit(position); @@ -172,7 +169,7 @@ void Edits::insert_edits(Edits *source_edits, { EDL *dest_nested_edl = 0; if(source_edit->nested_edl) - dest_nested_edl = edl->nested_edls->get_copy(source_edit->nested_edl); + dest_nested_edl = edl->nested_edls.get_nested(source_edit->nested_edl); // Update Assets Asset *dest_asset = 0; @@ -295,25 +292,20 @@ void Edits::resample(double old_rate, double new_rate) } } - - - - - - - - - - - - +int Edits::is_glitch(Edit *edit) +{ + if( track->data_type != TRACK_AUDIO ) return 0; + int64_t threshold = edl->session->frame_rate > 0 ? + 0.5 * edl->session->sample_rate / edl->session->frame_rate : 0; +// audio edit shorter than .5 frames is a glitch + return edit->length < threshold ? 1 : 0; +} int Edits::optimize() { int result = 1; Edit *current; - //printf("Edits::optimize %d\n", __LINE__); // Sort edits by starting point while(result) @@ -379,42 +371,55 @@ int Edits::optimize() current = next; } -//printf("Edits::optimize %d result=%d\n", __LINE__, result); -// merge same files or transitions - if(track->data_type == TRACK_SUBTITLE ) continue; - - for(current = first; !result && current && current->next; ) { - Edit *next_edit = current->next; - -// printf("Edits::optimize %d %lld=%lld %d=%d %p=%p %p=%p\n", -// __LINE__, current->startsource + current->length, next_edit->startsource, -// current->channel, next_edit->channel, current->asset, next_edit->asset, -// current->nested_edl, next_edit->nested_edl); - +// merge same files or transitions, and deglitch + if( !result && track->data_type != TRACK_SUBTITLE ) { + current = first; + if( current && !current->hard_right && + current->next && !current->next->hard_left && + is_glitch(current) ) { +// if the first edit is a glitch, change it to silence + current->asset = 0; + current->nested_edl = 0; + } + Edit *next_edit = 0; + for( ; current && (next_edit=current->next); current=NEXT ) { +// both edges are not hard edges + if( current->hard_right || next_edit->hard_left ) continue; +// next edit is a glitch + if( is_glitch(next_edit) ) + break; // both edits are silence & not a plugin -// source channels are identical, assets are identical - if( (current->silence() && next_edit->silence() && !current->is_plugin) || - (current->startsource + current->length == next_edit->startsource && - current->channel == next_edit->channel && - current->asset == next_edit->asset && - current->nested_edl == next_edit->nested_edl)) { -//printf("Edits::optimize %d\n", __LINE__); - current->length += next_edit->length; - remove(next_edit); - result = 1; - break; - } - - current = current->next; + if( !current->is_plugin && current->silence() && + !next_edit->is_plugin && next_edit->silence() ) + break; +// source channels are identical & assets are identical + if( !result && current->channel == next_edit->channel && + current->asset == next_edit->asset && + current->nested_edl == next_edit->nested_edl ) { +// and stop and start in the same frame + int64_t current_end = current->startsource + current->length; + int64_t next_start = next_edit->startsource; + if( current_end == next_start || + EQUIV(edl->frame_align(track->from_units(current_end), 1), + edl->frame_align(track->from_units(next_start), 1)) ) + break; + } + } + if( next_edit ) { + int64_t current_start = current->startproject; + int64_t next_end = next_edit->startproject + next_edit->length; + current->length = next_end - current_start; + remove(next_edit); + result = 1; + } } - if(last && last->silence() && !last->transition ) { + if( last && last->silence() && !last->transition ) { delete last; result = 1; } } -//track->dump(); return 0; } @@ -454,11 +459,10 @@ int Edits::load_edit(FileXML *file, int64_t &startproject, int track_offset) file->tag.get_property("SRC", path); //printf("Edits::load_edit %d path=%s\n", __LINE__, path); if(path[0] != 0) { - current->nested_edl = edl->nested_edls->get(path); + current->nested_edl = edl->nested_edls.load(path); } // printf("Edits::load_edit %d nested_edl->path=%s\n", -// __LINE__, -// current->nested_edl->path); +// __LINE__, current->nested_edl->path); } else if(file->tag.title_is("FILE")) { char filename[BCTEXTLEN]; @@ -592,7 +596,7 @@ void Edits::clear(int64_t start, int64_t end) end = this->length(); } - if(edit1 != edit2) + if( edit1 && edit2 && edit1 != edit2) { // in different edits @@ -768,7 +772,7 @@ int Edits::modify_handles(double oldposition, double newposition, int currentend else { // move end of edit out -//printf("Edits::modify_handle 6\n"); +//printf("Edits::modify_handle %d edit_mode=%d\n", __LINE__, edit_mode); current_edit->shift_end_out(edit_mode, track->to_units(newposition, 0), track->to_units(oldposition, 0),