Simple script to fade adjacent events

johnmeyer wrote on 2/10/2006, 2:18 PM
There are lots of scripts that do things similar to this one, so you may already have something you like that works. However, I wanted something that matches my workflow.

What this one does is to add fade to black from the current position of the cursor to the end of the event that is under the cursor. It then adds exactly the same fade up from black, of exactly the same duration, at the beginning of the next track. If the track below the selected track contains audio, then the exact same things is done on that track as well.

Like most of my other scripts, while you DO have to make sure a track is selected, you DON'T have to select any event to make this work. The event under the cursor is the one that is considered the first event, and the location of the cursor relative to the end of that event determines the length of the fade.

If the cursor is over the last event on the timeline, then it just simply fades that to black.

If you do a lot of this sort of thing, you'll like this script.

Here it is:
==================
/**
* Fade this event and next event to black.
* Fade length is set using distance from cursor position to end of event
* that is under the cursor on the first selected track.
* If there is an audio track under the selected track, it is also faded.
*
* Copyright 2006, John H. Meyer
* February 10, 2006
**/

import System;
import System.Collections;
import System.Text;
import System.IO;
import System.Drawing;
import System.Windows.Forms;
import Sony.Vegas;


try {


var dStart : Double;
var dLength : Double;
var dCursor : Double;
var trackEnum : Enumerator;
var evnt : TrackEvent;
var track : Track;
var Fadelength : Timecode;

dCursor = Vegas.Cursor.ToMilliseconds();
track = FindSelectedTrack(); // Find first selected track

//Add fades to both event under cursor -- and next event -- on selected track
var eventEnum = new Enumerator(track.Events);
while (!eventEnum.atEnd()) {
evnt = TrackEvent(eventEnum.item());
AddFades();
eventEnum.moveNext();
} // End while eventEnum

trackEnum.moveNext(); // Go to next track and do fades, if track is audio
if (!trackEnum.atEnd()) {
track = Track(trackEnum.item());
if (track.IsAudio()) { // Proceed only if selected track is audio track.
eventEnum = new Enumerator(track.Events);
while (!eventEnum.atEnd()) {
evnt = TrackEvent(eventEnum.item());
AddFades();
eventEnum.moveNext();
} // End while TrackEvent
}
}

Vegas.UpdateUI();

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



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;
}


function AddFades() {
evnt.Selected = false; // De-select the event
dStart = evnt.Start.ToMilliseconds(); // Get the event's start and length timecode, in milliseconds.
dLength = evnt.Length.ToMilliseconds();

// Test if event is under the cursor.
if ( (dCursor >= dStart) && ( dCursor < (dLength + dStart) ) ) {
evnt.Selected = true; // If under the cursor, select this event.
Fadelength = evnt.Length - (Vegas.Cursor - evnt.Start);
evnt.FadeOut.Length = Fadelength;
evnt.FadeOut.Curve = CurveType.Smooth;
evnt.FadeOut.ReciprocalCurve = CurveType.Smooth;

eventEnum.moveNext();
if (!eventEnum.atEnd()) {
evnt = TrackEvent(eventEnum.item());
evnt.FadeIn.Length = Fadelength;
evnt.FadeIn.Curve = CurveType.Smooth;
evnt.FadeIn.ReciprocalCurve = CurveType.Smooth;
}
}

}

//For information purposes:
//CurveType.Sharp cubic sharp fade
//CurveType.Slow logarithmic slow fade
//CurveType.None no fade (hold)
//CurveType.Linear linear fade
//CurveType.Fast logarithmic fast fade
//CurveType.Smooth cubic smooth fade


Comments

MRe wrote on 4/11/2006, 2:46 AM
Hi John,
would it require major rewriting this if one would like to change this to "fade to color"? I myself prefer "fade to white" in some cases and it is a real pain in the butt to manage the envelope for each event.

I understood that much that one should change the addFades -function/subroutine to get the job done, or?

BR,
MRe
johnmeyer wrote on 4/11/2006, 8:27 AM
There is probably a simple change that can be made with the VideoColor class, but I'm afraid I don't have time to play with it. My guess is that you probably just need to add one statement to set the track VideoColor, and it will fade to that color.