An event in a group is not equal to itself?

JohnnyRoy wrote on 7/14/2004, 6:12 PM
OK, My split problems have now turned into grouping problems. Can someone please explain? ;-)

It seems there may be a bug here somewhere because this defies logic. How can an event that is in its own group not compare to itself? The following code should return TRUE but it doesn’t:

Here is the function that should work:
/*
* This function compares the event that is passed in to every event in the group for equality.
*/
function isEventInGroup(evnt : TrackEvent, group : TrackEventGroup) : Boolean
{
for (var groupEvent in group)
{
if (groupEvent.Equals(evnt))
{
return true;
}
}
return false;
}
Now if I pass in an event that is known to be in a group and I also pass in its group, the results should always be true but its not. Here is the calling code:
. . .
if (evnt.IsGrouped) // we establish that the event is in a group
{
// the event should be in its own group?
MessageBox.Show(isEventInGroup(evnt, evnt.Group));
}
. . .
Can someone please explain what’s going on here? This doesn’t make sense to me. Are you making a copy of the event when you place it in a group? Because that would explain why the instances don’t compare. But why would you not just store a pointer to it? How do you know if an event is in a group?

~jr

Comments

dust wrote on 7/14/2004, 11:07 PM
Yes, I noticed the same problem that I asked about in the as well. I suspect the problem is that comparison of events compare references, which are different as soon as a clone (like in Group) is done. The same problem appears if you try to compare Tracks (like comapring Vegas.Project.Tracks[i] against event.Track). Also, as soon as you changed something in an event or track, I would not rely the changed event would still compare as equal to an earlier copy (something like "var e2:TrackEvent=e1; e1.Track = newTrack; if (e1==e2) ...").

The solution is to compare event.Index (index of event in its track) and evnt.Track.Index (index of event's track in Vegas.Project.Tracks). If both are equal, it must be the same event. So, try:


/*
* This function compares the event that is passed in to every event in the group for equality.
*/
function isEventInGroup(evnt : TrackEvent, group : TrackEventGroup) : Boolean
{
for (var groupEvent in group)
{
if (groupEvent.Track.Index == evnt.Track.Index && groupEvent.Index == evnt.Index)
{
return true;
}
}
return false;
}


The problem is known to Sony. SonyPJM stated in this message that this behaviour might be fixed in a future version.

Be careful that the same appears as soon as you compare groups, for example if you try to compare "event.Group" against "Vegas.Project.Groups[..]", which will always return false. Worse, you don't even have an Index property within Group you could use for comparision, as you can using Tracks and Events. To compare groups, you actually must see if all events are equal (using e.Index and e.Track.Index). Not very programmer-friendly.
JohnnyRoy wrote on 7/15/2004, 7:49 AM
Andy,

I'm with ya' Now going back and re-reading those past threads makes sense to me. This is definitely broken. I’ll try the comparison you suggested in my script and see if it solves the problem for now. Obviously as you move events on the timeline its index will change so index is not an immutable property that can be trusted. But this should work if events are not moved out of sequence.

Sony, if you’re listening, add my vote to the fix for this. We really need a way to compare two objects for equality when working with collections.

~jr
dust wrote on 8/4/2004, 11:24 PM
I might have found another workaround for your problem,
see this thread
JohnnyRoy wrote on 8/5/2004, 4:27 AM
I love it! This seems like a reasonable workaround. Perhaps we can get Sony to just make them public in the next release of the API. That would Rock! Thanks for figuring this out.

~jr