Skip to content

Add just intonation and Pythagorean temperaments - #28

Open
dpsanders wants to merge 1 commit into
mainfrom
just-intonation
Open

Add just intonation and Pythagorean temperaments#28
dpsanders wants to merge 1 commit into
mainfrom
just-intonation

Conversation

@dpsanders

Copy link
Copy Markdown
Collaborator

Summary

Builds on the existing equal_temperament.jl to add two ratio-based tuning systems, so pitches can be sounded in tunings other than equal temperament.

  • JustIntonation(tonic) — five-limit pure ratios above the tonic (perfect fifth = exactly 3/2, major third = exactly 5/4), giving acoustically beat-free intervals.
  • Pythagorean(tonic) — pitches built from stacked pure perfect fifths (wide thirds, pure fifths).

Both share a new abstract RatioTemperament <: Temperament that handles octave folding generically (via fldmod), so a concrete tuning only supplies its 12-entry ratio table. The tonic is anchored to its equal-tempered frequency, so a just/Pythagorean scale starts on the same pitch as the equal-tempered one and only the intervals in between differ.

julia> ji = JustIntonation(C);

julia> frequency(ji, G[4]) / frequency(ji, C[4])   # pure 3/2 fifth
1.5

julia> frequency(ji, E[4]) / frequency(ji, C[4])   # pure 5/4 third
1.25

Also in this PR

  • Make EqualTemperament an actual subtype of Temperament (it previously wasn't), so every tuning dispatches generically through frequency.
  • Export Temperament, EqualTemperament, JustIntonation, Pythagorean, and frequency (none were exported before).
  • Fix the existing equal-temperament test: @testest@testset, and add it to runtests.jl, which never included it — so it wasn't running at all. New tests cover the just and Pythagorean tunings.
  • Add a Temperaments section to the README.

Test plan

Pkg.test() passes, including the now-running equal-temperament test plus the new just-intonation (10) and Pythagorean (6) assertions.

Notes

The README's "Play the notes" TODO (audio synthesis/playback) is a natural follow-up that this frequency mapping enables, but it's intentionally left out of this PR to keep the package dependency-free and the change focused.

🤖 Generated with Claude Code

Extend the existing temperament support with two ratio-based tuning systems
alongside equal temperament:

- `JustIntonation` — five-limit pure ratios above a tonic (e.g. a 3/2 fifth,
  5/4 major third), giving beat-free intervals.
- `Pythagorean` — pitches built from stacked pure perfect fifths.

Both share a new abstract `RatioTemperament <: Temperament` that handles octave
folding generically; concrete tunings only supply their 12-entry ratio table.
The tonic is anchored to its equal-tempered frequency, so a just/Pythagorean
scale starts on the same pitch as the equal-tempered one.

Also:
- Make `EqualTemperament` a subtype of `Temperament` (it previously was not), so
  all tunings dispatch generically through `frequency`.
- Export `Temperament`, `EqualTemperament`, `JustIntonation`, `Pythagorean` and
  `frequency`.
- Fix the equal-temperament test (`@testest` -> `@testset`) and wire it into
  `runtests.jl`, which never included it; add tests for the new temperaments.
- Document temperaments in the README.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant