https://github.com/danigb/note-pitch
Note pitch manipulation in javascript
https://github.com/danigb/note-pitch
Last synced: 7 months ago
JSON representation
Note pitch manipulation in javascript
- Host: GitHub
- URL: https://github.com/danigb/note-pitch
- Owner: danigb
- License: mit
- Created: 2015-05-18T20:20:22.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2016-06-02T23:04:50.000Z (about 10 years ago)
- Last Synced: 2024-12-27T11:34:49.582Z (over 1 year ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 1
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
- License: LICENSE
Awesome Lists containing this project
README
## *** deprecated: use [tonal](http://github.com/danigb/tonal) ***
__This library is not longer maintained.__
# note-pitch
[](https://codeclimate.com/github/danigb/note-pitch)
[](https://github.com/feross/standard)
Extends [note-parser](http://github.com/danigb/note-parser) to add note pitch manipulation.
As an extension of note-parser, you can parse notes:
```js
var Note = require('note-pitch');
Note.parse('a4'); // => { pc: 'a', acc: '', oct: 4, midi: 69, freq: 440 }
```
But also you can transpose them:
```js
Note.transpose('e4', 'M2'); // => 'f#4'
Note.transpose('c2', ["P1","M2","M3"]); // => ['c2', 'd2', 'e2']
```
Or find distances (in intervals):
```js
Note.distance('c2', 'd2'); // => 'M2'
Note.distance('c', ['c', 'd', 'eb', 'f', 'g']); // => ['P1', 'M2', 'm3', 'P4', 'P5']
```
## Installation
Install the module: `npm i --save note-pitch` and require it:
```js
var Note = require('note-pitch');
```
If you want to use it inside a browser you will need a node module compatible
packager (like browserify or webpack).
This is part of a higher level library
that performs transpositions (and much more) ready to browser:
[ScoreJs](http://github.com/danigb/ScoreJS)
## API
### Note.parse(note)
Returns the note as parsed object.
See [note-parser](http://github.com/danigb/note-parser) for more information.
### Note.semitones(noteA, noteB)
Returns the distance in semitones between noteA and noteB (can be positive or negative number)
### Note.transpose(note, interval)
Transpose the given note by a interval:
```js
Note.transpose('g5', 'm3'); // => "bb5";
```
If you skip the note, you get a _transposer_, a function that transpose notes by
a certain interval:
```js
var transposer = Note.transpose('M2');
transposer('c2'); // => "d2"
transposer('d2'); // => "e2"
transposer('e2'); // => "f#2"
```
Also, you can specify an array of intervals, ideal for building chords or scales:
```js
Note.transpose('c2', ['P1', 'M2', 'm3']); // => ["c2", "d2", "eb3"]
Note.transpose('a2', ['P1', 'M3', 'P5']); // => ["a2", "c#3", "e3"]
```
### Note.distance(root, notes)
Returns the distance between a root note and a list of notes:
```js
Note.distance('c2', 'd2'); // => "M2"
Note.distance('c2', ['c2', 'd2', 'e2']); // => ['P1', 'M2', 'M3']
```
If you skip the notes, you get a _distancer_, a function that returns the
distance from the root to another note:
```js
var distance = Note.distance('c2');
distance('c2'); // => 'P1'
distance('d2'); // => 'M2'
```
## License
MIT License