GP32 How To Detect The End Of A Music In Chn's Lib?


Oankali

Member
Joined
Jan 5, 2004
Messages
133
Age
56
Location
Andorra
Website
www.nekanium.com
In my game Pyramids 2 I've implemented a ring to play MODs randomly with CHN's lib.
When all was finished and debugged and I played for a long time, I noted that CHN's lib plays the same melody eternally if you don't stop it intentionally.
Is there a way to detect the end of a music?

Oankali
 
In the old days of mod trackers, the mods would just repeat again after coming to the end of the song. It shouldn't be hard to determine the end of a song (it occurs when you play the last row of the last pattern in the pattern order table), though I'd imagine you may have to modify the code of the mod player if it doesn't support this already.
 
You can use the songpos attribute of the mod object to determine wich pattern is currently being played. If that attribute changes from a nonzero value to zero, the player has looped the song and you can stop it, load another tune and start playing that.
 
You can use the songpos attribute of the mod object to determine wich pattern is currently being played. If that attribute changes from a nonzero value to zero, the player has looped the song and you can stop it, load another tune and start playing that.

Thanks Inopia, that seems to work, you will see the result in the last version of Pyramids 2, a lot better than the ADIC2004 version. It's a shame I didn't have time to finish it for the compo.

But now I have two little doubts: if the mod is small and has only one pattern, won't it loop eternally? Should I track also mod.patternline?
And also, can it be possible to a mod to play patterns in this order ABBACCA...? That would mean that mod.songpos can return to 0, without having played all the patterns, right?
I don't know how mods are generated, that's why I'm asking.

Oankali
 
Last edited by a moderator:
From the name of the variable, I think modpos is the position in the pattern-order list, not the actual pattern id number. So it, in theory, should work.
 
Back
Top