Advice Needed

Cheesehole wrote on 1/9/2004, 11:17 PM
My goal is to create a single collection of events encompassing multiple tracks in order by each event's start time. I feel like there must be a better way than what I am doing.

I didn't have any success using the Track.Events.CopyTo() method. It kept telling me my target index was too low. Or it was too small. Or it was the wrong type. Picky picky..

I used this round about method and it works but it's really ugly! I made a function to convert the Track.Events into arrays and then .concat'd them into a single Array.

var eventArray = new Array;
eventArray = eventArray.concat( getArrayfromCollection(track1.Events) , getArrayfromCollection(track2.Events) , getArrayfromCollection(track3.Events) , getArrayfromCollection(audio_track.Events));

eventArray.sort(compareStartTimes);

function getArrayfromCollection(col) {
c = new Enumerator (col);
var a = new Array;
while(!c.atEnd()) {
a.push(c.item());
c.moveNext();
}
return a;
}

function compareStartTimes(a,b) {
var num_a = a.Start.ToMilliseconds();
var num_b = b.Start.ToMilliseconds();
if (num_a < num_b) return -1;
else {
if (num_a > num_b) return 1;
else return 0;
}
}

Comments

jetdv wrote on 1/10/2004, 5:25 AM
Not sure I understand what your goal is, but I might be able to help with the copy command. How were you using it?
Cheesehole wrote on 1/29/2004, 2:31 PM
My goal is to get all the events from various tracks into a single collection so I can perform operations on ALL the events at once. As far as I can tell, you can only access events by Track.Events, but that only gives me a collection of events from that specific track object. Maybe I'm missing something obvious.

For example, I wrote a script that extends the lengths of all events to butt up against the next event whether the next event is on the same track or not. So I had to use that method above of creating an Array of objects from one track and concatenating it with another Array of objects (events) from the next track, etc... and then sort them by start time so I can perform operations on the events in sequence by start time.

I realized after posting my initial question that by using the CopyTo function I was actually trying to add events to the actual track in Vegas. That was a flaw in my logic. I don't want to actually combine all the events onto a single track, I just want to work on them in a single Collection.

I'm wondering if everyone else does it like I did... just make a new Array to hold all the Event objects from various Tracks.