From e4dcca146ae4f3417666edbc8154d41f11cee748 Mon Sep 17 00:00:00 2001 From: laserjeyes Date: Wed, 2 Aug 2023 17:28:50 +0200 Subject: [PATCH] when checking for metronome mark, look in the first two MCs, allowing pieces with incipit or pickup to have theirs only in MC2 --- src/ms3/bs4_parser.py | 8 ++++++-- src/ms3/transformations.py | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ms3/bs4_parser.py b/src/ms3/bs4_parser.py index eaef45cf..8442a295 100644 --- a/src/ms3/bs4_parser.py +++ b/src/ms3/bs4_parser.py @@ -471,8 +471,12 @@ def perform_checks(self): by extension, by ms3 review, too).""" # check if the first measure includes a metronome mark events = self._events - first_bar_event_types = events.loc[events.mc == 1, "event"] - if 'Tempo' not in first_bar_event_types.values: + first_two_mcs_event_types = events.loc[events.mc.isin((1,2)), "event"] + metronome_mark_missing = True + if 'Tempo' in first_two_mcs_event_types.values: + metronome_mark_missing = False + # here we could insert logic for treating incipit measure groups differently + if metronome_mark_missing: msg = "No metronome mark found in the very first measure" tempo_selector = (events.event == 'Tempo').fillna(False) if tempo_selector.sum() == 0: diff --git a/src/ms3/transformations.py b/src/ms3/transformations.py index 45ea6b2c..453160bd 100644 --- a/src/ms3/transformations.py +++ b/src/ms3/transformations.py @@ -47,12 +47,12 @@ def add_quarterbeats_col(df: pd.DataFrame, offset_dict: Union[pd.Series, dict], interval_index: bool = False) -> pd.DataFrame: """ Insert a column measuring the distance of events from MC 1 in quarter notes. If no 'mc_onset' column is present, - the column corresponds to the values given in the offset_dict.. + the column corresponds to the values given in the offset_dict. Parameters ---------- df : :obj:`pandas.DataFrame` - DataFrame with an ``mc_playthrough`` and an ``mc_onset`` column. + DataFrame with an ``mc`` or ``mc_playthrough`` column, and an ``mc_onset`` column. offset_dict : :obj:`pandas.Series` or :obj:`dict`, optional | If unfolded: {mc_playthrough -> offset} | Otherwise: {mc -> offset}