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

@patrady/chord-js

v2.2.2

Published

Chord JS is a music theory package that identifies notes, chords, and key signatures on an 88-key piano.

Downloads

16

Readme

Chord JS

Chord JS is a music theory package that identifies notes, chords, and key signatures on an 88-key piano.

To install run

npm install @patrady/chord-js

or if you're using yarn

yarn add @patrady/chord-js

Chords

To translate a series of notes into a chord, use

import { Chord } from '@patrady/chord-js';

const chord = new Chord.for('C E G');

chord?.getName(); // C

This table shows the type of supported chords with examples

| Chord | Example | | -------------------------------------------------------------------------------------- | ---------------------------------- | | Major | Chord.for("C E G"); // C | | Minor | Chord.for("C Eb G"); // Cm | | Suspended | Chord.for("C F G"); // Csus | | Suspended Second | Chord.for("C D G"); // Csus2 | | Augmented | Chord.for("C E G#"); // Caug | | Diminished | Chord.for("C Eb Gb"); // Cdim | | Inverted | Chord.for("E G C"); // C/E | | Sixth | Chord.for("C E G A"); // C6 | | Minor Sixth | Chord.for('C Eb G A'); // Cm6 | | Dominant Seventh | Chord.for("C E G Bb"); // C7 | | Diminished Seventh | Chord.for("C Eb Gb A"); // Cdim7 | | Augmented Seventh | Chord.for("C E G# Bb"); // C+7 | | Major Seventh | Chord.for("C E G B"); // Cmaj7 | | Augmented Major Seventh | Chord.for("C E G# B"); // Cmaj+7 | | Minor Seventh | Chord.for("C Eb G Bb"); // Cm7 | | Minor Major Seventh | Chord.for("C Eb G B"); // Cm7+ | | Half-Diminished Seventh | Chord.for("C Eb Gb Bb"); // Cø7 |

Key Signatures

A Key Signature is a combination of sharps and flats at the beginning of each stave.

import { Note, KeySignatureOfD } from '@patrady/chord-js';

new KeySignatureOfD().getNotes(); // D, E, F#, G, A, B, C#, D

new KeySignatureOfD().normalize(new Note('Gb')); // F#

new KeySignatureOfD().isInKey(new Note('Gb')); // false
new KeySignatureOfD().isInKey(new Note('F#')); // true

| Attribute | Description | Example | | ----------------- | ---------------------------------------------------------------------- | --------------------------------------------------------------- | | getNotes() | Returns an array of eight notes from the base to the octave. | new KeySignatureOfD().getNotes(); // D, E, F#, G, A, B, C#, D | | normalize(note) | Normalizes a note from one key signature to the current key signature. | new KeySignatureOfD().normalize(new Note("Gb")); // F# | | isInKey(note) | Returns whether a note is in the key signature | new KeySignatureOfD().isInKey(new Note("Gb")); // false |

Supported Key Signatures

The major key signatures are supported but less popular ones are not. Check this table to see if the one you need is supported:

| Key Signature | Supported | Name | | ------------- | --------- | ---------------------- | | C | ✅ | KeySignatureOfC | | Cb | ❌ | | | C# | ❌ | | | D | ✅ | KeySignatureOfD | | Db | ✅ | KeySignatureOfDb | | D# | ❌ | | | E | ✅ | KeySignatureOfE | | Eb | ✅ | KeySignatureOfEb | | E# | ❌ | | | F | ✅ | KeySignatureOfF | | Fb | ❌ | | | F# | ✅ | KeySignatureOfFsharp | | G | ✅ | KeySignatureOfG | | Gb | ✅ | KeySignatureOfGb | | G# | ❌ | | | A | ✅ | KeySignatureOfA | | Ab | ✅ | KeySignatureOfAb | | A# | ❌ | | | B | ✅ | KeySignatureOfB | | Bb | ✅ | KeySignatureOfBb | | B# | ❌ | |

Notes

A Note is the fundamental element of music. Notes are simply frequencies and are used to create chords and key signatures.

import { Note } from '@patrady/chord-js';

const note = new Note('Eb4');

| Attribute | Description | Example | | --------------------- | -------------------------------------------------------------------------------------------------- | ----------------------------------- | | getName() | The name of the note and accidental | note.getName(); // Eb | | getScientificName() | The name of the note, accidental, and octave | note.getScientificName(); // Eb4 | | getOctave() | The octave between 0 and 8 | note.getOctave(); // 4 | | getFrequency() | The frequency in Hz, up to 5 decimal places | note.getFrequency(); // 311.12698 | | getKeyNumber() | The number of the key on an 88-key piano | note.getKeyNumber(); // 43 | | getMidiValue() | The MIDI note of the key on an 88-key piano | note.getMidiValue(); // 63 |

MIDI Keyboard

When interacting with a MIDI keyboard and you want to convert a MIDI value to a note, use

import { Note } from '@patrady/chord-js';

const note = Note.fromMidi(24);

note.getScientificName(); // C1

For enharmonic notes, the MIDI value will be the same. For example, C# and Db in the 1st octave will have the same MIDI value of 25. To choose a specific enharmonic, normalize the note to a key signature:

import { Note, KeySignatureOfD, KeySignatureOfDb } from '@patrady/chord-js';

const note = Note.fromMidi(25);

new KeySignatureOfD().normalize(note); // C#
new KeySignatureOfDb().normalize(note); // Db

A chord can also be determined from the MIDI notes like so

import { Note } from '@patrady/chord-js';

const C = Note.fromMidi(60);
const E = Note.fromMidi(64);
const G = Note.fromMidi(67);

Chord.for([C, E, G])?.getName(); // C