Key signature import/export and accidental spelling in midi

• Feb 11, 2017 - 13:46

I am using midi output from MuseScore in another application and want to see if I understand some things correctly. I have tried to look through the code, and base part of this on that, but ... there's a lot of code, so hoping someone just knows for sure.

On import of a Midi song, I THINK the score determines key signature heuristically, but looking at notes, and not from the key signature (if any) inside the Midi. I ran across a piece (Flight of the Bumble Bee I downloaded from 8notes) that explicitly has F-Major in the midi data, but imports in A-Major, and exports in A-Major from MuseScore.

On export of a midi file, it looks like the actual key signature is written as midi data.

Correct?

For export of explicitly coded accidentals, it looks like MuseScore does not use the convention for encoding spelling in the low order bits of velocity. That this was ever done was news to me, but I ran across it in the MidiFile program (in craigsapp on git) which referred to a book here, see page 100. I've confirmed experimentally it does not honor that encoding, I think my question is more whether this sort of encoding was ever mainstream?

My goal in the longer term is to take MuseScore exports of PDF's and exports of Midi, and use them in a separate application, so not trying to change what MuseScore does so much as make sure I understand it.


Comments

in this part of the book: there are some essays on potential improvements. These are not standard. and I hope it never happens.

It does not make sense to add some value to the lower two bits of the velocity-value.
Let's say we changed the entire velocity value in an external sequencer. In this case, all information goes away. While the user only thinks that it changes the velocity value, it does not know what some information is going to disappear.

Instead, it should use some sequencer-specific codes if desired.
The MIDI implementation allows for adding text and hex values to the applications.

Someone theoretically making up some remedies.
But it does not think about the problems that might arise.

In reply to by Ziya Mete Demircan

Thanks. I am new to this, so when I see code using something (and a book about it) it is hard to tell by context if it is accepted practice or trial balloons. I'm a database programmer at heart, and abusing a field by mixing values in it is not a good practice. But there's plenty of bad practices in old code that are "standard" also. :)

Any comments on how key signatures on import of midi are handled? Ignored and recalculated?

Sounds from your description like you are asking how "another application" handles MIDI import? Obviously, we cannot guess. But if you actually are asking how *MuseScore* handles it, then we could help better if you attach the MIDI file in question. Normally, MuseScore *does* read the key signature if present. However, my recollection is tht there are at least two different ways this can be written to the file - something about a "control track" versus embedding it within data tracks? - and maybe we are looking somewhere different from where your file actually places it.

I've never heard of any convention for encoding enharmonic spelling in the low order bits of velocity. Not saying it doesn't exist today, but I don't remember hearing about when I was more up on MIDI internals back in the 1980's, nor do I remember hearing it discussed here on the forums or anywhere else, including when various MIDI improvements were being made a couple of years ago.

In reply to by [DELETED] 5

Thanks. I'll look more closely at that code, I had seen it but sort of stopped at the indication at the top it tried to guess. I looked at isHumanPerformance, and it wasn't easily obvious what it is trying to do but it looks to be an estimation. I wonder if it is estimating wrongly in this case? Not sure. And not terribly important, but if anyone is curious the example is above.

In reply to by Marc Sabatella

I am indeed asking how MuseScore handles the midi import, though it is more curiosity than need in that direction.

I'm unclear if it is appropriate to post a score I downloaded from another site, even if free. Here is a link that will download it if you wish to try: https://www.8notes.com/school/midi/piano/bumble_bee.mid

If you look in the midi data there's a Key Signature at the top (two actually) for F major. Interestingly the lead in web page calls it D minor, which would match the 1 flat implied.

When imported into MuseScore as a midi file, it appears in the key of A major (three sharps).

If I then export the Key of A score from MuseScore to midi, the MuseScore output (using the same structure of key signature) reports correctly it is in "A".

My impression is that it's ignoring the import and using an internal heuristic to determine it is in "A".

But... I am just playing the midi in my application, so I do not actually need to know the key. I was using it internally in some debugging output, and got curious.

In reply to by Ferguson

Yes;

| Key Sig | 1b Major = F Major |

This does not tell the Key correctly. But at least, It seems that the MIDI file clearly states that a single flat is specified.

What it should be:

| Key Sig | 1b Minor = D Minor |

However, when MS takes it in, the first chord is set to Main Key (A Major). .
I think there is an error\bug in the MIDI import module.

In reply to by Ferguson

What MuseScore sees when it looks at this file is two tracks, neither of which have keys. Like I said before, there are multiple places the key can be recorded, and it looks like this file records the key somewhere other than it is expecting to see it. I'm not expert enough on the MIDI format to say more.

Do you still have an unanswered question? Please log in first to post your question.