Overview
This reference details the classes and methods provided by the Python implementation of Meantonal.
External links to the project repo and PyPI page can be found below.
If you haven’t already, get started by installing the meantonal package from PyPI:
pip install meantonalConventions
Section titled “Conventions”The Python implementation mirrors the JS implementation class for class and method for method, adapted to Python idiom:
- Method and property names are
snake_case:SPN.toPitchbecomesSPN.to_pitch,Interval.fromNamebecomesInterval.from_name, and so on. Class names are unchanged. - Derived values that are getters in TypeScript are properties in Python, accessed identically:
p.midi,m.quality,m.name. - Anywhere the JS implementation throws an
Error, the Python implementation raises aValueErrorwith the same message. - Range methods like
Pitch.range.diatonicreturn generators; iterate them withfor, or collect them withlist(). - All vector classes support
==structural equality and have a usefulrepr().
Operators
Section titled “Operators”Uniquely to the Python implementation, Pitch and Interval support natural arithmetic through operator overloading, in the style of datetime/timedelta. A Pitch is a point and an Interval is a displacement, so:
from meantonal import SPN, Interval
p = SPN.to_pitch("C4")m = Interval.from_name("M3")
q = p + m # E4 -- same as p.transpose_real(m)q - p # M3 -- same as Interval.between(p, q)p - m # Ab3 -- transpose downm + m # A5 -- same as m.add(m)-m # descending M3 -- same as m.negativem * 3 # A7 -- same as m.times(3)Pitch + Pitch is deliberately undefined (adding two points is meaningless) and raises a TypeError.
The named methods (add, subtract, times, transpose_real, between, …) are all still present, keeping the vocabulary consistent across the JS, Python and C implementations.
If you want to get a better understanding of how Meantonal works under the hood, check out the Learn category.