tonal

A functional music theory library for Javascript

Github stars Tracking Chart

tonal

npm version
build status
minified size
gzipped size

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 Javascript npm packages.

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.

Install

Install all modules:

npm install --save @tonaljs/modules

Or individually:

npm install --save @tonaljs/note @tonaljs/key

Usage

Tonal is compatible with both ES5 and ES6 modules, and browser.

ES6 import:

import { Tonal, Scale } from '@tonaljs/modules';
// or individually
import * as Tonal from "@tonaljs/tonal";

ES5 require:

const { Tonal, Scale } = require('@tonaljs/modules');

Browser

Grab the minified browser ready version from the repository and include in the html file:

<script src="tonal.min.js"></script>
<script>
console.log(Tonal.Key.minorKey("Ab"));
</script>

Bundle size

@tonaljs/modules includes all published modules. Altough it is small (8kb gzipped), you can reduce bundle sizes by importing the modules individually, or even only the functions you need:

import { transpose } from '@tonaljs/tonal'
import { scale } from '@tonaljs/scale'

Example

import { Tonal } from "@tonaljs/modules";
// or individually:
import * as Tonal from "@tonaljs/tonal";

Tonal.note("A4").midi; // => 60
Tonal.note("a4").freq; // => 440
Tonal.note("c#2").accidentals; // => '#'
Tonal.note("x").midi; // => undefined
Tonal.interval("5P").semitones; // => 7
Tonal.transpose("C4", "5P"); // => "G4"
Tonal.distance("C4", "G4"); // => "5P"

Documentation

The API documentation lives inside README.md file of each module:

Contributing

Read contributing document for instructions

Inspiration

This library takes inspiration from other music theory libraries:

License

MIT License

Main metrics

Overview
Name With Ownertonaljs/tonal
Primary LanguageTypeScript
Program languageTypeScript (Language Count: 4)
Platform
License:
所有者活动
Created At2015-07-17 18:55:18
Pushed At2025-04-20 16:00:17
Last Commit At
Release Count426
Last Release Namev4.6.9 (Posted on 2022-11-18 17:23:42)
First Release Name0.11.0 (Posted on )
用户参与
Stargazers Count4k
Watchers Count58
Fork Count229
Commits Count1k
Has Issues Enabled
Issues Count209
Issue Open Count27
Pull Requests Count182
Pull Requests Open Count0
Pull Requests Close Count36
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private