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
- Host: GitHub
- URL: https://github.com/danigb/pitch-transpose
- Owner: danigb
- License: mit
- Created: 2015-10-14T09:10:26.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-10-21T19:35:39.000Z (over 10 years ago)
- Last Synced: 2024-12-27T11:34:49.036Z (over 1 year ago)
- Language: JavaScript
- Size: 129 KB
- Stars: 2
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
- License: LICENSE
Awesome Lists containing this project
README
# pitch-transpose
[](https://travis-ci.org/danigb/pitch-transpose)
[](https://codeclimate.com/github/danigb/pitch-transpose/coverage)
[](https://codeclimate.com/github/danigb/pitch-transpose)
[](https://github.com/feross/standard)
[](https://www.npmjs.com/package/pitch-transpose)
[](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
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