Key signature in "master" track of MIDI file is ignored
Reported version
3.5
Priority
P1 - High
Type
Functional
Frequency
Once
Severity
S5 - Suggestion
Reproducibility
Always
Status
active
Regression
No
Workaround
No
Project
The attached MIDI file is one of many that can be used to see this problem. The file contains a key signature meta message in the header, but it is ignored. It was suggested in the forum thread about this that musescore instead makes a guess at what the key signature should be.
I suspect it guesses correctly sometimes, but the key signature message should be honored instead of making a guess.
The meta message in the attached file stipulates that it is in C major, but musescore falsely shows 2 sharps.
Attachment | Size |
---|---|
Fantasisa1-a6.mid | 8.38 KB |
Comments
As discussed on the forum, my belief is the problem is that the MIDI file fails to include the key signature in the track containing the data, Different tracks can potentially have different key signatures, so MuseScore is most likely not looking at one track to determine the key signature for another. Even though it seems it would be better if the MIDI file did contain the key signature with the actual track it applies to, apparently there are MIDI files out there that don't do this, and in such cases, probably we should consider the initial key signature to apply to all tracks.
In reply to As discussed on the forum,… by Marc Sabatella
It is not a MIDI requirement that each track stipulate a key signature, and in fact, I have yet to come across a MIDI file that does do that, so I strongly disagree that this is a "suggestion". In my experience this is the standard. When given the explicit information about what the key signature is, why ignore it?
In reply to It is not a MIDI requirement… by tpgettys
Master-Track (or Control-Track or Tempo Track) has been used by industry-leading companies such as Rol4nd and yamah4 for years. I have worked with hardware and software sequencers (sound recording studios) for years.
Master-Track works like System elements in Musescore. It's unnecessary to write this information in each track because this information is global. Also, the MIDI-file interpreter doesn't calculate tempo (time-sig, etc) separately for each track.
See: https://acad.carleton.edu/courses/musc108-00-f14/pages/03/03StandardMID…
(From MMA's "Complete MIDI 96-1-3" specification; with advanced examples)
Example: Suppose you do ritardando (ie decrease the tempo) you don't write this information on each of the 16 tracks. you just write on the Master-track (first track of the SMF Type1).
Or you have made permanent modulation from one key to the other. you don't write such information on all tracks, you just write on the Master track.
Or you switched from 4/4 pace to 6/8. You don't want to write this on all 16 tracts individually. You just write on the Master track.
Or Marker events (like "Section A", "Bridge", "Intro", "Final", etc) ...
Can you understand the logic?
Some sequencer software automatically carries this information to the Master / Control /Tempo track, regardless of which track it is on, some software will alert you, and the remaining software will ignore this information silently. Note: Since some DAW's keep Audio, MIDI and VST separately, it may be correct to provide track-based information on them, but this is not an SMF implementation.
(copied from the forum, since I was that first; probably best to continue discussion here only)
Yes, I am aware there is convention used by many to have a master track. Some use it only for tempo and time signature changes, and there I absolutely see the value. It's much less clear why this same model should be used for key signatures, though., but some apparently some implementations do this. I'm not aware of anything in the MIDI spec that actually calls for or otherwise sanctions this, but I'm not an expert. So I certainly wouldn't be the one trying to change our own implementation. I'm just trying to help people see how they actually can create MIDI files that work as expected, by embedding key signature information the way we expect it.
I would think that any software that was written first and foremost to help you edit MIDI data would provide controls for this, just as software like MuseScore that was written first and foremost to help you edit notation data provides system vs staff text etc. But maybe there exist some sequencers that lack this control, just as there are presumably some notation programs that lack the concept of "system text". So, we should indeed be prepared to handle output of such programs. But again, I'm not the expert, I'm not the one who could implement this. I'm just the one trying to help users achieve the desired goal today, using the tools we have.
I categorized this a suggestion because we do currently handle input that is formatted the way we expect, and indeed the vast majority of MIDI files I have ever seen in the wild are formatted this way. It's a suggestion that we also handle MIDI files that are formatted in a different way. I agree with the suggestion.
In reply to (copied from the forum,… by Marc Sabatella
My experience is wildly different from yours Marc, as I don't think I have ever encountered a MIDI file that is formatted that way (and it is my primary file format for music; I have may hundreds of such files). Sharpeye, Photoscore are but two music recognition programs that generate MIDI files with the key signature in the control track.
Could you post one here so I could take a look at it?
I'm confused, why would you be using two OMR programs as examples in a discussion of MIDI? that's not really their native language either - MusicXML is. Why not just export MusicXML from programs that understand notation? MIDI is more for programs that don't have a concept of notation, like sequencers.
Anyhow, as I have said repeatedly, I'm not enough of a MIDI expert to say what exactly is going on, what I do know is the vast majority of MIDI files imported into MuseScore - files which usually come from sequencers, not OMR or notation programs - work just fine. I have hundreds I've collected from various sources over the years, some posted the forums as part of some other support question, some downloaded to illustrate some musical point or other, only once or twice have I seen this go wrong.
Attached is literally the first one I grabbed just now, from https://www.mfiles.co.uk/classical-midi.htm. Maybe you can tell me if there is something different about how it's formatted or if we just happen to be guessing correctly.
In reply to I'm confused, why would you… by Marc Sabatella
Thanks for the file Marc; I look forward to looking at it.
So, OMR programs are what I use to create MIDI files, which are then used as rehearsal tools (music-minus-1), used to transpose into a different key for instruments other than the original nominations, used to create score and part sheet music, etc. MIDI files are very versatile in that they allow the tempo, key, instrument, etc to be manipulated. I personally know next to nothing about MusicXML, sequencers, DAWs, etc.
Some of the MIDI files I have were created via OMR, others from out in the wild, such as the ones I uploaded here. I think part of the problem is that the music I am interested in is Renaissance music, which is modal, so the key signature often doesn't map onto our major-minor system well. D dorian and F lydian both have a C major key signature, but would sound like they are in the key of D or F, respectively, so musescore will likely guess incorrectly. Better is to simply use the supplied key signature in the MIDI file.
I'll be curious what you learn after examining this file! As I said, normally we do use the supplied key signature, but I think this particular file just happens to store it in a place we don't expect.
To clarify something about formats: MIDI was never ever designed to record information about music notation, and is lacking in some really fundamental ways in that regard. For instance, it has no way of recording the distinction between G# and Ab, or the difference between a staccato quarter note and a sixteenth notes, or the fact that a passage was marked with accent marks or a slur, or any number of really basic things like that. This is why MusicXMl exists - to actually record all that information. So even if the key signature issue were straightened out, using MIDI will lose a ton of essential information after scanning a score. That's why programs like the ones you mention are really designed primarily for MusicXML. That format records all the information I mentioned and more. The difference between the results you get after importing a MIDI file versus importing MusicXMl are like night and day. Because it is so limited, MIDI is something one normally relies on only if one doesn't have access to MusicXML. But if you are scanning to software that understands MusicXML, it's absolutely the immensely superior format for then importing into notation software like MuseScore. Export MIDI to to get a quick-and-dirty sense of the playback,a nd as you mention, maybe play around with tempo etc, but all that stuff and tons more is doable in notation software, and it will all work much better working from MusicXML.
In reply to I'll be curious what you… by Marc Sabatella
Thank you for your considered reply Marc. The problem is, I run a website that offers MIDI files to musicians of early music, and a big hurdle often is how to even play a MIDI. I direct them to very simple, unsophisticated players. For generating parts I direct them to Musescore, so I really want it to work correctly.
Regarding the file you posted, as is typical in my experience, it has a key signature message in the "header" and that is all; NOT on a track by track basis. I feel confident that if musescore guesses the correct key it is because it is "modern" music. Early music presents difficulties in this regard.
It seems to me that honoring the key signature message that is present is vastly more reliable that guessing at it, even if the guess is correct quite often.
In reply to (copied from the forum,… by Marc Sabatella
The thing to do is simple: If there is a key-sig in Master-Track, the software will first consider it.
If there are key-sig (s) in musical tracks, it will process them secondaryly.
Thus, both problems are solved at once. No need to be an expert. :)
Knowing that the context here is offering MIDI files does help explain why you aren't using MusicXML, so thanks for that additional info :-). Still, I would say if you are concerned with people being able to create notation from the files you provide, you definitely should strongly consider offering MusicXML files in the future. They take no more effort to create than MIDI but are definitely much better for the purposes of getting good notation. But that doesn't help for the MIDI files you have already.
I think you are right that the algorithm used to detect key is likely to work better for tonal than modal music. FWIW, according to the comments in the source code, the algorithm used comes from "Inferring Score Level Musical Information From Low-Level Musical Data", 2004, by Jürgen Kilian.
Anyhow, hopefully someone who understands both the structure of MIDI files and the structure of the MIDI import algorithms in the MuseScore source code can look at implementing this suggestion in the future. Unfortunately, this does indeed require more expertise than I possess.
In reply to Knowing that the context… by Marc Sabatella
Thanks Marc. I appreciate that on an abstract level MusicXML offers much more information for the purpose of reconstituting accurate sheet music. With the music I am involved with, however, dynamics and articulation marks were unheard of. A MIDI file yields an accurate rendering of the music (except that there are barlines, which were also not used in part music; no time signature existed either!)
Anyway, back to the issue at hand. In the MIDI files that I have examined, regardless of source, the "header" (or control track, I'm not sure what the proper term is) always contains as a minimum the time signature, key signature and tempo meta events (FF 58 04, FF 59 02 and FF 51 03 respectively). It would seem musescore is extracting the time signature and tempo data from the header, so it would be simple to grab the key signature at the same point in the code.
Of course, how to use the key signature info after that may be more complicated. I can hope that it would be as simple as stuffing it into as-yet uninitialized fields in a data structure.
You said: "Anyhow, hopefully someone who understands both the structure of MIDI files and the structure of the MIDI import algorithms in the MuseScore source code can look at implementing this suggestion in the future. Unfortunately, this does indeed require more expertise than I possess."
I implore you to elevate this from suggestion to minor so that it will get attention sooner than later.
It is not a bug, just something not yet coded, so Suggestion is just fine
In reply to It is not a bug, just… by Jojo-Schmitz
Hi Jojo. I am having a hard time understanding why this should not be considered a defect, since musescore consistently gets the key signature wrong for a lot of music. It is especially frustrating because the correct key signature is embedded in the file.
If you visit my website (https://tpgettys.weebly.com/) you will see that I advocate visitors to consider musescore repeatedly, to the point that they may think I somehow profit from it, but it is just that I am so very enthusiastic about musescore. Perhaps you can see how this defect regarding the key signature is thus a bit embarrassing to me, since it shows up with quite a few of the files I offer on the site.
We categorize issues for good reasons, to help with tracking. The priority of an issue is not necessarily related to whether it is considered a bug or suggestion, and it is counteproductive to miscategorize something in an a effort to increase its priority.
I’m attaching a P1 priority to this, doesn’t guarantee anything because it’s still a question of whether some volunteer chooses to implement the feature or not, but at least it shows up with other P1 issues near the top of the heap.
But for record - not that it matters - if someone can show where in the MIDI spec it actually says it is correct and necessary for MIDI files to omit key signature info in the tracks themselves, then it will be completely proper to co sided this a bug rather than a suggestion. but again, that’s not really an important distinction at this point in terms of prioritization.
Thank you for bumping the priority Marc. I'm sorry if you felt I was being pushy or asking for the process in place to be bent. I have been greatly impressed by how professionally your team is managing this massive project.
It would have been nice if the MIDI spec were more unambiguous, but trying to appease all the equipment manufacturers seems to have resulted in a free-form, broad-stroke "specification".
I have done some further research. I had friends send me MIDI files they exported from Finale and Sibelius. In all cases the key signature is specified once in the “header”, so this method of indicating the key signature seems to be a de facto standard.