Skip to content

Commit 4182794

Browse files
NoRinesicculus
authored andcommitted
Fix bug: fluidsynth not looping if predecode is turned off
When playing a midi song with fluidsynth and looping is turned on it only works when predecoding the song. Otherwise the program hangs and in my case must be shutdown with 'kill -9'. This commit fixes the bug by ensuring that the fluidsynth player is in playing mode if seek is called on a finished song.
1 parent bdcc9e2 commit 4182794

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/decoder_fluidsynth.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,12 @@ static void *SoundFontOpen(const char *filename)
196196
}
197197
return ptr; // (this is actually an SDL_IOStream pointer.)
198198
}
199-
199+
200200
static int SoundFontRead(void *buf, fluid_long_long_t count, void *handle)
201201
{
202202
return (SDL_ReadIO((SDL_IOStream *) handle, buf, count) == count) ? FLUID_OK : FLUID_FAILED;
203203
}
204-
204+
205205
static int SoundFontSeek(void *handle, fluid_long_long_t offset, int origin)
206206
{
207207
SDL_IOWhence whence;
@@ -213,13 +213,13 @@ static int SoundFontSeek(void *handle, fluid_long_long_t offset, int origin)
213213
}
214214
return (SDL_SeekIO((SDL_IOStream *) handle, offset, whence) >= 0) ? FLUID_OK : FLUID_FAILED;
215215
}
216-
216+
217217
static int SoundFontClose(void *handle)
218218
{
219219
SDL_CloseIO((SDL_IOStream *) handle);
220220
return FLUID_OK;
221221
}
222-
222+
223223
static fluid_long_long_t SoundFontTell(void *handle)
224224
{
225225
return SDL_TellIO((SDL_IOStream *) handle);
@@ -374,7 +374,14 @@ static bool SDLCALL FLUIDSYNTH_seek(void *track_userdata, Uint64 frame)
374374
}
375375

376376
// !!! FIXME: docs say this will fail if a seek was requested and then a second seek happens before we play more of the midi file, since the first seek will still be in progress.
377-
return (fluidsynth.fluid_player_seek(tdata->player, (int)ticks) == FLUID_OK);
377+
bool result = (fluidsynth.fluid_player_seek(tdata->player, (int)ticks) == FLUID_OK);
378+
379+
if (result && fluidsynth.fluid_player_get_status(tdata->player) != FLUID_PLAYER_PLAYING) {
380+
/* start playing if player is done */
381+
result = (fluidsynth.fluid_player_play(tdata->player) == FLUID_OK);
382+
}
383+
384+
return result;
378385
#endif
379386
}
380387

0 commit comments

Comments
 (0)