Skip to content
forked from tonaljs/tonal

A functional music theory library for Javascript

Notifications You must be signed in to change notification settings

Noise-Labs/tonal

 
 

Repository files navigation

tonal

Build Status Code Climate js-standard-style

Tonal is a library to create and manipulate tonal elements of music (pitches, chords, scales and keys). It deals with abstractions (not actual music) and can be used to develop midi or audio software:

var tonal = require('tonal/pitch')

// pitches
tonal.fromMidi(60) // => 'C4'
tonal.toMidi('A4') // => 69
tonal.fromFreq(220) // => 'A3'
tonal.toFreq('C') // => ...

// intervals and tranposition
tonal.tranpose('D4', '2M') // => 'E#4'
tonal.interval('C', 'G') // => '5P'
['c', 'd', 'e'].map(tonal.transpose('3M')) // => ['E4', 'F#4', 'G#4']

// harmonizers
var major = tonal.harmonizer(['1P', '3M', '5M'])
major('C6') // => ['C6', 'E6', 'G6']
major('E5', true) /// => ['E', 'G#', 'B'] (only pitch classes)
var V7 = tonal.harmonizer(['1P', '3M', '5M', '7m'])
var V7ofV = function(pitch) { V7(tonal.transpose(pitch, '5P')) }
var V7ofV('D') // => ['A4', 'C#5', 'E5', 'G7']

Tonal has a number of characteristics that make it unique:

  • It is pure functional: no classes, no side effects, no mutations, just data-in-and-out and functions
  • Heavy use of strings to represent entities: pitches ('C#2', 'Bb', 'G##'), intevals ('2M', '-9m'), chords ('Cmaj7', 'Bb79'), scales ('C major', 'Bb bebop'), collections ('C D E F', '1P 2M 3M', 'Cmaj7 D9m'), keys ('C major', 'Bb minor', '###')
  • Extremely modular: your can require the whole library, a module or an individual function, so the dependencies are reduced to the minimum. Think each function in tonal like a npm micro-module.
  • Advanced features: binary scales, chord and scale detection, chord voicings, chord progressions

This is still beta software and it's being actively developed. For a stable library see teoria

What

The library is divided in a number of modules:

  • Pitch module: the main module of tonal. Work with pitches (C#4 is one), midi and frequencies. Transpose pitches and find distances (using semitones or intervals).
  • Interval module: Work with intervals.
  • Scale: provides dictionaries to create scales using names
  • Chord: get chord intervals or pitches by its name (more than 100) and detect chords by its pitches And more ...

Usage

Install via npm: npm i --save tonal

Then you can load the whole library...

var tonal = require('tonal')
tonal.pitch.transpose(tonal.pitch.fromMidi(60), '2M')

... one module ...

var pitch = require('tonal/pitch')
pitch.transpose(pitch.fromMidi(60), '2M')

or a function:

var transpose = require('tonal/pitch/transpose')
tranpose('C', '5P')

## Documentation and tests

The functions are extensively documented inside the code. The documentation can be read here

To run the tests, clone this repository and run:

npm install
npm test

Resources and inspiration

This library takes inspiration from lot of places:

And many more... (see documentation)

License

MIT License

About

A functional music theory library for Javascript

Resources

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 98.8%
  • Other 1.2%