shithub: choc

Download patch

ref: 33120be8fa37ddb48ab09c7de955bd54a070e4c1
parent: 01e91aab21ad457dc7cd04d4288d38eaf46286df
author: Simon Howard <[email protected]>
date: Wed Jan 4 21:33:25 EST 2012

Add hack command-line option for on-screen OPL status output - useful
for GENMIDI development.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 2482

--- a/src/i_oplmusic.c
+++ b/src/i_oplmusic.c
@@ -47,11 +47,14 @@
 
 #define MAXMIDLENGTH (96 * 1024)
 #define GENMIDI_NUM_INSTRS  128
+#define GENMIDI_NUM_PERCUSSION 47
 
 #define GENMIDI_HEADER          "#OPL_II#"
 #define GENMIDI_FLAG_FIXED      0x0001         /* fixed pitch */
 #define GENMIDI_FLAG_2VOICE     0x0004         /* double voice (OPL3) */
 
+#define PERCUSSION_LOG_LEN 16
+
 typedef struct
 {
     byte tremolo;
@@ -314,6 +317,8 @@
 
 static genmidi_instr_t *main_instrs;
 static genmidi_instr_t *percussion_instrs;
+static char (*main_instr_names)[32];
+static char (*percussion_names)[32];
 
 // Voices:
 
@@ -328,6 +333,11 @@
 static unsigned int running_tracks = 0;
 static boolean song_looping;
 
+// Mini-log of recently played percussion instruments:
+
+static uint8_t last_perc[PERCUSSION_LOG_LEN];
+static unsigned int last_perc_count;
+
 // Configuration file variable, containing the port number for the
 // adlib chip.
 
@@ -352,6 +362,8 @@
 
     main_instrs = (genmidi_instr_t *) (lump + strlen(GENMIDI_HEADER));
     percussion_instrs = main_instrs + GENMIDI_NUM_INSTRS;
+    main_instr_names = (char (*)[32]) (percussion_instrs + GENMIDI_NUM_PERCUSSION);
+    percussion_names = main_instr_names + GENMIDI_NUM_INSTRS;
 
     return true;
 }
@@ -894,6 +906,9 @@
         }
 
         instrument = &percussion_instrs[key - 35];
+
+        last_perc[last_perc_count] = key;
+        last_perc_count = (last_perc_count + 1) % PERCUSSION_LOG_LEN;
     }
     else
     {
@@ -1467,4 +1482,96 @@
     I_OPL_StopSong,
     I_OPL_MusicIsPlaying,
 };
+
+//----------------------------------------------------------------------
+//
+// Development / debug message generation, to help developing GENMIDI
+// lumps.
+//
+//----------------------------------------------------------------------
+
+static int NumActiveChannels(void)
+{
+    int i;
+
+    for (i = MIDI_CHANNELS_PER_TRACK - 1; i >= 0; --i)
+    {
+        if (tracks[0].channels[i].instrument != &main_instrs[0])
+        {
+            return i + 1;
+        }
+    }
+
+    return 0;
+}
+
+static int ChannelInUse(opl_channel_data_t *channel)
+{
+    opl_voice_t *voice;
+
+    for (voice = voice_alloced_list; voice != NULL; voice = voice->next)
+    {
+        if (voice->channel == channel)
+        {
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
+void I_OPL_DevMessages(char *result)
+{
+    int instr_num;
+    int lines;
+    int i;
+
+    if (num_tracks == 0)
+    {
+        sprintf(result, "No OPL track!");
+        return;
+    }
+
+    sprintf(result, "Tracks:\n");
+    lines = 1;
+
+    for (i = 0; i < NumActiveChannels(); ++i)
+    {
+        if (tracks[0].channels[i].instrument == NULL)
+        {
+            continue;
+        }
+
+        instr_num = tracks[0].channels[i].instrument - main_instrs;
+
+        sprintf(result + strlen(result),
+                "chan %i: %c i#%i (%s)\n",
+                i,
+                ChannelInUse(&tracks[0].channels[i]) ? '\'' : ' ',
+                instr_num + 1,
+                main_instr_names[instr_num]);
+        ++lines;
+    }
+
+    sprintf(result + strlen(result), "\nLast percussion:\n");
+    lines += 2;
+
+    i = (last_perc_count + PERCUSSION_LOG_LEN - 1) % PERCUSSION_LOG_LEN;
+
+    do {
+        if (last_perc[i] == 0)
+        {
+            break;
+        }
+
+        sprintf(result + strlen(result),
+                "%cp#%i (%s)\n",
+                i == 0 ? '\'' : ' ',
+                last_perc[i],
+                percussion_names[last_perc[i] - 35]);
+        ++lines;
+
+        i = (i + PERCUSSION_LOG_LEN - 1) % PERCUSSION_LOG_LEN;
+    } while (lines < 25 && i != last_perc_count);
+}
 
--- a/src/m_menu.c
+++ b/src/m_menu.c
@@ -161,6 +161,7 @@
 
 char	endstring[160];
 
+static boolean opldev;
 
 //
 // MENU TYPEDEFS
@@ -1886,7 +1887,40 @@
     itemOn = currentMenu->lastOn;   // JDC
 }
 
+// Display OPL debug messages - hack for GENMIDI development.
 
+static void M_DrawOPLDev(void)
+{
+    extern void I_OPL_DevMessages(char *);
+    char debug[1024];
+    char *curr, *p;
+    int line;
+
+    I_OPL_DevMessages(debug);
+    curr = debug;
+    line = 0;
+
+    for (;;)
+    {
+        p = strchr(curr, '\n');
+
+        if (p != NULL)
+        {
+            *p = '\0';
+        }
+
+        M_WriteText(0, line * 8, curr);
+        ++line;
+
+        if (p == NULL)
+        {
+            break;
+        }
+
+        curr = p + 1;
+    }
+}
+
 //
 // M_Drawer
 // Called after the view has been rendered,
@@ -1937,6 +1971,11 @@
 	return;
     }
 
+    if (opldev)
+    {
+        M_DrawOPLDev();
+    }
+
     if (!menuactive)
 	return;
 
@@ -1964,7 +2003,6 @@
     V_DrawPatchDirect(x + SKULLXOFF,currentMenu->y - 5 + itemOn*LINEHEIGHT, 0,
 		      W_CacheLumpName(DEH_String(skullName[whichSkull]),
 				      PU_CACHE));
-
 }
 
 
@@ -2045,6 +2083,7 @@
       default:
 	break;
     }
-    
+
+    opldev = M_CheckParm("-opldev") > 0;
 }