From 89551c3bd4f45e54e594b9d620ccfd22775f8d93 Mon Sep 17 00:00:00 2001 From: Patrice Mandin Date: Sat, 9 Jul 2005 14:39:59 +0000 Subject: [PATCH] Add RWops support also for native midi gpl (todo: mac and win32 native midi) --- music.c | 17 ++++++++++++++--- native_midi/native_midi.h | 3 +++ native_midi/native_midi_mac.c | 5 +++++ native_midi/native_midi_win32.c | 5 +++++ native_midi_gpl/native_midi_gpl.c | 24 ++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) diff --git a/music.c b/music.c index 01d406d6..441d1a45 100644 --- a/music.c +++ b/music.c @@ -1355,10 +1355,21 @@ Mix_Music *Mix_LoadMUS_RW(SDL_RWops *rw) { /* MIDI files have the magic four bytes "MThd" */ if ( strcmp((char *)magic, "MThd") == 0 ) { music->type = MUS_MID; + music->error = 1; +#ifdef USE_NATIVE_MIDI + if ( native_midi_ok ) { + music->data.nativemidi = native_midi_loadsong_RW(rw); + if ( music->data.nativemidi ) { + music->error = 0; + } + } MIDI_ELSE +#endif #ifdef USE_TIMIDITY_MIDI - music->data.midi = Timidity_LoadSong_RW(rw); - if ( music->data.midi == NULL ) { - music->error = 1; + if ( timidity_ok ) { + music->data.midi = Timidity_LoadSong_RW(rw); + if ( music->data.midi ) { + music->error = 0; + } } #endif } else diff --git a/native_midi/native_midi.h b/native_midi/native_midi.h index 5869def4..3b8e6db6 100644 --- a/native_midi/native_midi.h +++ b/native_midi/native_midi.h @@ -23,10 +23,13 @@ #ifndef _NATIVE_MIDI_H_ #define _NATIVE_MIDI_H_ +#include + typedef struct _NativeMidiSong NativeMidiSong; int native_midi_detect(); NativeMidiSong *native_midi_loadsong(char *midifile); +NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *rw); void native_midi_freesong(NativeMidiSong *song); void native_midi_start(NativeMidiSong *song); void native_midi_stop(); diff --git a/native_midi/native_midi_mac.c b/native_midi/native_midi_mac.c index 3590a27a..a9569f06 100644 --- a/native_midi/native_midi_mac.c +++ b/native_midi/native_midi_mac.c @@ -150,6 +150,11 @@ NativeMidiSong *native_midi_loadsong(char *midifile) return NULL; } +NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *rw) +{ + return NULL; +} + void native_midi_freesong(NativeMidiSong *song) { if(!song || !song->tuneSequence) diff --git a/native_midi/native_midi_win32.c b/native_midi/native_midi_win32.c index 0631c291..89546834 100644 --- a/native_midi/native_midi_win32.c +++ b/native_midi/native_midi_win32.c @@ -215,6 +215,11 @@ NativeMidiSong *native_midi_loadsong(char *midifile) return newsong; } +NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *rw) +{ + return NULL; +} + void native_midi_freesong(NativeMidiSong *song) { if (hMidiStream) diff --git a/native_midi_gpl/native_midi_gpl.c b/native_midi_gpl/native_midi_gpl.c index 2fc85c15..d783b74f 100644 --- a/native_midi_gpl/native_midi_gpl.c +++ b/native_midi_gpl/native_midi_gpl.c @@ -212,6 +212,30 @@ NativeMidiSong *native_midi_loadsong(char *midifile) return NULL; } +NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *rw) +{ + NativeMidiSong *song = NULL; + char *extra; + + song = malloc(sizeof(NativeMidiSong)); + if (!song) { + return NULL; + }; + + SDL_RWseek(rw, 0, SEEK_END); + song->file_size = SDL_RWtell(rw, 0, SEEK_CUR); + SDL_RWseek(rw, 0, SEEK_SET); + + song->filebuf = malloc(song->file_size); + if (!song->filebuf) { + free(song); + return NULL; + } + + SDL_RWread(rw, song->filebuf, song->file_size, 1); + return song; +} + void native_midi_freesong(NativeMidiSong *song) { free(song->filebuf);