foxygit / doom Log in
commit 9cc843c60027cb9365f3eaae3028343769d17a26
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Sat Aug 29 21:22:32 2009 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Sat Aug 29 21:22:32 2009 +0000

    Load MIDI file.

    Subversion-branch: /branches/opl-branch
    Subversion-revision: 1637
---
 src/i_oplmusic.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/i_oplmusic.c b/src/i_oplmusic.c
index f50c3322..c444dfd8 100644
--- a/src/i_oplmusic.c
+++ b/src/i_oplmusic.c
@@ -40,6 +40,7 @@
 #include "z_zone.h"

 #include "opl.h"
+#include "midifile.h"

 #define MAXMIDLENGTH (96 * 1024)
 #define GENMIDI_NUM_INSTRS  128
@@ -507,6 +508,11 @@ static void I_OPL_UnRegisterSong(void *handle)
     {
         return;
     }
+
+    if (handle != NULL)
+    {
+        MIDI_FreeFile(handle);
+    }
 }

 // Determine whether memory block is a .mid file
@@ -544,6 +550,7 @@ static boolean ConvertMus(byte *musdata, int len, char *filename)

 static void *I_OPL_RegisterSong(void *data, int len)
 {
+    midi_file_t *result;
     char *filename;

     if (!music_initialised)
@@ -567,7 +574,12 @@ static void *I_OPL_RegisterSong(void *data, int len)
         ConvertMus(data, len, filename);
     }

-    // ....
+    result = MIDI_LoadFile(filename);
+
+    if (result == NULL)
+    {
+        fprintf(stderr, "I_OPL_RegisterSong: Failed to load MID.\n");
+    }

     // remove file now

@@ -575,7 +587,7 @@ static void *I_OPL_RegisterSong(void *data, int len)

     Z_Free(filename);

-    return NULL;
+    return result;
 }

 // Is the song playing?