Skip to content
/ pitch Public

Tools for working with musical pitch in TypeScript for Deno.

License

Notifications You must be signed in to change notification settings

eibens/pitch

Repository files navigation

pitch

pitch is a collection of tools for working with musical pitch. It is implemented in TypeScript for Deno.

License Deno doc Deno module Github tag Build Code coverage

A Cent is a musical unit that equals 1/1200th of an octave.

A centitone is a musical unit that equals 1/600th of an octave, which is equal to 2 cent.

A diatonic scale consists of seven of the twelve tones of the chromatic scale.

The MIDI standard associates numbers with the notes of the chromatic scale, for example 69 for the pitch A4.

The MIDI Tuning Standard (MTS) defines how MIDI numbers get converted to absolute frequencies. For example, A4 at 440 hz corresponds to MIDI number 69.

The Pitch type defines an absolute pitch with a Letter, Accidental, and octave number. The Chroma type defines a pitch without an octave and models the concept of a pitch class.

In Scientific Pitch Notation (SPN) a musical pitch is specified by combining a musical note name (with accidental if needed) and a number identifying the pitch's octave. For example, A4, C#4, and Eb2 are valid pitches in SPN. Such strings can be parsed with the parse function.

import { parse } from "https://deno.land/x/pitch/spn.ts";

const { letter, accidental, octave } = parse("C#4");
console.assert(letter === "C");
console.assert(accidental === "#");
console.assert(octave === 4);

Given a Pitch object, the stringify function generates an SPN string.

import { stringify } from "https://deno.land/x/pitch/spn.ts";

const spn = stringify({
  letter: "C",
  accidental: "#",
  octave: 4,
});

console.assert(spn === "C#4");