Xenharmlib (music theory library) adds support for Just Intonation
Xenharmlib (Music Theory Library) Now Supports Just Intonation
🚀 What's New in Xenharmlib 0.4.0?
Version 0.4.0 isn't just a minor update; it is a quantum leap for the library. The core architecture of xenharmlib has been completely refactored. While previous versions focused primarily on equal-division temperaments, the new core supports tunings utilizing multiple generator intervals.
Expanding the Musical Horizon
By enabling support for the full spectrum of regular temperaments, the library now includes Just Intonation.
Only equal temperament is possible.Almost every musical tradition can now be mathematically represented.
The only remaining exceptions are irregular temperaments (such as the Werckmeister systems). Aside from those, xenharmlib can now be utilized for the precise analysis of:
- Ancient & Classical: Byzantine Empire music, European Renaissance.
- Global Traditions: Indian classical music, Indonesian Gamelan, Arabic Maqam.
- Modern Experimentalism: 20th-century American works (e.g., Ben Johnston or Harry Partch).
Holistic Analytical Integration
The library maintains a consistent approach, allowing existing analytical tools to function across all regular temperaments, provided there is mathematical compatibility. For instance, calculations for Normal Form and Prime Form are now applicable to multi-dimensional regular temperaments.
📚 Documentation Overhaul
The documentation has been entirely redesigned:
- Feature examples are now categorized by notation and tuning.
- Comprehensive guides for all harmonic primitives have been added.
🎼 Just Intonation & Prime Limit Tunings
Just Intonation (JI) is a system of tuning based on "pure intervals." A pure interval is defined by a ratio of two integers, expressed as:
Historically, JI was the standard for most tuning systems. It wasn't until the 18th and 19th centuries that equal temperament became the dominant practical standard.
Implementing JI in Python
xenharmlib introduces the PrimeLimitTuning construct to handle this. For example, to define an 11-limit tuning:
from xenharmlib import PrimeLimitTuning
limit11 = PrimeLimitTuning(11)
To generate a Pythagorean 12-tone chromatic scale (which uses 3-limit tuning), one can stack 5 ascending and 6 descending pure fifths:
from xenharmlib import PrimeLimitTuning, periodic
pythagorean = PrimeLimitTuning(3)
# Generating the normalized pitch classes
chromatic_scale = pythagorean.pcs_normalized()
print(chromatic_scale)
# Output: PrimeLimitPitchScale([1, 256/243, 9/8, 32/27, 81/64, 4/3, 1024/729, 3/2, 128/81, 27/16, 16/9, 243/128], 3-Limit)
The Transposition Dilemma: Scalar vs. Regular
Most software treats Just Intonation as a system of scalar transposition. In this model, transposing by a fifth is simply shifting 7 degrees within a predefined scale.
Comparison of Transposition Methods
| Feature | Scalar Transposition | Regular Transposition |
|---|---|---|
| Mechanism | Shifts index in a fixed list | Applies mathematical ratio |
| Consistency | Irregular (interval size varies) | Regular (interval size is constant) |
| Constraint | Limited to available notes | Can produce notes outside the scale |
| Analogy | A fixed-key Piano/Harpsichord | Human voice or Fretless strings |
The Problem with Scalar Transposition: If you use scalar transposition on a Pythagorean scale, the final note () transposed by a fifth does not result in a true pure fifth. This is because the "keyboard" is limited.
# Example of the scalar "error" in other software:
# 243/128 -- 2048/729 (Result is 262144/177147, not a pure 3/2)
The xenharmlib Solution:
xenharmlib defaults to regular transposition. This ensures mathematical soundness, allowing the result to fall outside the predefined scale if necessary.
for i in range(0, 12):
pitch = chromatic_scale[i]
result = pitch.transpose(3/2) # Regular transposition
try:
scale_degree = chromatic_scale.index(result)
except ValueError:
scale_degree = 'not in scale'
print(f"{pitch.short_repr} -- (3/2) - degree: {scale_degree}")
This allows the library to handle complex compositions that utilize the full tuning space rather than just a limited chromatic subset.
🛠 Custom Regular Temperaments
Users can now create their own regular temperaments via MultiGenTuning.
Example: Quarter-Comma-Meantone Temperament This system flattens the tritave by a quarter of the syntonic comma.
from fractions import Fraction
from xenharmlib import MultiGenTuning, FrequencyRatio
# Define the generator
g3 = FrequencyRatio(3) * FrequencyRatio(80, 81) ** Fraction(1, 4)
# Create the tuning
qcm = MultiGenTuning((FrequencyRatio(2), g3), eq_diff_vec=(1, 0))
Tuning Architecture Overview
🧮 Full Interval Arithmetic
Finally, version 0.4.0 introduces a critical feature for theoretical musicology: Interval Arithmetic. This fills a long-standing gap in the library's capabilities.
from xenharmlib import WesternNotation
western = WesternNotation()
# Interval arithmetic can now be performed here...
Figure 1: Conceptual representation of the new arithmetic capabilities.