Skip to content

Saving a stream as musicxml alters the stream #1557

@TimFelixBeyer

Description

@TimFelixBeyer

music21 version

8.1.0

Problem summary
When saving a Stream s to musicxml, the object s is altered after saving to disk.
The documentation does not mention this side effect, in fact quite the opposite: "Some formats, including .musicxml, create a copy of the stream, pack it into a well-formed score if necessary, and run makeNotation()." which suggests that the original stream is left unaltered.

Steps to reproduce
Get e.g., this .mxl file: https://musescore.com/user/27439014/scores/5316979

from music21 import converter
path = "La_Campanella.mxl"
song = converter.parse(path, forceSource=True).expandRepeats().stripTies()
a = ([m.offset for m in song.flat.getElementsByClass('Note')])  # Note is just an example class, other's are affected too.
song.write("musicxml", "/tmp/_.musicxml")
b = ([m.offset for m in song.flat.getElementsByClass('Note')])
for a_, b_ in zip(a, b):
    if a_ != b_:
        print(a_, b_)

Expected vs. actual behavior
Expected: No output
Actual:

87.5 88.0
87.75 88.25
88.0 88.5
88.25 88.75
88.5 89.0
88.75 89.25
89.0 89.5
89.5 90.0
90.0 90.5
90.5 91.0
92.5 93.0
93.0 93.5
93.5 94.0
93.75 94.25
...

More information
I traced the changes and believe these lines are responsible:

inner_part.makeRests(
inPlace=True,
fillGaps=fillGaps,
hideRests=hideRests,
refStreamOrTimeRange=refStreamOrTimeRange,
timeRangeFromBarDuration=timeRangeFromBarDuration,
)

Please let me know if the behaviour is intended.
Thanks for your help!

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