This patch by Achraf cherti adds MIDI file support to Red Pixel 1.

diff -u -urN redpixel-1.0/makefile.red redpixel-1.0-midi/makefile.red
--- redpixel-1.0/makefile.red	2001-12-23 19:53:42.000000000 +1100
+++ redpixel-1.0-midi/makefile.red	2004-02-02 12:42:31.000000000 +1100
@@ -85,6 +85,7 @@
 	rpagup		\
 	rpcd		\
 	rpjgmod		\
+	rpmidi      	\
 	setweaps	\
 	sk		\
 	sklibnet	\
diff -u -urN redpixel-1.0/src/include/music.h redpixel-1.0-midi/src/include/music.h
--- redpixel-1.0/src/include/music.h	2001-12-09 19:39:13.000000000 +1100
+++ redpixel-1.0-midi/src/include/music.h	2003-07-19 04:15:23.000000000 +1000
@@ -5,7 +5,7 @@
 #define MUSIC_FMT_NONE	0
 #define MUSIC_FMT_MOD	1
 #define MUSIC_FMT_CD	2
-
+#define MUSIC_FMT_MIDI  3
 
 void music_init(void);
 void music_shutdown(void);
diff -u -urN redpixel-1.0/src/include/rpmidi.h redpixel-1.0-midi/src/include/rpmidi.h
--- redpixel-1.0/src/include/rpmidi.h	1970-01-01 10:00:00.000000000 +1000
+++ redpixel-1.0-midi/src/include/rpmidi.h	2004-02-02 12:42:31.000000000 +1100
@@ -0,0 +1,15 @@
+/************************************
+ * Midi support for Red pixel
+ *
+ * Added by Achraf cherti
+ ***********************************/
+
+#ifndef _rpmidi_H
+#define _rpmidi_H
+void rpmidi_shutdown();
+void rpmidi_init();
+void rpmidi_play_random_track();
+void rpmidi_stop(void);
+void rpmidi_poll();
+void rpmidi_set_volume(int volume);
+#endif
diff -u -urN redpixel-1.0/src/main.c redpixel-1.0-midi/src/main.c
--- redpixel-1.0/src/main.c	2001-12-22 13:42:12.000000000 +1100
+++ redpixel-1.0-midi/src/main.c	2004-02-02 12:42:31.000000000 +1100
@@ -119,10 +119,10 @@
     reserve_voices(32, -1);
 #ifdef TARGET_WINDOWS
     /* the default hardware-based mixer sounds bad with jgmod */
-    if (install_sound(DIGI_DIRECTAMX(0), MIDI_NONE, NULL) != 0)
-	install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL);    
+    if (install_sound(DIGI_DIRECTAMX(0), MIDI_AUTODETECT, NULL) != 0)
+	install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL);    
 #else
-    install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL);
+    install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL);
 #endif
 
     /* set up game path */
diff -u -urN redpixel-1.0/src/music.c redpixel-1.0-midi/src/music.c
--- redpixel-1.0/src/music.c	2001-12-15 22:18:27.000000000 +1100
+++ redpixel-1.0-midi/src/music.c	2004-02-02 12:47:41.000000000 +1100
@@ -10,7 +10,7 @@
 #include "music.h"
 #include "rpcd.h"
 #include "rpjgmod.h"
-
+#include "rpmidi.h" //added by Achraf.c
 
 static int inited = 0;
 static int format =  MUSIC_FMT_MOD;
@@ -29,6 +29,7 @@
 {
     rpcd_init();
     rpjgmod_init();
+	rpmidi_init();
     LOCK_VARIABLE(need_poll);
     LOCK_FUNCTION(need_poll_ticker);
     install_int(need_poll_ticker, 4000);
@@ -42,6 +43,7 @@
 	remove_int(need_poll_ticker);
 	rpjgmod_shutdown();
 	rpcd_shutdown();
+	rpmidi_shutdown();
 	inited = 0;
     }
 }
@@ -55,7 +57,8 @@
 
 void music_set_format(int music_format)
 {
-    if ((music_format == MUSIC_FMT_MOD) || (music_format == MUSIC_FMT_CD))
+    if ((music_format == MUSIC_FMT_MOD) || (music_format == MUSIC_FMT_CD) || 
+		music_format == MUSIC_FMT_MIDI)
 	format = music_format;
     else
 	format = MUSIC_FMT_NONE;
@@ -70,6 +73,8 @@
 	rpcd_play_random_track();
     else if (format == MUSIC_FMT_MOD)
 	rpjgmod_play_random_track();
+	else if(format == MUSIC_FMT_MIDI)
+	rpmidi_play_random_track();
 }
 
 
@@ -80,6 +85,8 @@
 	    rpcd_poll();
 	else if (format == MUSIC_FMT_MOD)
 	    rpjgmod_poll();
+	else if (format == MUSIC_FMT_MIDI) 
+	    rpmidi_poll();
 	need_poll = 0;
     }
 }
@@ -93,4 +100,6 @@
 	rpcd_stop();
     else if (format == MUSIC_FMT_MOD)
 	rpjgmod_stop();
+	else if (format == MUSIC_FMT_MIDI)
+	rpmidi_stop();
 }
diff -u -urN redpixel-1.0/src/options.c redpixel-1.0-midi/src/options.c
--- redpixel-1.0/src/options.c	2001-12-22 13:42:00.000000000 +1100
+++ redpixel-1.0-midi/src/options.c	2004-02-02 12:42:31.000000000 +1100
@@ -23,7 +23,7 @@
 #include "statlist.h"
 #include "suicide.h"
 #include "vidmode.h"
-
+#include "rpmidi.h"
 
 
 int mouse_speed;
@@ -34,6 +34,7 @@
 
 static int sfx_volume;
 static int mod_volume;
+static int midi_volume;
 static int cd_volume;
 
 
@@ -78,6 +79,13 @@
     return D_O_K;
 }
 
+static int midi_volume_callback(void *dp3, int d2)
+{
+    rpmidi_set_volume(d2 * 32);
+    return D_O_K;
+}
+
+
 
 static int push_stats_button(DIALOG *d)
 {
@@ -118,18 +126,18 @@
 
     { d_agup_box_proc,        10,   65,   300, 100, 0,    0,    0,   0,           0,    0,  NULL,             NULL,  NULL }, /* 7 */
 
-    { d_agup_check_proc,      15,   70,   130, 20,  0,    0,    0,   0,           0,    0,  "MUTE SOUND EFFECTS", NULL,  NULL }, /* 8 */
-    { d_agup_radio_proc,      15,   95,   130, 20,  0,    0,    0,   0,           1,    0,  "NO MUSIC",       NULL,  NULL }, /* 9 */
-    { d_agup_radio_proc,      15,   115,  130, 20,  0,    0,    0,   0,           1,    0,  "PLAY MODULES",   NULL,  NULL }, /* 10 */
-    { d_agup_radio_proc,      15,   135,  130, 20,  0,    0,    0,   0,           1,    0,  "PLAY CD",        NULL,  NULL }, /* 11 */
+    { d_agup_check_proc,      15,   67,   130, 17,  0,    0,    0,   0,           0,    0,  "MUTE SOUND EFFECTS", NULL,  NULL }, /* 8 */
+    { d_agup_radio_proc,      15,   94,   130, 20,  0,    0,    0,   0,           1,    0,  "NO MUSIC",      NULL, NULL }, /* 9 */
+    { d_agup_radio_proc,      15,   126,  130, 20,  0,    0,    0,   0,           1,    0,  "PLAY MODULES",  NULL, NULL}, /* 10 */
+    { d_agup_radio_proc,      15,   141,  130, 20,  0,    0,    0,   0,           1,    0,  "PLAY CD",       NULL, NULL}, /* 11 */
 
-    { d_agup_check_proc,      180,  70,   100, 20,  0,    0,    0,   0,           0,    0,  "RECORD DEMOS",   NULL,  NULL }, /* 12 */
+    { d_agup_check_proc,      180,  67,   100, 17,  0,    0,    0,   0,           0,    0,  "RECORD DEMOS",   NULL,  NULL }, /* 12 */
 
-    { d_text_proc,            160,  95,   40,  8,   0,    0,    0,   0,           0,    0,  "MOUSE SPEED",    NULL,  NULL }, /* 13 */
-    { d_agup_slider_proc,     225,  93,   60,  12,  0,    0,    0,   0,           3,    0,  NULL,             mouse_speed_callback,  NULL }, /* 14 */
+    { d_text_proc,            160,  86,   40,  8,   0,    0,    0,   0,           0,    0,  "MOUSE SPEED",    NULL,  NULL }, /* 13 */
+    { d_agup_slider_proc,     225,  85,   60,  12,  0,    0,    0,   0,           3,    0,  NULL,             mouse_speed_callback,  NULL }, /* 14 */
 
-    { d_text_proc,            160,  117,  20,  8,   0,    0,    0,   0,           0,    0,  "SFX",            NULL,  NULL }, /* 15 */
-    { d_agup_slider_proc,     185,  115,  100, 12,  0,    0,    0,   0,           8,    0,  NULL,             sfx_volume_callback,  NULL }, /* 16 */
+    { d_text_proc,            160,  102,  20,  8,   0,    0,    0,   0,           0,    0,  "SFX",            NULL,  NULL }, /* 15 */
+    { d_agup_slider_proc,     185,  100,  100, 12,  0,    0,    0,   0,           8,    0,  NULL,             sfx_volume_callback,  NULL }, /* 16 */
     { d_text_proc,            160,  132,  20,  8,   0,    0,    0,   0,           0,    0,  "MODS",           NULL,  NULL }, /* 17 */
     { d_agup_slider_proc,     185,  130,  100, 12,  0,    0,    0,   0,           8,    0,  NULL,             NULL,  NULL }, /* 18 */
     { d_text_proc,            160,  147,  20,  8,   0,    0,    0,   0,           0,    0,  "CD",             NULL,  NULL }, /* 19 */
@@ -140,8 +148,13 @@
     { d_agup_button_proc,     170,  170,  60,  20,  0,    0,    0,   D_EXIT,      0,    0,  "ACCEPT",         NULL,  NULL }, /* 22 */
     { d_agup_button_proc,     245,  170,  60,  20,  0,    0,    27,  D_EXIT,      0,    0,  "REJECT",         NULL,  NULL }, /* 23 */
 
-    { d_yield_proc,           0,    0,    0,   0,   0,    0,    0,   0,           0,    0,  NULL,             NULL,  NULL },
-    { NULL,                   0,    0,    0,   0,   0,    0,    0,   0,           0,    0,  NULL,             NULL,  NULL },
+    { d_yield_proc,           0,    0,    0,   0,   0,    0,    0,   0,           0,    0,  NULL,             NULL,  NULL }, /* 24 */
+// MIDI option
+	{ d_agup_radio_proc,      15,   110,   130, 20,  0,    0,    0,   0,           1,    0,  "PLAY MIDI",       NULL,  NULL },  /* 25 */
+    { d_text_proc,            160,  117,  20,  8,   0,    0,    0,   0,           0,    0,  "MID",            NULL,  NULL }, /* 26 */
+    { d_agup_slider_proc,     185,  115,  100, 12,  0,    0,    0,   0,           8,    0,  NULL,             midi_volume_callback,  NULL }, /* 27 */
+ 
+    { NULL,                   0,    0,    0,   0,   0,    0,    0,   0,           0,    0,  NULL,             NULL,  NULL }, 
 };
 
 
@@ -161,7 +174,8 @@
 #define I_STATS		21
 #define I_ACCEPT	22
 #define I_REJECT	23
-
+#define I_MIDVOLUME 27
+#define I_PLAYMIDI	25
 
 static void set_D_SELECTED(DIALOG *d, int yes)
 {
@@ -178,13 +192,12 @@
     int old_desired_video_mode = desired_video_mode;
     int old_want_scanlines = want_scanlines;
     int old_sfx_volume = sfx_volume;
-    
+	
     old_font = font;
     font = dat[MINI].dat;
 
     push_stat_block();
 
-
     /* set up config_dlg */
     {
 	config_dlg[I_RESLIST].d1 = desired_video_mode;
@@ -198,8 +211,10 @@
 	    config_dlg[I_NOMUSIC].flags &=~ D_SELECTED;
 	    config_dlg[I_PLAYMODULES].flags &=~ D_SELECTED;
 	    config_dlg[I_PLAYCD].flags &=~ D_SELECTED;
-	    switch (music_get_format()) {
+	    config_dlg[I_PLAYMIDI].flags &=~ D_SELECTED;
+		switch (music_get_format()) {
 		case MUSIC_FMT_NONE: config_dlg[I_NOMUSIC].flags |= D_SELECTED; break;
+		case MUSIC_FMT_MIDI: config_dlg[I_PLAYMIDI].flags |= D_SELECTED;  break;
 		case MUSIC_FMT_MOD: config_dlg[I_PLAYMODULES].flags |= D_SELECTED; break;
 		case MUSIC_FMT_CD: config_dlg[I_PLAYCD].flags |= D_SELECTED; break;
 	    }
@@ -212,6 +227,7 @@
 	config_dlg[I_SFXVOLUME].d2 = sfx_volume;
 	config_dlg[I_MODVOLUME].d2 = mod_volume;
 	config_dlg[I_CDVOLUME].d2 = cd_volume;
+	config_dlg[I_MIDVOLUME].d2 = midi_volume;
 
 	strncpy(stats_filename, get_filename(current_stats), sizeof stats_filename);
 	strncpy(stats_path, current_stats, sizeof stats_path);
@@ -235,12 +251,19 @@
 	mute_sfx = config_dlg[I_MUTESFX].flags & D_SELECTED;
 	
 	{
-	    if (config_dlg[I_NOMUSIC].flags & D_SELECTED)
-		music_set_format(MUSIC_FMT_NONE);
-	    else if (config_dlg[I_PLAYMODULES].flags & D_SELECTED)
-		music_set_format(MUSIC_FMT_MOD);
-	    else if (config_dlg[I_PLAYCD].flags & D_SELECTED)
-		music_set_format(MUSIC_FMT_CD);
+	    if (config_dlg[I_NOMUSIC].flags & D_SELECTED) {
+			music_set_format(MUSIC_FMT_NONE);
+		}
+	    else if (config_dlg[I_PLAYMODULES].flags & D_SELECTED) {
+			music_set_format(MUSIC_FMT_MOD);
+		}
+	    else if (config_dlg[I_PLAYCD].flags & D_SELECTED) {
+			music_set_format(MUSIC_FMT_CD);
+		}
+	    else if (config_dlg[I_PLAYMIDI].flags & D_SELECTED) {
+			music_set_format(MUSIC_FMT_MIDI);
+		}
+	
 	}
 	
 	record_demos = config_dlg[I_RECORDREMOS].flags & D_SELECTED;
@@ -249,6 +272,7 @@
 
 	sfx_volume = config_dlg[I_SFXVOLUME].d2;
 	mod_volume = config_dlg[I_MODVOLUME].d2;
+	midi_volume = config_dlg[I_MIDVOLUME].d2;
 	cd_volume = config_dlg[I_CDVOLUME].d2;
 	
 	set_current_stats(stats_path);
@@ -272,8 +296,9 @@
     set_mouse_speed(mouse_speed, mouse_speed);
 
     set_volume(sfx_volume * 32, -1);
-    rpjgmod_set_volume(mod_volume * 32);
-    rpcd_set_volume(cd_volume * 32);
+    rpjgmod_set_volume(mod_volume * 32); 
+	rpmidi_set_volume(midi_volume*32);
+	rpcd_set_volume(cd_volume * 32);
 
     
     set_weapon_stats();
@@ -281,7 +306,7 @@
     font = old_font;
 
     show_mouse(NULL);
-
+	
     /* In modes where not the full screen is used, we don't want the
      * top and bottom parts to be gray. */
     clear_bitmap(screen);
@@ -325,6 +350,8 @@
     set_current_stats((char *)get_config_string(section, "stats_file", "stats/default.st"));
     sfx_volume = get_config_int(section, "sfx_volume", 8); set_volume(sfx_volume * 32, -1);
     mod_volume = get_config_int(section, "mod_volume", 3); rpjgmod_set_volume(mod_volume * 32);
+    midi_volume = get_config_int(section, "midi_volume", 3); rpmidi_set_volume(midi_volume * 32);
+	
     cd_volume = rpcd_get_volume() / 32;
     
     close_cfg();
@@ -346,6 +373,7 @@
     set_config_string(section, "stats_file", current_stats);
     set_config_int(section, "sfx_volume", sfx_volume);
     set_config_int(section, "mod_volume", mod_volume);
+    set_config_int(section, "midi_volume", midi_volume);
 
     close_cfg();
 }
diff -u -urN redpixel-1.0/src/rpmidi.c redpixel-1.0-midi/src/rpmidi.c
--- redpixel-1.0/src/rpmidi.c	1970-01-01 10:00:00.000000000 +1000
+++ redpixel-1.0-midi/src/rpmidi.c	2004-02-02 12:42:31.000000000 +1100
@@ -0,0 +1,126 @@
+/*
+ *  Red Pixel, a violent game.
+ *  Copyright (C) 1999 Psyk Software.
+ * 
+ *
+ *  Midi support added by Achraf cherti. 
+ */
+
+#ifndef NO_MIDI_CODE
+
+#include <allegro.h>
+#include "rpmidi.h"
+#include <string.h>
+
+static char **filename=0;
+static int sizeof_filename=0;
+
+static int actual_midi=0;
+static MIDI *music=0;
+static int inited=0;
+
+// INIT
+void rpmidi_init()
+{ 
+	int n;
+	int i=0;
+	struct al_ffblk info;
+	
+	inited = 1; 
+	
+	n = al_findfirst("music/*.mid",&info,FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_ARCH);
+
+	// Pas de midi?
+	if(n) {
+			// aucun fichier midi
+			inited=0;
+			al_findclose(&info);
+			return;
+	}
+	
+	while(!n) {
+		// Reallocation du fichier
+		if(!(filename = (char **) realloc(filename, (i+1)*sizeof(char *)))) {
+				inited=0; i=0;
+				break;
+		}
+	
+		// Copie du nom de fichier 
+		if(!(filename[i]=malloc(strlen(info.name)+strlen("music/")+1))) {
+			// Jouer seulement les midis alloqués...
+			break;
+		}
+		strcpy(filename[i], "music/");
+		strcat(filename[i], info.name);
+		
+		// End
+		n = al_findnext(&info);
+		i++;
+	}
+	al_findclose(&info);
+	sizeof_filename = i;
+}
+
+// SHUTDOWN
+void rpmidi_shutdown()
+{ 
+	int j;
+	
+	// destroy the music
+	if(music) {
+		destroy_midi(music); 
+		music = 0;
+	}
+  
+	// free all
+	if(filename) {
+		for(j=0;j<sizeof_filename;j++) 
+			free(filename[j]);
+		free(filename);
+	}
+}
+
+// VOLUME
+void rpmidi_set_volume(int volume)
+{
+	set_volume(-1,volume);
+}
+
+// PLAY RANDOM TRACK
+void rpmidi_play_random_track()
+{ 
+	int i;
+	
+	if(!inited) return;
+	
+	// Si mauvais midi alors il essaye 3 fois
+	for (i=0;i<=3;i++) {
+		music = load_midi(filename[actual_midi]);
+		actual_midi = (actual_midi + 1) % sizeof_filename;
+		if(music) break;
+	}
+	if(music) play_midi(music,TRUE);
+}
+
+// STOP
+void rpmidi_stop(void)
+{
+		if(!inited) return;
+		stop_midi(); 
+}
+
+// POLL
+void rpmidi_poll()
+{}
+
+#else 
+
+void rpmidi_poll() {}
+void rpmidi_stop(void) {}
+void rpmidi_play_random_track() {}
+void rpmidi_set_volume(int volume) {}
+void rpmidi_shutdown() {}
+void rpmidi_init() {}
+
+#endif /* define: NO MIDI CODE */
+
