Skip to content

Commit 86c5a6b

Browse files
author
Johannes Hentschel
committed
fix: fixes bug when creating an excerpt containing an incomplete volta
1 parent 557a4d5 commit 86c5a6b

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

src/ms3/bs4_measures.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

tests/test_metarepo_files/debugging.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"""
99
import os.path
1010

11-
from ms3 import Parse
11+
from ms3 import Parse, Score
1212
from ms3.logger import get_logger
1313
from ms3.operations import transform_to_resources
1414

@@ -64,5 +64,19 @@ def transform_cmd():
6464
)
6565

6666

67+
def single_score():
68+
path = "~/distant_listening_corpus/ABC/MS3/n13op130_06.mscx"
69+
return Score(path)
70+
71+
6772
if __name__ == "__main__":
68-
extraction()
73+
score = single_score()
74+
score.mscx.store_excerpt(
75+
start_mc=62,
76+
start_mc_onset=0,
77+
end_mc=102,
78+
end_mc_onset=0,
79+
exclude_end=True,
80+
directory="/home/laser/Documents/phd/phrase_excerpts/231220_distant_listening_corpus",
81+
suffix="_phrase776",
82+
)

0 commit comments

Comments
 (0)