ExportMidi::writeHeader() should only write keysig meta events into first track
Current MuseScore::writeHeader() in 2.0.3 and 2.1 will iterate over all tracks: https://github.com/musescore/MuseScore/blob/8ff4a8f95eb5df55fc68e0ae96e…
and then export key sig for each track:
https://github.com/musescore/MuseScore/blob/8ff4a8f95eb5df55fc68e0ae96e…
So for instance diff-key-sigs-each-staff_.mscx which looks like:
will produce midi like diff-key-sigs-each-staff_.mid which contains time sigs on every staff:
But those circled key sig meta events should not be there. Some programs will complain and pop up a warning when detect key sig meta events in tracks other than the first.
Please see discussion at https://musescore.org/en/node/184296#comment-685361
There is a question about what to do when conflicts occur. It seems the simplest programming solution is to just look at the first staff when searching for key sig events, and then only write key sigs from the first staff.
Comments
Note: I've had to modify:
mtest/libmscore/midi/testMidiPort-ref.mid
mtest/libmscore/midi/testBends2-ref.mid
so that they only had the initial (C) key sig in the first track.
The fix has been appended to https://github.com/musescore/MuseScore/pull/3109 as the 2nd commit.
There is nothing in the MIDI 1.0 spec to restrict the use of key sig events in the first track. Only tempo *must* be on first track. timesig *should* be on first track. Keysig is not enforced or advised.
MIDI spec can be downloaded here https://www.midi.org/specifications/item/the-midi-1-0-specification
OK, well to be honest, that is what my initial thought was, and indeed that is what the original '96 somplete_midi_96-1-3.pdf specs say. SO these other programs and these other specs which say that key sigs should only appear in the master track must be incorrect, and probably have diverged from the initial spec via the telephone game.