music-dictionary

0.2.2 • Public • Published

music-dictionary

Build Status Test Coverage Code Climate js-standard-style npm version license tonal

music-dictionary is a function to create musical dictionaries. A musical dictionary is a collection of notes with a name:

var dictionary = require('music-dictionary')
var chords = dictionary({'Maj7': ['1 3 5 7', ['maj7', 'M7']]})
chords('CMaj7') // => ['C', 'E', 'G', 'B']
chords('BbM7') // => ['Bb', 'D', 'F', 'A']

This is part of tonal and the foundation of the tonal.scale and chord.dictionary dictionaries.

Install

Via npm only: npm i --save music-dictionary

Usage

The function returned by music-dictionary creates list of notes (or intervals) from a name. The name may include a root:

var chords = dictionary({'Maj7', ['1 3 5 7', ['maj7', 'M7']], 'm7': ['1 3m 7 7m']})
chords('CMaj7') // => ['C', 'E', 'G', 'B']
chords('Maj7', 'C') // => ['C', 'E', 'G', 'B']
chords('Fm7') // => ['F', 'Ab', 'C', 'Eb']

Without root, a list of intervals is returned:

chords('Maj7') // => ['1P', '3M', '5P', '7M']

It never returns null. If no name is found, an empty array is returned:

chords('Cdim') // => []
chords(null) // => []
chords() // => []

Dictionary data

The data property of the dictionary is a hashmap of names mapped to data objects. The data objects has the following properties:

  • name: the name
  • aliases: an array with the alternative names
  • intervals: an array with the intervals
  • steps: an array with the intervals in array notation
  • binary: a binary representation of the set
  • decimal: the decimal representation of the set
var chords = dictionary({'Maj7', ['1 3 5 7', ['maj7', 'M7']]})
// dictionary data
chords.data['M7'] // => { name: 'Maj7', aliases: ['M7'],
                  //      intervals: ['1', '3', '5', '7'], steps: [ ...],
                  //      binary: '10010010001', decimal: 2193 }

// get chord by binary numbers
chords.data['100010010001'] === chords.data['Maj7']
chords.data[2193] === chords.data['Maj7']

Get available names

The property names is an array with the available names. The property aliases adds the aliases names:

var chords = dictionary({'Maj7', ['1 3 5 7', ['maj7', 'M7']], 'm': ['1 3b 5']})
chords.names // => ['Maj7', 'm']
chords.aliases // => ['Maj7', 'm', 'maj7', 'M7']

More...

Read the generated documentation or take a look at tonal

License

MIT License

Dependents (0)

Package Sidebar

Install

npm i music-dictionary

Weekly Downloads

0

Version

0.2.2

License

MIT

Last publish

Collaborators

  • danigb