foxygit / doom Log in
commit b2e5952c454dd46b29ca6c64e742b4505c20d5b7
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Tue May 6 22:03:00 2014 -0400
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Tue May 6 22:03:00 2014 -0400

    oplmusic: Handle key-on with volume 0 as key-off.

    Some MIDI files, such as the music tracks in AV.wad, use a second
    "key on" event with a volume of zero to mean "key off". Handle this
    case correctly.
---
 src/i_oplmusic.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/i_oplmusic.c b/src/i_oplmusic.c
index c07146a7..a2bc22d8 100644
--- a/src/i_oplmusic.c
+++ b/src/i_oplmusic.c
@@ -881,12 +881,21 @@ static void KeyOnEvent(opl_track_data_t *track, midi_event_t *event)
            event->data.channel.param2);
 */

-    // The channel.
-
-    channel = &track->channels[event->data.channel.channel];
     key = event->data.channel.param1;
     volume = event->data.channel.param2;

+    // A volume of zero means key off. Some MIDI tracks, eg. the ones
+    // in AV.wad, use a second key on with a volume of zero to mean
+    // key off.
+    if (volume <= 0)
+    {
+        KeyOffEvent(track, event);
+        return;
+    }
+
+    // The channel.
+    channel = &track->channels[event->data.channel.channel];
+
     // Percussion channel (10) is treated differently.

     if (event->data.channel.channel == 9)