Skip to content

Commit

Permalink
Partial fix for bug 934 - Native MIDI on OS X does not loop
Browse files Browse the repository at this point in the history
This fixes short midi files with large sound buffers when the application stops the music if it ever stops playing for a period of time.
  • Loading branch information
slouken committed Jan 1, 2012
1 parent aa932c8 commit d2188c2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGES
@@ -1,4 +1,6 @@
1.2.12:
Sam Lantinga - Sat Dec 31 22:56:34 EST 2011
* Fixed looping MIDI music
Sam Lantinga - Sat Dec 31 19:11:59 EST 2011
* Fixed dropping audio in the FLAC audio decoding
Sam Lantinga - Sat Dec 31 18:32:05 EST 2011
Expand Down
17 changes: 5 additions & 12 deletions music.c
Expand Up @@ -196,7 +196,6 @@ void Mix_HookMusicFinished(void (*music_finished)(void))
static int music_halt_or_loop (void)
{
/* Restart music if it has to loop */

if (!music_internal_playing())
{
/* Restart music if it has to loop at a high level */
Expand Down Expand Up @@ -252,10 +251,6 @@ void music_mixer(void *udata, Uint8 *stream, int len)
}
}

music_halt_or_loop();
if (!music_internal_playing())
return;

switch (music_playing->type) {
#ifdef CMD_MUSIC
case MUS_CMD:
Expand All @@ -282,14 +277,14 @@ void music_mixer(void *udata, Uint8 *stream, int len)
#ifdef USE_FLUIDSYNTH_MIDI
if ( fluidsynth_ok ) {
fluidsynth_playsome(music_playing->data.fluidsynthmidi, stream, len);
goto skip;
break;
}
#endif
#ifdef USE_TIMIDITY_MIDI
if ( timidity_ok ) {
int samples = len / samplesize;
Timidity_PlaySome(stream, samples);
goto skip;
break;
}
#endif
break;
Expand Down Expand Up @@ -319,14 +314,12 @@ void music_mixer(void *udata, Uint8 *stream, int len)
/* Unknown music type?? */
break;
}
}

skip:
/* Handle seamless music looping */
if (left > 0 && left < len) {
/* Handle seamless music looping */
music_halt_or_loop();
if (music_internal_playing())
if (left > 0 && left < len && music_internal_playing()) {
music_mixer(udata, stream+(len-left), left);
}
}
}

Expand Down

0 comments on commit d2188c2

Please sign in to comment.