0

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?

Invariant
  • 185
  • 1
  • 11
  • If you attach the MIDI file you are having trouble with, I could have a look... –  Nov 04 '21 at 18:14
  • @Sema- Try for example: http://midkar.com/MidiStudio/ERock/Spice_Girls_Wannabe_XG.mid Notice how the Steel String Guitar track is really a drum track. – Invariant Nov 04 '21 at 20:52

2 Answers2

1

The general answer is there is no "simple" way of detecting that a midi file uses XG drums notes.

If you assume drums are on channel 10 [1-16], which is not mandatory with a XG synth, the presence of drums notes which are out of the GM drum map [pitch 35-81] might give you a hint. But it could also be a GM2 file! And some drums styles may not use these non-GM notes, even if it's really a XG file.

A better way is probably to search for a XG specific SysEx message, such as XG SYSTEM ON (F0,43,10,4C,00,00,7E,00,F7), which is necessary to enable the 'XG Mode' of a XG synthesizer.

Also, if your XG files always come from the same source, you could check if the Midi file contains some Meta messages such as Text, Copyright notice, Instrument name, Track name, which might indicate it's a XG file.

jjazzboss
  • 1,261
  • 8
  • 14
  • Alright I managed to find the F0,43,10,4C,00,00,7E,00,F7 sysex message. So now I know how to detect its an XG file. Now I just need to know which notes are drums and which are notes. – Invariant Nov 04 '21 at 22:20
  • Most of the time drums notes are on channel 10 [1-16]. – jjazzboss Nov 04 '21 at 22:53
1

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