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!).
This commit is contained in:
Fabian Greffrath 2017-12-11 14:46:09 +01:00
parent 95bd2d4483
commit 241d056f60
3 changed files with 14 additions and 9 deletions

View file

@ -99,6 +99,7 @@ static void UnregisterSong()
} }
Mix_FreeMusic(music); Mix_FreeMusic(music);
music = NULL;
} }
// //
@ -121,6 +122,9 @@ static boolean RegisterSong(const char *filename)
UnregisterSong(); UnregisterSong();
music = Mix_LoadMUS(filename); music = Mix_LoadMUS(filename);
// Remove the temporary MIDI file
remove(filename);
if (music == NULL) if (music == NULL)
{ {
return false; return false;
@ -218,6 +222,7 @@ boolean MidiPipe_PlaySong(buffer_reader_t *reader)
boolean MidiPipe_StopSong() boolean MidiPipe_StopSong()
{ {
StopSong(); StopSong();
UnregisterSong();
return true; return true;
} }

View file

@ -58,7 +58,7 @@ boolean midi_server_registered = false;
// Data // 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_reader; // Input stream for midi process.
static HANDLE midi_process_in_writer; static HANDLE midi_process_in_writer;

View file

@ -1242,7 +1242,6 @@ static void *I_SDL_RegisterSong(void *data, int len)
// Failed to load // Failed to load
fprintf(stderr, "Error loading midi: %s\n", Mix_GetError()); fprintf(stderr, "Error loading midi: %s\n", Mix_GetError());
} }
}
// Remove the temporary MIDI file; however, when using an external // Remove the temporary MIDI file; however, when using an external
// MIDI program we can't delete the file. Otherwise, the program // MIDI program we can't delete the file. Otherwise, the program
@ -1253,6 +1252,7 @@ static void *I_SDL_RegisterSong(void *data, int len)
{ {
remove(filename); remove(filename);
} }
}
free(filename); free(filename);