tonal

A functional music theory library for Javascript

Github星跟踪图

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

主要指标

概览
名称与所有者tonaljs/tonal
主编程语言TypeScript
编程语言TypeScript (语言数: 4)
平台
许可证
所有者活动
创建于2015-07-17 18:55:18
推送于2025-04-20 16:00:17
最后一次提交
发布数426
最新版本名称v4.6.9 (发布于 2022-11-18 17:23:42)
第一版名称0.11.0 (发布于 )
用户参与
星数4k
关注者数58
派生数229
提交数1k
已启用问题?
问题数209
打开的问题数27
拉请求数182
打开的拉请求数0
关闭的拉请求数36
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?