Files
product-vamp/generator/engraving/repeats.py
T
khodowany 80873a0896
ci / checks (push) Has been cancelled
Tone Generation
2026-09-18 01:17:36 -05:00

43 lines
2.1 KiB
Python

from generator.engraving.attributes import barline
from generator.engraving.types import line
from generator.repeats import analyze
def draw_boundary(previous, following, x, top, fonts, style):
backward = previous.get('repeats', {}).get('right') if previous else None
forward = following.get('repeats', {}).get('left') if following else None
source = previous or following
if not backward and not forward:
value = previous.get('barlines', {}).get('right', 'regular') if previous else following.get('barlines', {}).get('left', 'none')
return barline(value, x, top, source['id'])
refs = tuple(m['id'] for m in (previous, following) if m)
result = [line('repeat-bar', refs, ((x, top), (x, 0)), 4)]
for marker, direction in ((backward, -1), (forward, 1)):
if not marker:
continue
result.append(line('repeat-bar', refs, ((x + direction * 6, top), (x + direction * 6, 0)), 1.4))
for offset in (-0.5, 0.5):
result.append(fonts.glyph('augmentationDot', x + direction * 13 - 2, top / 2 + style.space * offset, style.space, 'repeat-dot', refs))
if backward and backward.get('times', 2) != 2:
result.append(fonts.text(f'{backward["times"]} times', x - 10, top - 12, 14, 'repeat-count', refs, True))
return result
def draw_endings(index, items, start, end, positions, fonts, style):
_, endings = analyze(index.staff['measures'])
result = list(items)
boundaries = [a for a, _, _ in index.measures] + [index.end]
top = min((p.box.top for p in items), default=0) - 25
for ending in endings:
low, high = boundaries[ending.start], boundaries[ending.end]
if not ending.visible or high <= start or low >= end:
continue
x1 = positions[max(low, start)]
x2 = positions[min(high, end)]
refs = (index.measures[ending.start][2]['id'] + ':ending',)
result.append(line('ending', refs, ((x1, top), (x2, top))))
if low >= start:
result.append(line('ending', refs, ((x1, top), (x1, top + 10))))
result.append(fonts.text(ending.text, x1 + 5, top - 4, 16, 'ending-label', refs))
if high <= end and ending.closed:
result.append(line('ending', refs, ((x2, top), (x2, top + 10))))
return result