Skip to content

Commit

Permalink
Stop/Start/Pause/Resume for Fluidsynth
Browse files Browse the repository at this point in the history
The fluidsynth player would resume from the point when the track
was stopped instead of the beginning when Play was called. This
was the desired behaviour for the unsupported Pause/Resume
functions, so I moved the definitions to those functions and
added new Start/Stop functions that seek to the beginning of the
track before playing.

When paused SDL_mixer should return true for IsPlaying. Fix
supplied by Wohlstand.
  • Loading branch information
TheCycoONE authored and slouken committed Mar 3, 2024
1 parent 839be00 commit 252c6c8
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/codecs/music_fluidsynth.c
Expand Up @@ -39,6 +39,7 @@ typedef struct {
#if (FLUIDSYNTH_VERSION_MAJOR >= 2)
void (*delete_fluid_player)(fluid_player_t*);
void (*delete_fluid_synth)(fluid_synth_t*);
int (*fluid_player_seek)(fluid_player_t *, int);
#else
int (*delete_fluid_player)(fluid_player_t*);
int (*delete_fluid_synth)(fluid_synth_t*);
Expand Down Expand Up @@ -85,6 +86,7 @@ static int FLUIDSYNTH_Load()
#if (FLUIDSYNTH_VERSION_MAJOR >= 2)
FUNCTION_LOADER(delete_fluid_player, void (*)(fluid_player_t*))
FUNCTION_LOADER(delete_fluid_synth, void (*)(fluid_synth_t*))
FUNCTION_LOADER(fluid_player_seek, int (*)(fluid_player_t *, int))
#else
FUNCTION_LOADER(delete_fluid_player, int (*)(fluid_player_t*))
FUNCTION_LOADER(delete_fluid_synth, int (*)(fluid_synth_t*))
Expand Down Expand Up @@ -135,6 +137,7 @@ typedef struct {
void *buffer;
int buffer_size;
int volume;
SDL_bool is_paused;
} FLUIDSYNTH_Music;

static void FLUIDSYNTH_Delete(void *context);
Expand Down Expand Up @@ -277,14 +280,25 @@ static int FLUIDSYNTH_Play(void *context, int play_count)
{
FLUIDSYNTH_Music *music = (FLUIDSYNTH_Music *)context;
fluidsynth.fluid_player_set_loop(music->player, play_count);
#if (FLUIDSYNTH_VERSION_MAJOR >= 2)
fluidsynth.fluid_player_seek(music->player, 0);
#endif
fluidsynth.fluid_player_play(music->player);
music->is_paused = SDL_FALSE;
return 0;
}

static void FLUIDSYNTH_Resume(void *context)
{
FLUIDSYNTH_Music *music = (FLUIDSYNTH_Music *)context;
fluidsynth.fluid_player_play(music->player);
music->is_paused = SDL_FALSE;
}

static SDL_bool FLUIDSYNTH_IsPlaying(void *context)
{
FLUIDSYNTH_Music *music = (FLUIDSYNTH_Music *)context;
return fluidsynth.fluid_player_get_status(music->player) == FLUID_PLAYER_PLAYING ? SDL_TRUE : SDL_FALSE;
return music->is_paused || fluidsynth.fluid_player_get_status(music->player) == FLUID_PLAYER_PLAYING ? SDL_TRUE : SDL_FALSE;
}

static int FLUIDSYNTH_GetSome(void *context, void *data, int bytes, SDL_bool *done)
Expand Down Expand Up @@ -316,6 +330,17 @@ static void FLUIDSYNTH_Stop(void *context)
{
FLUIDSYNTH_Music *music = (FLUIDSYNTH_Music *)context;
fluidsynth.fluid_player_stop(music->player);
#if (FLUIDSYNTH_VERSION_MAJOR >= 2)
fluidsynth.fluid_player_seek(music->player, 0);
#endif
music->is_paused = SDL_FALSE;
}

static void FLUIDSYNTH_Pause(void *context)
{
FLUIDSYNTH_Music *music = (FLUIDSYNTH_Music *)context;
fluidsynth.fluid_player_stop(music->player);
music->is_paused = SDL_TRUE;
}

static void FLUIDSYNTH_Delete(void *context)
Expand Down Expand Up @@ -367,8 +392,8 @@ Mix_MusicInterface Mix_MusicInterface_FLUIDSYNTH =
NULL, /* GetMetaTag */
NULL, /* GetNumTracks */
NULL, /* StartTrack */
NULL, /* Pause */
NULL, /* Resume */
FLUIDSYNTH_Pause,
FLUIDSYNTH_Resume,
FLUIDSYNTH_Stop,
FLUIDSYNTH_Delete,
NULL, /* Close */
Expand Down

0 comments on commit 252c6c8

Please sign in to comment.