Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danigb/music-chord
Music chords made easy
https://github.com/danigb/music-chord
Last synced: 13 days ago
JSON representation
Music chords made easy
- Host: GitHub
- URL: https://github.com/danigb/music-chord
- Owner: danigb
- License: mit
- Created: 2015-10-14T16:33:23.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-10-21T11:09:23.000Z (about 9 years ago)
- Last Synced: 2023-04-11T13:58:26.896Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 168 KB
- Stars: 13
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
- License: LICENSE
Awesome Lists containing this project
README
# music-chord
[![Build Status](https://travis-ci.org/danigb/music-chord.svg?branch=master)](https://travis-ci.org/danigb/music-chord)
[![Code Climate](https://codeclimate.com/github/danigb/music-chord/badges/gpa.svg)](https://codeclimate.com/github/danigb/music-chord)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)
[![npm version](https://img.shields.io/npm/v/music-chord.svg)](https://www.npmjs.com/package/music-chord)
[![license](https://img.shields.io/npm/l/music-chord.svg)](https://www.npmjs.com/package/music-chord)
[![pitch-array](https://img.shields.io/badge/pitch--array-compatible-yellow.svg)](https://github.com/danigb/pitch-array)Music chords made easy:
```js
var chord = require('music-chord')
var M9 = chord('1 3 5 7 9')
M9('D3') // => ['D3', 'F#3', 'A#3', 'C#4', 'E4']
var dom7 = chord('C E G Bb')
dom7('A4') // => ['A4', 'C#5', 'E5', 'G5']
```## Install
#### Node
Install via npm: `npm i --save music-chord` and require it.
#### Browsers
Currently there's no distribution for browsers, but is planned. You can use browserify, webpack or a similar tool to create one.
## Usage
#### Build chords from intervals
This is the basic usage:
```js
var chord = require('music-chord')
chord('1 3 5 7b 9', 'F2') // => ['F2', 'A2', 'C3', 'Eb3', 'G3']
```You can partially apply the function:
```js
var dom79 = chord('1 3 5 7b 9')
dom79('F2') // => ['F2', 'A2', 'C3', 'Eb3', 'G3']
```__Its important to note that all chord notes are ordered by pitch:__
```js
chord('1 3 5 7 2', 'C') // => ['C', 'D', 'E', 'G', 'B']
```#### Build from notes
You can build from notes the same way (again, ordered notes):
```js
var m7b5 = chord('C Eb Gb Bb')
m7b5('D4') // => ['D4', 'F4', 'Ab4', 'C5']
var maj7drop2 = chord('C2 E2 G1 B2')
maj7drop2('C4') // => [ 'G3', 'C4', 'E4', 'B4' ]
```#### Get chord intervals
Set `null` as tonic to get the chord intervals:
```js
var chord('C E G B', null) // => ['1P', '3M', '5P', '7M']
```#### Dictionaries
You can create a dictionary of chords with the `dictionary` function:
```js
var dictionary = require('music-chord/dictionary')
var chords = dictionary({ M: 'C E G', m: 'C Eb G'})
chords('M', 'G') // => ['G', 'B', 'D']
chords('m', 'G') // => ['G', 'Bb', 'D']
```Use the built-in dictionaries with the `fromName`:
```js
var fromName = require('music-chord/fromName')
fromName('mMaj7', 'F') // => ['F', 'Ab', 'C', 'E']
```As bonus, with `fromName` function you can place the tonic before the type (with a space if you want to specify the octave):
```js
var fromName = require('music-chord/fromName')
fromName('FmMaj7') // => ['F', 'Ab', 'C', 'E']
fromName('F2 mMaj7') // => ['F2', 'Ab2', 'C3', 'E3']
```#### Chord detection
Cooming soon...
## API
addAdd interval to a gamut
Like all the functions from gamut, this works with pitch-array notation format arrays.
Probably you will want to decorate this function withgamut.notes
orgamut.intervals
(see example)
- Source:
Example
gamut.add([1, 0, 0], [ [1, 0, 0], [2, 0, 0]]) // => [ [2, 0, 0], [3, 1, 0] ]
var transpose = gamut.notes(gamut.add)
transpose('2M', 'C D E') // => [ 'D', 'E', 'F#' ]
var addIntervals = gamut.intevals(gamut.add)
addIntervals('2M', '1P 2M 3M') // => [ '2M', '3M', '4A' ]
asArray(source) → {Array}Get an array from a source. The source can be a string separated by
spaces, commas or bars (|
), an array or an object.This function does not perform any transformation to the items of the array.
This function always return an array, even if its emptyParameters:
Name
Type
Description
source
String
|
Array
|
Objectthe source
- Source:
Returns:
the source converted to an array
Type
ArrayExample
gamut.asArray('c d e') // => [ 'c', 'd', 'e' ]
gamut.asArray('CMaj7 | Dm7 G7') // => [ 'CMaj7', 'Dm7', 'G7' ]
gamut.asArray('1, 2, 3') // => ['1', '2', '3']
gamut.asArray([1, 'a', 3]) // => [1, 'a', 3]
gamut.asArray(object) // => [ object ]
gamut.asArray(null) // => [ ]
chord(source, tonic) → {Array}Build a chord from a source and a tonic
A source can be a list of intervals or notes. The tonic must be
a pitch (with or without octave)This function is currified, so you can partially apply the function passing
one parameter instead of two (see example)Parameters:
Name
Type
Description
source
Array
the list of intervals or notes
tonic
String
the tonic of the chord or null to get the intervals
Returns:
the chord notes (or intervals if null tonic)
Type
ArrayExample
var chord = require('music-chord')
chord('1 3 5 6', 'G') // => ['G', 'B', 'D', 'E']
var maj79 = chord('C E G B D')
maj79('A4') // => ['A4', 'C#5', 'E5', 'G#5', 'B5']
dictionary(chordNames, aliases) → {function}Create a chord dictionary
Parameters:
Name
Type
Description
chordNames
Hash
a hash that maps names to intervals (or notes)
aliases
Hash
(Optional) a hash that maps names to names or null
- Source:
Returns:
a function
chord(name, tonic)
Type
functionExample
var dictionary = require('music-chord/dictionary')
chords = dictionary({M: 'C E G', m: 'C Eb G'})
chords('m', 'F') // => ['F', 'Ab', 'C']
chords('M', 'A4') // => ['A4', 'C#5', 'E5']
fromName(name, tonic) → {Array}Build chords by name
The same as
chord
function but using chord names instead of intervals.
The chord name may contain the tonic placed before the type (see example)Parameters:
Name
Type
Description
name
String
the chord name
tonic
String
(Optional) the tonic
- Source:
Returns:
an array of notes in ascending order or null
Type
ArrayExample
var fromName = require('music-chord/fromName')
fromName('C7b9') // => ['C', 'E', 'G', 'Bb', 'Db']
gamut()Gamut
- Source:
intervals()Get the gamut as intervals or decorate a function to return intervals
- Source:
Example
gamut.intervals('C D E') // => []
var addIntervals = gamut.intervals(gamut.add)
addIntervals('2M', '1P 5P') // => ['2M', '6M']
map(fn, source) → {Array}Get a gamut mapped to a function
Is important to notice that the function will receive pitches in pitch-array notation format.
This function can be partially applied
Parameters:
Name
Type
Description
fn
function
the function to map the gamut with
source
String
|
Arraythe gamut
- Source:
Returns:
the mapped gamut
Type
ArrayExample
var addOctave = function(p) { return [p[0], p[1], p[2] + 1]}
gamut.map(addOctave, [ [0, 0, 0], [1, 0, 0] ]) // => [ [0, 0, 1], [1, 0, 1]]
var octaveUp = gamut.map(addOctave)
octaveUp([ [0, 0, 0], [1, 0, 0] ]) // => [ [0, 0, 1], [1, 0, 1]]
notes()Get notes from a gamut, or decorate a function to return notes
- Source:
Example
gamut.notes('1P 2M 3M') // => ['C0', 'D0', 'E0']
var transpose = gamut.notes(gamut.add)
transpose('2M', 'C D E') // => [ 'D', 'E', 'F#' ]
parse(source) → {Array}Convert a list of notes or intervals to pitch-array notation format
Parameters:
Name
Type
Description
source
String
|
Arraythe gamut
- Source:
Returns:
the gamut with notes or intervals in pitch-array notation format
Type
ArrayExample
gamut.parse('C D E') // => [ [0, 0, null], [1, 0, null], [2, 0, null] ]
gamut.parse('1P 3M 5P') // => [ [0, 0, 0], [2, 0, 0], [4, 0, 0] ]
pitchClass()Get the pitch classes of a gamut
- Source:
set()Get a set
- Source:
sort()Sort a gamut by frequency
- Source:
uniq()Remove duplicates from a gamut
- Source:
*generated with [docme](https://github.com/thlorenz/docme)*
## License
MIT License