Get loop region in code or find total playtime of event

I’m trying to synchronize some gameplay events to the beat of a song. I can retrieve the BPM of the event that is currently playing, but for testing and ease of use I need to set various loop regions in the song, meaning the duration of the event does not match the actual duration in practice.

I would be able to account for this if I could either retrieve the loop region somehow, or if I could find the total playtime of the event.

getTimelinePosition isn’t viable because it will reset as the loop region loops.

I could count time myself or possibly detect the looping by looking at the position in the callback and maintaining my own loop counter, but since the length and position of the loop will change, this seems brittle.

Currently you can make use of TIMELINE_MARKER and TIMELINE_BEAT callbacks for synchronization.

What is it that you are trying to do?

Ideally I would like to have a timer/counter that can tell me how long the event has been playing. TIMELINE_BEAT will reset as the loop marker loops, so that doesn’t convey the actual passed time.

My current workaround is checking getTimelinePosition continuously, if it’s less than the last time I increment a loop counter and use the event length (which I can find via EventInstance.getDescription) to calculate a total playtime. This means I can’t set a loop region to anything but the entire event, but it’s an acceptable compromise.

What I am trying to achieve is to synchronize events in the game with the music, something will happen and I will adjust its timing to fall on a beat in the song. This is much easier if I don’t have to care about the song looping and can just have an ever increasing timer.

As an aside, because I am also animating things using the event timeline position and it only updates every 20ms (because fmod api) I need to interpolate that time myself to keep things smooth above 50 fps, which is also workable, but yet another hassle.

Either way, I worked it out. Thanks for an excellent piece of software!

1 Like