Skip to content

Commit

Permalink
Avoid altering score on write
Browse files Browse the repository at this point in the history
makeRests was called inPlace before copies were made.

See cuthbertLab#1557
  • Loading branch information
TimFelixBeyer authored and jacobtylerwalls committed May 11, 2023
1 parent 8d5cce8 commit 398a1a5
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions music21/musicxml/m21ToXml.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,13 @@ def fromGeneralObject(self, obj: prebase.ProtoM21Object):
outObj = None

if isinstance(obj, stream.Stream) and self.makeNotation:
obj.makeRests(refStreamOrTimeRange=[0.0, obj.highestTime],
fillGaps=True,
inPlace=True,
hideRests=True, # just to fill up MusicXML display
timeRangeFromBarDuration=True,
)
# This is where the first (and hopefully only) copy is made.
obj = obj.makeRests(refStreamOrTimeRange=[0.0, obj.highestTime],
fillGaps=True,
inPlace=False,
hideRests=True, # just to fill up MusicXML display
timeRangeFromBarDuration=True,
)

for cM, methName in self.classMapping.items():
if cM in classes:
Expand All @@ -517,14 +518,14 @@ def fromGeneralObject(self, obj: prebase.ProtoM21Object):

def fromScore(self, sc):
'''
Copies the input score and runs :meth:`~music21.stream.Score.makeNotation` on the copy.
Runs :meth:`~music21.stream.Score.makeNotation` on the copy.
'''
scOut = sc.makeNotation(inPlace=False)
if not scOut.isWellFormedNotation():
warnings.warn(f'{scOut} is not well-formed; see isWellFormedNotation()',
sc.makeNotation(inPlace=True)
if not sc.isWellFormedNotation():
warnings.warn(f'{sc} is not well-formed; see isWellFormedNotation()',
category=MusicXMLWarning)
# scOut.makeImmutable()
return scOut
# sc.makeImmutable()
return sc

def fromPart(self, p):
'''
Expand All @@ -548,20 +549,20 @@ def fromMeasure(self, m):
solutions in Part or Stream production.
'''
m.coreGatherMissingSpanners()
mCopy = m.makeNotation()
if mCopy.style.measureNumbering is None:
m.makeNotation(inPlace=True)
if m.style.measureNumbering is None:
# Provide a default
mCopy.style.measureNumbering = 'measure'
m.style.measureNumbering = 'measure'
clef_from_measure_start_or_context = m.getContextByClass(
clef.Clef,
getElementMethod=common.enums.ElementSearch.AT_OR_BEFORE_OFFSET
)
if clef_from_measure_start_or_context is None:
mCopy.clef = clef.bestClef(mCopy, recurse=True)
m.clef = clef.bestClef(m, recurse=True)
else:
mCopy.clef = clef_from_measure_start_or_context
m.clef = clef_from_measure_start_or_context
p = stream.Part()
p.append(mCopy)
p.append(m)
p.metadata = copy.deepcopy(getMetadataFromContext(m))
context_part = m.getContextByClass(stream.Part)
if context_part is not None:
Expand Down

0 comments on commit 398a1a5

Please sign in to comment.