shithub: choc

Download patch

ref: bcfb28aa35a93d2bdaf289fbf3f64f1d6f632964
parent: ef4d8b14d86af2aed000eab966342c1bd223edb0
author: Roman Fomin <[email protected]>
date: Thu Nov 11 12:28:24 EST 2021

Fix Windows native MIDI playback for Heretic/Hexen

--- a/src/i_sdlmusic.c
+++ b/src/i_sdlmusic.c
@@ -454,8 +454,15 @@
     // music with the Windows native MIDI.
     if (win_midi_stream_opened)
     {
-        music = NULL;
-        I_WIN_RegisterSong(filename);
+        if (I_WIN_RegisterSong(filename))
+        {
+            music = (void *) 1;
+        }
+        else
+        {
+            music = NULL;
+            fprintf(stderr, "Error loading midi: Failed to register song.\n");
+        }
     }
     else
 #endif
--- a/src/i_winmusic.c
+++ b/src/i_winmusic.c
@@ -411,7 +411,7 @@
     }
 }
 
-void I_WIN_RegisterSong(char *filename)
+boolean I_WIN_RegisterSong(char *filename)
 {
     int i;
     midi_file_t *file;
@@ -424,7 +424,7 @@
     if (file == NULL)
     {
         fprintf(stderr, "I_WIN_RegisterSong: Failed to load MID.\n");
-        return;
+        return false;
     }
 
     // Initialize channels volume.
@@ -440,7 +440,7 @@
     if (mmr != MMSYSERR_NOERROR)
     {
         MidiErrorMessageBox(mmr);
-        return;
+        return false;
     }
 
     // Set initial tempo.
@@ -451,7 +451,7 @@
     if (mmr != MMSYSERR_NOERROR)
     {
         MidiErrorMessageBox(mmr);
-        return;
+        return false;
     }
 
     MIDItoStream(file);
@@ -463,6 +463,8 @@
 
     FillBuffer();
     StreamOut();
+
+    return true;
 }
 
 void I_WIN_UnRegisterSong(void)
--- a/src/i_winmusic.h
+++ b/src/i_winmusic.h
@@ -25,7 +25,7 @@
 void I_WIN_PlaySong(boolean looping);
 void I_WIN_StopSong(void);
 void I_WIN_SetMusicVolume(int volume);
-void I_WIN_RegisterSong(char* filename);
+boolean I_WIN_RegisterSong(char* filename);
 void I_WIN_UnRegisterSong(void);
 void I_WIN_ShutdownMusic(void);