npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tonaljs/chord

v6.1.0

Published

Musical chords and its relations

Downloads

9,158

Readme

@tonaljs/chord tonal npm version

Usage

ES6:

import { Chord } from "tonal";

Nodejs:

const { Chord } = require("tonal");

API

Chord.getChord(type: string, tonic?: string, root?: string) => Chord

Chord.get(name: string | [string, string] | [string, string, string]) => Chord

Given a chord symbol or tokens, it returns the chord properties.

Chord properties is the the same object that ChordType.get but with additional fields:

  • symbol: the chord symbol (a combination of the tonic, chord type shortname and root, if present). For example: Cmaj7, Db7b5/F. The symbol always uses pitch classes (note names without octaves) for both the tonic and root.
  • tonic: the tonic of the chord (or an empty string if not present)
  • bass: the bass of the chord (or an empty string if not present). The bass can be any pitch class.
  • root: the root of the chord (or an empty string if not present). The root is present if the bass not belongs to the chord. It could be chords with bass without root field, but not the opposite.
  • rootDegree: the degree of the root. NaN if root not present. A number greater than 0 if present, where 1 indicates the tonic, 2 the second note (normally the 3th), 2 the third note (normally the 5th), etc.
  • notes: an array of notes, or empty array if tonic is not present. The notes will be always pitch classes.

Example:

Chord.get("Cmaj7/B"); // =>
// {
//   empty: false,
//   name: 'C major seventh over B',
//   setNum: 2193,
//   chroma: '100010010001',
//   normalized: '100010010001',
//   intervals: [ '7M', '8P', '10M', '12P' ],
//   quality: 'Major',
//   aliases: [ 'maj7', 'Δ', 'ma7', 'M7', 'Maj7', '^7' ],
//   symbol: 'Cmaj7/B',
//   tonic: 'C',
//   type: 'major seventh',
//   root: 'B',
//   bass: 'B',
//   rootDegree: 4,
//   notes: [ 'B', 'C', 'E', 'G' ]
// }

Chord.chord is an alias that is handy if using the @tonaljs/chord directly:

import { chord } from "@tonaljs/chord";

chord("C6add2");

Chord.getChord(chordType, tonic, bass) is very similar but with arguments for each chord part:

Chord.getChord("maj7", "C", "B") === Chord.get("Cmaj7/B");

Chord.notes(chordType: string, tonic?: string) => string[]

Print the notes of the given chord at the given tonic:

Chord.notes("maj4", "C4"); // => ["C4", "E4", "G4", "B4"]

Chord.degrees(chordType: string, tonic?: string) => (degree: number) => string

Scale.degrees returns a function to get a note name from a scale degree:

const c4m7 = Chord.degrees("m7", "C4");
c4m7(1); // => "C4"
c4m7(2); // => "Eb4"
c4m7(3); // => "G4"
c4m7(4); // => "Bb4"
c4m7(1); // => "C5"

It can be used, for example, to get the notes of chord inversions:

[1, 2, 3, 4].map(c4m7); // => ["C4", "Eb4", "G4", "Bb4"]
[2, 3, 4, 5].map(c4m7); // => ["Eb4", "G4", "Bb4", "C5"]
[3, 4, 5, 6].map(c4m7); // => ["G4", "Bb4", "C5", "Eb5"]
[4, 5, 6, 7].map(c4m7); // => ["Bb4", "C5", "Eb5", "G5"]

Bear in mind that degree numbers starts with 1 and 0 returns an empty string:

c4m7(0); // => ""

See Scale.degrees

Chord.steps(chordName: string) => (degree: number) => string

Same as Chord.degrees but 0 is the tonic. Plays better with numeric ranges:

import { Range, Chord } from "tonal";

Range.numeric([-3, 3]).map(Chord.steps(["C4", "aug"]));
// => ["G#3", "E3", "C3", "C4", "E4", "G#4", "C5"]

Chord.detect(notes: string[]) => string[]

Given a list of notes, get the possible chord names:

Chord.detect(["D", "F#", "A", "C"]); // => ["D7"]
Chord.detect(["F#", "A", "C", "D"]); // => ["D7/F#"]

Read more at chord-detect

Chord.transpose(chordName: string, intervalName: string) => string

Transpose a chord symbol by an interval:

Chord.transpose("Eb7b9", "5P"); // => "Bb7b9"

Chord.chordScales(chordName: string) => string[]

Get all scales where the given chord fits:

Chord.chordScales("C7b9");
// => ["phrygian dominant", "flamenco", "spanish heptatonic", "half-whole diminished", "chromatic"]

Chord.extended(chord: string) => string[]

Get all chords names that are a superset of the given one (has the same notes and at least one more)

Chord.extended("Cmaj7");
// => [ 'Cmaj#4', 'Cmaj7#9#11', 'Cmaj9', 'CM7add13', 'Cmaj13', 'Cmaj9#11', 'CM13#11', 'CM7b9' ]

Chord.reduced(chord: string) => string[]

Find all chords names that are a subset of the given one (less notes but all from the given chord)

Chord.reduced("Cmaj7"); // => ["C5", "CM"]