/**
* Program: AddGaps&Overlaps.js
*
* Description: This script will add a gap between all events on SELECTED tracks
* in the input dialog box you should enter gap length in form of
* "hh:mm:ss.ff" or input a number of frames.
* First event on each track is placed at time "00:00:00.00"
*
* TIP: if you enter minus (-) before gap length, you'll get overlaps
* instead of gaps :)
*
**/
import System;
import ScriptPortal.Vegas;
import System.Windows.Forms;
var StartTime : Timecode = new Timecode("00:00:00.00"); // starting time of first event on each track
var Gap : Timecode = new Timecode("00:00:01.00"); // default gap length
var evnt : TrackEvent;
try
{
var dialog = new InputDialog(); // show the dialog
dialog.eventTextBox.Text = Gap.ToString(); // fill the dialog with default Gap length
if (DialogResult.OK == dialog.ShowDialog())
{
Gap = dialog.getGapLength();
for (var track in Vegas.Project.Tracks)
{ // step through all project tracks and work on selected ones
if( !track.Selected) continue;
if(track.MediaType=="Video")
{
var trackTemp = new VideoTrack(1, "Temp"); // create new video track
};
if(track.MediaType=="Audio")
{
var trackTemp = new AudioTrack(1, "Temp"); // create new audio track
};
Vegas.Project.Tracks.Add(trackTemp); // add temporary track
var tracktime = StartTime;
var eventEnum = new Enumerator(track.Events);
while (!eventEnum.atEnd())
{ // move all events from current track to temporary track with given gaps between them
evnt = TrackEvent(eventEnum.item());
evnt.Track = trackTemp; // move event to temp track
evnt.Start = tracktime; // set event's start time
tracktime = tracktime + evnt.Length + Gap;
eventEnum.moveFirst(); // always use first event on current track, because when
// you move the first event to temporary track, what was
// previously second event on current track, becomes first!
}
var eventEnumTemp = new Enumerator(trackTemp.Events);
while (!eventEnumTemp.atEnd())
{ // move all events back to "source track"
evnt = TrackEvent(eventEnumTemp.item());
evnt.Track = track
eventEnumTemp.moveFirst(); // always use first event on current track (look above for reason)
}
Vegas.Project.Tracks.Remove(trackTemp); // remove temporary track
Vegas.UpdateUI(); // redraw Vegas interface
}
}
}//try
catch (errorMsg)
{ // Error handler
MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
/************************************************
* Dialog: Input dialog for gap lengths
************************************************/
class InputDialog extends Form
{
var label1 : Label;
var eventTextBox : TextBox;
var cancelButton : Button;
var okButton : Button;
function InputDialog()
{
this.okButton = new Button();
this.cancelButton = new Button();
this.label1 = new Label();
this.eventTextBox = new TextBox();
this.SuspendLayout();
//
// eventTextBox
//
this.eventTextBox.Location = new System.Drawing.Point(100, 17);
this.eventTextBox.Name = "eventTextBox";
this.eventTextBox.Size = new System.Drawing.Size(80, 20);
this.eventTextBox.TabIndex = 1;
this.eventTextBox.Text = "00:00:00.00";
//
// okButton
//
this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
this.okButton.Location = new System.Drawing.Point(24, 50);
this.okButton.Name = "okButton";
this.okButton.TabIndex = 2;
this.okButton.Text = "OK";
//
// cancelButton
//
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelButton.Location = new System.Drawing.Point(120, 50);
this.cancelButton.Name = "cancelButton";
this.cancelButton.TabIndex = 3;
this.cancelButton.Text = "Cancel";
//
// label1
//
this.label1.Location = new System.Drawing.Point(30, 20);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(70, 16);
this.label1.TabIndex = 4;
this.label1.Text = "Gap Length:";
//
// Form
//
this.AcceptButton = this.okButton;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.cancelButton;
this.ClientSize = new System.Drawing.Size(220, 90);
this.ControlBox = false;
this.Controls.Add(this.eventTextBox);
this.Controls.Add(this.label1);
this.Controls.Add(this.cancelButton);
this.Controls.Add(this.okButton);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MinimizeBox = false;
this.Name = "Form";
this.StartPosition = FormStartPosition.CenterScreen;
this.Text = "Set Gap (negative for OVERLAP!)";
this.ResumeLayout(false);
}
// Returns the event length as a timecode
function getGapLength()
{
return new Timecode(eventTextBox.Text);
}
}