I played with 5.0b's grouping support, and it seems to work flawlessly so far, which is great!!
One thing that has to be noted now though is that the Split-method of the API doesn't work like "S" (split command from keyboard) because it puts all events into only one group. This can now be handled better and because there are a few critical points about it, I thought it might be interesting to post the function I wrote here (I didn't check this against syntax errors, as it looks slightly different in the script I originally wrote - take it as a template). The function takes an event and a timecode as input and then splits all events grouped with the original event at this location; the "left" and "right" halves will end in their own groups:
One bug I originally had and you should be careful about is that if an event e is not grouped, e.Group will be empty. But of course an event is inherently always "grouped with itself". This is why I had to take care of the case that e.IsGrouped is false above.
One thing I miss is the ability to compare 2 groups. I didn't find a way... for example, if you want to find out if 2 events e1 and e2 are grouped, you can't say "e1.Group == e2.Group", this will always be false (as is the case with tracks). Something like "e1.Group.Index == e2.Group.Index" would work - if Group had an Index property (like Track does - you can compare tracks by comparing their indexes). The only way I found is using a function that returns a group index for an event, like (returning -1 for isolated events):
...and then compare the 2 events getGroup(e)-results.
So, to find out if an event is inside a given group, I must compare it to all events of this group. To make it worse, you can only compare 2 events by comparing their track indices and their event-indices-within-this-track. This is quite tedious for something where a simple
One thing that has to be noted now though is that the Split-method of the API doesn't work like "S" (split command from keyboard) because it puts all events into only one group. This can now be handled better and because there are a few critical points about it, I thought it might be interesting to post the function I wrote here (I didn't check this against syntax errors, as it looks slightly different in the script I originally wrote - take it as a template). The function takes an event and a timecode as input and then splits all events grouped with the original event at this location; the "left" and "right" halves will end in their own groups:
...
import System.Collections;
...
function doSplit(evnt:TrackEvent, tc:Timecode)
{
var group : TrackEventGroup = new TrackEventGroup();
Vegas.Project.Groups.Add(group);
var evntsToSplit = new Queue();
if (evnt.IsGrouped)
for (var e in evnt.Group)
{
if (e.Start < tc && tc < e.Start+e.Length)
evntsToSplit.Enqueue(e);
}
else evntsToSplit.Enqueue(evnt);
for (var toSplit in evntsToSplit)
group.Add(toSplit.Split(tc - toSplit.Start));
}
...
One bug I originally had and you should be careful about is that if an event e is not grouped, e.Group will be empty. But of course an event is inherently always "grouped with itself". This is why I had to take care of the case that e.IsGrouped is false above.
One thing I miss is the ability to compare 2 groups. I didn't find a way... for example, if you want to find out if 2 events e1 and e2 are grouped, you can't say "e1.Group == e2.Group", this will always be false (as is the case with tracks). Something like "e1.Group.Index == e2.Group.Index" would work - if Group had an Index property (like Track does - you can compare tracks by comparing their indexes). The only way I found is using a function that returns a group index for an event, like (returning -1 for isolated events):
...
function getGroup(e:TrackEvent): int
{
if (!e.IsGrouped) return -1;
for (var gr = 0; gr < Vegas.Project.Groups.Count; gr++)
{
for (var e2 in Vegas.Project.Groups[gr])
{
if (e2.Track.Index == e.Track.Index && e2.Index == e.Index)
return (gr);
}
}
return -1;
}
...
...and then compare the 2 events getGroup(e)-results.
So, to find out if an event is inside a given group, I must compare it to all events of this group. To make it worse, you can only compare 2 events by comparing their track indices and their event-indices-within-this-track. This is quite tedious for something where a simple
if (grp.Index == e.Group.Index)would suffice. Or did I oversee something simple..?