Sepearate Generation
This commit is contained in:
+4
-5
@@ -17,6 +17,7 @@ class Event:
|
||||
dots: int = 0
|
||||
beams: tuple[tuple[int, str], ...] = ()
|
||||
continuation: bool = False
|
||||
ratio: fractions.Fraction = fractions.Fraction(1)
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Bar:
|
||||
@@ -53,8 +54,8 @@ class Library:
|
||||
def read_snippet(path: pathlib.Path, identifier: str) -> Snippet:
|
||||
document = generator.musicxml.load_musicxml(path)
|
||||
staff = document['staves'][0]
|
||||
if len(staff['measures']) not in (1, 2) or staff.get('tuplets'):
|
||||
raise ValueError(f'{path}: rhythm snippets require one or two bars without tuplets')
|
||||
if len(staff['measures']) not in (1, 2):
|
||||
raise ValueError(f'{path}: rhythm snippets require one or two bars')
|
||||
meter = staff['measures'][0]['time_signature']
|
||||
bars = []
|
||||
for measure in staff['measures']:
|
||||
@@ -69,9 +70,7 @@ def read_snippet(path: pathlib.Path, identifier: str) -> Snippet:
|
||||
onset, duration = generator.model.fraction(note['onset']), generator.model.fraction(note['duration'])
|
||||
if onset != cursor or duration <= 0 or note.get('grace') or note['kind'] not in ('note', 'rest') or note.get('tremolo'):
|
||||
raise ValueError(f'{path}, measure {measure["number"]}: rhythm events must fill the bar sequentially')
|
||||
if 'ratio' in note['written']:
|
||||
raise ValueError(f'{path}, measure {measure["number"]}: rhythm snippets do not support time modifications')
|
||||
events.append(Event(onset, duration, note['kind'] == 'note', note['written']['type'], note['written'].get('dots', 0), tuple((b['level'], b['type']) for b in note.get('beams', [])), any('tie_from' in p for p in note['pitches'])))
|
||||
events.append(Event(onset, duration, note['kind'] == 'note', note['written']['type'], note['written'].get('dots', 0), tuple((b['level'], b['type']) for b in note.get('beams', [])), any('tie_from' in p for p in note['pitches']), generator.model.fraction(note['written'].get('ratio',generator.model.rational(1)))))
|
||||
cursor += duration
|
||||
if cursor != length:
|
||||
raise ValueError(f'{path}: rhythm events do not fill the bar')
|
||||
|
||||
Reference in New Issue
Block a user