BouKiCHi/mdxplayer — pull request #5 by mistydemeo (2012-11-14 05:31:23+00:00)
Title: Make it possible to keep multiple mdxmini instances operating

mdxmini uses a few global variables to store critical song data, so it's not possible to work with multiple songs at the same time. Opening a new song erases the data from the other song.

Unfortunately that also means that using `mdx_stop()` can cause the program to crash if you've created more than one `t_mdxmini` pointer - after all, running it on separate pointers is double-freeing the global pointers!

That didn't work too well for me with the object-oriented mdxmini interface I'm writing, so I've replaced the global variables with proper local variables. The global pointers are now stored in a new `songdata` struct, which is stored at the end of a `t_mdxmini` struct, and I've modified all of the mdxplay internals to pass those around as appropriate. (I had to do a lot of major surgery to make it work. :cry:)

But it's finished! I've tested using sdlplay and my own player, as well as using valgrind, and it completely works as expected without causing any negative side effects.

This necessitated a few API changes at the mdxmini level, but only a few; most of the changes are in the original mdxplay innards.

The changed functions are:

mdx_make_buffer (also takes a struct as the first argument)
mdx_get_buffer_size (takes a struct as an argument rather than void)
mdx_get_sample_size (takes a struct as an argument rather than void)