Skip to content

Commit

Permalink
Fixed bug 2909 - Mix_PauseMusic and Mix_ResumeMusic not working on MI…
Browse files Browse the repository at this point in the history
…DI (.mid)

Philipp Wiesemann

This is a patch to make Mix_PauseMusic() and Mix_ResumeMusic() work with the Windows native MIDI decoder.
  • Loading branch information
slouken committed Oct 18, 2017
1 parent 7f11e57 commit 13b57d6
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
14 changes: 12 additions & 2 deletions music_nativemidi.c
Expand Up @@ -53,6 +53,16 @@ static SDL_bool NATIVEMIDI_IsPlaying(void *context)
return native_midi_active() ? SDL_TRUE : SDL_FALSE;
}

static void NATIVEMIDI_Pause(void *context)
{
native_midi_pause();
}

static void NATIVEMIDI_Resume(void *context)
{
native_midi_resume();
}

static void NATIVEMIDI_Stop(void *context)
{
native_midi_stop();
Expand Down Expand Up @@ -81,8 +91,8 @@ Mix_MusicInterface Mix_MusicInterface_NATIVEMIDI =
NATIVEMIDI_IsPlaying,
NULL, /* GetAudio */
NULL, /* Seek */
NULL, /* Pause */
NULL, /* Resume */
NATIVEMIDI_Pause,
NATIVEMIDI_Resume,
NATIVEMIDI_Stop,
NATIVEMIDI_Delete,
NULL, /* Close */
Expand Down
2 changes: 2 additions & 0 deletions native_midi/native_midi.h
Expand Up @@ -30,6 +30,8 @@ int native_midi_detect(void);
NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *src, int freesrc);
void native_midi_freesong(NativeMidiSong *song);
void native_midi_start(NativeMidiSong *song, int loops);
void native_midi_pause(void);
void native_midi_resume(void);
void native_midi_stop(void);
int native_midi_active(void);
void native_midi_setvolume(int volume);
Expand Down
11 changes: 11 additions & 0 deletions native_midi/native_midi_haiku.cpp
Expand Up @@ -253,6 +253,7 @@ void native_midi_freesong(NativeMidiSong *song)
delete song->store;
delete song; song = 0;
}

void native_midi_start(NativeMidiSong *song, int loops)
{
native_midi_stop();
Expand All @@ -261,6 +262,15 @@ void native_midi_start(NativeMidiSong *song, int loops)
song->store->Start();
currentSong = song;
}

void native_midi_pause(void)
{
}

void native_midi_resume(void)
{
}

void native_midi_stop(void)
{
if (currentSong == NULL) return;
Expand All @@ -270,6 +280,7 @@ void native_midi_stop(void)
usleep(1000);
currentSong = NULL;
}

int native_midi_active(void)
{
if (currentSong == NULL) return 0;
Expand Down
8 changes: 8 additions & 0 deletions native_midi/native_midi_mac.c
Expand Up @@ -242,6 +242,14 @@ void native_midi_start(NativeMidiSong *song, int loops)
SDL_PauseAudio(0);
}

void native_midi_pause(void)
{
}

void native_midi_resume(void)
{
}

void native_midi_stop(void)
{
if (gTunePlayer == NULL)
Expand Down
8 changes: 8 additions & 0 deletions native_midi/native_midi_macosx.c
Expand Up @@ -287,6 +287,14 @@ void native_midi_start(NativeMidiSong *song, int loops)
SDL_PauseAudio(0);
}

void native_midi_pause(void)
{
}

void native_midi_resume(void)
{
}

void native_midi_stop(void)
{
if (currentsong) {
Expand Down
14 changes: 14 additions & 0 deletions native_midi/native_midi_win32.c
Expand Up @@ -272,6 +272,20 @@ void native_midi_start(NativeMidiSong *song, int loops)
}
}

void native_midi_pause(void)
{
if (!hMidiStream)
return;
midiStreamPause(hMidiStream);
}

void native_midi_resume(void)
{
if (!hMidiStream)
return;
midiStreamRestart(hMidiStream);
}

void native_midi_stop(void)
{
if (!hMidiStream)
Expand Down

0 comments on commit 13b57d6

Please sign in to comment.