libsdl-org / SDL_mixer

An audio mixer that supports various file formats for Simple Directmedia Layer.
zlib License
435 stars 147 forks source link

add Mix_SetMusicBeat and Mix_GetMusicBeat #481

Open connorjclark opened 1 year ago

connorjclark commented 1 year ago

I have a use case where I must set the position of MIDI music to a particular beat index (something supported by the old allegro 4 midi player, and perhaps other midi players).

Example MIDI: https://drive.google.com/file/d/1qiE7sVyvQoVRxJftKhz-n4juuArfwri8/view?usp=share_link

And positions of tunes within:

0:    Wind Fish
81:   Overworld
233:  Hyrule Castle
553:  Lost Woods
814:  Great Sea
985:  East Hyrule
1153: Dancing Dragon
1333: Stone Tower
1556: Villages
1801: Swamp + Desert
2069: Outset Island
2189: Kakariko Village
2569: Clock Town
2753: Temple
2856: Dark World
3042: Dragon Roost
3125: Horse Race
3217: Credits
3296: Zelda's Lullaby

Note: I'm not certain if there's an off-by-one error in this code, or in the source midi player these positions are defined to work in (allegro 4), but I found I need to take the beat values above and subtract one to get the exact right positioning.

You can use the playmus example program to seek to a specific tune (you'll need a timidity.cfg and soundfont within your build directory, as always):

./playmus -n 552 TheTravelsOfLink.mid

Draft until some feedback (then I'll update the other music interfaces with NULL stubs).