{
if( !checkProcess() ) return null;
final BlendContext bc;
final long cutLength, docLength, newDocLength, maxLen;
final Flag hasSelectedAudio;
final List tis;
final AbstractCompoundEdit edit;
final boolean cutTimeline;
final Span cutTimelineSpan, selSpan;
Span visiSpan;
hasSelectedAudio = new Flag( false );
tis = Track.getInfos( selectedTracks.getAll(), tracks.getAll() );
if( !checkSyncedAudio( tis, mode == EDIT_INSERT, null, hasSelectedAudio )) return null;
docLength = timeline.getLength();
cutLength = span.getLength();
if( mode == EDIT_INSERT ) {
/*
* before delete:
*
* |,,,,,,,,,,,,,,,,,|$$$$$$$#######|............|
* |,,,,,,,,,,,,,,,,,|$$$$$$$#######|............|
* |,,,,,,,,,,,,,,,,,|$$$$$$$#######|............|
* |,,,,,,,,A,,,,,,,,|$$B1$$$###B2##|......C.....|
* +-----------------+--------------+------------+
* | span |
*
* after delete:
* left right
* |,,,,,,,,,,,,, | |
* |,,,,,,,,,,,,,,, | |
* |,,,,,,,,,,,,,,,,,| |
* |,,,,,,,,,,,,,,,,,|$$ |
* |,,,,,,,,,,,,,,,,,|$$$$ |
* |,,,,,,,,A,,,,,,,,|$B2$$$ |
* +-----------------+------------+
* |
* plus
* | | ........|
* | | ..........|
* | |............|
* | ##|............|
* | ####|............|
* | ###B2#|......C.....|
* +-----------------+------------+
* |
* span.start
*/
maxLen = Math.min( cutLength, Math.min( span.start, docLength - span.stop ) << 1 );
bc = createBlendContext( maxLen >> 1, (maxLen + 1) >> 1, hasSelectedAudio.isSet() );
} else {
/*
* after delete:
* blend- blend-
* Len Len
* |,,,,,,,,,,,,,,,,,|$ #|............|
* |,,,,,,,,,,,,,,,,,|$$ ##|............|
* |,,,,,,,,,,,,,,,,,|$$$ ###|............|
* |,,,,,,,,A,,,,,,,,|$B1$ #B2#|......C.....|
* +-----------------+--------------+------------+
* | span |
*/
maxLen = cutLength >> 1;
bc = createBlendContext( maxLen, 0, hasSelectedAudio.isSet() );
}
// bc = createBlendContext( Math.min( cutLength, span.start ), Math.min( cutLength, docLength - span.stop ), hasSelectedAudio );
edit = new BasicCompoundEdit( name );
// if( bc != null ) System.out.println( "bc : " + bc.getLen() + ", " + bc.getLeftLen() + ", "+ bc.getRightLen() );
cutTimeline = (mode == EDIT_INSERT) && hasSelectedAudio.isSet();
newDocLength = cutTimeline ? docLength - cutLength : docLength;
cutTimelineSpan = cutTimeline ? new Span( newDocLength, docLength ) : null;
selSpan = timeline.getSelectionSpan();
if( (mode == EDIT_INSERT) && !selSpan.isEmpty() ) {