shithub: choc

Download patch

ref: 241d056f6018b6c1700affdfae4e87ccf8a88be0
parent: 95bd2d4483435285113a55281a8d713688ef2a1b
author: Fabian Greffrath <[email protected]>
date: Mon Dec 11 09:46:09 EST 2017

midiproc: some further improvements

Recent versions of SDL_Mixer allow for rendering MIDI songs using
the fluidsynth backend and recent versions of fluidsynth allow for
using soundfonts in SF3 format (which contain OGG compressed samples).

The midiproc process currently assumes that it is possible to remove
the temporary music file immediately after Mix_LoadMUS() has been
called, which is true if the music is rendered using Windows's limited
intrnal MIDI playback. However, when using an advanced backend like
fluidsynth, this file maybe locked by this library. Furthermore,
midiproc currently assumes that it is possible to override the
temporary music file as soon as Mix_HaltMusic() has been called which
is again not true if fluidsynth is used. In this case, this is only
possible after Mix_FreeMusic() has been called (and returned).
Additionally, we increase the time-out value after which we give up
waiting for the midiproc process to send an acknowledgement to 1s to
give it some time to load the fluidsynth library and a soundfont
(although 1s will still not be enough for soundfonts in SF3 format
which reportedly load up to the order of 10s!).

--- a/midiproc/main.c
+++ b/midiproc/main.c
@@ -99,6 +99,7 @@
     }
 
     Mix_FreeMusic(music);
+    music = NULL;
 }
 
 //
@@ -121,6 +122,9 @@
     UnregisterSong();
     music = Mix_LoadMUS(filename);
 
+    // Remove the temporary MIDI file
+    remove(filename);
+
     if (music == NULL)
     {
         return false;
@@ -218,6 +222,7 @@
 boolean MidiPipe_StopSong()
 {
     StopSong();
+    UnregisterSong();
 
     return true;
 }
--- a/src/i_midipipe.c
+++ b/src/i_midipipe.c
@@ -58,7 +58,7 @@
 // Data
 //
 
-#define MIDIPIPE_MAX_WAIT 500 // Max amount of ms to wait for expected data.
+#define MIDIPIPE_MAX_WAIT 1000 // Max amount of ms to wait for expected data.
 
 static HANDLE  midi_process_in_reader;  // Input stream for midi process.
 static HANDLE  midi_process_in_writer;
--- a/src/i_sdlmusic.c
+++ b/src/i_sdlmusic.c
@@ -1242,16 +1242,16 @@
             // Failed to load
             fprintf(stderr, "Error loading midi: %s\n", Mix_GetError());
         }
-    }
 
-    // Remove the temporary MIDI file; however, when using an external
-    // MIDI program we can't delete the file. Otherwise, the program
-    // won't find the file to play. This means we leave a mess on
-    // disk :(
+        // Remove the temporary MIDI file; however, when using an external
+        // MIDI program we can't delete the file. Otherwise, the program
+        // won't find the file to play. This means we leave a mess on
+        // disk :(
 
-    if (strlen(snd_musiccmd) == 0)
-    {
-        remove(filename);
+        if (strlen(snd_musiccmd) == 0)
+        {
+            remove(filename);
+        }
     }
 
     free(filename);