Generation
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import generator.engraving.notes
|
||||
import generator.engraving.types
|
||||
import generator.model
|
||||
|
||||
@@ -40,19 +39,24 @@ def staff(index, items, start, end, left, right, fonts, style):
|
||||
for bar in (p for p in notation if p.role == 'barline'):
|
||||
drawing.append(generator.engraving.types.line('tab-barline', bar.sources, tuple((x, offset + y * 5 * style.tab_space / (4 * style.space)) for x, y in bar.points), bar.thickness))
|
||||
by_source = {source: p for p in numbers if p.role == 'tab' for source in p.sources[1:]}
|
||||
for identifier, (event, tone) in index.tones.items():
|
||||
target = tone.get('tie_to')
|
||||
finish = event.start + generator.model.fraction(tone['duration'])
|
||||
if not target and not (event.start < start < finish or event.start < end < finish):
|
||||
continue
|
||||
if target:
|
||||
finish = index.tones[target][0].start
|
||||
if finish < start or event.start >= end:
|
||||
continue
|
||||
first, last = by_source.get(identifier), by_source.get(target)
|
||||
x1 = first.box.right + 2 if first else left
|
||||
x2 = last.box.left - 2 if last else right
|
||||
|
||||
def tie(identifier, tone, x1, x2):
|
||||
y = offset - (6 - tone['tablature']['string']) * style.tab_space + 6
|
||||
if x2 > x1:
|
||||
drawing.append(generator.engraving.types.curve('tab-tie', (identifier,), ((x1, y), (x1 + (x2 - x1) / 3, y + 5), (x2 - (x2 - x1) / 3, y + 5), (x2, y))))
|
||||
|
||||
for identifier, (event, tone) in index.tones.items():
|
||||
first = by_source.get(identifier)
|
||||
finish = event.start + generator.model.fraction(tone['duration'])
|
||||
if first and event.start < start < finish:
|
||||
tie(identifier, tone, left, first.box.left - 2)
|
||||
if first and finish > end:
|
||||
tie(identifier, tone, first.box.right + 2, right)
|
||||
elif target := tone.get('tie_to'):
|
||||
destination = index.tones[target][0].start
|
||||
if event.start >= end or destination < start:
|
||||
continue
|
||||
last = by_source.get(target)
|
||||
if first or last:
|
||||
tie(identifier, tone, first.box.right + 2 if first else left, last.box.left - 2 if last else right)
|
||||
return notation + drawing
|
||||
|
||||
Reference in New Issue
Block a user