Comments

lnetzel wrote on 8/8/2003, 1:54 AM
It would be good if you posted the actually row of code so that we would know what the problem is. And maybe even the whoel script and mark that row.. and also, explain WHEN it happens in the execute.
jetdv wrote on 8/8/2003, 8:11 AM
You may try adding "var " in front of this line. Especially if it says something like "PanOptionForm = ??????" change it to "var PanOptionForm = ?????"
herb wrote on 8/8/2003, 12:52 PM
Here is the code hope it helps again thanks I said I'm new at this and know about scripting.

//******************************************************************
// Program: QuickPan
// Version: 1.0
// Author: John Rofrano (a.k.a JohnnyRoy) john_rofrano@hotmail.com
// Comments: This script will create a Pan envelope that pans either
// left or right for the duration of a timeline selection.
// History: 1.0 - initial release
//
// Special thanks to Roger Magnusson for his QuickEnvelope script
// from which most of this code is based.
//******************************************************************

import SonicFoundry.Vegas;
import System.Windows.Forms;
import Microsoft.Win32;
import QuickPan;

try
{
// Start by making sure you have a timeline selection and a selected track
// otherwise its useless to show the dialog and go on
var selectionStart : Timecode = Vegas.SelectionStart;
var selectionLength : Timecode = Vegas.SelectionLength;
if (selectionLength.FrameCount == 0) throw "Error: You must make a Timeline selection first.";

// Get the first selected Audio track
var selectedTrack : Track = FindSelectedTrack(MediaType.Audio);
if (selectedTrack == null)
{
throw "Error: You must select an Audio track.";
}

// declare some variables to use as output from dialog interaction
var leadInLeadOut : Timecode;
var panAmount : double = 0.0;

var panSelection : PanOptionForm = new PanOptionForm();
var result = panSelection.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
leadInLeadOut = new Timecode(panSelection.LeadInLeadOut * 100); // multiply for milliseconds
panAmount = panSelection.Pan / 100; // valid Pan amount is a fraction between -1 and 1

// Check to make sure leadin/out does not exceed selection. If so, adjust to half selection length
var doubleLeadin : Timecode = new Timecode(leadInLeadOut.ToMilliseconds() * 2);
if (doubleLeadin > selectionLength)
{
leadInLeadOut = new Timecode((selectionLength.ToMilliseconds() / 2) - 2); // keep 2ms appart
}

AddPanPoints(selectedTrack, selectionStart, selectionLength, leadInLeadOut, panAmount);
}
}
catch (errorMsg)
{
MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}

/*
* Adds a Pan envelope given an Audio track and start position and a length
*/
function AddPanPoints(selectedTrack : Track, selectionStart : Timecode, selectionLength : Timecode, leadInLeadOut : Timecode, panAmount : double)
{
const MinimumPointDelay : Timecode = new Timecode(0.00005);

//You can't add two points at the same Timecode, which is what we probably want to do if the track is to be muted.
//So, we add a delay of 0.00005 milliseconds between the points.
if (leadInLeadOut.ToMilliseconds() == 0) leadInLeadOut = MinimumPointDelay

// Try and get the Pan Envelope and add one if it doesn't exist
var panEnvelope : Envelope = FindEnvelope(selectedTrack, EnvelopeType.Pan);
if (panEnvelope == null)
{
panEnvelope = new Envelope(EnvelopeType.Pan);
selectedTrack.Envelopes.Add(panEnvelope);
}

//Get the pan on any point before the selected time
var previousPointY : double = FindPointYBeforeTimecode(selectionStart, panEnvelope.Points);

// Check to see if there are any pan points already within the selection and
// change the outermost two (i.e., first and last) to have the new panAmount
var firstInnerPoint : EnvelopePoint = FindPointBetweenTimecode(selectionStart, selectionStart + selectionLength,panEnvelope.Points, true);
if (firstInnerPoint != null)
{
firstInnerPoint.Y = panAmount;
}

var lastInnerPoint: EnvelopePoint = FindPointBetweenTimecode(selectionStart, selectionStart + selectionLength,panEnvelope.Points, false);
if (lastInnerPoint != null)
{
lastInnerPoint.Y = panAmount;
}

// Adjust existing points or add new points as needed
ProcessEnvelopePoint(panEnvelope.Points, selectionStart, previousPointY);
ProcessEnvelopePoint(panEnvelope.Points, selectionStart + leadInLeadOut, panAmount);
ProcessEnvelopePoint(panEnvelope.Points, selectionStart + selectionLength - leadInLeadOut, panAmount);
ProcessEnvelopePoint(panEnvelope.Points, selectionStart + selectionLength, previousPointY);
}

/*
* Finds the first selected track based on the MediaType passed in
*/
function FindSelectedTrack(trackType : MediaType) : Track
{
var trackEnum : Enumerator = new Enumerator(Vegas.Project.Tracks);
while (!trackEnum.atEnd())
{
var track : Track = Track(trackEnum.item());
if (track.Selected && (track.MediaType == trackType))
{
return track;
}
trackEnum.moveNext();
}
return null;
}

/*
* Finds the envelope of the type passed in
*/
function FindEnvelope(track : Track, etype : EnvelopeType) : Envelope
{
var envelopeEnum : Enumerator = new Enumerator(track.Envelopes);
//Go through all envelopes and look for the specified type
while (!envelopeEnum.atEnd())
{
var envelope : Envelope = envelopeEnum.item();

if (envelope.Type == etype)
{
return envelope;
}
envelopeEnum.moveNext();
}
return null;
}

/*
* This function will search for the first point before the timecode.
*/
function FindPointYBeforeTimecode(selstart : Timecode, envPoints : EnvelopePoints) : double
{
var pointsEnum : Enumerator = new Enumerator(envPoints);
var time : Timecode = new Timecode(0);
var lastY : double = 0;

while (!pointsEnum.atEnd() && time < selstart)
{
var point : EnvelopePoint = pointsEnum.item();

time = point.X;
if (time < selstart)
{
lastY = point.Y;
}
else
{
break; // optimization: no need to continue one time > selstart
}
pointsEnum.moveNext();
}
return lastY;
}

/*
* This function will search for the first or last point between two timecodes (selstart and selend)
* It will return a valid EnvelopePoint or null to indicate none was found
* Set the stopAtFirst flag to true for the first point or false for last point
*/
function FindPointBetweenTimecode(selstart : Timecode, selend : Timecode, envPoints : EnvelopePoints, stopAtFirst : boolean) : EnvelopePoint
{
var pointsEnum : Enumerator = new Enumerator(envPoints);
var time : Timecode = new Timecode(0);
var firstPoint : EnvelopePoint = null;

// process for duration of selection
while (!pointsEnum.atEnd() && time < selend)
{
var point : EnvelopePoint = pointsEnum.item();
time = point.X;

if (time < selstart)
{
pointsEnum.moveNext();
continue; // iterate again until past the start
}

if (time < selend)
{
firstPoint = point;
if (stopAtFirst)
{
break;
}
}
pointsEnum.moveNext();
}
return firstPoint;
}

/*
* This function will modify an existing envelope point or add a new one if needed
*/
function ProcessEnvelopePoint(envPoints : EnvelopePoints, position : Timecode, value : double)
{
if (envPoints.Contains(position))
{
var point : EnvelopePoint = envPoints.GetPointAtX(position);
point.Y = value;
}
else
{
envPoints.Add(new EnvelopePoint(position, value));
}
}
jetdv wrote on 8/8/2003, 2:06 PM
Do you have a QuickPan.dll and a QuickPan.xml file? Sounds like you may be missing one or the other. The "Imports QuickPan" is actually importing the screen. You could always e-mail John at the e-mail address in the script.
herb wrote on 8/8/2003, 2:43 PM
Thank you yes I have the other files and I placed them in the Vegas Dir and in the dir I named scripts. I e-mailed John and now waiting for his reply. Thanks for trying to help me.
JohnnyRoy wrote on 8/21/2003, 6:57 PM
Sorry, I was on vacation for the last 2 weeks. Herb emailed me but this one has got me stumped as well. Line 37 of the code is:

var panSelection : PanOptionForm = new PanOptionForm();

I had Herb move the DLL and XML file to the same directory as the JS file but now he’s getting:

"Error on line 37 Type Name Expected"

I looked this error up and got the following explanation:

JScript .NET
JS1112: Type name expected
A required type name is misspelled or omitted. Type names are required following a colon in the definition of a variable, constant, function, or parameter.

To correct this error
Make sure that a valid data type identifier is used where a type name is expected.

The error message sounds like it should happen on everyones machine if it were really misspelled or omitted. This works fine on my Windows XP Home machine. Does anyone have a clue as to why this might not be working on his XP Pro machine?

~jr