Script to evenly space events on timeline?

Former user wrote on 7/24/2009, 7:44 AM
Morning!

I am starting to do a lot more phone messaging voiceover jobs - basically where 6-10 voice prompts need to be spread out evenly across the length of the music bed.

Anyone come across anything that would let me select all events on an audio track and have the script "space" the events evenly against an overall selection length?

Ideally - I would love to see a small dialog that would let me select the target track to space against and have an option for a start point (for first event) and end point (tailend of last event)...

Appreciate any tips...

Cheers!

VP

Comments

JohnnyRoy wrote on 7/24/2009, 9:31 AM
Mornin' VP,

The way I figure it, there is no need for a GUI. It would just get in the way of your workflow.

Here is a script that I just wrote for you that should be much faster than using a GUI. Just select the track(s) you want to process and then make a Timeline Selection (i.e., Loop Selection) to designate the area that the events should occupy and this script will evenly space them within that area. They will start at the timeline selection start and end at the timeline selection end. Easy peasy!

Save it as EvenlySpaceEvents.cs and place it in your Vegas Script Menu folder.

/**
* Program: EvenlySpaceEvents.cs
* Description: This script will evenly space all the events on the selected track within
* the timeline selection.
* Author: John Rofrano
* Copyright: (c) 2009 Sundance Media Group / VASST
*
* Revision Date: July 24, 2009
**/

using System;
using System.Collections;
using System.Windows.Forms;
using Sony.Vegas;

class EntryPoint
{
public void FromVegas(Vegas vegas)
{
try
{
Timecode selectionLength = vegas.Transport.LoopRegionLength;
Timecode selectionStart = vegas.Transport.LoopRegionStart;

// make sure a loop selection is made
if (selectionLength.ToMilliseconds() == 0)
{
throw new ApplicationException("You must create a loop region on the timeline.");
}

foreach (Track track in vegas.Project.Tracks)
{
// only process selected tracks
if (!track.Selected) continue;

// make sure there are at least two events to space
if (track.Events.Count < 2)
{
string errorMessage = "You must have at least two or more events on the selected track to space.";
MessageBox.Show(errorMessage, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
continue; // skip this track
}

// calculate the combined events length
Timecode totalEventTime = Timecode.FromMilliseconds(0);
foreach (TrackEvent trackEvent in track.Events)
{
totalEventTime += trackEvent.Length;
}

// warn if the events won't fit in the selection
if (totalEventTime > selectionLength)
{
string errorMessage = String.Format("You cannot fit {0} of events into a {1} selection.", totalEventTime, selectionLength);
MessageBox.Show(errorMessage, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
continue; // skip this track
}

// calculate the event gap
Timecode emptySpace = selectionLength - totalEventTime;
int gapCount = track.Events.Count - 1; // there is one less gap than events
Timecode eventGap = Timecode.FromMilliseconds(emptySpace.ToMilliseconds() / gapCount);

// space the events evenly
ArrayList eventList = new ArrayList(track.Events);
Timecode nextPosition = selectionStart;
foreach (TrackEvent trackEvent in eventList)
{
trackEvent.Start = nextPosition;
nextPosition = trackEvent.End + eventGap;
}
}
}
catch (Exception e)
{
MessageBox.Show(e.Message, "Evenly Space Events - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}

Enjoy,

~jr
Former user wrote on 7/24/2009, 1:07 PM
JR,

WOW! I am stunned...thank you so much for this....never expected you to just break out the code writer just for little ole me :)

Hey - while I have you here - the VASST freeby Trackilizer is your work - yes? Can it be installed under Vegas Pro 9.0a?

I just bought the 9 upgrade and will be putting it into play here in the coming weeks....and I remember how great this little utility was...here's hoping I can get it going in 9.x...

Update when you can and thanks again!

Cheers!

VP
JohnnyRoy wrote on 7/28/2009, 3:47 AM
You are very welcome. I'm glad you like the new script. If you have any ideas for scripts that would make audio work easier, let me know.

As for Trackalizer, I haven't ported the Freeware applications to Vegas Pro 9.0 yet. I need to get all of the "paid" plug-ins updated first and we're still doing that. But at some point in the near future, Trackalizer along with the others will be updated. It just doesn't work with 9.0 yet (sorry).

~jr
Vadim-Kupriyanov wrote on 10/29/2023, 1:25 PM
Mornin' VP,

The way I figure it, there is no need for a GUI. It would just get in the way of your workflow.

Here is a script that I just wrote for you that should be much faster than using a GUI. Just select the track(s) you want to process and then make a Timeline Selection (i.e., Loop Selection) to designate the area that the events should occupy and this script will evenly space them within that area. They will start at the timeline selection start and end at the timeline selection end. Easy peasy!

Save it as EvenlySpaceEvents.cs and place it in your Vegas Script Menu folder.
Enjoy,

~jr

Hi!
Is it possible to make this script works on Vegas 20?
Best regards,
Vadim

Robert Johnston wrote on 10/29/2023, 3:04 PM

@Vadim-Kupriyanov Hi. Just change Using Sony.Vegas; to Using ScriptPortal.Vegas;

It's the 13th line down with text.

Intel Core i7 10700K CPU @ 3.80GHz (to 4.65GHz), NVIDIA GeForce RTX 2060 SUPER 8GBytes. Memory 32 GBytes DDR4. Also Intel UHD Graphics 630. Mainboard: Dell Inc. PCI-Express 3.0 (8.0 GT/s) Comet Lake. Bench CPU Multi Thread: 5500.5 per CPU-Z.

Vegas Pro 21.0 (Build 108) with Mocha Vegas

Windows 11 not pro

Bofus wrote on 10/29/2023, 3:19 PM

Update to VAAST Pro Ultimate S coming?