Skip to content

Commit

Permalink
Avoid altering score on write cuthbertLab#1557
Browse files Browse the repository at this point in the history
  • Loading branch information
TimFelixBeyer authored May 9, 2023
1 parent 42534a3 commit fb2e29b
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions music21/musicxml/m21ToXml.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,10 @@ def fromGeneralObject(self, obj: prebase.ProtoM21Object):
outObj = None

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

Please sign in to comment.