Skip to main content
The Deno 2 Release Candidate is here
Learn more

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

spn.ts

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 Letter, Accidental, and octave number, 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");