From c6c7c91d7c9d6b6e66be0005266b056238e2c8af Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Thu, 24 Oct 2019 05:47:29 +0000 Subject: [PATCH] Add MIDI_GetDevice and use it so that the default driver value doesn't show as "Custom" in the menu git-svn-id: https://svn.eduke32.com/eduke32@8261 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/audiolib/include/fx_man.h | 1 + source/audiolib/include/music.h | 1 + source/audiolib/src/fx_man.cpp | 5 +++++ source/audiolib/src/midi.cpp | 5 +++++ source/duke3d/src/sounds.cpp | 11 ++++++++++- source/sw/src/sounds.cpp | 11 ++++++++++- 6 files changed, 32 insertions(+), 2 deletions(-) diff --git a/source/audiolib/include/fx_man.h b/source/audiolib/include/fx_man.h index 09bb3dbbc..ad6e9ef12 100644 --- a/source/audiolib/include/fx_man.h +++ b/source/audiolib/include/fx_man.h @@ -56,6 +56,7 @@ enum FX_LOOP_HOW const char *FX_ErrorString(int ErrorNumber); int FX_Init(int numvoices, int numchannels, int mixrate, void *initdata); int FX_Shutdown(void); +int FX_GetDevice(void); diff --git a/source/audiolib/include/music.h b/source/audiolib/include/music.h index 0fe4b03a5..91bf9a7c7 100644 --- a/source/audiolib/include/music.h +++ b/source/audiolib/include/music.h @@ -63,6 +63,7 @@ extern const char *MUSIC_ErrorString(int ErrorNumber); int MUSIC_Init(int SoundCard); int MUSIC_Shutdown(void); +int MIDI_GetDevice(void); void MUSIC_SetVolume(int volume); int MUSIC_GetVolume(void); void MUSIC_SetLoopFlag(int loopflag); diff --git a/source/audiolib/src/fx_man.cpp b/source/audiolib/src/fx_man.cpp index 292fe8b69..5b830f614 100644 --- a/source/audiolib/src/fx_man.cpp +++ b/source/audiolib/src/fx_man.cpp @@ -141,6 +141,11 @@ int FX_Shutdown(void) return status; } +int FX_GetDevice() +{ + return ASS_PCMSoundDriver; +} + static wavefmt_t FX_DetectFormat(char const * const ptr, uint32_t length) { if (length < 12) diff --git a/source/audiolib/src/midi.cpp b/source/audiolib/src/midi.cpp index dc9bd9ab6..a2d210bd5 100644 --- a/source/audiolib/src/midi.cpp +++ b/source/audiolib/src/midi.cpp @@ -46,6 +46,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. extern int MV_MixRate; extern int ASS_MIDISoundDriver; +int MIDI_GetDevice() +{ + return ASS_MIDISoundDriver; +} + static const int _MIDI_CommandLengths[NUM_MIDI_CHANNELS] = { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 1, 1, 2, 0 }; static track * _MIDI_TrackPtr; diff --git a/source/duke3d/src/sounds.cpp b/source/duke3d/src/sounds.cpp index b3c96ed88..434562759 100644 --- a/source/duke3d/src/sounds.cpp +++ b/source/duke3d/src/sounds.cpp @@ -118,7 +118,16 @@ void S_MusicStartup(void) initprintf("Initializing MIDI driver... "); int status; - if ((status = MUSIC_Init(ud.config.MusicDevice)) != MUSIC_Ok && (status = MUSIC_Init(0)) != MUSIC_Ok && (status = MUSIC_Init(1)) != MUSIC_Ok) + if ((status = MUSIC_Init(ud.config.MusicDevice)) == MUSIC_Ok) + { + if (ud.config.MusicDevice == ASS_AutoDetect) + ud.config.MusicDevice = MIDI_GetDevice(); + } + else if ((status = MUSIC_Init(ASS_AutoDetect)) == MUSIC_Ok) + { + ud.config.MusicDevice = MIDI_GetDevice(); + } + else { initprintf("S_MusicStartup(): failed initializing: %s\n", MUSIC_ErrorString(status)); return; diff --git a/source/sw/src/sounds.cpp b/source/sw/src/sounds.cpp index 2fa5a0fc7..b728e860a 100644 --- a/source/sw/src/sounds.cpp +++ b/source/sw/src/sounds.cpp @@ -1197,7 +1197,16 @@ void MusicStartup(void) buildprintf("Initializing MIDI driver... "); int status; - if ((status = MUSIC_Init(MusicDevice)) != MUSIC_Ok && (status = MUSIC_Init(0)) != MUSIC_Ok && (status = MUSIC_Init(1)) != MUSIC_Ok) + if ((status = MUSIC_Init(MusicDevice)) == MUSIC_Ok) + { + if (MusicDevice == ASS_AutoDetect) + MusicDevice = MIDI_GetDevice(); + } + else if ((status = MUSIC_Init(ASS_AutoDetect)) == MUSIC_Ok) + { + MusicDevice = MIDI_GetDevice(); + } + else { buildprintf("Music error: %s\n", MUSIC_ErrorString(status)); mus_enabled = FALSE;