Skip to content

danigb/pitch-transpose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pitch-transpose

Build Status Test Coverage Code Climate js-standard-style npm array-notation

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

Installation

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

Pitch transposition

The simplest usage is with a pitch and interval (the order doesn't matter):

transpose('C2', '4A') // => 'F#2'
transpose('4A', 'C2') // => 'F#2'

Pitch class transposition

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'

Transposers

Also, you can partially apply to get a transposer:

var major3th = transpose('3M')
major3th('D') // => 'F#'

Work with pitch or interval arrays

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']

Using different interval or pitch representations

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

transpose(a, b) → {String|Array}

Transposes pitch by an interval

Parameters:
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

Source:
Returns:

the transposed pitch

Type
String | Array
Example
transpose('3m', 'C4') // => 'Eb4'
transpose('C4', '3m') // => 'Eb4'
tranpose([1, 0, 2], [3, -1, 0]) // => [3, 0, 2]

generated with docme

License

MIT License

About

Simple and fast pitch transposition

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published