Skip to content

Commit

Permalink
separate method for FretBend
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre D'Hooge committed Mar 18, 2024
1 parent 03e6117 commit 85cc6a8
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions music21/musicxml/m21ToXml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5469,16 +5469,7 @@ def articulationToXmlTechnical(self, articulationMark: articulations.Articulatio
assert isinstance(articulationMark, articulations.FretIndication)
mxTechnicalMark.text = str(articulationMark.number)
if musicXMLTechnicalName == 'bend':
bendAlterSubElement = SubElement(mxTechnicalMark, 'bend-alter')
bendAlterSubElement.text = str(articulationMark.bendAlter.semitones)
if articulationMark.preBend:
preBendSubElement = SubElement(mxTechnicalMark, 'pre-bend')
if articulationMark.release is not None:
releaseSubElement = SubElement(mxTechnicalMark, 'release')
releaseSubElement.set('offset', str(articulationMark.release))
if articulationMark.withBar is not None:
withBarSubElement = SubElement(mxTechnicalMark, 'with-bar')
withBarSubElement.text = str(articulationMark.withBar)
self.setBend(mxTechnicalMark, articulationMark)
# harmonic needs to check for whether it is artificial or natural, and
# whether it is base-pitch, sounding-pitch, or touching-pitch
if musicXMLTechnicalName == 'harmonic':
Expand All @@ -5494,6 +5485,42 @@ def articulationToXmlTechnical(self, articulationMark: articulations.Articulatio
# mxArticulations.append(mxArticulationMark)
return mxTechnicalMark

@staticmethod
def setBend(mxh: Element, bend: articulations.FretBend) -> None:
'''
Sets the bend-alter SubElement and the pre-bend,
release and with-bar SubElements when present.
Called from articulationToXmlTechnical
>>> MEXClass = musicxml.m21ToXml.MeasureExporter
>>> a = articulations.FretBend()
>>> from xml.etree.ElementTree import Element
>>> mxh = Element('bend')
>>> MEXClass.setBend(mxh, a)
>>> MEXClass.dump(mxh)
<bend>
<bend-alter></bend-alter>
</bend>
'''
bendAlterSubElement = SubElement(mxh, 'bend-alter')
alter = bend.bendAlter
if alter is not None:
# musicxml expects a number of semitones but not sure how to get it
# from a GeneralInterval
pass
if bend.preBend:
SubElement(mxh, 'pre-bend')
if bend.release is not None:
releaseSubElement = SubElement(mxh, 'release')
releaseSubElement.set('offset', str(bend.release))
if bend.withBar is not None:
withBarSubElement = SubElement(mxh, 'with-bar')
withBarSubElement.text = str(bend.withBar)

@staticmethod
def setHarmonic(mxh: Element, harm: articulations.StringHarmonic) -> None:
# noinspection PyShadowingNames
Expand Down

0 comments on commit 85cc6a8

Please sign in to comment.