MIDI export: incorrect key signature event xFF\x59\x02 (major/minor byte)


When exporting midi files in Hookpad the key signature is incorrectly written. The number of sharps/flats appears to be correct, but the byte which indicates whether the key is major or minor is left empty so all keys are interpreted as major.

I’ve confirmed this myself from the midi spec and with a hex editor, then asked ChatGPT to confirm which it did after writing a Python script to analyze a file I exported which was a simple chord progression in Em. The forum doesn’t allow uploading .mid, .zip so I just pasted the chords directly from Hookpad at the bottom.

This shows the file in hex. FF 59 02 indicates the location of the key signature event. 01 indicates 1 sharp, however the scale type value is incorrect (or possibly never written so defaults to major)
MIDI hex2


The following is from ChatGPT-4:

The key signature event in the “Em MIDI Test.mid” file is 01 00. The bytes break down as follows:

  • 01 represents the key signature. In this case, as a signed byte, it stands for 1 sharp. This is typical for the key of G major or E minor, both of which share the same single sharp (F#) in their key signature.
  • 00 represents the scale type, which indicates a major scale. This is contradictory to your expectation of it being E minor, as a minor scale would be indicated by 01.

Given that you’ve set the project as Em and you’re expecting a minor key signature, the metadata should indeed show 01 01 (1 sharp and minor scale), but it’s showing 01 00 (1 sharp and major scale) instead. This is likely why Reaper is displaying G major as the key. It seems the issue might be related to how the key signature is being set or interpreted in the software or website you used to create the MIDI file, as it is not marking the file as minor despite your settings.

It might be worth verifying the settings or methods used when exporting or setting up the MIDI file in your music creation tool to ensure the minor key is correctly encoded. If it’s consistently incorrect, you might need to check for software updates, documentation, or support regarding key signature handling.

Hookpad information to recreate the project if needed:


i create a quick Em key x 4 measures = same 01 00. given the nature of how different programs view this, will be G Major or Em because they share the same key signature. e.g. importing my MIDI into Musescore:

obviously the scale degrees will be different between G Major and Em even with the same set of underlying values.

1 Like

Yes, that’s correct. We’re currently only exporting the accidentals, not the mode. I’ll ask around if there’s a reason for that. Apart from that the exported notes themselves are correct.



Please do ask around.

It’s very helpful to have correct metadata for manually transposing midi for preview playback in a DAW when searching/filtering by key.

i.e If I’m in Fm I can set the playback pitch to +1 and midi files in Em can be previewed in context, but if the root note of a midi file in Em is written as G I’ll think the pitch needs to be -3.

Major and minor scales may share the same notes, but I don’t think I need to explain to a music theory company that they have different emotional qualities that are relevant to know. :wink:

If the reason is a trade-off of some kind it would be best to allow the user to make that choice based on their individual circumstances.

Also, including relevant information like key in the default filenames for rather than using generic ones like harmony piano 1_4s.mid would make metadata less relevant.


1 Like

you have to wonder if modes beyond minor or major can be represented in the MIDI ( MIDI Key Signature meta message | RecordingBlogs

Standard MIDI files do not define any modes other than 0 = major and 1 = minor. Key signature is a message rather than meta-event in MIDI 2.0 (see section 7.5.7), and you can supposedly represent all 7 diatonic modes by specifying the correct tonic key, but it’s going to take many years before .midi2 files gain mainstream support


technically i suppose you could write more than 0 or 1 in the current MIDI structure and have your program interpret it (or translate it into something which scripts your DAW understanding) but no one is going to support that extension :slight_smile: this is one of those areas where something like Musescore is handy to tweak things.

so i guess we’ll have to wait for 2.0 and see…

7.5.7 Set Key Signature Message
This message sets the Key Signature for up to 7 sharps or up to 7 flats. A field is provided to declare which note within the key is the tonic note.

Thanks for chiming in with the added details.
I don’t think most DAWs will take long to implement basic MIDI 2.0 support (which is backwards compatible) though I don’t see Hookpad supporting it without other big advantages.

The main thing for now is supporting MIDI 1.0. :wink:
Hooktheory likely has a complete breakdown, but I think minor key support would cover the overwhelming cases other than major.