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( !AudioTracks.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( procName );
// 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() ) {
edit.addPerform( TimelineVisualEdit.position( this, Session.this, span.start ));
edit.addPerform( TimelineVisualEdit.select( this, Session.this, new Span() ));
}
if( cutTimeline ) {
visiSpan = timeline.getVisibleSpan();
if( visiSpan.stop > span.start ) {
if( visiSpan.stop > newDocLength ) {
visiSpan = new Span( Math.max( 0, newDocLength - visiSpan.getLength() ), newDocLength );
TimelineVisualEdit tve = TimelineVisualEdit.scroll( this, Session.this, visiSpan );
edit.addPerform( tve );
} // else visiSpan untouched
}
edit.addPerform( new EditSetTimelineLength( this, Session.this, newDocLength ));