Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing chord symbols from MusicXML with both bass and inversion tags results in the loss of the bass tag upon export to MusicXML #1756

Open
dszeto opened this issue Feb 27, 2025 · 3 comments

Comments

@dszeto
Copy link

dszeto commented Feb 27, 2025

music21 version

9.5.0

Problem summary

When reading a chord symbol from MusicXML that contains both the bass tag and inversion tag, the bass is removed from _overrides. When writing it out as MusicXML again, the resulting XML file does not contain the bass tag but only the inversion tag, causing the slash chord to be lost.

I am not sure if this is intentional. I've dug into decades of music21 commit history, issues, and PRs, but couldn't find anything that explicitly state this is intended behavior.

Steps to reproduce

Below is a chord symbol in MusicXML that is triggering this problem:

      <harmony default-y="40">
        <root>
          <root-step>A</root-step>
        </root>
        <kind text="m">minor</kind>
        <inversion>1</inversion>
        <bass>
          <bass-step>C</bass-step>
        </bass>
      </harmony>

Just simply parsing and writing it out will cause it to lost the bass:

score = music21.converter.parse("cs_with_bass_and_inversion.musicxml")
score.write("musicxml", "cs_with_only_inversion.musicxml")

Expected vs. actual behavior

Not sure what the expected behavior should be. It looks like MusicXML spec doesn't say whether bass or inversion should take precedence. The chord symbol MusicXML in question was generated by Finale, and it does not always produce a slash chord MusicXML with both tags present.

More information

OS: macOS, Linux

@mscuthbert
Copy link
Member

mscuthbert commented Feb 27, 2025

Thanks for the excellent problem statement -- in MusicXML if a Harmony object contains a <root> object, then the <bass> object is all that is necessary and <inversion> normally should not be given:

The <bass>element is used to indicate a bass note in popular music chord symbols, e.g. G/C. It is generally not used in functional harmony, as inversion is generally not used in pop chord symbols. As with <root>, it is divided into step and alter elements, similar to pitches.

https://www.w3.org/2021/06/musicxml40/musicxml-reference/elements/bass/

So music21 should only give a <bass> with pop/jazz Chord Symbols. It can optionally also give an <inversion> but it definitely shouldn't give an <inversion> alone.

@dszeto
Copy link
Author

dszeto commented Feb 27, 2025

What do you think would be a good fix here? I can take a stab at it with your advice. The stack trace follows these:

@mscuthbert
Copy link
Member

Not going to be able to get to this till the weekend. Thanks for the pokes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants