Skip to content

ChordSymbol.placement not exported/imported to/from MusicXML (<harmony placement="...">) #1867

@yuanyelele

Description

@yuanyelele

music21 version

9.9.1

Operating System(s) checked
Windows 11

Problem summary
When setting ChordSymbol.placement (e.g. cs.placement = 'below') the value is not written into the MusicXML element as a placement attribute on export, and MusicXML is not read back into ChordSymbol.placement on import. The code contains # TODO: attrGroup: placement comments in both the exporter and parser, indicating this feature is intended but unimplemented.

This makes it impossible to preserve staff placement hints for chord symbols when round-tripping MusicXML.

Steps to reproduce

from music21 import stream, harmony
p = stream.Part()
cs = harmony.ChordSymbol('C')
cs.placement = 'below'   # expectation: saved to musicxml
p.append(cs)
p.write('musicxml', fp='tmp.xml')

Output:

      <harmony>
        <root>
          <root-step>C</root-step>
        </root>
        <kind>major</kind>
      </harmony>

Expected vs. actual behavior
If ChordSymbol.placement is set to 'above' or 'below', the MusicXML exporter should write it to .

More information
music21/harmony.py — the object (Harmony / ChordSymbol) needs a placement attribute (or to expose it if already present).
music21/musicxml/m21ToXml.py — exporter function chordSymbolToXml (TODO: attrGroup: placement).
music21/musicxml/xmlToM21.py — parser function xmlToChordSymbol / code path that constructs ChordSymbol from (TODO: attrGroup: placement).
music21/musicxml/helpers.py — contains useful helpers such as setXMLAttributeFromAttribute and setPlacement that can/should be reused.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions