From 1579fd1c1c1b39d7514016b27c5672bc16fadead Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 20 May 2011 00:26:22 +0000 Subject: [PATCH] - Fixed: Selecting TiMidity++ as a MIDI device without a working timidity.exe, then switching to a different MIDI device would leave music silent until a new song was started. (The discrepancy between mus_playing.handle and currSong is one which should probably be handled properly at some point.) SVN r3212 (trunk) --- src/s_sound.cpp | 15 +++++++++++++++ src/s_sound.h | 2 ++ src/sound/music_midi_base.cpp | 17 ++++++++++++----- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/s_sound.cpp b/src/s_sound.cpp index 4c4053899b..052d049527 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -2517,6 +2517,21 @@ void S_RestartMusic () } } +//========================================================================== +// +// S_MIDIDeviceChanged +// +//========================================================================== + +void S_MIDIDeviceChanged() +{ + if (mus_playing.handle != NULL && mus_playing.handle->IsMIDI()) + { + mus_playing.handle->Stop(); + mus_playing.handle->Start(mus_playing.loop, -1, mus_playing.baseorder); + } +} + //========================================================================== // // S_GetMusic diff --git a/src/s_sound.h b/src/s_sound.h index 12e7ee3c65..d82e273ac2 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -313,6 +313,8 @@ bool S_ChangeCDMusic (int track, unsigned int id=0, bool looping=true); void S_RestartMusic (); +void S_MIDIDeviceChanged(); + int S_GetMusic (char **name); // Stops the music for sure. diff --git a/src/sound/music_midi_base.cpp b/src/sound/music_midi_base.cpp index 86134c9548..e0d67683d7 100644 --- a/src/sound/music_midi_base.cpp +++ b/src/sound/music_midi_base.cpp @@ -43,13 +43,20 @@ static void MIDIDeviceChanged(int newdev) static int oldmididev = INT_MIN; // If a song is playing, move it to the new device. - if (oldmididev != newdev && currSong != NULL && currSong->IsMIDI()) + if (oldmididev != newdev) { - MusInfo *song = currSong; - if (song->m_Status == MusInfo::STATE_Playing) + if (currSong != NULL && currSong->IsMIDI()) { - song->Stop(); - song->Start(song->m_Looping); + MusInfo *song = currSong; + if (song->m_Status == MusInfo::STATE_Playing) + { + song->Stop(); + song->Start(song->m_Looping); + } + } + else + { + S_MIDIDeviceChanged(); } } oldmididev = newdev;