tonal
is a music theory library. Contains functions to manipulate tonal elements of music (note, intervals, chords, scales, modes, keys). It deals with abstractions (not actual music or sound).
tonal
is implemented in Typescript and published as a collection of npm modules. It uses a functional programing style: all functions are pure, there is no data mutation, and entities are represented by data structures instead of objects.
New version of tonal
is written in Typescript.
Unfortunately, there's a lot of breaking changes. See migrate from v2 to learn about that changes.
import { note, interval, transpose, distance } from "@tonaljs/tonal";
note("A4").midi; // => 60
note("a4").freq; // => 440
note("c#2").accidentals; // => '#'
note("x").midi; // => undefined
interval("5P").semitones; // => 7
transpose("C4", "5P"); // => "G4"
distance("C4", "G4"); // => "5P"
The API documentation lives inside README.md file of each module:
- @tonaljs/tonal: Parse notes and intervals, calculate distances and transpositions
- @tonaljs/midi: Midi number conversions
- @tonaljs/note: Note operations (simplify, transposeBy )
- @tonaljs/interval: Interval operations (add, simplify, invert)
- @tonaljs/pcset: Pitch class sets properties
- @tonaljs/mode: Parse (greek) tonal modes (ionian, dorian, ...)
- @tonaljs/scale-dictionary: A dictionary of scales
- @tonaljs/chord-dictionary: A dictionary of chords
- @tonaljs/scale: Scales and its relations
- @tonaljs/chord: Chords and its relations
- @tonaljs/roman-numeral: Parse roman numeral symbols
Read contributing document for (wip) instructions
This library takes inspiration from other music theory libraries:
- Teoria: https://github.com/saebekassebil/teoria
- Impro-Visor: https://www.cs.hmc.edu/~keller/jazz/improvisor/
- MusicKit: https://github.com/benzguo/MusicKit
- Music21: http://web.mit.edu/music21/doc/index.html
- Sharp11: https://github.com/jsrmath/sharp11