tonal.transpose
is a compact function to transpose notes:
var transpose = require('tonal.transpose')
transpose('C3', '3m') // => 'Eb3'
It's part of tonal
Via npm: npm i --save tonal.transpose
and require the function. Use browserify or webpack to create a browser ready distribution.
Or use the distribution file (adds transpose
function to window globals):
<script src="tonal.transpose.min.js"></script>
<script>console.log(transpose('C3', '3m'))</script>
The simplest usage is with a note name (pitch) and interval (the order doesn't matter):
transpose('C2', '4A') // => 'F#2'
transpose('4A', 'C2') // => 'F#2'
You can transpose pitch classes (note names without octaves), and the returned value will be a pitch class:
tranpose('A', '3M') // => 'C#'
tranpose('A5', '3M') // => 'C#5'
If you need it you can transpose an interval:
transpose('3M', '3M') // => '5A'
Also, you can partially apply the function to get a transposer:
var major3th = transpose('3M')
major3th('D') // => 'F#'
Partially applied transposers allows to work with arrays seamlessly:
['C', 'D', 'E', 'F', 'G'].map(transpose('3M')) // => ['E', 'F#', 'G#', 'A', 'B']
['1P', '3m', '5P'].map(transpose('C')) // => ['C', 'Eb', 'G']
See tonal
MIT License