Delete event under cursor (Vegas 6)

johnmeyer wrote on 5/31/2006, 8:58 AM
I wrote several scripts to help with "cuts-only" editing and posted these at several sites. I updated them to work with Vegas 6. Here is the first of those three, updated for Vegas 6:
/** 
* PURPOSE OF THIS SCRIPT:
*
* Delete the event under the cursor, including the associated audio.
* Ripple remaining events on the video and associated audio tracks (but not on other tracks).
* Select the event that "ripples into" the space left by the deleted event,
* and then put the cursor at the beginning of this event.
*
* A video track must be selected. If an audio track is selected, nothing happens, and you get an error message.
* If the track beneath the video track contains audio, the audio event in that track
* that lies beneath the cursor will also be deleted, and subsequent events rippled.
*
* Since the audio for a video event is sometimes shorter, the length of the video event is used
* to ripple the audio event, to make sure everything lines up the same way as it did prior to the ripple.
*
* Also, Vegas has all sorts of crazy internal roundoff errors which cause problems when the cursor
* is on the event boundary, so a "slop" variable is used to "forgive" slight errors. If you set this
* variable to zero, you will get strange behavior -- but only sometimes -- when the cursor is at the event
* boundaries.
*
* (One side note: This roundoff can cause problems when using Vegas without scripts -- beware.)
*
* Copyright © John Meyer 2004
* Written: September 23, 2004
* Revised to work on Vegas 6.0d in January 9, 2006
*
**/

import System;
import System.IO;
import System.Windows.Forms;
import Sony.Vegas;


try {

//Global declarations
var dStart : Double; // Start of event
var dLength : Double; // Length of event
var dCursor : Double; // Current cursor position
var NewCursorPos : Timecode; // Used to position cursor at start of next event, after deletion
var RippleLength = new Timecode("00:00:00:00");
var dSlop : Double = 0.1; // Variable needed because Vegas is sloppy and doesn't
// make audio and video exactly the same length
var trackEnum : Enumerator;
var evnt : TrackEvent;

var track = FindSelectedTrack(); // Function to find the first selected track.
var eventEnum = new Enumerator(track.Events); // List of events on this track

if (track.IsVideo()) { // Proceed only if selected track is video track.

if ( SelectEventAtCursor() ) { // Function that selects and removes event under cursor.
trackEnum.moveNext(); // If success on video track, go to next track.
if (!trackEnum.atEnd()) { // Only proceed if there is a track below the video track.
track = Track(trackEnum.item());
if (track.IsAudio()) { // Only trim the event if this is an audio track.
eventEnum = new Enumerator(track.Events);
SelectEventAtCursor();
} // End If track.IsAudio()
} // End If !trackEnum.atEnd()
} // End If SelectEventAtCursor()

Vegas.Cursor = NewCursorPos ; // Before finishing, put cursor at beginning of event
} // immediately after deleted event.

else {
MessageBox.Show ("You need to select the video track, not the audio track", "Alert");
} // End track.IsVideo()

Vegas.UpdateUI(); // Update the UI.

} // End try

catch (e) {
MessageBox.Show(e);
}

// End of main program


// Beginning of functions

function FindSelectedTrack() : Track {
trackEnum = new Enumerator(Vegas.Project.Tracks);
while (!trackEnum.atEnd()) {
var track : Track = Track(trackEnum.item());

if (track.Selected) {
return track;
}
trackEnum.moveNext();
}
return null;
}


/**
*
* The following function finds, selects, then deletes the event on the selected track
* that lies under the cursor. It also deselects all other events on the selected track.
*
**/

function SelectEventAtCursor( ) {

var EventFound : boolean = false; // Function returns false if no video media under cursor.
dCursor = Vegas.Cursor.ToMilliseconds(); // Remember the cursor position.

while (!eventEnum.atEnd()) { // Go through each event on the track.
evnt = TrackEvent(eventEnum.item()); // Get next event
evnt.Selected = false; // De-select the event
dStart = evnt.Start.ToMilliseconds(); // Get the event's start and
dLength = evnt.Length.ToMilliseconds(); // length timecode, in milliseconds.

// If the cursor timecode is between the beginning and end of the
// event timecodes, then select and delete the event.

if ( (dCursor >= dStart) && ( dCursor < (dStart + dLength - dSlop) ) ) {

evnt.Selected = true; // Select this event.
EventFound = true; // Notify calling function that event was found
if (RippleLength.ToMilliseconds()<1) { // If ripple length was previously set to video length,
RippleLength = evnt.Length; // (i.e., it is non-zero) don't reset. Use video length
} // to ripple audio (because audio may not be same length as video)
NewCursorPos = evnt.Start; // At end of script, move cursor to where this event used to start
track.Events.Remove(evnt); // Remove the event
eventEnum = new Enumerator(track.Events); // Removing the event screws up enumeration, so start over
evnt = TrackEvent(eventEnum.item());
dStart = evnt.Start.ToMilliseconds(); // Recompute the event's start and
dLength = evnt.Length.ToMilliseconds(); // Recompute length timecode, in milliseconds.
} // End If dCursor (etc.)

if ( (dCursor < dStart) ) { // If cursor is to left of this event, then ripple.
evnt.AdjustStartLength(evnt.Start - RippleLength, evnt.Length, false); //False for V6
dStart = evnt.Start.ToMilliseconds(); // Event has moved, so recompute the event's start and
dLength = evnt.Length.ToMilliseconds(); // length timecode, in milliseconds.

if ( (NewCursorPos.ToMilliseconds() >= dStart) && ( NewCursorPos.ToMilliseconds() < (dLength + dStart) ) ) {
evnt.Selected = true; // Select the event that "replaced" the removed event
}
} // End if ( (dCursor < dStart) )

eventEnum.moveNext(); // Go to next event on this timeline.
}
return EventFound;
}

Comments

No comments yet - be the first to write a comment...