semitones
Get the size in semitones of an interval:
var semitones = // => 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'// => [ 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'// => [ 0, 12, 24, 36, 48, 60, 72, 84 ]
So it can be used to find distances (in semitones) between notes:
{ return - } // => 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'// => [ 0, 2, 4, 5, 7, 9, 11, 0 ]