subsequence.tuning
The API reference for Tuning.
Tuning
class Tuning(cents: typing.List[float], description: str = '')
A microtonal tuning system expressed as cent offsets from the unison.
The cents list contains the cent values for scale degrees 1 through N.
Degree 0 (the unison, 0.0 cents) is always implicit and not stored.
The last entry is typically 1200.0 cents (the octave) for octave-repeating
scales, but any period is supported.
Create a Tuning from a file or programmatically:
Tuning.from_scl("meanquar.scl") # Scala .scl file
Tuning.from_cents([100, 200, ..., 1200]) # explicit cents
Tuning.from_ratios([9/8, 5/4, ..., 2]) # frequency ratios
Tuning.equal(19) # 19-tone equal temperament
Members: cents, description, equal, from_cents, from_ratios, from_scl, from_scl_string, period_cents, pitch_bend_for_note, size
Tuning.cents
Tuning.cents: typing.List[float]
Tuning.description
Tuning.description: str = ''
Tuning.size
property Tuning.size: int
Number of scale degrees per period (the .scl count line).
Tuning.period_cents
property Tuning.period_cents: float
Cent span of one period (typically 1200.0 for octave-repeating scales).
Tuning.from_scl
classmethod Tuning.from_scl(
source: typing.Union[str, os.PathLike],
) -> Tuning
Parse a Scala .scl file.
source is a file path. Lines beginning with ! are comments.
The first non-comment line is the description. The second is the
integer count of pitch values. Each subsequent line is a pitch:
- Contains
.→ cents (float). - Contains
/or is a bare integer → ratio; converted to cents via1200 × log₂(ratio).
Raises ValueError for malformed files.
Tuning.from_scl_string
classmethod Tuning.from_scl_string(text: str) -> Tuning
Parse a Scala .scl file from a string (useful for testing).
Tuning.from_cents
classmethod Tuning.from_cents(
cents: typing.List[float],
description: str = '',
) -> Tuning
Construct a tuning from a list of cent values for degrees 1..N.
The implicit degree 0 (unison, 0.0 cents) is not included in cents.
The last value is typically 1200.0 for an octave-repeating scale.
Tuning.from_ratios
classmethod Tuning.from_ratios(
ratios: typing.List[float],
description: str = '',
) -> Tuning
Construct a tuning from frequency ratios relative to 1/1.
Each ratio is converted to cents via 1200 × log₂(ratio).
Pass 2 or 2.0 for the octave (1200 cents).
Tuning.equal
classmethod Tuning.equal(
divisions: int = 12,
period: float = 1200.0,
) -> Tuning
Construct an equal-tempered tuning with divisions equal steps per period.
Tuning.equal(12) is standard 12-TET (no pitch bend needed).
Tuning.equal(19) gives 19-tone equal temperament.
Tuning.pitch_bend_for_note
Tuning.pitch_bend_for_note(
midi_note: int,
reference_note: int = 60,
bend_range: float = 2.0,
) -> typing.Tuple[int, float]
Return (nearest_12tet_note, bend_normalized) for a MIDI note number.
The MIDI note number is interpreted as a scale degree relative to
reference_note (default 60 = C4, degree 0 of the scale). The
tuning's cent table determines the exact frequency, and the nearest
12-TET MIDI note plus a fractional pitch bend corrects the remainder.
Parameters
midi_note: The MIDI note to tune (0–127).reference_note: MIDI note number that maps to degree 0 of the scale.bend_range: Pitch wheel range in semitones (must match the synth's pitch-bend range setting). Default ±2 semitones.
Returns
typing.Tuple[int, float]: A tuple(nearest_note, bend_normalized)wherenearest_noteis the integer MIDI note to send andbend_normalizedis the normalised pitch bend value (-1.0 to +1.0).