MusicXML export strips key signatures with 0 accidentals

• Oct 20, 2019 - 21:01
Reported version
3.0
Type
Functional
Frequency
Few
Severity
S3 - Major
Reproducibility
Always
Status
active
Regression
No
Workaround
No
Project

System info

OS: macOS 10.14, Arch.: x86_64, MuseScore version (64-bit): 3.3.0.23833 (3.3 RC), revision: d3bff12

Description of issue

MusicXML export removes key signatures with 0 accidentals before generating the MusicXML. This means that even with the mode enhancements introduced in #271505: Allow user to set mode along with key signature, there is no way to export a key signature of A minor, D Dorian, or any other 0-accidental signature (except C major) to MusicXML. MuseScore's MusicXML export support is otherwise pretty good, so the fact that there's no way to get it to write a key signature of A minor to a MusicXML file is a pretty big problem.


Comments

No, it doesn't :-).

The actual issue seems to be that MuseScore strips or does not create the key signatures with 0 accidentals. This happens when importing either a MuseScore or MusicXML file, when creating a file in C major / A minor using the wizard or when deleting a key signature (using the delete key). It is possible to create a key signatures with 0 accidentals: by using the palette to replace an existing key signature with C major / A minor, or by using the workaround specified in #295910: UI for setting mode with key signature doesn't function properly. Such a score does export correctly to MusicXML.

MuseScore "mostly" takes the stance that C major / A minor isn't a key signature, it's the absence of one. The idea being there shouldn't be an element in the score that doesn't display. We're not 100% consistent about this because we do need to show changes to C major / A minor, and also we need to handle scores for multiple instruments with different transpositions where some are C major / A minor and others aren't. There are also any number of special cases where you can end up with one of these invisible key signatures. But given the opportunity, we'll delete them - this may include save/reload, although there have been so many back and forth changes on this, it's tough to rely on anything.

Bottom line is, I think you should not rely on seeing a 0-accidental key signature at the beginning of a score, but the absence of one should imply C major / A minor. MusicXML should be able to rely on that, I think. Any changes to a 0-accidental key after that should be reasonable to expect in the score, so I would hope those always export.

Leon:

> It is possible to create a key signatures with 0 accidentals: by using the palette to replace an existing key signature with C major / A minor, or by using the workaround specified in #295910: UI for setting mode with key signature doesn't function properly. Such a score does export correctly to MusicXML.

When I tried doing this (admittedly a month or two ago) by editing the XML content in the MSCX file, it did not work, and the key got removed (IIRC) as soon as I saved the file in the GUI. I can retry if it would be helpful.

Marc:

> MuseScore "mostly" takes the stance that C major / A minor isn't a key signature, it's the absence of one. The idea being there shouldn't be an element in the score that doesn't display.

...except as you yourself pointed out, it does display, except in certain circumstances. I understand why this design decision was made, but it looks to me like it might not have been the right decision. At least in the longer term, I suspect it would be useful to swap the semantics of neutral key and C major etc., so that 0 accidentals is C major and no key signature is neutral key.

I recognize that that may not be feasible quickly, though; I suspect it would touch a lot of code, and I seem to recall that MuseScore doesn’t have great test coverage to help the change.

Anyway, I don’t want to tell you how to implement this, unless I accompany that with a pull request. :)

> but the absence of one should imply C major / A minor.

Those are not the same key, especially with the improved mode support in recent versions of MuseScore.

> MusicXML should be able to rely on that, I think.

But how can it? There’s no mode data in a nonexistent key signature, which means that the MusicXML export routine doesn’t have enough information to write the right thing. (Granted, the wrong mode would be better than nothing.)

In theory, any key signature for which you have explicitly set the mode or any other property should cause it to be marked "non-generated" and thus it shouldn't be optimized away anymore. The reality is this isn't true - it is saved to the file, but then still deleted on load. That's a bug, it should not be deleted if it has any customized properties.

Worked fine for me when I tried it:

  • add key signature other than C/a
  • change to C/a
  • use Inspector to set mode to minor
  • export to MusicXML

The exported file contains a key element with a "minor" mode tag.

Awesome, thanks. Will try these tricks on the Kostakowsky project.

I don’t remember if I’ve provided a link before, but you can see the code at http://www.github.com/marnen/kostakowsky and the current state of the site at http://kostakowsky-preview.firebaseapp.com. I’m doing a lot of programmatic conversion and processing of music files, which is why I’ve been such a pest about this and related issues. :) Of special interest might be https://github.com/marnen/kostakowsky/blob/master/helpers/music_xml_hel… , where I get a bunch of metadata from the MusicXML that’s generated by MuseScore from MSCX.