jianpu-pitch
v0.1.0
Published
Offline numbered-music pitch helpers: scale degrees to MIDI, note names and frequencies. By 简谱小站.
Maintainers
Readme
jianpu-pitch
Small, offline pitch helpers for numbered music notation (简谱). Convert a scale degree to a MIDI note, a chromatic note name, or a frequency. No dependencies, network requests, song database, or account required.
Made for the 简谱小站 — clear, A4-printable numbered scores companion pitch tool.
Install
npm install jianpu-pitchExample
import { degreeToMidi, midiToFrequency, midiToNoteName, parseDegrees } from 'jianpu-pitch';
const midi = degreeToMidi(6, { key: 'C' }); // 69
midiToNoteName(midi); // 'A4'
midiToFrequency(midi); // 440
degreeToMidi(1, { key: 'G' }); // 67 = G4
degreeToMidi(0); // null (rest)
const notes = parseDegrees("1 2 #4 | 5 1' 6, 0");
const pitches = notes.map(({ degree, ...modifiers }) =>
degreeToMidi(degree, { key: 'D', ...modifiers })
);Conventions
1is the tonic named bykey;1=Cstarts on C4 by default,1=Gon G4.tonicOctavechanges that scientific-pitch octave.octaveshifts it by -3 to +3 octaves.- Degrees
1through7use the intervals 0, 2, 4, 5, 7, 9, 11 semitones.0is a rest.accidentalis -1, 0, or 1. parseDegreesaccepts whitespace/bar-separated degrees, optional#/b(also ♯/♭), and one to three apostrophes for upper octaves or commas for lower octaves. Example:1',6,. It does not infer minor keys, rhythm, lyrics, dots, ties, or complete scores. A bar is only a separator. Accidentals affect one token only.midiToNoteNameuses chromatic sharp names (A#, notBb), not contextual enharmonic spelling.- Equal temperament, A4=440 Hz by default. Invalid input throws. MIDI range: 0–127; input limit: 128 notes / 4096 characters.
- ESM and TypeScript declarations. Node 18+ and modern browsers.
中文说明
这是一个独立的小型音高工具。可以将简谱级数换算为 MIDI 音高、音名和频率,适合做唱谱练习、音高按钮和教学小工具。它不识别图片、不搜索歌曲、不包含网站的处理流程,也不是完整简谱解析器。
找谱、预览标准版和大字版、了解 A4 打印,请访问 简谱小站官网。
License
MIT. This license covers this package only.
