Skip to content
Permalink
Browse files

Add RWops support also for native midi gpl (todo: mac and win32 nativ…

…e midi)
  • Loading branch information
pmandin committed Jul 9, 2005
1 parent f0868f5 commit 89551c3bd4f45e54e594b9d620ccfd22775f8d93
Showing with 51 additions and 3 deletions.
  1. +14 −3 music.c
  2. +3 −0 native_midi/native_midi.h
  3. +5 −0 native_midi/native_midi_mac.c
  4. +5 −0 native_midi/native_midi_win32.c
  5. +24 −0 native_midi_gpl/native_midi_gpl.c
17 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
@@ -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();
@@ -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)
@@ -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)
@@ -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);

0 comments on commit 89551c3

Please sign in to comment.