It uses a functional programing style: all functions are pure, there is no data mutation, entities are represented by data structures instead of objects, and lot of functions accept partial application.
;; // => 60; // => 'F#4'; // => ['C2', 'D2', 'E2', 'F2', 'G2', 'A2', 'B2']
;// note propertiesNote; // => 11Note; // => 'Db'Note; // => 138.59Note; // => 69Note; // => 'A4'Note; // => 'C##4'Note; // => 'C2'// interval propertiesInterval; // => 7Interval; // => '6M'Interval; // => '5P'// distancesDistance; // => 'E#4'Distance; // => '5P'Distance; // => 7// scalesScale; // => [ 'Bb', 'C', 'D', 'E', 'F', 'G', 'A']Scale; // => [ 'Eb', 'F', 'G', 'Ab', 'Bb', 'C', 'Db', 'D' ]Scale; // => ["major", "minor", "bebop", ... and 90 more]// chordsChord; // => [ 'F', 'Ab', 'Cb', 'Eb' ]Chord; // => ['M', 'm', 'm7b5', ... and 100 more]
;Key; // => ["BbMaj7", "Cm7", "Dm7", "EbMaj7", "F7", "Gm7", "Am7b5W]
tonal is still a work in progress, but currently has implemented:
- Note, intervals, transposition, distances, enharmonics, midi, frecuency
- Scales and chords, dictionaries
- Utilities to work arrays of notes: sort, filter, rotate, shuffle
- Pitch sets comparations, chord and scale detection
- Keys, keys signatures, key scales
- Complex note range generation
- Chord progressions
This library is evolving with this ideas in mind:
- Functional: no classes, no side effects, no mutations. Just functions, data-in data-out. Most of the functions has the data to operate on as last argument and lot of functions are currified.
- Notes and intervals are represented with strings, instead of objects.
- Carefully written: small, fast and modular.
- Documented: all public functions are fully documented inside the code. Read the generated API documentation here
- Learneable: since all the modules share the same philosophy is easy to work with them.
- Tested: every public method is tested with coverage support.
- Advanced features: chord and scale detection, binary sets, chord progressions, key signatures...
yarn add tonal (or a single module:
yarn add tonal-scale)
npm install --save tonal (or:
npm install --save tonal-scale)
Browser: grab the minified file here (20kb) and include it in your html page (use a
Tonal global object)
var Tonal = ;Tonal;TonalScale;
Browser (use the
Tonal global object):
Mostly, because I want to learn:
Reinventing the wheel is bad for business, but it’s great for learning *
I want to learn about music theory and I want to express the concepts I learn using functional programming style.
Also, I want a complete library, where I can model some (for me) esoteric features like interval classes, pitch sets, dft to pitch class sets, and so on.
Tonal itself is built from a collection of packages.
Please read the generated API documentation here to get an overview.
Build, test and documentation
It's a multipackage module that uses lerna to manage.
To build the library from the first time use
npm run init or
To run the tests:
npm run test or just
jest if you have jest globally installed.
tonal.min.js file is generated with
npm run dist
The documentation can be generated with:
npm run docs
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