Skip to content

Commit

Permalink
⤴️ bend export
Browse files Browse the repository at this point in the history
  • Loading branch information
adhooge committed Nov 21, 2022
1 parent 6c1e570 commit 03fdb47
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# music21 #
# music21 for TABASCO #

Modified version of music21 for the TABASCO project, with additional support to tab features.


## Modifications

`music21/musicxml/xmlObjects.py`:
- **72**: Add bend articulations to the OrderedDict;

`music21/musicxml/m21ToXml.py`:
- **5184, 5209:5212**: Export bend articulations;

`music21/articulations.py`:
- *87*: import `interval` for `bendAlter`
- **578**: add attributes to `FretBend` class;

___
`music21` -- A Toolkit for Computer-Aided Musical Analysis and
Computational Musicology

Expand Down
18 changes: 18 additions & 0 deletions music21/articulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
from music21.common.classTools import tempAttribute
from music21 import environment
from music21 import style
from music21 import interval

if t.TYPE_CHECKING:
from music21 import interval
Expand Down Expand Up @@ -580,6 +581,23 @@ class FretBend(FretIndication):
release: t.Any = None
withBar: t.Any = None

def __init__(self, number=0, preBend=False, release=None, withBar=None, **keywords):
'''
bend indication for fretted instruments
bend in musicxml
number is the interval of the bend in number of semitones, bend-alter in musicxml
preBend indicates wether the note is prebended or not
release is the offset value for releasing the bend, if Any
withBar indicates if the bend is done using a whammy bar movement
'''
super().__init__(**keywords)
self.bendAlter = interval.ChromaticInterval(number)
self.preBend = preBend
self.release = release
self.withBar = withBar

class FretTap(FretIndication):
pass

Expand Down
19 changes: 14 additions & 5 deletions music21/musicxml/m21ToXml.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
from music21.musicxml import helpers
from music21.musicxml.partStaffExporter import PartStaffExporterMixin
from music21.musicxml import xmlObjects
from music21.musicxml.xmlObjects import MusicXMLExportException
from music21.musicxml.xmlObjects import MusicXMLExportException, booleanToYesNo
from music21.musicxml.xmlObjects import MusicXMLWarning

environLocal = environment.Environment('musicxml.m21ToXml')
Expand Down Expand Up @@ -5159,7 +5159,7 @@ def articulationToXmlTechnical(self, articulationMark):
<other-technical>unda maris</other-technical>
Same with technical marks not yet supported.
TODO: support HammerOn, PullOff, Bend, Hole, Arrow.
TODO: support HammerOn, PullOff, Hole, Arrow.
>>> h = articulations.HammerOn()
>>> mxOther = MEX.articulationToXmlTechnical(h)
Expand All @@ -5169,7 +5169,6 @@ def articulationToXmlTechnical(self, articulationMark):
# these technical have extra information
# TODO: hammer-on
# TODO: pull-off
# TODO: bend
# TODO: hole
# TODO: arrow
musicXMLTechnicalName = None
Expand All @@ -5181,7 +5180,7 @@ def articulationToXmlTechnical(self, articulationMark):
musicXMLTechnicalName = 'other-technical'

# TODO: support additional technical marks listed above
if musicXMLTechnicalName in ('hammer-on', 'pull-off', 'bend', 'hole', 'arrow'):
if musicXMLTechnicalName in ('hammer-on', 'pull-off', 'hole', 'arrow'):
musicXMLTechnicalName = 'other-technical'

mxTechnicalMark = Element(musicXMLTechnicalName)
Expand All @@ -5206,7 +5205,17 @@ def articulationToXmlTechnical(self, articulationMark):
mxTechnicalMark.text = str(articulationMark.number)
if musicXMLTechnicalName == 'fret':
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)
# 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 Down
3 changes: 1 addition & 2 deletions music21/musicxml/xmlObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@
('string', articulations.StringIndication),
('hammer-on', articulations.HammerOn),
('pull-off', articulations.PullOff),
# bend not implemented because it needs many subcomponents
# ('bend', articulations.FretBend),
('bend', articulations.FretBend),
('tap', articulations.FretTap),
('fret', articulations.FretIndication),
('heel', articulations.OrganHeel),
Expand Down

0 comments on commit 03fdb47

Please sign in to comment.