From 26d30c5994c09fdb0d65a4c9fcba916e9f269faa Mon Sep 17 00:00:00 2001 From: melkisedeath Date: Wed, 28 Aug 2024 15:09:37 +0200 Subject: [PATCH 1/4] Edits to support or remove editorials. --- partitura/io/importkern.py | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/partitura/io/importkern.py b/partitura/io/importkern.py index 1935faf4..4c81f50f 100644 --- a/partitura/io/importkern.py +++ b/partitura/io/importkern.py @@ -69,6 +69,14 @@ "256": {"type": "256th"}, } +class KernElement(object): + def __init__(self, element): + self.editorial_start = True if "ossia" in element else False + self.editorial_end = True if "Xstrophe" in element else False + self.voice_end = True if "*v" in element else False + self.voice_start = True if "*^" in element else False + self.element = element.replace("*", "") + def add_durations(a, b): return a * b / (a + b) @@ -102,8 +110,10 @@ def parse_by_voice(file: list, dtype=np.object_): data[line, voice] = file[line][voice] data = data.T if num_voices > 1: - # Copy global lines from the first voice to all other voices + # Copy global lines from the first voice to all other voices unless they are the string "*S/ossia" cp_idx = np.char.startswith(data[0], "*") + un_idx = np.char.startswith(data[0], "*S/ossia") + cp_idx = np.logical_and(cp_idx, ~un_idx) for i in range(1, num_voices): data[i][cp_idx] = data[0][cp_idx] # Copy Measure Lines from the first voice to all other voices @@ -171,10 +181,16 @@ def element_parsing( ): divs_pq = part._quarter_durations[0] current_tl_pos = 0 + editorial = False measure_mapping = {m.number: m.start.t for m in part.iter_all(spt.Measure)} for i in range(elements.shape[0]): element = elements[i] - if element is None: + if isinstance(element, KernElement): + if element.editorial_start: + editorial = True + if element.editorial_end: + editorial = False + if element is None or editorial: continue if isinstance(element, spt.GenericNote): if total_duration_values[i] == 0: @@ -251,8 +267,8 @@ def load_kern( # Get Splines splines = file[1:].T[note_parts] # Inverse Order - splines = splines[::-1] - parsing_idxs = parsing_idxs[::-1] + # splines = splines[::-1] + # parsing_idxs = parsing_idxs[::-1] prev_staff = 1 has_instrument = np.char.startswith(splines, "*I") # if all parts have the same instrument, then they are the same part. @@ -326,6 +342,7 @@ def load_kern( for part in copy_partlist: part.set_quarter_duration(0, divs_pq) + for part, elements, total_duration_values, same_part in zip( copy_partlist, elements_list, total_durations_list, part_assignments ): @@ -351,7 +368,7 @@ def load_kern( ) doc_name = get_document_name(filename) - score = spt.Score(partlist=partlist, id=doc_name) + score = spt.Score(partlist=partlist[::-1], id=doc_name) return score @@ -503,10 +520,16 @@ def meta_tandem_line(self, line: str): return self.process_key_line(rest) elif line.startswith("*-"): return self.process_fine() + else: + return KernElement(element=line) + def process_tempo_line(self, line: str): return spt.Tempo(float(line)) + def process_ossia_line(self): + return + def process_fine(self): return spt.Fine() From 0a139f2bf59a8846a0ee3cc003c70631ddeb8026 Mon Sep 17 00:00:00 2001 From: melkisedeath Date: Wed, 28 Aug 2024 15:19:29 +0200 Subject: [PATCH 2/4] Removed unnecessary code. --- partitura/io/importkern.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/partitura/io/importkern.py b/partitura/io/importkern.py index 4c81f50f..783f7939 100644 --- a/partitura/io/importkern.py +++ b/partitura/io/importkern.py @@ -527,9 +527,6 @@ def meta_tandem_line(self, line: str): def process_tempo_line(self, line: str): return spt.Tempo(float(line)) - def process_ossia_line(self): - return - def process_fine(self): return spt.Fine() From 91ee51931ed53f857d17d4d43bf87cca794dd30f Mon Sep 17 00:00:00 2001 From: Emmanouil Karystinaios Date: Wed, 2 Oct 2024 15:15:24 +0200 Subject: [PATCH 3/4] Update importkern.py --- partitura/io/importkern.py | 1 + 1 file changed, 1 insertion(+) diff --git a/partitura/io/importkern.py b/partitura/io/importkern.py index 783f7939..17b32407 100644 --- a/partitura/io/importkern.py +++ b/partitura/io/importkern.py @@ -368,6 +368,7 @@ def load_kern( ) doc_name = get_document_name(filename) + # inversing the partlist results to correct part order and visualization for exporting musicxml files score = spt.Score(partlist=partlist[::-1], id=doc_name) return score From ee8dfd35ba5e62f758a8e086f1df9ffdc8f8ec0f Mon Sep 17 00:00:00 2001 From: Emmanouil Karystinaios Date: Wed, 2 Oct 2024 15:16:33 +0200 Subject: [PATCH 4/4] Update importkern.py removing unused comments. --- partitura/io/importkern.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/partitura/io/importkern.py b/partitura/io/importkern.py index 17b32407..2768d0c4 100644 --- a/partitura/io/importkern.py +++ b/partitura/io/importkern.py @@ -266,9 +266,6 @@ def load_kern( ) # Get Splines splines = file[1:].T[note_parts] - # Inverse Order - # splines = splines[::-1] - # parsing_idxs = parsing_idxs[::-1] prev_staff = 1 has_instrument = np.char.startswith(splines, "*I") # if all parts have the same instrument, then they are the same part.