@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
import dataclasses
|
||||
import fractions
|
||||
import hashlib
|
||||
import json
|
||||
|
||||
import generator.harmony
|
||||
import generator.model
|
||||
@@ -16,6 +17,16 @@ class Analysis:
|
||||
tempo: fractions.Fraction
|
||||
melody: tuple[generator.solo.types.Note, ...]
|
||||
|
||||
def identity(analysis, measures, part):
|
||||
anchor = analysis.melody[0].pitch.number() if analysis.melody else 0
|
||||
melody = [(str(n.start), str(n.end), n.pitch.number() - anchor) for n in analysis.melody]
|
||||
harmony = []
|
||||
for measure in measures:
|
||||
for chord in measure['harmonies']:
|
||||
pitches = sorted((int(p) - anchor) % 12 for p in generator.harmony.pitch_classes(chord)) if chord['kind'] != 'none' else []
|
||||
harmony.append((chord['kind'], pitches, chord['onset']))
|
||||
return hashlib.sha256(json.dumps((part, melody, harmony), sort_keys=True).encode()).hexdigest()
|
||||
|
||||
def attacks(document: dict) -> tuple[generator.solo.types.Note, ...]:
|
||||
"""Collapse tied tones before extracting monophonic melody fragments."""
|
||||
result, pending = [], {}
|
||||
|
||||
Reference in New Issue
Block a user