@libraz/libcantus - v1.1.0
    Preparing search index...

    Class Tuning

    An immutable equal temperament: a reference pitch and a number of equal divisions of the octave, with the conversions of the tuning module bound to it. A thin convenience wrapper over a plain TuningTable.

    Every conversion still takes a temperament of its own, defaulting to this one, so nothing the tuning functions offer is out of reach from the class — two temperaments can be read from a single object.

    import { Tuning } from '@libraz/libcantus';
    Tuning.edo(19).divisions; // 19
    Tuning.twelveTet().frequencyOf('A4'); // 440
    Index
    • get divisions(): number

      Equal divisions of the octave; 12 is the standard temperament.

      Returns number

    • Wrap a plain tuning table.

      Every field is read off the table, so a deserialized or hand-written one cannot enter carrying a division count or a reference frequency no frequency follows from. None of the three has a default here, unlike Tuning.edo: a table that lost its reference frequency on the way through storage is refused rather than quietly retuned to A=440.

      Parameters

      Returns Tuning

      The wrapped tuning.

      If a field is missing, the divisions are not a positive integer, the reference frequency is not a finite positive number, or the reference step is not finite.

      import { TWELVE_TET, Tuning } from '@libraz/libcantus';
      Tuning.of(TWELVE_TET).divisions; // 12
    • Build an equal temperament with divisions divisions of the octave.

      Parameters

      • divisions: number

        Divisions of the octave (e.g. 19, 24, 31).

      • OptionalrefFreq: number

        Reference frequency in Hz; 440 by default.

      • OptionalrefStep: number

        Step index of the reference; 69 by default, the MIDI number of A4.

      Returns Tuning

      The tuning.

      If the divisions are not a positive integer, the reference frequency is not a finite positive number, or the reference step is not finite. A negative or fractional reference step is accepted: it is what a tuner reading or a pitch-bend calibration lands on.

      import { Tuning } from '@libraz/libcantus';
      Math.round(Tuning.edo(19).centsOfSteps(1)); // 63
    • Standard twelve-tone equal temperament, A4 (MIDI 69) = 440 Hz.

      Returns Tuning

      The tuning in which a step index is an ordinary MIDI number.

      import { Tuning } from '@libraz/libcantus';
      Tuning.twelveTet().stepOf(440); // 69
    • Cents of a frequency ratio, e.g. 3:2 for the just perfect fifth.

      A ratio is a relation between two frequencies rather than a place in a temperament, so this is the same figure under every tuning.

      Parameters

      • numerator: number

        Ratio numerator.

      • denominator: number

        Ratio denominator.

      Returns number

      The interval in cents.

      If either side is not a finite positive number.

      import { Tuning } from '@libraz/libcantus';
      Math.round(Tuning.ratioToCents(3, 2)); // 702
    • The frequency ratio an interval in cents spans, the inverse of Tuning.ratioToCents. Multiply a frequency by it to move the pitch by that many cents.

      Parameters

      • cents: number

        The interval in cents.

      Returns number

      The frequency ratio.

      If cents is not finite, or the ratio it spans falls outside the range a number holds.

      import { Tuning } from '@libraz/libcantus';
      Tuning.centsToRatio(0); // 1
    • Interval in cents between two frequencies.

      Parameters

      • a: number

        Lower/first frequency in Hz.

      • b: number

        Upper/second frequency in Hz.

      Returns number

      Cents from a to b, negative when b is lower.

      If either frequency is not a finite positive number.

      import { Tuning } from '@libraz/libcantus';
      Math.round(Tuning.centsBetweenFreq(440, 880)); // 1200
    • Cents by which a five-limit just interval departs from its 12-TET tempering; positive means the just interval is the wider one.

      Parameters

      • semitoneClass: number

        Semitone class in [0, 12].

      Returns number

      The deviation in cents.

      If semitoneClass is not an integer in [0, 12].

      import { Tuning } from '@libraz/libcantus';
      Math.round(Tuning.justDeviationCents(7)); // 2
    • Frequency in Hz of a note.

      The note's MIDI number is read as a step index, which is how the tuning module numbers steps: under twelve divisions the two coincide, and under any other the step index keeps counting from the same reference.

      Parameters

      • note: NoteLike

        A note name, a MIDI number, plain note data, or a Note; it must carry an octave, since a bare pitch class has no frequency.

      • tuning: TuningTable = ...

        A temperament to read the note under instead of this one.

      Returns number

      The frequency in Hz.

      If the value is not a note, has no octave, or the frequency falls outside the range a number holds.

      import { Note } from '@libraz/libcantus';
      import { Tuning } from '@libraz/libcantus';
      const tuning = Tuning.twelveTet();
      tuning.frequencyOf('A4'); // 440
      tuning.frequencyOf(69); // 440
      tuning.frequencyOf(Note.parse('A4')); // 440
    • Frequency in Hz of a step index.

      The step-numbered form of Tuning.frequencyOf, for the steps of a temperament that no twelve-tone note names.

      Parameters

      • step: number

        Step index; a MIDI number under twelve divisions.

      • tuning: TuningTable = ...

        A temperament to read the step under instead of this one.

      Returns number

      The frequency in Hz.

      If the step is not finite, or the frequency falls outside the range a number holds.

      import { Tuning } from '@libraz/libcantus';
      const et19 = Tuning.edo(19);
      et19.frequencyOfStep(69); // 440
      et19.frequencyOfStep(70) > 440; // true
    • Nearest step index to a frequency, the rounded inverse of Tuning.frequencyOfStep.

      Parameters

      • freq: number

        Frequency in Hz.

      • tuning: TuningTable = ...

        A temperament to read the frequency under instead of this one.

      Returns number

      The nearest step index.

      If the frequency is not a finite positive number.

      import { Tuning } from '@libraz/libcantus';
      Tuning.twelveTet().nearestStep(442); // 69
    • Step index of a frequency, unrounded.

      The exact inverse of Tuning.frequencyOfStep, keeping how far off the pitch sits — the figure a tuner display or a pitch-bend amount is built on, which Tuning.nearestStep rounds away.

      Parameters

      • freq: number

        Frequency in Hz.

      • tuning: TuningTable = ...

        A temperament to read the frequency under instead of this one.

      Returns number

      The fractional step index.

      If the frequency is not a finite positive number.

      import { Tuning } from '@libraz/libcantus';
      Tuning.twelveTet().stepOf(442) > 69; // true
    • How far a frequency sits from its nearest step, in cents; positive means sharp of the step, negative flat.

      Parameters

      • freq: number

        Frequency in Hz.

      • tuning: TuningTable = ...

        A temperament to read the frequency under instead of this one.

      Returns number

      The signed deviation in cents.

      If the frequency is not a finite positive number.

      import { Tuning } from '@libraz/libcantus';
      Math.round(Tuning.twelveTet().centsFromNearestStep(442)); // 8
    • Cents spanned by a number of steps.

      Parameters

      • steps: number

        Number of steps.

      • tuning: TuningTable = ...

        A temperament to measure the steps in instead of this one.

      Returns number

      The cents.

      If the step count is not finite.

      import { Tuning } from '@libraz/libcantus';
      Tuning.twelveTet().centsOfSteps(1); // 100
    • Steps spanned by an interval in cents, unrounded — the inverse of Tuning.centsOfSteps.

      Parameters

      • cents: number

        The interval in cents.

      • tuning: TuningTable = ...

        A temperament to measure the interval in instead of this one.

      Returns number

      The fractional step count.

      If the cents are not finite.

      import { Tuning } from '@libraz/libcantus';
      Tuning.twelveTet().stepsOfCents(700); // 7
    • Whether another tuning divides the octave the same way from the same reference pitch.

      Parameters

      • other: Tuning

        The tuning to compare with.

      Returns boolean

      True when reference step, reference frequency, and divisions all match.

    • The plain tuning table, for JSON serialization.

      Private class fields do not serialize, so an explicit toJSON keeps JSON.stringify(tuning) from collapsing to {}.

      Returns TuningTable

      A copy of the reference step, reference frequency, and divisions.

    • The temperament as a readable label, so a template literal or a log line reads as the tuning.

      Returns string

      The divisions and the reference pitch, e.g. '12-EDO (step 69 = 440 Hz)'.

      import { Tuning } from '@libraz/libcantus';
      Tuning.twelveTet().toString(); // '12-EDO (step 69 = 440 Hz)'