Skip to content

Commit 0f0542e

Browse files
Compare ArpeggioMarkSpanners (ArpeggioMarks come for free, since they are in gnote.expressions).
Note that this only works with my music21 arpeggio additions (music21 v8.0.0a9), and if you care about Humdrum, my converter21 arpeggio additions (converter21 v1.3.1). If you have an earlier version of music21 (or converter21), arpeggio differences will simply not be found.
1 parent ffe05e6 commit 0f0542e

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

build_dist.commands

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Clean up previous stuff:
22
rm -r __pycache__
33
rm -r musicdiff/__pycache__
4+
rm -r tests/__pycache__
5+
rm -r musicdiff.egg-info
46
rm -r dist build
57

68
# Build dist and wheel:

musicdiff/annotation.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,9 @@ def __init__(self, extra: m21.base.Music21Object, measure: m21.stream.Measure, s
263263
self.extra = extra.id
264264
self.offset: float
265265
self.duration: float
266+
self.numNotes: int = 1
266267
if isinstance(extra, m21.spanner.Spanner):
268+
self.numNotes = len(extra)
267269
firstNote: m21.note.GeneralNote = extra.getFirst()
268270
lastNote: m21.note.GeneralNote = extra.getLast()
269271
self.offset = float(firstNote.getOffsetInHierarchy(measure))
@@ -301,6 +303,8 @@ def __str__(self):
301303
str: the compared representation of the AnnExtra. Does not consider music21 id.
302304
"""
303305
string = f'{self.content},off={self.offset},dur={self.duration}'
306+
if self.numNotes != 1:
307+
string += f',numNotes={self.numNotes}'
304308
# and then any style fields
305309
for k, v in self.styledict.items():
306310
string += f",{k}={v}"

musicdiff/m21utils.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -424,14 +424,20 @@ def get_extras(measure: m21.stream.Measure, spannerBundle: m21.spanner.SpannerBu
424424
if M21Utils.extra_to_string(el) != '':
425425
output.append(el)
426426

427-
# we must add any Crescendo/Diminuendo spanners that start on GeneralNotes in this measure
427+
# Add any ArpeggioMarkSpanners/Crescendos/Diminuendos that start
428+
# on GeneralNotes in this measure
429+
if hasattr(m21.expressions, 'ArpeggioMarkSpanner'):
430+
spanner_types = (m21.expressions.ArpeggioMarkSpanner, m21.dynamics.DynamicWedge)
431+
else:
432+
spanner_types = (m21.dynamics.DynamicWedge,)
433+
428434
for gn in measure.recurse().getElementsByClass(m21.note.GeneralNote):
429-
dwList: List[m21.dynamics.DynamicWedge] = gn.getSpannerSites(m21.dynamics.DynamicWedge)
430-
for dw in dwList:
431-
if dw not in spannerBundle:
435+
spannerList: List[m21.spanner.Spanner] = gn.getSpannerSites(spanner_types)
436+
for sp in spannerList:
437+
if sp not in spannerBundle:
432438
continue
433-
if dw.isFirst(gn):
434-
output.append(dw)
439+
if sp.isFirst(gn):
440+
output.append(sp)
435441

436442
return output
437443

@@ -691,6 +697,17 @@ def dynwedge_to_string(dynwedge: m21.dynamics.DynamicWedge) -> str:
691697
output = 'wedge'
692698
return f'DY:{output}'
693699

700+
@staticmethod
701+
def arpeggiomark_to_string(
702+
arp: m21.expressions.Expression) -> str:
703+
if hasattr(m21.expressions, 'ArpeggioMark'):
704+
if isinstance(arp, m21.expressions.ArpeggioMark):
705+
return f'ARP:{arp.type}'
706+
if hasattr(m21.expressions, 'ArpeggioMarkSpanner'):
707+
if isinstance(arp, m21.expressions.ArpeggioMarkSpanner):
708+
return f'ARPS:{arp.type}:len={len(arp)}'
709+
return ''
710+
694711
@staticmethod
695712
def extra_to_string(extra: m21.base.Music21Object) -> str:
696713
if isinstance(extra, (m21.key.Key, m21.key.KeySignature)):
@@ -709,6 +726,10 @@ def extra_to_string(extra: m21.base.Music21Object) -> str:
709726
return M21Utils.tempo_to_string(extra)
710727
if isinstance(extra, m21.bar.Barline):
711728
return M21Utils.barline_to_string(extra)
729+
if (hasattr(m21.expressions, 'ArpeggioMark')
730+
and hasattr(m21.expressions, 'ArpeggioMarkSpanner')):
731+
if isinstance(extra, (m21.expressions.ArpeggioMark, m21.expressions.ArpeggioMarkSpanner)):
732+
return M21Utils.arpeggiomark_to_string(extra)
712733

713734
print(f'Unexpected extra: {extra.classes[0]}', file=sys.stderr)
714735
return ''

0 commit comments

Comments
 (0)