logo
Kurashizu Blogwhere ideas flow
  • Home
  • News
  • Blog
  • About
  • Home
  • News
  • Blog
  • About

© 2026 Kurashizu. All rights reserved.

Admin·New Post·Service Status
Powered by Cloudflare·01.11.26
← Back to news

Xenharmlib (music theory library) adds support for Just Intonation

Original article
xenharmlib.readthedocs.io|9 points|1 comments|by retooth|Jul 28, 2026

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. →\rightarrow→ 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: nm\frac{n}{m}mn​

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

FeatureScalar TranspositionRegular Transposition
MechanismShifts index in a fixed listApplies mathematical ratio
ConsistencyIrregular (interval size varies)Regular (interval size is constant)
ConstraintLimited to available notesCan produce notes outside the scale
AnalogyA fixed-key Piano/HarpsichordHuman voice or Fretless strings

The Problem with Scalar Transposition: If you use scalar transposition on a Pythagorean scale, the final note (243128\frac{243}{128}128243​) 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...

Music Theory Visualization Figure 1: Conceptual representation of the new arithmetic capabilities.