MCPcopy Index your code
hub / github.com/tonaljs/tonal

github.com/tonaljs/tonal @v4.6.9 sqlite

repository ↗ · DeepWiki ↗ · release v4.6.9 ↗
430 symbols 1,006 edges 79 files 0 documented · 0% 12 cross-repo links
README

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.

Example

import { Interval, Note, Scale } from "@tonaljs/tonal";

Note.midi("A4"); // => 60
Note.freq("a4").freq; // => 440
Note.accidentals("c#2"); // => '#'
Note.transpose("C4", "5P"); // => "G4"
Interval.semitones("5P"); // => 7
Interval.distance("C4", "G4"); // => "5P"
Scale.get("C major").notes; // =>["C", "D", "E", "F", "G", "A", "B"];

Install

Install all packages at once:

npm install --save @tonaljs/tonal

Usage

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

ES6 import:

import { Note, Scale } from "@tonaljs/tonal";

ES5 require:

const { Note, Scale } = require("@tonaljs/tonal");

Browser

You can use the browser version from jsdelivr CDN directly in your html:

<script src="https://cdn.jsdelivr.net/npm/@tonaljs/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.

Bundle size

@tonaljs/tonal includes all published modules.

Although the final bundle it is small (~10kb minified and gzipped), you can reduce bundle sizes even more by installing the modules individually, and importing only the functions you need:

npm i @tonaljs/note
import { transpose } from "@tonaljs/note";
transpose("A4", "P5");

Documentation

Generally, you just need to install:

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

Notes and intervals

Scales and chords

Keys, chord progressions

Time, rhythm

Utilities

Contributing

Read contributing document for instructions

Inspiration

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
  • python-mingus: https://github.com/bspaans/python-mingus

Projects using tonal

Showcase of projects that are using Tonal:

Thank you all!

Add your project here by editing this file

License

MIT License

Extension points exported contracts — how you extend this code

Chord (Interface)
(no doc)
packages/chord/index.ts
Mode (Interface)
(no doc)
packages/mode/index.ts
Scale (Interface)
(no doc)
packages/scale/index.ts
DurationValue (Interface)
(no doc)
packages/duration-value/index.ts
Pitch (Interface)
(no doc)
packages/core/src/pitch.ts
ToNoteNameOptions (Interface)
(no doc)
packages/midi/index.ts
ScaleType (Interface)
(no doc)
packages/scale-type/index.ts
FoundChord (Interface)
(no doc)
packages/chord-detect/index.ts

Core symbols most depended-on inside this repo

note
called by 46
packages/core/src/note.ts
interval
called by 32
packages/core/src/interval.ts
tokenize
called by 29
packages/chord/index.ts
$
called by 27
packages/interval/test.ts
$
called by 26
packages/pcset/test.ts
$
called by 17
packages/scale/test.ts
parse
called by 16
packages/roman-numeral/index.ts
$
called by 14
packages/note/test.ts

Shape

Function 407
Interface 23

Languages

TypeScript100%

Modules by API surface

packages/tonal/browser/tonal.min.js178 symbols
packages/note/index.ts23 symbols
packages/pcset/index.ts21 symbols
packages/key/index.ts11 symbols
packages/interval/index.ts11 symbols
packages/core/src/note.ts11 symbols
packages/chord-type/index.ts11 symbols
packages/scale/index.ts10 symbols
packages/mode/index.ts9 symbols
packages/core/src/interval.ts9 symbols
packages/array/index.ts9 symbols
packages/scale-type/index.ts8 symbols

Dependencies from manifests, versioned

@tonaljs/abc-notation4.6.9 · 1×
@tonaljs/array4.6.9 · 1×
@tonaljs/chord4.6.5 · 1×
@tonaljs/chord-detect4.6.9 · 1×
@tonaljs/chord-type4.6.9 · 1×
@tonaljs/collection4.6.9 · 1×
@tonaljs/core4.6.9 · 1×
@tonaljs/duration-value4.6.9 · 1×
@tonaljs/interval4.6.9 · 1×
@tonaljs/key4.6.9 · 1×
@tonaljs/midi4.6.9 · 1×
@tonaljs/mode4.6.9 · 1×

For agents

$ claude mcp add tonal \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact