mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-26 06:27:22 +01:00
New subproject porting Luke Haas's "Music Theory for Programmers" section by section into typed Python: pitch (MIDI <-> Hz), tuning (harmonic series, the Pythagorean comma, brute-forced "why twelve"), scales as step arrays with modes as rotations, chords stacked in thirds with Roman numerals and the V7 -> I resolution, named progressions, a numpy synth (waveforms, ADSR, low-pass), a bar-exact sequencer, and a seeded Recipe -> WAV composer. `degrade` is the same piece ruined by a 0..1 amount, so an ending can be the opening destroyed on the same seed; filtering runs LAST because filtering first measured brighter than the clean render. 17 demos (`python -m music_theory demo all`) each print the article's numbers -- the comma is 1.013643, the tempered fifth is 0.113 % flat, twelve is the first acceptable division -- and the FFT of the render, so the claims are tested rather than asserted. 157 tests, 100 % branch coverage, ruff ALL, mypy strict, pylint 10. Consumed next by roadside-assistance for its three world-state beds. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VC17zymxkeiUcHrMvt8W5W
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
# Copyright (c) 2026 Krzysztof Rudnicki
|
|
import pytest
|
|
|
|
from music_theory import progressions, scales
|
|
|
|
MAJOR = scales.STEP_PATTERNS["major"]
|
|
|
|
|
|
def test_named_lookup_is_case_insensitive() -> None:
|
|
assert progressions.named("POP") == (1, 5, 6, 4)
|
|
|
|
|
|
def test_named_rejects_unknown() -> None:
|
|
with pytest.raises(ValueError, match="unknown progression"):
|
|
progressions.named("prog rock")
|
|
|
|
|
|
def test_chords_for_resolves_degrees() -> None:
|
|
prog = progressions.chords_for(60, MAJOR, (1, 5, 6, 4))
|
|
assert progressions.numerals(prog) == "I V vi IV"
|
|
assert prog[1].notes == (67, 71, 74)
|
|
assert prog[2].degree == 6
|
|
|
|
|
|
def test_chords_for_rejects_out_of_range_degree() -> None:
|
|
with pytest.raises(ValueError, match="outside"):
|
|
progressions.chords_for(60, MAJOR, (8,))
|
|
with pytest.raises(ValueError, match="outside"):
|
|
progressions.chords_for(60, MAJOR, (0,))
|
|
|
|
|
|
def test_transpose_adds_a_constant_to_every_note() -> None:
|
|
prog = progressions.chords_for(60, MAJOR, (1, 4))
|
|
moved = progressions.transpose(prog, 4)
|
|
assert moved[0].notes == (64, 68, 71)
|
|
assert moved[1].numeral == "IV"
|