Giter VIP home page Giter VIP logo

tonal.chord's Introduction

tonal.chord

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

Music chords made easy:

var chord = require('tonal.chord')
chord('CMaj7') // => ['C', 'E', 'G', 'B']
var dom7 = chord.build('C E G Bb')
dom7('A4') // => ['A4', 'C#5', 'E5', 'G5']

tonal.chord is a compact library to create and manipulate chords, and a chord dictionary

This is part of tonal

Install

Via npm: npm i --save tonal.chord or add the distribution file to your html page (will set chord global variable with the library)

Usage

A chord is an array of notes ordered by pitch starting with a tonic. Sometimes it can be expressed with intervals. With tonal.chord you can:

  • chord: create chords by name (and optionally a tonic)
  • build: create chords from a list of notes
  • type: get the chord type (major, minor, diminished, augmented)

Create a chord from name

You can get a chord by its tonic and name:

chord('Bb7') // => ['Bb', 'D', 'F', 'Ab']

Optionally, you can set the tonic as second parameter:

chord('7', 'Bb') // => ['Bb', 'D', 'F', 'Ab']

Or pass false to get the intervals:

chord('7', false) // => ['1P', '3M', '5M', '7m']

Finally, you can partially apply the function by specifying only the chord type:

var V7 = chord('7')
V7('Bb') // => ['Bb', 'D', 'F', 'Ab']

Build chords from intervals

You don't need the dictionary to create a chord. You can build a chord with a list of intervals:

chord.build('1 3 5 7b 9', 'F2') // => ['F2', 'A2', 'C3', 'Eb3', 'G3']

You can partially apply the function:

var dom79 = chord.build('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.build('1 3 5 7 2', 'C') // => ['C', 'D', 'E', 'G', 'B']

If you don't need the chord dictionary you can require only the build function to save size:

var chord = require('tonal.chord/build')

Build chord from notes

You can build from notes the same way (again, ordered notes):

var m7b5 = chord.build('C Eb Gb Bb')
m7b5('D4') // => ['D4', 'F4', 'Ab4', 'C5']
var maj7drop2 = chord.build('C2 E2 G1 B2')
maj7drop2('C4') // => [ 'G3', 'C4', 'E4', 'B4' ]

More...

Read the generated documentation or get the whole stuff

Example

To run the example npm install -g beefy then beefy example/chords.js and navigate to http://localhost:9966/

License

MIT License

tonal.chord's People

Contributors

danigb avatar

Watchers

 avatar James Cloos avatar  avatar

tonal.chord's Issues

Issue with the chord function

It seems that when calling

chord('Bb7')

I get ["Bb7", "D8", "F8"] where I should get ["Bb", "D", "F","Ab"] as mentioned in the readme.

Apparently the function understands the 7 as an octave parameter and not as a dominant 7th.
But when I build it like this

chord('7','Bb') I do get the right result though.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.