Tonos handles all aspects of pitch and harmonic material including individual tones,
pitch collections, scales, chords, harmonic systems and spaces, interval relationships,
and frequency-based transformations.
A musical pitch with frequency, pitch class, octave, and partial information.
Pitch represents a specific musical frequency with associated metadata including
pitch class name, octave number, cents offset from equal temperament, and
partial number for harmonic series calculations.
Parameters:
pitch_input (str or None, optional) – Pitch class name (e.g., "C", "F#") or pitch with octave
(e.g., "C4", "Bb-1").
Defines the common interface for both relative (interval-based) and
absolute (pitch-based) collections, including properties for degrees,
pitches, intervals, equave, and indexing operations.
Return the index of the first occurrence of value in the collection.
Parameters:
value (Pitch, float, Fraction, int, or str) – The value to search for. Interpreted as a degree for relative
collections without a reference pitch, or as a Pitch otherwise.
start (int, optional) – Index at which to begin the search. Default is 0.
stop (int or None, optional) – Index at which to stop searching. Default is None (end).
A collection of pitches defined by interval degrees relative to a root.
Degrees are stored as ratios (Fraction) or cents (float) and can
optionally be anchored to a reference pitch to resolve concrete Pitch
objects. Supports equave-cyclic indexing when enabled.
Parameters:
degrees (list of float, Fraction, int, or str) – Scale/chord degrees as ratios or cent values.
interval_type (str, optional) – "ratios" or "cents". Default is "ratios".
equave (float, Fraction, int, str, or None, optional) – Interval of equivalence. When provided, equave-cyclic indexing
is enabled.
reference_pitch (Pitch, str, or None, optional) – If given, the collection is instanced at this pitch and indexing
returns Pitch objects.
A RelativePitchCollection that always carries a reference pitch.
Slicing or sequence-indexing a RelativePitchCollection with a
reference pitch produces a RootedPitchCollection so that the
root information is preserved through subsetting.
Factory class providing unified constructors for pitch collections.
All methods are classmethods that delegate to RelativePitchCollection
or AbsolutePitchCollection depending on the input format. Use this
class when you want a single entry point for creating collections from
degrees, intervals, set classes, pitches, MIDI notes, MIDI cents, or
frequencies.
A pitch contour represented as a 1-D numpy array of integers.
Contour provides element-wise arithmetic operations and an outer sum method
for Cartesian sum (chord multiplication). All operations return new Contour
instances (immutable design).
A contour represents the shape of pitch motion as a sequence of scale degree
indices. It can be used to index into pitch collections (Scale, Chord, etc.)
to retrieve actual pitches.
Compute the outer sum (Cartesian sum) of two sequences.
Also known as “chord multiplication” in set-theoretic music theory
(Boulez). For each element in a, adds all elements of b, returning
a flattened result.
Unlike standard Python mod which always returns non-negative values,
this preserves the sign of the input to maintain musical semantics
where negative indices indicate pitches below the root.
A musical scale with automatic sorting, deduplication, and equave reduction.
Scale represents a collection of pitch intervals that form a musical scale.
It automatically sorts degrees, removes duplicates, equave-reduces intervals,
and ensures the unison (1/1 or 0 cents) is present. Scales always use
equave-cyclic indexing for accessing pitches in different octaves.
Parameters:
degrees (list of str, float, int, or Fraction) – Intervals as ratios (e.g., "5/4"), decimals, or numbers.
interval_type (str, optional) – "ratios" or "cents". Default is "ratios".
equave (float, Fraction, int, or str, optional) – Interval of equivalence. Default is "2/1" (octave).
reference_pitch (Pitch, str, or None, optional) – If provided, the scale is instanced at this pitch.
A musical chord with automatic sorting and deduplication.
Chord represents a collection of pitch intervals that form a musical chord.
It automatically sorts degrees, removes duplicates, and equave-reduces intervals,
but unlike Scale, it does NOT enforce the presence of unison. Chords always use
equave-cyclic indexing for accessing chord tones in different octaves.
Parameters:
degrees (list of str, float, int, or Fraction) – Intervals as ratios (e.g., "5/4"), decimals, or numbers.
interval_type (str, optional) – "ratios" or "cents". Default is "ratios".
equave (float, Fraction, int, or str, optional) – Interval of equivalence. Default is "2/1" (octave).
reference_pitch (Pitch, str, or None, optional) – If provided, the chord is instanced at this pitch.
A musical voicing with no equave reduction, removing only exact duplicates.
Voicing represents a “frozen” set of intervals that preserves exact pitch
relationships without equave cycling. Unlike Chord, it does not reduce
intervals to within an equave, allowing voicings that span multiple octaves.
Exact duplicates are removed, but the same pitch-class in different octaves
is allowed.
Parameters:
degrees (list of str, float, int, or Fraction) – Intervals as ratios, decimals, or numbers.
interval_type (str, optional) – "ratios" or "cents". Default is "ratios".
equave (float, Fraction, int, or str, optional) – Interval of equivalence. Default is "2/1".
reference_pitch (Pitch, str, or None, optional) – If provided, the voicing is instanced at this pitch.
A CPS is a scale generated by taking all k-element combinations of a
set S of n positive integers, computing their products, equave-reducing,
and sorting. The resulting pitches form a highly symmetrical scale used
extensively in just-intonation microtonality.
Named presets (hexany, dekany, etc.) are available as classmethods.
rules (list of tuple) – Each rule is a tuple whose first element is the operation
('product', 'power', or 'ratio') followed by
operation-specific arguments.
master_set (str or MasterSet) – Geometric layout template.
normalized (bool, optional) – Normalize ratios by the largest factor. Default is False.
A geometric layout template for Combination Product Sets.
Defines node positions and edges that determine the spatial
arrangement and relational structure of CPS nodes. Named
constructors (tetrad, asterisk, etc.) provide common
geometric templates in 2-D, 3-D, or N-D.
Parameters:
positions (dict) – Mapping of single-letter node labels to coordinate tuples.
edges (list of tuple) – Pairs of node labels defining the edge connections.
name (str or None, optional) – Human-readable name for this layout.
factors (tuple of int or None, optional) – If provided, assigns integer factors to node labels in
sorted order.
Center + 5 spokes along a deterministic Fibonacci spiral on S^2.
Native 3-D, 6 nodes. Fits any 6-factor nkany preset
(Pentadekany, Eikosany). Spokes are at unit directions
determined only by the node index, so the geometry is entirely
number-agnostic.
Trigonal antiprism: two triangles rotated 60 degrees along z.
Native 3-D, 6 nodes, no center hub. Top triangle is slightly
smaller than the bottom to break translational symmetry that
would otherwise trigger subset-sum collisions. Fits any
6-factor nkany preset.
Center + (n-1) unit spokes on S^(ambient_d - 1) via Halton inverse-CDF.
A generic-position N-D generalization of Klotho’s asterisk
family. Default (n=6,ambient_d=5) matches the node count
and ambient dimension of asterisk_nd while replacing its
orthogonal-axes geometry with deterministically quasi-random
unit spokes.
Parameters:
n (int, optional) – Number of master-set nodes (1 center + n-1 spokes). Default 6.
Hub + ring of (n-1) outer nodes, with per-label Halton offsets
in every dim >= 2.
The outer ring lives in dims 0/1 as a regular polygon; each
ring node additionally receives a unique, deterministic offset
in every higher dim, which makes the master set genuinely N-D
while preserving hub-and-ring topology. Default parameters
(n=6, ambient_d=5) match asterisk_nd’s factor count and
ambient dim.
Parameters:
n (int, optional) – Number of master-set nodes (1 hub + n-1 ring nodes). Default 6.
ambient_d (int, optional) – Ambient dimension. Default 5. Must be >= 2.
Find all groups of nodes forming the same geometric shape as the input nodes.
The match is purely geometric: two node sets match if they occupy congruent
positions (same shape, allowing rotation and reflection). Each returned match
is ordered so that match[i] occupies the same structural position as
node_ids[i].
A harmonic spectrum built from a fundamental frequency and partial numbers.
Manages a collection of pitches derived from a fundamental and a list of
partial numbers (harmonic or non-harmonic). Provides operations for
reinterpreting, retargeting, and modulating the spectrum.
Parameters:
fundamental (int, float, or Pitch) – The fundamental frequency (Hz) or a Pitch object.
partials (list of int, float, or Fraction) – Partial numbers defining the spectrum.
equave_reduce (bool, optional) – Whether to equave-reduce represented ratios. If True and an equave
generator is present, that generator axis is removed.
equave (int | Fraction | str, optional) – Equivalence interval used for reduction.
lookup ({"first", "unique", "all"}, optional) – Resolution mode:
- "first": return one deterministic coordinate match.
- "unique": return coordinate only when exactly one match exists.
- "all": return all matches in current lattice bounds.
warn (bool, optional) – Emit ToneLatticeLookupWarning when lookup fails or is ambiguous.
warn_once (bool, optional) – When True, suppress repeated identical warning messages per instance.
Returns:
Coordinate result according to lookup mode, or None when
unresolved.
Find optimal generator bases for a prime-limit JI/EJI lattice.
Searches for unimodular generator sets that span the same group as the
prime basis, ranked by a configurable scoring function that balances
simplicity, conditioning, superparticular preference, and target intervals.
Parameters:
primes (List[int]) – Ordered list of prime numbers defining the prime-limit group.
Example: [2, 3, 5] for 5-limit, [2, 3, 5, 7] for 7-limit.
Generation (Candidate)
--------------------
exp_bound (int, default 3) – Maximum absolute exponent per prime when generating candidates.
max_int (int, default 256) – Maximum numerator/denominator allowed in candidate ratios.
candidate_cap (int, default 60) – Maximum number of candidates to keep (after sorting by simplicity).
include_octave (bool, default True) – Force 2/1 as the first generator (recommended for pitch-class lattices).
octave_reduce (bool, default True) – Normalize candidates into [ratio_lo, ratio_hi) by adjusting powers of 2.
target_curve (float, default 1.0) – Nonlinearity for target penalty.
target_fold (bool, default True) – If True, fold cents to [0, 600] (interval class equivalence).
coverage (bool, default True) – If True, penalize for each target not covered by a generator.
If False, penalize for each generator not near a target.
Returns:
DataFrame with columns:
- generators: List of generator ratios (Fractions)
- generator_cents: List of generator sizes in cents
- score: Final composite score (lower is better)
- simplicity_sum: Sum of generator simplicity terms
- conditioning_max: Max absolute entry in A_inv
- conditioning_sum: Sum of absolute entries in A_inv
- superparticular_term: Superparticular bonus (negative)
- target_term: Target cents penalty
- conditioning_term: Conditioning penalty
- det: Determinant (+/-1 for valid bases)
- A: Basis matrix
- A_inv: Inverse basis matrix
Sorted by score (ascending). Use standard DataFrame methods to
sort/filter by other columns.
Convert a frequency in Hertz to MIDI cents notation.
MIDI cents combine MIDI note numbers with cent offsets. A value of
6900 corresponds to A4 (440 Hz). Each increment of 100 is one
12-TET semitone; non-multiples of 100 indicate microtonal pitches.
Calculate the fundamental from a pitch and its partial number.
Given a pitch that represents a specific partial of an unknown
fundamental, this function back-calculates the fundamental frequency
and returns its pitch-class information.
Parameters:
pitchclass (str) – Pitch class name (e.g., "A", "C#").
octave (int, optional) – Octave number. Default is 4.
partial (int, optional) – Partial number (non-zero). Negative values indicate undertones.
Default is 1.
cent_offset (float, optional) – Microtonal offset in cents. Default is 0.0.
Returns:
A named tuple with fields pitchclass, octave, and
cents_offset for the fundamental.
This implements interval class equivalence, treating intervals
and their inversions as equivalent. A minor third (~316 cents)
and a major sixth (~884 cents) both fold to ~316 cents.
The folding works by:
1. Taking the absolute value
2. Reducing modulo 1200 (one octave)
3. If > 600, reflecting: 1200 - value
Calculate the harmonic mean of two values: 2/(1/a+1/b).
In music, the harmonic mean of two intervals produces the
interval that divides the span harmonically (unequal division
weighted toward the smaller value).
Compute the Tenney height (harmonic distance) of a ratio.
For a ratio p/q in lowest terms the Tenney height is defined as
log2(p * q). Simpler ratios (small numerator and denominator)
yield lower values; more complex ratios yield higher values.
Parameters:
ratio (int, float, Fraction, or str) – The ratio to measure. Strings like '3/2' are accepted.
Returns:
The Tenney height (base-2 logarithm of numerator * denominator).