Skip to content
Permalink
Browse files

Merge branch 'master' of https://github.com/chocolate-doom/chocolate-…

  • Loading branch information...
fabiangreffrath committed Aug 5, 2019
2 parents eb5bc15 + 59e2dec commit 43c4507134f74cb3f85711bcb8c1d8e4ce7b7c64
Showing with 76 additions and 32 deletions.
  1. +18 −18 midiproc/main.c
  2. +4 −2 midiproc/proto.h
  3. +42 −8 src/i_midipipe.c
  4. +1 −0 src/i_midipipe.h
  5. +11 −4 src/i_sdlmusic.c
@@ -119,7 +119,6 @@ static void ShutdownSDL(void)

static boolean RegisterSong(const char *filename)
{
UnregisterSong();
music = Mix_LoadMUS(filename);

// Remove the temporary MIDI file
@@ -165,29 +164,18 @@ static void StopSong()

static boolean MidiPipe_RegisterSong(buffer_reader_t *reader)
{
CHAR buffer[2];
DWORD bytes_written;

char *filename = Reader_ReadString(reader);
if (filename == NULL)
{
return false;
}

if (!RegisterSong(filename))
{
return false;
}

if (!WriteInt16(buffer, sizeof(buffer),
MIDIPIPE_PACKET_TYPE_REGISTER_SONG_ACK))
{
return false;
}

WriteFile(midi_process_out, buffer, sizeof(buffer),
&bytes_written, NULL);
return RegisterSong(filename);
}

static boolean MidiPipe_UnregisterSong(buffer_reader_t *reader)
{
UnregisterSong();
return true;
}

@@ -222,7 +210,6 @@ boolean MidiPipe_PlaySong(buffer_reader_t *reader)
boolean MidiPipe_StopSong()
{
StopSong();
UnregisterSong();

return true;
}
@@ -246,6 +233,8 @@ boolean ParseCommand(buffer_reader_t *reader, uint16_t command)
{
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:
@@ -264,6 +253,8 @@ boolean ParseCommand(buffer_reader_t *reader, uint16_t command)
//
boolean ParseMessage(buffer_t *buf)
{
CHAR buffer[2];
DWORD bytes_written;
int bytes_read;
uint16_t command;
buffer_reader_t *reader = NewReader(buf);
@@ -286,6 +277,15 @@ boolean ParseMessage(buffer_t *buf)
DeleteReader(reader);
Buffer_Shift(buf, bytes_read);

// Send acknowledgement back that the command has completed.
if (!WriteInt16(buffer, sizeof(buffer), MIDIPIPE_PACKET_TYPE_ACK))
{
goto fail;
}

WriteFile(midi_process_out, buffer, sizeof(buffer),
&bytes_written, NULL);

return true;

fail:
@@ -20,11 +20,13 @@

typedef enum {
MIDIPIPE_PACKET_TYPE_REGISTER_SONG,
MIDIPIPE_PACKET_TYPE_REGISTER_SONG_ACK,
MIDIPIPE_PACKET_TYPE__DEPRECATED_1,
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,
MIDIPIPE_PACKET_TYPE_ACK,
} net_midipipe_packet_type_t;

#endif
@@ -215,6 +215,19 @@ void RemoveFileSpec(TCHAR *path, size_t size)
*(fp + 1) = '\0';
}

static boolean BlockForAck(void)
{
boolean ok;
net_packet_t *packet;

packet = NET_NewPacket(2);
NET_WriteInt16(packet, MIDIPIPE_PACKET_TYPE_ACK);
ok = ExpectPipe(packet);
NET_FreePacket(packet);

return ok;
}

//=============================================================================
//
// Protocol Commands
@@ -239,27 +252,44 @@ boolean I_MidiPipe_RegisterSong(char *filename)

midi_server_registered = false;

ok = ok && BlockForAck();
if (!ok)
{
DEBUGOUT("I_MidiPipe_RegisterSong failed");
return false;
}

packet = NET_NewPacket(2);
NET_WriteInt16(packet, MIDIPIPE_PACKET_TYPE_REGISTER_SONG_ACK);
ok = ExpectPipe(packet);
midi_server_registered = true;

DEBUGOUT("I_MidiPipe_RegisterSong succeeded");
return true;
}

//
// 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);

ok = ok && BlockForAck();
if (!ok)
{
DEBUGOUT("I_MidiPipe_RegisterSong ack failed");
return false;
DEBUGOUT("I_MidiPipe_UnregisterSong failed");
return;
}

midi_server_registered = true;
midi_server_registered = false;

DEBUGOUT("I_MidiPipe_RegisterSong succeeded");
return true;
DEBUGOUT("I_MidiPipe_UnregisterSong succeeded");
}

//
@@ -278,6 +308,7 @@ void I_MidiPipe_SetVolume(int vol)
ok = WritePipe(packet);
NET_FreePacket(packet);

ok = ok && BlockForAck();
if (!ok)
{
DEBUGOUT("I_MidiPipe_SetVolume failed");
@@ -303,6 +334,7 @@ void I_MidiPipe_PlaySong(int loops)
ok = WritePipe(packet);
NET_FreePacket(packet);

ok = ok && BlockForAck();
if (!ok)
{
DEBUGOUT("I_MidiPipe_PlaySong failed");
@@ -329,6 +361,7 @@ void I_MidiPipe_StopSong()

midi_server_registered = false;

ok = ok && BlockForAck();
if (!ok)
{
DEBUGOUT("I_MidiPipe_StopSong failed");
@@ -353,6 +386,7 @@ void I_MidiPipe_ShutdownServer()
ok = WritePipe(packet);
NET_FreePacket(packet);

ok = ok && BlockForAck();
FreePipes();

midi_server_initialized = false;
@@ -29,6 +29,7 @@ extern boolean midi_server_initialized;
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();
@@ -345,12 +345,19 @@ static void I_SDL_UnRegisterSong(void *handle)
return;
}

if (handle == NULL)
#if defined(_WIN32)
if (midi_server_registered)
{
return;
I_MidiPipe_StopSong();
}
else
#endif
{
if (handle != NULL)
{
Mix_FreeMusic(music);
}
}

Mix_FreeMusic(music);
}

// Determine whether memory block is a .mid file

0 comments on commit 43c4507

Please sign in to comment.
You can’t perform that action at this time.