javamidijavax.sound.midi

XG MIDI messages


I am working on a Java program that uses javax.sound.midi for reading MIDI files.

I have come across a MIDI file that is encoded in XG.

When I play it on my Yamaha keyboard the drums sound fine. But in Java I do not know how to detect a track is drums if the MIDI is XG, or how to find out the MIDI is XG for that sake.

The way of doing it by detecting if channel is equal to 9 in Note ON messages, does not seem to detect all XG drum notes.

Anyone knows a (hopefully simple) way to detect XG drum notes?


Solution

  • XG allows drum sets on any channel.

    You need to check for "Bank Select" and "Program Change" messages.

    Here are your drums on channels 9, 10, 11:

    offset   tick  message
    ...
    [  545]   842: b8 00 7f -- Bank Select MSB
    [  549]   844: b8 20 00 -- Bank Select LSB
    [  553]   846: c8 10 -- Program Change (Rock Drum Kit)
    ...
    [  602]   872: b9 00 7f -- Bank Select MSB
    [  606]   874: b9 20 00 -- Bank Select LSB
    [  610]   876: c9 00 -- Program Change (Standard Drum Kit)
    ...
    [  648]   900: ba 00 7f -- Bank Select MSB
    [  652]   902: ba 20 00 -- Bank Select LSB
    [  656]   904: ca 19 -- Program Change (Analog Drum Kit)
    

    The above listing was made using https://github.com/jazz-soft/test-midi-files