https://github.com/tonaljs/tonal
Skip to content
Toggle navigation
Sign in
* Product
+
Actions
Automate any workflow
+
Packages
Host and manage packages
+
Security
Find and fix vulnerabilities
+
Codespaces
Instant dev environments
+
Copilot
Write better code with AI
+
Code review
Manage code changes
+
Issues
Plan and track work
+
Discussions
Collaborate outside of code
Explore
+ All features
+ Documentation
+ GitHub Skills
+ Blog
* Solutions
For
+ Enterprise
+ Teams
+ Startups
+ Education
By Solution
+ CI/CD & Automation
+ DevOps
+ DevSecOps
Resources
+ Learning Pathways
+ White papers, Ebooks, Webinars
+ Customer Stories
+ Partners
* Open Source
+
GitHub Sponsors
Fund open source developers
+
The ReadME Project
GitHub community articles
Repositories
+ Topics
+ Trending
+ Collections
* Pricing
Search or jump to...
Search code, repositories, users, issues, pull requests...
Search
[ ]
Clear
Search syntax tips
Provide feedback
We read every piece of feedback, and take your input very seriously.
[ ] [ ] Include my email address so I can be
contacted
Cancel Submit feedback
Saved searches
Use saved searches to filter your results more quickly
Name [ ]
Query [ ]
To see all available qualifiers, see our documentation.
Cancel Create saved search
Sign in
Sign up
You signed in with another tab or window. Reload to refresh your
session. You signed out in another tab or window. Reload to refresh
your session. You switched accounts on another tab or window. Reload
to refresh your session. Dismiss alert
{{ message }}
tonaljs / tonal Public
* Notifications
* Fork 196
* Star 2.9k
*
A functional music theory library for Javascript
tonaljs.github.io/tonal/docs
2.9k stars 196 forks Branches Tags Activity
Star
Notifications
* Code
* Issues 24
* Pull requests 3
* Discussions
* Actions
* Projects 0
* Security
* Insights
Additional navigation options
* Code
* Issues
* Pull requests
* Discussions
* Actions
* Projects
* Security
* Insights
tonaljs/tonal
This commit does not belong to any branch on this repository, and may
belong to a fork outside of the repository.
main
BranchesTags
Go to file
Code
Folders and files
Name Name Last commit Last commit
message date
Latest commit
History
1,011 Commits
.changeset .changeset
.github/workflows .github/workflows
docs docs
packages packages
site site
.gitignore .gitignore
README.md README.md
package-lock.json package-lock.json
package.json package.json
tsconfig.json tsconfig.json
tslint.json tslint.json
turbo.json turbo.json
typedoc.json typedoc.json
View all files
Repository files navigation
* README
* Code of conduct
tonal
npm version
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 { Chord, Interval, Note, Scale } from "tonal";
Note.midi("C4"); // => 60
Note.freq("a4"); // => 440
Note.accidentals("c#2"); // => '#'
Note.transpose("C4", "5P"); // => "G4"
Interval.semitones("5P"); // => 7
Interval.distance("C4", "G4"); // => "5P"
// Scales
Scale.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 inversions
const triad = 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
Install all packages at once:
npm install --save tonal
You can read CHANGELOG here.
Usage
Tonal is compatible with both ES5 and ES6 modules, and browser.
ES6 import:
import { Note, Scale } from "tonal";
ES5 require:
const { Note, Scale } = require("tonal");
Browser
You can use the browser version from jsdelivr CDN directly in your
html:
Or if you prefer, grab the minified browser ready version 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:
npm i @tonaljs/note
import { transpose } from "@tonaljs/note";
transpose("A4", "P5");
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)
* @tonaljs/abc-notation: Parse ABC 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.
Voicings
* @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
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 Shayan Javadi
* EarBeater by Morten Vestergaard
* Sonid (play store, apple store) by martijnmichel
* Songcraft by Gabe G'Sell
* React Guitar by 4lejandrito
* Fretty.app by tfeldmann
* Chordify by ashleymays
* Chordal by kad1kad
* muted.io by thisisseb
* Midi Sandbox by jdlee022
* music, eternal by kousun12
* Chromatone.center by davay42
* Super Oscillator by lukehorvat
Thank you all!
Add your project here by editing this file
License
MIT License
About
A functional music theory library for Javascript
tonaljs.github.io/tonal/docs
Topics
javascript music typescript functional scale music-theory chords
interval key-signatures transpose chord-progression
Resources
Readme
Code of conduct
Code of conduct
Activity
Custom properties
Stars
2.9k stars
Watchers
61 watching
Forks
196 forks
Report repository
Releases
426 tags
Packages 0
No packages published
Used by 1.2k
* @EatMyGoose
* @wipplelang
* @9incero
* @EricDuuu
* @kanade0525
* @VulcanWM
* @mantaroh
* @aceton2
+ 1,192
Contributors 57
* @danigb
* @rakannimer
* @dependabot[bot]
* @grimmdude
* @ajrussellaudio
* @rowild
* @apalm
* @sashakhad
* @gabrocheleau
* @holden-caulfield
* @felixroos
* @limking24
* @manniL
* @davidblurton
+ 43 contributors
Languages
* TypeScript 99.2%
* Other 0.8%
Footer
(c) 2024 GitHub, Inc.
Footer navigation
* Terms
* Privacy
* Security
* Status
* Docs
* Contact
* Manage cookies
* Do not share my personal information
You can't perform that action at this time.