A music theory library for Javascript
See the codetonal 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 Javascript
npm packages.
It uses a functional programming style: all functions are pure, there is no data mutation, and entities are represented by data structures instead of objects.
import { Chord, Interval, Note, Scale } from "tonal";
Note.midi("C4"); // => 60
Note.freq("a4"); // => 440
Note.accidentals("c#2"); // => '#'
Note.transpose("C4", "5P"); // => "G4"
Interval.semitones("5P"); // => 7
Interval.distance("C4", "G4"); // => "5P"
// Scales
Scale.get("C major").notes; // => ["C", "D", "E", "F", "G", "A", "B"];
[1, 3, 5, 7].map(Scale.degrees("C major")); // => ["C", "E", "G", "B"]
Chord.get("Cmaj7").name; // => "C major seventh"
// Chord inversions
const triad = Chord.degrees("Cm");
[1, 2, 3].map(triad); // => ["C", "Eb", "G"];
[2, 3, 1].map(triad); // => ["Eb", "G", "C"];
[3, 1, 2].map(triad); // => ["G", "C", "Eb"];
Install all packages at once:
npm install --save tonal
You can read CHANGELOG here.
Tonal is compatible with both ES5 and ES6 modules, and browser.
import:import { Note, Scale } from "tonal";
require:const { Note, Scale } = require("tonal");
You can use the browser version from jsdelivr CDN directly in your html:
<script src="https://cdn.jsdelivr.net/npm/tonal/browser/tonal.min.js"></script>
<script>
console.log(Tonal.Key.minorKey("Ab"));
</script>
Or if you prefer, grab the minified browser ready version from the repository.
tonal includes all published modules.
Although the final bundle it is small, you can reduce bundle sizes even more by installing the modules individually, and importing only the functions you need.
Note that individual modules are prefixed with @tonaljs/. For example:
npm i @tonaljs/note
import { transpose } from "@tonaljs/note";
transpose("A4", "P5");
Visit the documentation site or the README.md of each module 👇
Read contributing document. To contribute open a PR and ensure:
This library takes inspiration from other music theory libraries:
Showcase of projects that are using Tonal:
Thank you all!
Add your project here by editing this file
Overall
Maintained
Code review
npm
Latest release
Releases this year
(top 24 of 48)
331 followers · starred May 2023
218 followers · starred Apr 2024
1,021 followers · starred Nov 2020
4,534 followers · starred Apr 2024
A music theory library for Javascript
See the codetonal 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 Javascript
npm packages.
It uses a functional programming style: all functions are pure, there is no data mutation, and entities are represented by data structures instead of objects.
import { Chord, Interval, Note, Scale } from "tonal";
Note.midi("C4"); // => 60
Note.freq("a4"); // => 440
Note.accidentals("c#2"); // => '#'
Note.transpose("C4", "5P"); // => "G4"
Interval.semitones("5P"); // => 7
Interval.distance("C4", "G4"); // => "5P"
// Scales
Scale.get("C major").notes; // => ["C", "D", "E", "F", "G", "A", "B"];
[1, 3, 5, 7].map(Scale.degrees("C major")); // => ["C", "E", "G", "B"]
Chord.get("Cmaj7").name; // => "C major seventh"
// Chord inversions
const triad = Chord.degrees("Cm");
[1, 2, 3].map(triad); // => ["C", "Eb", "G"];
[2, 3, 1].map(triad); // => ["Eb", "G", "C"];
[3, 1, 2].map(triad); // => ["G", "C", "Eb"];
Install all packages at once:
npm install --save tonal
You can read CHANGELOG here.
Tonal is compatible with both ES5 and ES6 modules, and browser.
import:import { Note, Scale } from "tonal";
require:const { Note, Scale } = require("tonal");
You can use the browser version from jsdelivr CDN directly in your html:
<script src="https://cdn.jsdelivr.net/npm/tonal/browser/tonal.min.js"></script>
<script>
console.log(Tonal.Key.minorKey("Ab"));
</script>
Or if you prefer, grab the minified browser ready version from the repository.
tonal includes all published modules.
Although the final bundle it is small, you can reduce bundle sizes even more by installing the modules individually, and importing only the functions you need.
Note that individual modules are prefixed with @tonaljs/. For example:
npm i @tonaljs/note
import { transpose } from "@tonaljs/note";
transpose("A4", "P5");
Visit the documentation site or the README.md of each module 👇
Read contributing document. To contribute open a PR and ensure:
This library takes inspiration from other music theory libraries:
Showcase of projects that are using Tonal:
Thank you all!
Add your project here by editing this file
Overall
Maintained
Code review
npm
Latest release
Releases this year
(top 24 of 48)
331 followers · starred May 2023
218 followers · starred Apr 2024
1,021 followers · starred Nov 2020
4,534 followers · starred Apr 2024