The MIDI key signature meta message specifies the key signature and scale of a MIDI file.
This message belongs to the category of MIDI meta messages. Since this is a meta message, it may exist in MIDI files, but it is not sent over MIDI ports to a MIDI device.
This message consists of five bytes of data. The first byte is the status byte 0xFF, which shows that this is a meta message. The second byte is the meta message type 0x59, which shows that this is the key signature meta message. The third byte is 0x02, which shows that there are two remaining bytes. The fourth byte has values between -7 and 7 and specifies the key signature in terms of number of flats (if negative) or sharps (if positive). The fifth and last byte of the message specifies the scale of the MIDI file, where if this byte is 0 the scale is major and if the byte is 1 the scale is minor.
The following is an example of a key signature meta message.
0xFF 0x59 0x02 0x04 0x00
The status byte is 0xFF, which shows that this is a meta message. The meta message type is 0x59, which shows that this is the key signature meta message. The third byte is 2, which shows that there are two remaining bytes. The fourth byte 0x04 signifies four sharps and the last byte signifies that this is a major key. Thus, this message specifies that the MIDI file is in the key of E major (the major scale in E is E, F#, G#, A, B, C#, D# and has four sharps).
If there is key signature message, C major is assumed, which is equivalent to the message 0xFF 0x59 0x02 0x00 0x00.
The following are the flats and sharps in the major scales. Each row is a different major scale and the first column contains the root notes of each of these scales.
Cb | Db | Eb | Fb | Gb | Ab | Bb | 7 flats |
Gb | Ab | Bb | Cb | Db | Eb | F | 6 flats |
Db | Eb | F | Gb | Ab | Bb | C | 5 flats |
Ab | Bb | C | Db | Eb | F | G | 4 flats |
Eb | F | G | Ab | Bb | C | D | 3 flats |
Bb | C | D | Eb | F | G | A | 2 flats |
F | G | A | Bb | C | D | E | 1 flat |
C | D | E | F | G | A | B | no flats or sharps |
G | A | B | C | D | E | F# | 1 sharp |
D | E | F# | G | A | B | C# | 2 sharps |
A | B | C# | D | E | F# | G# | 3 sharps |
E | F# | G# | A | B | C# | D# | 4 sharps |
B | C# | D# | E | F# | G# | A# | 5 sharps |
F# | G# | A# | B | C# | D# | E# | 6 sharps |
C# | D# | E# | F# | G# | A# | B# | 7 sharps |
The flats and sharps in the minor scales are as follows.
Ab | Bb | Cb | Db | Eb | Fb | Gb | 7 flats |
Eb | F | Gb | Ab | Bb | Cb | Db | 6 flats |
Bb | C | Db | Eb | F | Gb | Ab | 5 flats |
F | G | Ab | Bb | C | Db | Eb | 4 flats |
C | D | Eb | F | G | Ab | Bb | 3 flats |
G | A | Bb | C | D | Eb | F | 2 flats |
D | E | F | G | A | Bb | C | 1 flat |
A | B | C | D | E | F | G | no flats or sharps |
E | F# | G | A | B | C | D | 1 sharp |
B | C# | D | E | F# | G | A | 2 sharps |
F# | G# | A | B | C# | D | E | 3 sharps |
C# | D# | E | F# | G# | A | B | 4 sharps |
G# | A# | B | C# | D# | E | F# | 5 sharps |
D# | E# | F# | G# | A# | B | C# | 6 sharps |
A# | B# | C# | D# | E# | F# | G# | 7 sharps |
Comments
how is this key signature used?
Is there a track identifier, or is it a global message, intended to apply to all tracks?
It depends on the file format
It depends on the MIDI file type/format specified in the header chunk of the MIDI file. If the file is type 0, then it contains only one MIDI track and the key signature occurs in that track and applies to that track. If the file is type 1, then it has several tracks that should be played together. Then the key signature would occur only in the first track and will apply to all tracks (global). If the file is type 2, then it contains several tracks that are separate songs. The key signature would be specific to the track in which it occurs.
can a midi file have multiple time signatures?
I have a song that has multiple time signatures. I'd like to translate that into midi so I can play along with certain measures. But, the translation I have only has the initial time signature, so when the signature changes the rest of the measures are off.
Yes
Yes. I don't see why not. Both the key signature message (this one) and the time signature message can be placed at any point in the MIDI file, so I assume you can have multiple ones. Both are just meta messages, so they don't affect the sound and are just for display purposes (i.e., they can show up in the display of a keyboard or transcribing software, but don't actually do anything to playback). I know that MuseScore, for example, allows you to change the time signature in the middle of playback.
P.S.
P.S. I wrote this assuming MuseScore uses MIDI. I can't image anything else, but, honestly, I can't be sure. I know you can feed MuseScore with MIDI input though. Either way, I have seen other software that does use MIDI and that allows multiple time signature messages.
Key signature negative values
Perhaps I'm being obtuse, but since MIDI data is sent as byte values, how can one send or receive a negative value for the number of flats when using a key signature meta event?
A byte can represent a
A byte can represent a negative number if you treat it as a signed byte (a signed 8-bit value): One bit will be used for the sign and 7 bits will be used for the value. So, a byte could be between -128 and 127 (e.g., in Java, cause, for the 7 bits, 2^7 = 128). This is standard "computer science" stuff. You can represent numbers using a bit (with only 2 values), a nibble (4 bits), a byte (8 bits), a short (2 bytes = 16 bits), an integer or any other 4 byte value, etc. etc., and anything in between. MIDI makes use of all of that.
Clarification for negative value representation.
Just for clarification, MIDI data bytes are 7 bits wide, so the sign bit is going to be bit 7, not bit 8. The range for a single signed MIDI 'byte' is -64 +63.
Add new comment