Add RWops support also for native midi gpl (todo: mac and win32 native midi)
authorPatrice Mandin <patmandin@gmail.com>
Sat, 09 Jul 2005 14:39:59 +0000
changeset 2691c015da5a712
parent 268 89be3dca06fa
child 270 d3c0033fed68
Add RWops support also for native midi gpl (todo: mac and win32 native midi)
music.c
native_midi/native_midi.h
native_midi/native_midi_mac.c
native_midi/native_midi_win32.c
native_midi_gpl/native_midi_gpl.c
     1.1 --- a/music.c	Sat Jul 09 05:55:12 2005 +0000
     1.2 +++ b/music.c	Sat Jul 09 14:39:59 2005 +0000
     1.3 @@ -1355,10 +1355,21 @@
     1.4  	/* MIDI files have the magic four bytes "MThd" */
     1.5  	if ( strcmp((char *)magic, "MThd") == 0 ) {
     1.6  		music->type = MUS_MID;
     1.7 +		music->error = 1;
     1.8 +#ifdef USE_NATIVE_MIDI
     1.9 +		if ( native_midi_ok ) {
    1.10 +			music->data.nativemidi = native_midi_loadsong_RW(rw);
    1.11 +			if ( music->data.nativemidi ) {
    1.12 +				music->error = 0;
    1.13 +			}
    1.14 +		} MIDI_ELSE
    1.15 +#endif
    1.16  #ifdef USE_TIMIDITY_MIDI
    1.17 -		music->data.midi = Timidity_LoadSong_RW(rw);
    1.18 -		if ( music->data.midi == NULL ) {
    1.19 -			music->error = 1;
    1.20 +		if ( timidity_ok ) {
    1.21 +			music->data.midi = Timidity_LoadSong_RW(rw);
    1.22 +			if ( music->data.midi ) {
    1.23 +				music->error = 0;
    1.24 +			}
    1.25  		}
    1.26  #endif
    1.27  	} else
     2.1 --- a/native_midi/native_midi.h	Sat Jul 09 05:55:12 2005 +0000
     2.2 +++ b/native_midi/native_midi.h	Sat Jul 09 14:39:59 2005 +0000
     2.3 @@ -23,10 +23,13 @@
     2.4  #ifndef _NATIVE_MIDI_H_
     2.5  #define _NATIVE_MIDI_H_
     2.6  
     2.7 +#include <SDL_rwops.h>
     2.8 +
     2.9  typedef struct _NativeMidiSong NativeMidiSong;
    2.10  
    2.11  int native_midi_detect();
    2.12  NativeMidiSong *native_midi_loadsong(char *midifile);
    2.13 +NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *rw);
    2.14  void native_midi_freesong(NativeMidiSong *song);
    2.15  void native_midi_start(NativeMidiSong *song);
    2.16  void native_midi_stop();
     3.1 --- a/native_midi/native_midi_mac.c	Sat Jul 09 05:55:12 2005 +0000
     3.2 +++ b/native_midi/native_midi_mac.c	Sat Jul 09 14:39:59 2005 +0000
     3.3 @@ -150,6 +150,11 @@
     3.4  	return NULL;
     3.5  }
     3.6  
     3.7 +NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *rw)
     3.8 +{
     3.9 +	return NULL;
    3.10 +}
    3.11 +
    3.12  void native_midi_freesong(NativeMidiSong *song)
    3.13  {
    3.14  	if(!song || !song->tuneSequence)
     4.1 --- a/native_midi/native_midi_win32.c	Sat Jul 09 05:55:12 2005 +0000
     4.2 +++ b/native_midi/native_midi_win32.c	Sat Jul 09 14:39:59 2005 +0000
     4.3 @@ -215,6 +215,11 @@
     4.4    return newsong;
     4.5  }
     4.6  
     4.7 +NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *rw)
     4.8 +{
     4.9 +	return NULL;
    4.10 +}
    4.11 +
    4.12  void native_midi_freesong(NativeMidiSong *song)
    4.13  {
    4.14    if (hMidiStream)
     5.1 --- a/native_midi_gpl/native_midi_gpl.c	Sat Jul 09 05:55:12 2005 +0000
     5.2 +++ b/native_midi_gpl/native_midi_gpl.c	Sat Jul 09 14:39:59 2005 +0000
     5.3 @@ -212,6 +212,30 @@
     5.4      return NULL;
     5.5  }
     5.6  
     5.7 +NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *rw)
     5.8 +{
     5.9 +	NativeMidiSong	*song = NULL;
    5.10 +	char 		*extra;
    5.11 +
    5.12 +	song = malloc(sizeof(NativeMidiSong));
    5.13 +	if (!song) {
    5.14 +		return NULL;
    5.15 +	};
    5.16 +
    5.17 +	SDL_RWseek(rw, 0, SEEK_END);
    5.18 +	song->file_size = SDL_RWtell(rw, 0, SEEK_CUR);
    5.19 +	SDL_RWseek(rw, 0, SEEK_SET);
    5.20 +
    5.21 +	song->filebuf = malloc(song->file_size);
    5.22 +	if (!song->filebuf) {
    5.23 +		free(song);
    5.24 +		return NULL;
    5.25 +	}
    5.26 +
    5.27 +	SDL_RWread(rw, song->filebuf, song->file_size, 1);
    5.28 +	return song;
    5.29 +}
    5.30 +
    5.31  void native_midi_freesong(NativeMidiSong *song)
    5.32  {
    5.33      free(song->filebuf);