An open API service indexing awesome lists of open source software.

https://github.com/danigb/pitch-transpose

Simple and fast pitch transposition
https://github.com/danigb/pitch-transpose

Last synced: 7 months ago
JSON representation

Simple and fast pitch transposition

Awesome Lists containing this project

README

          

# pitch-transpose

[![Build Status](https://travis-ci.org/danigb/pitch-transpose.svg?branch=master)](https://travis-ci.org/danigb/pitch-transpose)
[![Test Coverage](https://codeclimate.com/github/danigb/pitch-transpose/badges/coverage.svg)](https://codeclimate.com/github/danigb/pitch-transpose/coverage)
[![Code Climate](https://codeclimate.com/github/danigb/pitch-transpose/badges/gpa.svg)](https://codeclimate.com/github/danigb/pitch-transpose)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)
[![npm](https://img.shields.io/npm/v/pitch-transpose.svg)](https://www.npmjs.com/package/pitch-transpose)
[![array-notation](https://img.shields.io/badge/array--notation-compatible-yellow.svg)](https://github.com/danigb/pitch-array)

Simple and fast pitch transposition:

```js
transpose('E2', '2M') // => 'F#2'
transpose('F4', '3m') // => 'Ab4'
```

This is piece of a complete music manipulation library called [tonal](https://github.com/danigb/tonal)

## Installation

Install the npm module: `npm i --save pitch-transpose` and use it:

```js
var transpose = require('pitch-transpose')
transpose('3m', 'G') // => 'Bb'
```

For browser environments you need browserify, webpack or a similar tool (or use [tonal](https://github.com/danigb/tonal))

## Usage

#### Pitch transposition

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

```js
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:

```js
tranpose('A', '3M') // => 'C#'
tranpose('A5', '3M') // => 'C#5'
```

#### Transposers

Also, you can partially apply to get a transposer:

```js
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](https://github.com/danigb/a-pitch):

```js
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](https://github.com/thlorenz/docme)*

## License

MIT License