Skip to content

Commit

Permalink
added yannick's amazing method of tying notes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jellevanderwerff committed Dec 13, 2024
1 parent ca2a778 commit e028d99
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions thebeat/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,25 +766,26 @@ def _get_abjad_ties(self, durations):
# Keep track of how full the current bar is
bar_fullness = 0

for i, note in enumerate(durations):
for note in durations:
# if the note fits in the bar
if (note + bar_fullness) <= full_bar:
bar_fullness += note
notes.append(note)
# if note doesn't fit the bar
else:
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

while (remains + bar_fullness) > full_bar:
right_side = bar_fullness + remains - full_bar
left_side = remains - right_side
ties_at.append(len(notes)) # add tie at current index
notes.append(left_side)
remains = right_side
bar_fullness = 0

if remains != 0:
bar_fullness += remains
notes.append(remains)

# if bar is full set bar_fullness to zero
if bar_fullness % full_bar == 0:
Expand Down

0 comments on commit e028d99

Please sign in to comment.