19
19
import typing as t
20
20
21
21
import music21 as m21
22
- from music21 .common .numberTools import OffsetQL
22
+ from music21 .common .numberTools import OffsetQL , opFrac
23
23
24
24
from musicdiff import M21Utils
25
25
from musicdiff import DetailLevel
@@ -28,7 +28,7 @@ class AnnNote:
28
28
def __init__ (
29
29
self ,
30
30
general_note : m21 .note .GeneralNote ,
31
- offsetInMeasure : OffsetQL ,
31
+ gap_dur : OffsetQL ,
32
32
enhanced_beam_list : list [str ],
33
33
tuplet_list : list [str ],
34
34
tuplet_info : list [str ],
@@ -39,6 +39,8 @@ def __init__(
39
39
40
40
Args:
41
41
general_note (music21.note.GeneralNote): The music21 note/chord/rest to extend.
42
+ gap_dur (OffsetQL): gap since end of last note (or since start of measure, if
43
+ first note in measure). Usually zero.
42
44
enhanced_beam_list (list): A list of beaming information about this GeneralNote.
43
45
tuplet_list (list): A list of tuplet info about this GeneralNote.
44
46
detail (DetailLevel): What level of detail to use during the diff.
@@ -48,7 +50,7 @@ def __init__(
48
50
49
51
"""
50
52
self .general_note : int | str = general_note .id
51
- self .offsetInMeasure : OffsetQL = offsetInMeasure
53
+ self .gap_dur : OffsetQL = gap_dur
52
54
self .beamings : list [str ] = enhanced_beam_list
53
55
self .tuplets : list [str ] = tuplet_list
54
56
self .tuplet_info : list [str ] = tuplet_info
@@ -244,28 +246,31 @@ def __str__(self) -> str:
244
246
245
247
if len (self .articulations ) > 0 : # add for articulations
246
248
for a in self .articulations :
247
- string += a
249
+ string += ' ' + a
248
250
if len (self .expressions ) > 0 : # add for articulations
249
251
for e in self .expressions :
250
- string += e
252
+ string += ' ' + e
251
253
if len (self .lyrics ) > 0 : # add for lyrics
252
254
for lyric in self .lyrics :
253
- string += lyric
255
+ string += ' ' + lyric
254
256
255
257
if self .noteshape != 'normal' :
256
- string += f"noteshape={ self .noteshape } "
258
+ string += f" noteshape={ self .noteshape } "
257
259
if self .noteheadFill is not None :
258
- string += f"noteheadFill={ self .noteheadFill } "
260
+ string += f" noteheadFill={ self .noteheadFill } "
259
261
if self .noteheadParenthesis :
260
- string += f"noteheadParenthesis={ self .noteheadParenthesis } "
262
+ string += f" noteheadParenthesis={ self .noteheadParenthesis } "
261
263
if self .stemDirection != 'unspecified' :
262
- string += f"stemDirection={ self .stemDirection } "
264
+ string += f" stemDirection={ self .stemDirection } "
263
265
264
- # offset
265
- string += f" { self .offsetInMeasure } "
266
+ # gap_dur
267
+ if self .gap_dur != 0 :
268
+ string += f" spaceBefore={ self .gap_dur } "
266
269
267
270
# and then the style fields
268
271
for i , (k , v ) in enumerate (self .styledict .items ()):
272
+ if i == 0 :
273
+ string += ' '
269
274
if i > 0 :
270
275
string += ","
271
276
string += f"{ k } ={ v } "
@@ -286,25 +291,6 @@ def __eq__(self, other) -> bool:
286
291
# equality does not consider the MEI id!
287
292
return self .precomputed_str == other .precomputed_str
288
293
289
- # if not isinstance(other, AnnNote):
290
- # return False
291
- # elif self.pitches != other.pitches:
292
- # return False
293
- # elif self.note_head != other.note_head:
294
- # return False
295
- # elif self.dots != other.dots:
296
- # return False
297
- # elif self.beamings != other.beamings:
298
- # return False
299
- # elif self.tuplets != other.tuplets:
300
- # return False
301
- # elif self.articulations != other.articulations:
302
- # return False
303
- # elif self.expressions != other.expressions:
304
- # return False
305
- # else:
306
- # return True
307
-
308
294
309
295
class AnnExtra :
310
296
def __init__ (
@@ -466,11 +452,21 @@ def __init__(
466
452
# create a list of notes with beaming and tuplets information attached
467
453
self .annot_notes = []
468
454
for i , n in enumerate (note_list ):
469
- offset : OffsetQL = n .getOffsetInHierarchy (enclosingMeasure )
455
+ expectedOffsetInMeas : OffsetQL = 0
456
+ if i > 0 :
457
+ prevNoteStart : OffsetQL = (
458
+ note_list [i - 1 ].getOffsetInHierarchy (enclosingMeasure )
459
+ )
460
+ prevNoteDurQL : OffsetQL = (
461
+ note_list [i - 1 ].duration .quarterLength
462
+ )
463
+ expectedOffsetInMeas = opFrac (prevNoteStart + prevNoteDurQL )
464
+
465
+ gapDurQL : OffsetQL = n .getOffsetInHierarchy (enclosingMeasure ) - expectedOffsetInMeas
470
466
self .annot_notes .append (
471
467
AnnNote (
472
468
n ,
473
- offset ,
469
+ gapDurQL ,
474
470
self .en_beam_list [i ],
475
471
self .tuplet_list [i ],
476
472
self .tuplet_info [i ],
@@ -490,9 +486,6 @@ def __eq__(self, other) -> bool:
490
486
return False
491
487
492
488
return self .precomputed_str == other .precomputed_str
493
- # return all(
494
- # [an[0] == an[1] for an in zip(self.annot_notes, other.annot_notes)]
495
- # )
496
489
497
490
def notation_size (self ) -> int :
498
491
"""
0 commit comments