tonal

A functional music theory library for Javascript

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


  1. ``` js
  2. import { Interval, Note, Scale } from "tonal";

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

Install


Install all packages at once:

  1. ``` sh
  2. npm install --save tonal
  3. ```

Usage


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

ES6 import:


  1. ``` js
  2. import { Note, Scale } from "tonal";
  3. ```

ES5 require:


  1. ``` js
  2. const { Note, Scale } = require("tonal");
  3. ```

Browser


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

  1. ``` html
  2. <script src="https://cdn.jsdelivr.net/npm/tonal/browser/tonal.min.js"></script>
  3. <script>
  4.   console.log(Tonal.Key.minorKey("Ab"));
  5. </script>
  6. ```

Or if you prefer, grab the
from the repository.

Bundle size


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:

  1. ``` sh
  2. npm i @tonaljs/note
  3. ```

  1. ``` js
  2. import { transpose } from "@tonaljs/note";
  3. transpose("A4", "P5");
  4. ```

Documentation


Generally, you just need to install tonal package (before it was called @tonaljs/tonal).

The API documentation is inside README.md of each module 👇

Notes and intervals


- @tonaljs/note: Note operations (simplify, transposeBy )
- @tonaljs/midi: Midi number conversions
- @tonaljs/interval: Interval operations (add, simplify,
  invert)
  notation notes

Scales and chords


- @tonaljs/scale: Scales
- @tonaljs/scale-type: A dictionary of scales
- @tonaljs/chord: Chords
- @tonaljs/chord-type: A dictionary of chords
- @tonaljs/chord-detect: Detect chords from notes
- @tonaljs/pcset: Pitch class sets. Compare note groups.

Keys, chord progressions


- @tonaljs/key: Major and minor keys, it's scales and chords
- @tonaljs/mode: A dictionary of Greek modes (ionian,
  dorian...)
- @tonaljs/progression: Chord progressions
- @tonaljs/roman-numeral: Parse roman numeral symbols

Time, rhythm


- @tonaljs/time-signature: Parse time signatures
- @tonaljs/duration-value: Note duration values

Utilities


- @tonaljs/core: Core functions (note, interval, transpose and
  distance)
- @tonaljs/collection: Utility functions to work with
  collections (range, shuffle, permutations)
- @tonaljs/range: Create note ranges

Contributing


Read contributing document. To contribute open a PR and ensure:

- If is a music theory change (like the name of a scale) link to reliable references.
- If is a new feature, add documentation: changes to README of the affected module(s) are expected.
- Ad tests: changes to the test.ts file of the affected module(s) are expected.
- All tests are green

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:

- Solfej by
  apple store) by

Thank you all!

Add your project here by

License