foxygit / doom Log in
commit e8e2d602e6b4ff9d41bbb9e43023043bffc64e90
Author:     Alex Mayfield <alexmax2742@gmail.com>
AuthorDate: Mon Mar 13 23:40:21 2017 -0400
Commit:     Alex Mayfield <alexmax2742@gmail.com>
CommitDate: Mon Mar 13 23:40:51 2017 -0400

    Move midipipe messages out of net

    Rename them while we're at it.
---
 midiproc/Makefile.am |  2 +-
 midiproc/main.c      | 27 ++++++++++++++-------------
 midiproc/proto.h     | 31 +++++++++++++++++++++++++++++++
 src/i_midipipe.c     | 14 ++++++++------
 src/net_defs.h       |  9 ---------
 5 files changed, 54 insertions(+), 29 deletions(-)

diff --git a/midiproc/Makefile.am b/midiproc/Makefile.am
index 3de865ef..0ac60b9b 100644
--- a/midiproc/Makefile.am
+++ b/midiproc/Makefile.am
@@ -6,6 +6,6 @@ if HAVE_WINDRES
 noinst_PROGRAMS = @PROGRAM_PREFIX@midiproc

 @PROGRAM_PREFIX@midiproc_LDADD = @SDLMIXER_LIBS@
-@PROGRAM_PREFIX@midiproc_SOURCES = buffer.c buffer.h main.c
+@PROGRAM_PREFIX@midiproc_SOURCES = buffer.c buffer.h main.c proto.h

 endif
diff --git a/midiproc/main.c b/midiproc/main.c
index 4622c020..7e792388 100644
--- a/midiproc/main.c
+++ b/midiproc/main.c
@@ -28,16 +28,17 @@

 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
+#include <stdio.h>
 #include <stdlib.h>

 #include "SDL.h"
 #include "SDL_mixer.h"

 #include "buffer.h"
+#include "proto.h"

 #include "config.h"
 #include "doomtype.h"
-#include "net_defs.h"

 static HANDLE    midi_process_in;  // Standard In.
 static HANDLE    midi_process_out; // Standard Out.
@@ -158,7 +159,7 @@ static boolean MidiPipe_RegisterSong(buffer_reader_t *reader)

     // FIXME: We should probably have a function for writing Int16's into
     //        buffers, as opposed to simply winging it.
-    i = NET_MIDIPIPE_PACKET_TYPE_REGISTER_SONG_ACK;
+    i = MIDIPIPE_PACKET_TYPE_REGISTER_SONG_ACK;
     buffer[0] = (i >> 8) & 0xff;
     buffer[1] = i & 0xff;

@@ -220,15 +221,15 @@ boolean ParseCommand(buffer_reader_t *reader, uint16_t command)
 {
     switch (command)
     {
-    case NET_MIDIPIPE_PACKET_TYPE_REGISTER_SONG:
+    case MIDIPIPE_PACKET_TYPE_REGISTER_SONG:
         return MidiPipe_RegisterSong(reader);
-    case NET_MIDIPIPE_PACKET_TYPE_SET_VOLUME:
+    case MIDIPIPE_PACKET_TYPE_SET_VOLUME:
         return MidiPipe_SetVolume(reader);
-    case NET_MIDIPIPE_PACKET_TYPE_PLAY_SONG:
+    case MIDIPIPE_PACKET_TYPE_PLAY_SONG:
         return MidiPipe_PlaySong(reader);
-    case NET_MIDIPIPE_PACKET_TYPE_STOP_SONG:
+    case MIDIPIPE_PACKET_TYPE_STOP_SONG:
         return MidiPipe_StopSong();
-    case NET_MIDIPIPE_PACKET_TYPE_SHUTDOWN:
+    case MIDIPIPE_PACKET_TYPE_SHUTDOWN:
         return MidiPipe_Shutdown();
     default:
         return false;
@@ -400,12 +401,12 @@ int main(int argc, char *argv[])
     if (strcmp(PACKAGE_STRING, argv[1]) != 0)
     {
         char message[1024];
-        snprintf(message, sizeof(message),
-                 "It appears that the version of %s and %smidiproc are out of "
-                 " sync.  Please reinstall %s.\r\n\r\n"
-                 "Server Version: %s\r\nClient Version: %s",
-                 PACKAGE_NAME, PROGRAM_PREFIX, PACKAGE_NAME,
-                 PACKAGE_STRING, argv[1]);
+        _snprintf(message, sizeof(message),
+                  "It appears that the version of %s and %smidiproc are out "
+                  "of sync.  Please reinstall %s.\r\n\r\n"
+                  "Server Version: %s\r\nClient Version: %s",
+                  PACKAGE_NAME, PROGRAM_PREFIX, PACKAGE_NAME,
+                  PACKAGE_STRING, argv[1]);
         message[sizeof(message) - 1] = '\0';

         MessageBox(NULL, TEXT(message),
diff --git a/midiproc/proto.h b/midiproc/proto.h
new file mode 100755
index 00000000..c3e9287a
--- /dev/null
+++ b/midiproc/proto.h
@@ -0,0 +1,31 @@
+//
+// Copyright(C) 2017 Alex Mayfield
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// DESCRIPTION:
+//     Headers for all types of midipipe messages.
+//
+
+#ifndef __PROTO__
+#define __PROTO__
+
+typedef enum {
+    MIDIPIPE_PACKET_TYPE_REGISTER_SONG,
+    MIDIPIPE_PACKET_TYPE_REGISTER_SONG_ACK,
+    MIDIPIPE_PACKET_TYPE_SET_VOLUME,
+    MIDIPIPE_PACKET_TYPE_PLAY_SONG,
+    MIDIPIPE_PACKET_TYPE_STOP_SONG,
+    MIDIPIPE_PACKET_TYPE_SHUTDOWN
+} net_midipipe_packet_type_t;
+
+#endif
+
diff --git a/src/i_midipipe.c b/src/i_midipipe.c
index a5a86041..31d239c9 100644
--- a/src/i_midipipe.c
+++ b/src/i_midipipe.c
@@ -32,6 +32,8 @@
 #include "m_misc.h"
 #include "net_packet.h"

+#include "../midiproc/proto.h"
+
 #if defined(_DEBUG)
 #define DEBUGOUT(s) puts(s)
 #else
@@ -230,7 +232,7 @@ boolean I_MidiPipe_RegisterSong(char *filename)
     net_packet_t *packet;

     packet = NET_NewPacket(64);
-    NET_WriteInt16(packet, NET_MIDIPIPE_PACKET_TYPE_REGISTER_SONG);
+    NET_WriteInt16(packet, MIDIPIPE_PACKET_TYPE_REGISTER_SONG);
     NET_WriteString(packet, filename);
     ok = WritePipe(packet);
     NET_FreePacket(packet);
@@ -242,7 +244,7 @@ boolean I_MidiPipe_RegisterSong(char *filename)
     }

     packet = NET_NewPacket(2);
-    NET_WriteInt16(packet, NET_MIDIPIPE_PACKET_TYPE_REGISTER_SONG_ACK);
+    NET_WriteInt16(packet, MIDIPIPE_PACKET_TYPE_REGISTER_SONG_ACK);
     ok = ExpectPipe(packet);
     NET_FreePacket(packet);

@@ -269,7 +271,7 @@ void I_MidiPipe_SetVolume(int vol)
     net_packet_t *packet;

     packet = NET_NewPacket(6);
-    NET_WriteInt16(packet, NET_MIDIPIPE_PACKET_TYPE_SET_VOLUME);
+    NET_WriteInt16(packet, MIDIPIPE_PACKET_TYPE_SET_VOLUME);
     NET_WriteInt32(packet, vol);
     ok = WritePipe(packet);
     NET_FreePacket(packet);
@@ -294,7 +296,7 @@ void I_MidiPipe_PlaySong(int loops)
     net_packet_t *packet;

     packet = NET_NewPacket(6);
-    NET_WriteInt16(packet, NET_MIDIPIPE_PACKET_TYPE_PLAY_SONG);
+    NET_WriteInt16(packet, MIDIPIPE_PACKET_TYPE_PLAY_SONG);
     NET_WriteInt32(packet, loops);
     ok = WritePipe(packet);
     NET_FreePacket(packet);
@@ -319,7 +321,7 @@ void I_MidiPipe_StopSong()
     net_packet_t *packet;

     packet = NET_NewPacket(2);
-    NET_WriteInt16(packet, NET_MIDIPIPE_PACKET_TYPE_STOP_SONG);
+    NET_WriteInt16(packet, MIDIPIPE_PACKET_TYPE_STOP_SONG);
     ok = WritePipe(packet);
     NET_FreePacket(packet);

@@ -345,7 +347,7 @@ void I_MidiPipe_ShutdownServer()
     net_packet_t *packet;

     packet = NET_NewPacket(2);
-    NET_WriteInt16(packet, NET_MIDIPIPE_PACKET_TYPE_SHUTDOWN);
+    NET_WriteInt16(packet, MIDIPIPE_PACKET_TYPE_SHUTDOWN);
     ok = WritePipe(packet);
     NET_FreePacket(packet);

diff --git a/src/net_defs.h b/src/net_defs.h
index c55c7bbc..bedfb95b 100644
--- a/src/net_defs.h
+++ b/src/net_defs.h
@@ -142,15 +142,6 @@ typedef enum
     NET_MASTER_PACKET_TYPE_SIGN_END_RESPONSE,
 } net_master_packet_type_t;

-typedef enum {
-    NET_MIDIPIPE_PACKET_TYPE_REGISTER_SONG,
-    NET_MIDIPIPE_PACKET_TYPE_REGISTER_SONG_ACK,
-    NET_MIDIPIPE_PACKET_TYPE_SET_VOLUME,
-    NET_MIDIPIPE_PACKET_TYPE_PLAY_SONG,
-    NET_MIDIPIPE_PACKET_TYPE_STOP_SONG,
-    NET_MIDIPIPE_PACKET_TYPE_SHUTDOWN
-} net_midipipe_packet_type_t;
-
 // Settings specified when the client connects to the server.

 typedef struct