JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q52183F
  • License MIT

Music chords made easy

Package Exports

  • music-chord

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (music-chord) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

music-chord

Build Status Code Climate js-standard-style npm version

Music chords made easy:

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:

var chord = require('music-chord')
chord('1 3 5 7b 9', 'F2') // => ['F2', 'A2', 'C3', 'Eb3', 'G3']

You can partially apply the function:

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:

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

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

Dictionaries

You can create a dictionary of chords using hashes by require dictionary function:

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

music-chord brings some dictionaries you can use:

var dictionary = require('music-chord/dictionary')
var data = require('music-chord/dict/chords.json')
var chords = dictionary(data)
chords('mMaj7', 'F') // => ['F', 'Ab', 'C', 'E']

Or require the fromName function to have instant access to them:

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

var fromName = require('music-chord/fromName')
fromName('FmMaj7') // => ['F', 'Ab', 'C', 'E']
fromName('F2 mMaj7') // => ['F2', 'Ab2', 'C3', 'E3']

Chord detection

Cooming soon...

API

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

Source:
Returns:

the chord notes

Type
Array
Example
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
function
Example
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
Array
Example
var fromName = require('music-chord/fromName')
fromName('C7b9') // => ['C', 'E', 'G', 'Bb', 'Db']

generated with docme

License

MIT License