@tty-pt/pitch logo

@tty-pt/pitch

npm version License: BSD-2-Clause TypeScript Ready Node.js Native WebAssembly Zero Dependencies

Universal Node.js and Browser bindings for libpitch, the pure-C musical chord detection, key signature analysis, semitone transposition, and lyrics column-alignment engine. Canonical C header: <ttypt/pitch.h>.

๐Ÿ“– Full C & Music Theory Documentation: See the main libpitch GitHub README for the chord grammar specification, enharmonic spelling rules, and C AST (pitch_song_t) API.


1. Overview & Domain Concepts

libpitch (@tty-pt/pitch) parses, analyzes, and transposes plain-text chord-over-lyric song charts with zero external chord dictionaries:

  1. Grammar-Based Chord Detection:
  1. Automatic Key Signature Inference (getDetectedKey):
  1. Column-Preserving Lyric Alignment:
  1. Notation & Rendering Flags:

2. Installation

npm config set @tty-pt:registry https://tty.pt/npm/
npm install @tty-pt/pitch

Native OS & Mobile Packages (tty.pt): Prebuilt native C packages (libpitch) for Linux (apt, apk, pacman, dnf), macOS (brew), Windows (winget, MSYS2), and OpenBSD (pkg_add), plus static mobile sysroots for Android (https://tty.pt/android/) and iOS (https://tty.pt/ios/ โ€” libpitch.xcframework) are available via the tty.pt package repositories.


3. Quickstart

import {
  transposeText,
  getDetectedKey,
  getShiftTable,
  PITCH_HTML,
  PITCH_BEMOL,
  PITCH_LATIN
} from "@tty-pt/pitch";

const chart = [
  "C       G/B     Am      F",
  "Singing in the morning sun"
].join("\n");

// 1. Transpose up 2 semitones and render HTML
const html = transposeText(chart, 2, PITCH_HTML);
console.log(html);
// <div><b>D       A/C#    Bm      G</b></div><div>Singing in the morning sun</div>

// 2. Transpose to flat enharmonics in Latin solfege (Do, Re, Mi...)
const solfege = transposeText(chart, 3, PITCH_BEMOL | PITCH_LATIN);
console.log(solfege);

// 3. Inspect detected chromatic key (0 = C, 2 = D, ...) & key shift options
console.log("Detected key index:", getDetectedKey());
console.log("Key shift table HTML:", getShiftTable(0));

4. JavaScript / TypeScript API Reference

transposeText(text: string, semitones: number, flags?: number): string

Parses text, shifts all detected chords by semitones (positive or negative), and formats the output according to flags.

Key Analysis & Shift Table Helpers

Formatting Flags Bitmask

ConstantValueDescription
PITCH_HIDE_CHORDS0x01Strip chord lines and emit lyrics only
PITCH_HIDE_LYRICS0x02Strip lyric lines and emit chords only
PITCH_HTML0x04Wrap chord (<div><b>...</b></div>) and lyric lines in HTML
PITCH_BEMOL0x08Prefer flat enharmonic spellings (Bb, Eb) over sharps
PITCH_REMOVE_COMMENTS0x10Strip {...} / [...] performance comment annotations
PITCH_BREAK_SLASH0x20Break slash bass notes onto a secondary alignment line
PITCH_LATIN0x80Render chord roots in Romance/Latin solfege (Do, Re, Mi, ...)

getPitchWasm(): WebAssembly.Instance

Returns the initialized pitch.wasm reactor instance on @tty-pt/stele's shared linear memory substrate.


5. C Development Headers & Native Integration

CFLAGS += -I./node_modules/@tty-pt/pitch/include
LDLIBS += -lpitch

License

BSD-2-Clause โ€” Copyright (c) 2026, Paulo Quirino <quirinpa@gmail.com>. See LICENSE.

Documentation