Skip to content

Commit bd85029

Browse files
mkunkacncicculus
authored andcommitted
Update SDL_native_midi_macos.c
1 parent e5ff4b2 commit bd85029

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/SDL_native_midi_macos.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,18 @@ void NativeMidi_DestroySong(NativeMidi_Song *song)
274274
}
275275
}
276276

277+
static NativeMidi_Song* paused_song = NULL;
278+
static MusicTimeStamp paused_time = 0;
279+
static bool resume = false;
280+
277281
void NativeMidi_Start(NativeMidi_Song *song, int loops)
278282
{
283+
if (!resume) {
284+
// If we are not resuming a paused song, clear any existing paused info.
285+
paused_song = NULL;
286+
paused_time = 0;
287+
}
288+
279289
if (song) {
280290
if (currentsong) {
281291
MusicPlayerStop(currentsong->player);
@@ -294,17 +304,29 @@ void NativeMidi_Start(NativeMidi_Song *song, int loops)
294304
latched_volume += 1.0f; // +1 just make this not match.
295305
NativeMidi_SetVolume(vol);
296306

297-
MusicPlayerSetTime(song->player, 0);
307+
MusicPlayerSetTime(song->player, resume ? paused_time : 0);
298308
MusicPlayerStart(song->player);
299309
}
300310
}
301311

302312
void NativeMidi_Pause(void)
303313
{
314+
if (currentsong) {
315+
paused_song = currentsong;
316+
MusicPlayerGetTime(currentsong->player, &paused_time);
317+
NativeMidi_Stop();
318+
}
304319
}
305320

306321
void NativeMidi_Resume(void)
307322
{
323+
if (paused_song) {
324+
resume = true;
325+
NativeMidi_Start(paused_song, paused_song->loops);
326+
paused_song = NULL;
327+
paused_time = 0;
328+
resume = false;
329+
}
308330
}
309331

310332
void NativeMidi_Stop(void)

0 commit comments

Comments
 (0)