www.jetdv.com Forum Index Edward Troxel
Vegas Scripting and Newsletters
Home of Excalibur and Montage Magic
 
 FAQ   Search   Memberlist   Usergroups   Register   Profile 
 Log in to check your private messagesLog in to check your private messages   Log inLog in 

Add multiple files to a track

 
Post new topic   Reply to topic    www.jetdv.com Forum Index -> Scripting FAQ
View previous topic :: View next topic  
Author Message
johnw



Joined: 24 Mar 2006
Posts: 6

PostPosted: Fri Mar 24, 2006 9:47 pm    Post subject: Add multiple files to a track Reply with quote

Okay, this seems like it should be simple. I have a directory of wav files, and want to create a new track and add them to it so they're all in a single line. I adapted the script given as an answer to question 2.4 of Paul Manley's FAQ (http://www.ayizwe.net/VegasScripts/FAQ.html#2.4) but am having problems.

I can add the first file OK, but every file after that gets added in at exactly two seconds in. No matter how I set vegas.Cursor, it stays "stuck" at 00:02:00:00. Below is the code I'm currently using (in C#). At the moment, I'm trying to set the cursor to be at the end of the project by using project.Length, but I've also tried keeping track of the total number of milliseconds of the wav files, as well as trying to set the cursor using the current track.Length.

Also, I'm getting a lot of little orange flags on my track when I do this; I don't know what those things are.

Code:

vegas.NewProject(false, false);

Project proj = vegas.Project;
Track audioTrack = new AudioTrack(1, "myTrack");
proj.Tracks.Add(audioTrack);

string[] files = Directory.GetFiles(@"c:\myfiles\", "*.wav");

Array.Sort(files);

foreach( string file in files )
{
   
   Media media = new Media(file);
   if(media.IsValid())
   {
      vegas.Cursor = vegas.Project.Length;
      MediaStream stream = media.Streams.GetItemByMediaType(MediaType.Audio, 0);
      AudioEvent newEvent = new AudioEvent( vegas.Cursor, stream.Length );
      audioTrack.Events.Add(newEvent);
      Take take = new Take(stream);
      newEvent.Takes.Add(take);   
   }
}


If anyone could help me out it would be much appreciated. Thanks!
Back to top
View user's profile Send private message
Edward Troxel
Site Admin


Joined: 14 Jul 2004
Posts: 5475

PostPosted: Fri Mar 24, 2006 9:59 pm    Post subject: Reply with quote

At a quick glance, it certainly looks like it should work.

Wondering why this:
vegas.Cursor = vegas.Project.Length;

wasn't this:
vegas.Cursor = proj.Length;

Alternately, it could be:
vegas.Cursor = audioTrack.Length;


In looking at my code, this line:
AudioEvent newEvent = new AudioEvent( vegas.Cursor, stream.Length );

should be:
AudioEvent newEvent = new AudioEvent( vegas.Cursor, media.Length );

In fact, you could change it to:
AudioEvent newEvent = new AudioEvent( audioTrack.Length, media.Length );

and totally eliminate "vegas.Cursor" from the mix.
Back to top
View user's profile Send private message Send e-mail
johnw



Joined: 24 Mar 2006
Posts: 6

PostPosted: Fri Mar 24, 2006 10:13 pm    Post subject: Reply with quote

To answer your question I had tried all three of those but none of them helped.

However, changing this line
AudioEvent newEvent = new AudioEvent( vegas.Cursor, stream.Length );

to this:
AudioEvent newEvent = new AudioEvent( audioTrack.Length, media.Length );

made it work for me (but the FAQ says stream.Length! grr...).

At any rate, it's working now... Thanks!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    www.jetdv.com Forum Index -> Scripting FAQ All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.11 © 2001, 2002 phpBB Group