Invariant
Invariant

Reputation: 194

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?

Upvotes: 0

Views: 190

Answers (2)

user11930298
user11930298

Reputation:

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

Upvotes: 1

jjazzboss
jjazzboss

Reputation: 1422

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.

Upvotes: 1

Related Questions