Simple and fast pitch transposition:
transpose('E2', '2M') // => 'F#2'
transpose('F4', '3m') // => 'Ab4'
This is piece of a complete music manipulation library called tonal
Install the npm module: npm i --save pitch-transpose
and use it:
var transpose = require('pitch-transpose')
transpose('3m', 'G') // => 'Bb'
For browser environments you need browserify, webpack or a similar tool (or use tonal)
## Usage
The simplest usage is with a pitch and interval (the order doesn't matter):
transpose('C2', '4A') // => 'F#2'
transpose('4A', 'C2') // => 'F#2'
You can transpose pitch classes (pitches without octaves), and the returned value will be a pitch class:
tranpose('A', '3M') // => 'C#'
tranpose('A5', '3M') // => 'C#5'
Also, you can partially apply 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']
This library can work with pitches or intervals expressed as arrays:
transpose([0, 1, 3], [2, 0, 0]) // => [3, 1, 3]
// is the same as: transpose('C#3', '3M') => 'E#3'
It should be quite easy to write a custom parser/builder. TODO: write an example.
## API
-
Transposes pitch by an interval
Name Type Description a
String | Array a pitch or interval in string or array notation
b
String | Array a pitch or interval in string or array notation
the transposed pitch
- Type
- String | Array
transpose('3m', 'C4') // => 'Eb4' transpose('C4', '3m') // => 'Eb4' tranpose([1, 0, 2], [3, -1, 0]) // => [3, 0, 2]
generated with docme
MIT License