semitones
v1.0.1
Published
Get the size in semitones of a music interval
Downloads
10
Maintainers
Readme
semitones
Get the size in semitones of an interval:
var semitones = require('semitones')
semitones('P4') // => 5
You can install it via npm: npm i --save semitones
This tiny function is part of tonal
Usage
This straightforward use is to get the size of an interval:
['P1', 'M2', 'M3', 'P4', 'P5', 'M6', 'M7'].map(semitones)
// => [ 0, 2, 4, 5, 7, 9, 11, 12 ]
With notes
If you use it with notes, it returns the size in semitones from C0
to that note:
['C0', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7'].map(semitones)
// => [ 0, 12, 24, 36, 48, 60, 72, 84 ]
So it can be used to find distances (in semitones) between notes:
function distance(from, to) { return semitones(to) - semitones(from) }
distance('c3', 'd4') // => 14
With pitch classes
When used with pitch classes (notes without octaves) it returns the pitch class in integer notation:
['c', 'd', 'e', 'f', 'g', 'a', 'b'].map(semitones)
// => [ 0, 2, 4, 5, 7, 9, 11, 0 ]