Skip to content

Commit

Permalink
Add RWops support also for native midi gpl (todo: mac and win32 nativ…
Browse files Browse the repository at this point in the history
…e midi)
  • Loading branch information
pmandin committed Jul 9, 2005
1 parent f0868f5 commit 89551c3
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
17 changes: 14 additions & 3 deletions music.c
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions native_midi/native_midi.h
Expand Up @@ -23,10 +23,13 @@
#ifndef _NATIVE_MIDI_H_
#define _NATIVE_MIDI_H_

#include <SDL_rwops.h>

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();
Expand Down
5 changes: 5 additions & 0 deletions native_midi/native_midi_mac.c
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions native_midi/native_midi_win32.c
Expand Up @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions native_midi_gpl/native_midi_gpl.c
Expand Up @@ -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);
Expand Down

0 comments on commit 89551c3

Please sign in to comment.