mirror of
https://github.com/kennethreitz/pytheory.git
synced 2026-06-05 23:00:20 +00:00
cd8ace302047b4683217caaba1ce958ce7808691
Tone: - Add + operator for semitone addition (C4 + 7 → G4) - Add - operator for subtraction and interval measurement (G4 - C4 → 7) - Add <, <=, >, >= comparison by pitch frequency - Add str() support (str(tone) → "C4") - Add .frequency property as shorthand for .pitch() - Tones are now sortable: sorted([G4, C4, E4]) works Scale: - Add iteration: for tone in scale - Add len(): len(scale) → 8 - Add "in" operator: "C" in scale, tone in scale - Add .note_names property - Add .chord(*degrees) to build chords from scale degrees - Add .triad(root) to build triads with octave wrapping Chord: - Add iteration: for tone in chord - Add len(): len(chord) → 3 - Add "in" operator: "C" in chord Fretboard: - Add .guitar() classmethod for standard tuning - Add .bass() classmethod for standard bass tuning - Add .ukulele() classmethod for standard ukulele tuning - Add iteration and len() Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
PyTheory: Music Theory for Humans
This (work in progress) library attempts to make exploring music theory approachable to humans.
True Scale -> Pitch Evaluation
>>> from pytheory import TonedScale
>>> c_minor = TonedScale(tonic='C4')['minor']
>>> c_minor
<Scale I=C4 II=D4 III=Eb4 IV=F4 V=G4 VI=Ab4 VII=Bb5 VIII=C5>
>>> c_minor[0].pitch()
523.251130601197
>>> c_minor["I"].pitch(symbolic=True)
440*2**(1/4)
>>> c_minor["tonic"].pitch(temperament='pythagorean', symbolic=True)
14080/27
Audibly play a note (or chord)
>>> from pytheory import play
play(c_minor[0], t=1_000)
Chord Fingerings for Custom Tunings
>>> from pytheory import Tone, Fretboard, CHARTS
>>> tones = (
... Tone.from_string("F2"),
... Tone.from_string("C3"),
... Tone.from_string("G3"),
... Tone.from_string("D4"),
... Tone.from_string("A5"),
... Tone.from_string("E5")
... )
>>> fretboard = Fretboard(tones=tones)
>>>
>>> c_chord = CHARTS['western']["C"]
>>> print(c_chord.fingering(fretboard=fretboard))
(0, 0, 0, 3, 3, 3)
It can also generate charts for all known chords for any instrument (accuracy to be determined!).
✨🍰✨
Description
Languages
Python
100%
