@@ -695,6 +695,60 @@ def test_instrumentDoesNotCreateForward(self):
695695 self .assertTrue (tree .findall ('.//note' ))
696696 self .assertFalse (tree .findall ('.//forward' ))
697697
698+ def test_writeFromSpannerAnchorsGetsMeasureEndOffsetRight (self ):
699+ '''
700+ Write to MusicXML from a Measure containing SpannerAnchors was not positioning
701+ the current time offset correctly before starting the next written measure.
702+ Now the next measure is positioned at the correct offset.
703+ '''
704+ m1 = stream .Measure ()
705+ m1 .append (note .Note ())
706+ m1 .append (note .Note ())
707+ m1 .append (note .Note ())
708+ m1 .append (note .Note ())
709+ cresc = dynamics .Crescendo ()
710+ startAnchor = spanner .SpannerAnchor ()
711+ endAnchor = spanner .SpannerAnchor ()
712+ m1 .insert (0.5 , startAnchor )
713+ m1 .insert (1.5 , endAnchor )
714+ cresc .addSpannedElements (startAnchor , endAnchor )
715+ m1 .append (cresc )
716+ p = stream .Part ()
717+ p .append (m1 )
718+ s = stream .Score ()
719+ s .append (p )
720+ # write to MusicXML
721+ tree = self .getET (s )
722+
723+ # walk all the durations (notes, forwards, backups) and make sure they add up
724+ # to where the end of the measure should be (4.0ql)
725+ measEl = None
726+ divisionsEl = None
727+ for el in tree .iter ():
728+ if el .tag == 'measure' :
729+ measEl = el
730+ for el in measEl .iter ():
731+ if el .tag == 'divisions' :
732+ divisionsEl = el
733+ break
734+ break
735+
736+ self .assertIsNotNone (measEl )
737+ self .assertIsNotNone (divisionsEl )
738+
739+ divisionsInt = int (divisionsEl .text )
740+ currOffsetQL = 0.
741+ for el in measEl .findall ('*' ):
742+ dur = el .find ('duration' )
743+ if dur is not None :
744+ durInt = int (dur .text )
745+ durQL = common .opFrac (fractions .Fraction (durInt , divisionsInt ))
746+ if el .tag == 'backup' :
747+ currOffsetQL = common .opFrac (currOffsetQL - durQL )
748+ else :
749+ currOffsetQL = common .opFrac (currOffsetQL + durQL )
750+ self .assertEqual (currOffsetQL , 4. )
751+
698752 def testOutOfBoundsExpressionDoesNotCreateForward (self ):
699753 '''
700754 A metronome mark at an offset exceeding the bar duration was causing
0 commit comments