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?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?