ref: d832c5765cbd83ecc6a0035d8d8e277215bd4822
parent: f1d557ff6344e84595a5eb0b2ac2639224286d5b
author: Simon Howard <fraggle@soulsphere.org>
date: Sat Jul 13 19:52:11 EDT 2019
midiproc: Add command for song unregistration. This mirrors the RegisterSong command and makes the midiproc API match the internal music module API. This should help to avoid bugs caused by a difference in song unregistration when using the midiproc. Part of a fix for #963.
--- a/midiproc/main.c
+++ b/midiproc/main.c
@@ -119,7 +119,6 @@
static boolean RegisterSong(const char *filename)
{
- UnregisterSong();
music = Mix_LoadMUS(filename);
// Remove the temporary MIDI file
@@ -191,6 +190,12 @@
return true;
}
+static boolean MidiPipe_UnregisterSong(buffer_reader_t *reader)
+{
+ UnregisterSong();
+ return true;
+}
+
boolean MidiPipe_SetVolume(buffer_reader_t *reader)
{
int vol;
@@ -222,7 +227,6 @@
boolean MidiPipe_StopSong()
{
StopSong();
- UnregisterSong();
return true;
}
@@ -246,6 +250,8 @@
{
case MIDIPIPE_PACKET_TYPE_REGISTER_SONG:
return MidiPipe_RegisterSong(reader);
+ case MIDIPIPE_PACKET_TYPE_UNREGISTER_SONG:
+ return MidiPipe_UnregisterSong(reader);
case MIDIPIPE_PACKET_TYPE_SET_VOLUME:
return MidiPipe_SetVolume(reader);
case MIDIPIPE_PACKET_TYPE_PLAY_SONG:
--- a/midiproc/proto.h
+++ b/midiproc/proto.h
@@ -24,7 +24,8 @@
MIDIPIPE_PACKET_TYPE_SET_VOLUME,
MIDIPIPE_PACKET_TYPE_PLAY_SONG,
MIDIPIPE_PACKET_TYPE_STOP_SONG,
- MIDIPIPE_PACKET_TYPE_SHUTDOWN
+ MIDIPIPE_PACKET_TYPE_SHUTDOWN,
+ MIDIPIPE_PACKET_TYPE_UNREGISTER_SONG,
} net_midipipe_packet_type_t;
#endif
--- a/src/i_midipipe.c
+++ b/src/i_midipipe.c
@@ -263,6 +263,32 @@
}
//
+// I_MidiPipe_UnregisterSong
+//
+// Tells the MIDI subprocess to unload the current song.
+//
+void I_MidiPipe_UnregisterSong(void)
+{
+ boolean ok;
+ net_packet_t *packet;
+
+ packet = NET_NewPacket(64);
+ NET_WriteInt16(packet, MIDIPIPE_PACKET_TYPE_UNREGISTER_SONG);
+ ok = WritePipe(packet);
+ NET_FreePacket(packet);
+
+ if (!ok)
+ {
+ DEBUGOUT("I_MidiPipe_UnregisterSong failed");
+ return;
+ }
+
+ midi_server_registered = false;
+
+ DEBUGOUT("I_MidiPipe_UnregisterSong succeeded");
+}
+
+//
// I_MidiPipe_SetVolume
//
// Tells the MIDI subprocess to set a specific volume for the song.
--- a/src/i_midipipe.h
+++ b/src/i_midipipe.h
@@ -29,6 +29,7 @@
extern boolean midi_server_registered;
boolean I_MidiPipe_RegisterSong(char *filename);
+void I_MidiPipe_UnregisterSong(void);
void I_MidiPipe_SetVolume(int vol);
void I_MidiPipe_PlaySong(int loops);
void I_MidiPipe_StopSong();
--- a/src/i_sdlmusic.c
+++ b/src/i_sdlmusic.c
@@ -345,12 +345,19 @@
return;
}
- if (handle == NULL)
+#if defined(_WIN32)
+ if (midi_server_registered)
{
- return;
+ I_MidiPipe_StopSong();
}
-
- Mix_FreeMusic(music);
+ else
+#endif
+ {
+ if (handle != NULL)
+ {
+ Mix_FreeMusic(music);
+ }
+ }
}
// Determine whether memory block is a .mid file