- Notifications
You must be signed in to change notification settings - Fork226
A music theory library for Javascript
tonaljs/tonal
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
tonal
is a music theory library. Contains functions to manipulate tonalelements of music (note, intervals, chords, scales, modes, keys). It deals withabstractions (not actual music or sound).
tonal
is implemented in Typescript and published as a collection of Javascriptnpm packages.
It uses a functional programming style: all functions are pure, there is no datamutation, and entities are represented by data structures instead of objects.
import{Chord,Interval,Note,Scale}from"tonal";Note.midi("C4");// => 60Note.freq("a4");// => 440Note.accidentals("c#2");// => '#'Note.transpose("C4","5P");// => "G4"Interval.semitones("5P");// => 7Interval.distance("C4","G4");// => "5P"// ScalesScale.get("C major").notes;// => ["C", "D", "E", "F", "G", "A", "B"];[1,3,5,7].map(Scale.degrees("C major"));// => ["C", "E", "G", "B"]Chord.get("Cmaj7").name;// => "C major seventh"// Chord inversionsconsttriad=Chord.degrees("Cm");[1,2,3].map(triad);// => ["C", "Eb", "G"];[2,3,1].map(triad);// => ["Eb", "G", "C"];[3,1,2].map(triad);// => ["G", "C", "Eb"];
Install all packages at once:
npm install --save tonal
You can readCHANGELOG here.
Tonal is compatible with both ES5 and ES6 modules, and browser.
import{Note,Scale}from"tonal";
const{ Note, Scale}=require("tonal");
You can use the browser version from jsdelivr CDN directly in your html:
<scriptsrc="https://cdn.jsdelivr.net/npm/tonal/browser/tonal.min.js"></script><script>console.log(Tonal.Key.minorKey("Ab"));</script>
Or if you prefer, grab theminified browser ready versionfrom the repository.
tonal
includes all published modules.
Although the final bundle it is small, you canreduce bundle sizes even more by installing the modules individually, andimporting only the functions you need.
Note that individual modules are prefixed with@tonaljs/
. For example:
npm i @tonaljs/note
import{transpose}from"@tonaljs/note";transpose("A4","P5");
Visit thedocumentation site or the README.md of each module 👇
- @tonaljs/note: Note operations (simplify, transposeBy )
- @tonaljs/midi: Midi number conversions
- @tonaljs/interval: Interval operations (add, simplify,invert)
- @tonaljs/abc-notation: Parse ABCnotation notes
- @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.
- @tonaljs/voicing: Voicings and voice leadings for chords
- @tonaljs/voice-leading: Voice leading logic for transitions between voicings
- @tonaljs/voicing-dictionary: Collections of chord voicings
- @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
- @tonaljs/rhythm-pattern: Generate and manipulate rhythmic patterns
- @tonaljs/time-signature: Parse time signatures
- @tonaljs/duration-value: Note duration values
- @tonaljs/core: Core functions (note, interval, transpose anddistance)
- @tonaljs/collection: Utility functions to work withcollections (range, shuffle, permutations)
- @tonaljs/range: Create note ranges
Readcontributing 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
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:https://www.music21.org/music21docs/
- Sharp11:https://github.com/jsrmath/sharp11
- python-mingus:https://github.com/bspaans/python-mingus
- Open Music Theory:https://viva.pressbooks.pub/openmusictheory/
Showcase of projects that are using Tonal:
- Solfej byShayan Javadi
- EarBeater byMorten Vestergaard
- Sonid(play store,apple store) bymartijnmichel
- Songcraft byGabe G'Sell
- React Guitar by4lejandrito
- Fretty.app bytfeldmann
- Chordify byashleymays
- Chordal bykad1kad
- muted.io bythisisseb
- Midi Sandbox byjdlee022
- music, eternal bykousun12
- Chromatone.center bydavay42
- Super Oscillator bylukehorvat
- StringScales byAmbewas
- Polychron byi1li
Thank you all!
Add your project here byediting this file
About
A music theory library for Javascript