How to read MODs using RWops

Hi All,

Now with the MODs (and only MODs and other formats supported by MikMod, no
MP3, no MID, no nothing). This is for SDL_mixer-1.2.0. Again I don’t know
how to use diff, so here is the explanation:

. In file SDL_mixer.h line 93 change ‘#if 0’ to ‘#ifdef USE_RWOPS’
. In file music.c just after the function open_music:

-----cut here-----
#ifdef USE_RWOPS

Mix_Music *Mix_LoadMUS_RW(SDL_RWops rw) {
/Uint8 magic[5]; Apparently there is no way to check if the
file is really a MOD,
/
/
or there are too many formats supported by
MikMod or MikMod does /
/
this check by itself. If someone implements
other formats (e.g. MP3) /
/
the check can be uncommented */
Mix_Music *music;

  /* Just skip the check */
/* Figure out what kind of file this is */
/*if (SDL_RWread(rw,magic,1,4)!=4) {
	Mix_SetError("Couldn't read from RWops");
	return NULL;
}
magic[4]='\0';*/

/* Allocate memory for the music structure */
music=(Mix_Music *)malloc(sizeof(Mix_Music));
if (music==NULL ) {
	Mix_SetError("Out of memory");
	return(NULL);
}
music->error = 0;

#ifdef MOD_MUSIC
if (1) {
music->type=MUS_MOD;
music->data.module=MikMod_LoadSongRW(rw,64);
if (music->data.module==NULL) {
Mix_SetError("%s",MikMod_strerror(MikMod_errno));
music->error=1;
}
} else
#endif
{
Mix_SetError(“Unrecognized music format”);
music->error=1;
}
if (music->error) {
free(music);
music=NULL;
}
return(music);
}

#endif /* USE_RWOPS */
-----cut here-----

The rest of the work (inside MikMod) has already been done by Matt Campbell.
Just compile SDL_mixer with -DUSE_RWOPS and everything should work just fine
(no very ugly hacks with memory leaks like reading fonts with RWops, see
my previous post).

Regards,

Andre de Leiradella