def from_midi_file(cls, filename: str) -> "ChordProgression": """Creates a `ChordProgression` from an MIDI file. There is no attempt at quantization at this time, so the notes must be played at the exact same time to be grouped together as chords. """ notes = read_midi_file(filename) chords = group_notes_to_chords(notes) progression = [] for time, chord in chords.items(): progression.append( ChordWithRoot.from_midi([note.note for note in chord])) return cls(progression)
def test_chord_from_midi(midi, name): assert ChordWithRoot.from_midi(midi).name == name