Help with AudioBusTrack Mute property

LarryP wrote on 9/27/2004, 5:34 PM
I’m having some newbie problems understanding how to get to the Mute property on the AudioBusTrack class. I’ve been able to loop through the BusTracks to find a specific bus but haven’t been able to go from BusTrack to AudioBusTrack to access the Mute property. The script below gives a “cast” run time error.

Any insight would be appreciated.

Larry


import System.IO;
import System.Windows.Forms;
import Sony.Vegas;
try {
    var busEnum = new Enumerator(Vegas.Project.BusTracks);
    while (!busEnum.atEnd()) {
        MessageBox.Show (" after while statement");
        // Gives a cast error on the next statement
        var bustrack : AudioBusTrack = AudioBusTrack(busEnum.item() ) ;
        MessageBox.Show (" Before if statement");
        // Master should always exist for testing
        if ( bustrack.Name == "Master" ) {
            MessageBox.Show ("Master = " + bustrack);
            bustrack.Mute = true;
        }
        busEnum.moveNext();
    }

} // End try

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

Comments

JohnnyRoy wrote on 9/27/2004, 6:21 PM
Larry,

Because there are two kinds of bus tracks in the Vegas.Project.BusTracks collection (Video and Audio) you can’t simply cast them to AudoBusTracks blindly. That’s why you get a class cast exception when you try to cast the VideoBusTrack as an AudioBusTrack. To fix this you should test the type of BusTrack before you do the cast.

Make the following change to your code and it will work as desired:
var unknownBustrack : BusTrack = BusTrack(busEnum.item());
if (unknownBustrack.IsAudio())
{
var bustrack = AudioBusTrack(unknownBustrack); // safe cast to AudioBusTrack
. . .
}
I happen to favor for() loops instead of using enumerations. Then you can use the continue statement to skip the video bus tracks.

Try this:
for (var busTrack in Vegas.Project.BusTracks)
{
if (busTrack.IsVideo()) continue; // skip VideoBusTracks

if ( bustrack.Name == "Master" )
{
MessageBox.Show ("Master = " + bustrack);
AudioBusTrack(bustrack).Mute = true;
}
}
Notice I don’t do the cast until I need to use the Mute method. If I needed to use the AudioBusTrack in more than one place I would place the cast right after the check for video. Like this:
for (var busTrack in Vegas.Project.BusTracks)
{
if (busTrack.IsVideo()) continue; // skip VideoBusTracks

var audioBusTrack : AudioBusTrack = AudioBusTrack(busTrack);
if ( audioBusTrack.Name == "Master" )
{
MessageBox.Show ("Master = " + audioBusTrack);
audioBusTrack.Mute = true;
}
}
Hope this helps.

~jr
LarryP wrote on 9/27/2004, 7:15 PM
John

This helps immensely! Examples of the AudioBusTrack seem rather rare. Now if only I could set the routing… Maybe next version.

I do like the readability of the “for” structure.

Thanks for taking the time to respond. It’s been awhile since I did any programming (unless you include shell scripting) so this, though frustrating, has been fun.

BTW I figured out how to do the indenting on the forum. How did you get the fixed space font?

Fun back on!

Larry
JohnnyRoy wrote on 9/28/2004, 11:13 AM
> How did you get the fixed space font?

I used the <pre> and </pre> tags to identify that the text is preformatted. That causes the web browser to use a fixed space font.

~jr
johnmeyer wrote on 9/28/2004, 11:41 AM
Using the "pre" tags also preserves the indents, which is really important. THe only downside is that when you copy the listing from the browser to your editor, the end of line characters are line breaks instead of paragraph breaks. For most editors to still show the lines correctly, you need to search/replace the line breaks and replace with paragraph breaks.
LarryP wrote on 9/29/2004, 5:53 PM
I use vim under cygwin with no problems with pasted text but I realize vi isn't everyones favorite editor.

Larry
LarryP wrote on 9/29/2004, 6:22 PM
With a little help my script to do an AB comparison by toggling between the master fader and a track works nicely. The catch is that it stops the play in progress. This makes and AB comparison rather difficult. Bummer.

Unless there is a trick I suspect there is no way to run a script while playing.

[edit] This would sort of work if it were possible to have Vegas "pause" instead of "stop" when a script was run.

Sigh…

Larry
rcampbel wrote on 9/30/2004, 9:06 AM
Larry,

There might be a way to get this to work if you are using Vegas 5 (does not work in Vegas4).

Basically your script needs to display a form with a button(s) on it that do the muting (via the button's click event).

In your script, after you construct the form, use Form.Show() instead of Form.ShowDialog() to display the form. This will cause the form to be displayed, and the script will exit and the Vegas window will now become active. It may look like your script has disappeared, but it is still visible behind the Vegas window.

If you now start playback in the Vegas window and then switch to your script window, you should be able to toggle the mutes, hopefully without stopping playback.

Like I said, I am not sure that this will work for you, but you can give it a try.

Randall
michael_morlan wrote on 10/1/2004, 7:28 AM
Speaking (or writing, as it were) of forms. Are there any form generation tools for JS?

rcampbel wrote on 10/1/2004, 11:03 AM
This is one of the reasons that I write my scripts in C#.

Scripting in C#

Randall
jetdv wrote on 10/1/2004, 11:40 AM
I've created some c# forms in SharpDevelop and then "translated" them into JScript.