@@ -831,6 +831,16 @@ def check_measure_numbers(
831831 dont_count = "dont_count" ,
832832 numbering_offset = "numbering_offset" ,
833833 ):
834+ """Checks if ms3's conventions for counting measure-like units are respected by the score and warns about
835+ discrepancies. Conventions can be satisfied either by using "Exclude from bar count" or by setting values for
836+ "Add to bar number".
837+
838+ * anacrusis has MN 0; otherwise first measure as MN 1
839+ * Subsequent measures with irregular length shorter than the TimeSig's nominal length should add up and only
840+ the first increases the measure number, the other don't so that they have the same number
841+ * the measure of each alternative ending (volta) need to start with the same measure number
842+ """
843+
834844 def ordinal (i ):
835845 if i == 1 :
836846 return "1st"
@@ -843,15 +853,21 @@ def ordinal(i):
843853 mc2mn = dict (self .ml [[mc_col , mn_col ]].itertuples (index = False ))
844854 # Check measure numbers in voltas
845855 for volta_group in self .volta_structure .values ():
846- for i , t in enumerate (zip (* volta_group .values ()), start = 1 ):
847- m = t [0 ]
848- mn = mc2mn [m ]
849- for j , mc in enumerate (t [1 :], start = 2 ):
850- current_mn = mc2mn [mc ]
856+ for volta_count , volta_mcs in enumerate (
857+ zip (* volta_group .values ()), start = 1
858+ ):
859+ m = volta_mcs [0 ]
860+ if not (mn := mc2mn .get (m )):
861+ # this may arise when we are dealing with an excerpt where the volta has been removed
862+ continue
863+ for mc_count , mc in enumerate (volta_mcs [1 :], start = 2 ):
864+ if not (current_mn := mc2mn .get (mc )):
865+ # this may arise when we are dealing with an excerpt where the volta is only partially included
866+ continue
851867 if current_mn != mn :
852868 self .logger .warning (
853- f"MC { mc } , the { ordinal (i )} measure of a { ordinal (j )} volta, should have MN { mn } , "
854- f"not MN { current_mn } ." ,
869+ f"MC { mc } , the { ordinal (volta_count )} measure of a { ordinal (mc_count )} volta, should have "
870+ f"MN { mn } , not MN { current_mn } ." ,
855871 extra = {"message_id" : (2 , mc )},
856872 )
857873
0 commit comments