From ca2a778dfe8e94efba5e3b220afb632e0a56f317 Mon Sep 17 00:00:00 2001 From: jellevanderwerff Date: Thu, 1 Feb 2024 16:47:35 +0100 Subject: [PATCH] works now, but needs to be prettified --- thebeat/music.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/thebeat/music.py b/thebeat/music.py index c658549..05eed8c 100644 --- a/thebeat/music.py +++ b/thebeat/music.py @@ -773,18 +773,18 @@ def _get_abjad_ties(self, durations): notes.append(note) # if note doesn't fit the bar else: - # try to divide the note up into smaller bits - for division in (2, 4, 8): - # if now it fits in the bar - if (note / division) + bar_fullness <= 1: - # we split up the original note into a small bit, and the rest (e.g. 1/4 and 3/4) - split_notes = [note / division, note - (note / division)] - # We need to remember which notes to tie later - notes += split_notes - ties_at.append(i) - bar_fullness += sum(split_notes) - bar_fullness -= full_bar - break + remains = note + status = False + while status is False or remains > full_bar: + possibilities = [remains / division for division in range(2, 10)] # TODO consider range + left_side = [poss for poss in possibilities if (poss + bar_fullness) == full_bar and poss.numerator == 1][0] + remains = note - left_side + split_notes = [left_side, remains] + notes += split_notes + ties_at.append(i) + bar_fullness += sum(split_notes) + bar_fullness -= full_bar + status = True # if bar is full set bar_fullness to zero if bar_fullness % full_bar == 0: