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

music-theory-utils

v1.2.0

Published

Calculates intervals, chords, intervals, scales and so on.

Downloads

3

Readme

Music Theory Utilities

This library provides basic utilities for manipulating chords, notes, intervals and scales. Expect bugs since it is in a very early stage of development.

There are no dependencies inside this package.

Introduction

Note, Chord, Interval and Scale are class types that can be instantiated.

Every note has a pitch, and a accidental (can be empty), and an octave. A special note called relative note does not have an octave. Methods inside Note will work differently for them.

An interval is comprised of a size and a quality. Note that certain sizes are perfect intervals, so the sizes they require a different than those who are imperfect.

A Chord is merely a vertical stack of notes. In this library, a chord is defined by a note and a series of intervals.

A Scale is defined similarly to a Chord.

Read the docs for more details.

Some Small Examples

Note

Create a note, and add an interval onto it, returns a new note.

new Note("A", "", 4).addInterval(new Interval("M3")); // Note { pitch: 'C', accidental: '#', octave: 5 }

Compares if two notes are enharmonically equal. Since C sharp is the same as D flat, it returns true. For exact equals, omit the second argument.

new Note("C", "#", 3).equals(new Note("D", "b", 3), true); // true

Get string representation of a note.

new Note("C", "#", 3).toString(); // C#3

Intervals

Test is minor second is a perfect interval, it should be false.

new Interval("m2").isPerfectInterval(); // false

Get the number of semitones of an interval. There are four semitones between a major third, front exclusive and end inclusive.

new Interval("M3").valueOf(); // 4

Chord

Generate a chord if any kind of interval.

const c = new Chord(new Note("F"), [new Interval("M3"), new Interval("m3")]);
/* Chord {
base: Note { pitch: 'F', accidental: '', octave: null },
intervals: [
Interval { quality: 'M', size: 3 },
Interval { quality: 'm', size: 3 }
]
} */

Collect the notes of a chord as an array.

const cc = [...c];
/*
[
Note { pitch: 'F', accidental: '', octave: null },
Note { pitch: 'A', accidental: '', octave: null },
Note { pitch: 'C', accidental: '', octave: null }
]
*/

The library also provides several interval helpers like minor seventh, major seventh and so on.

new Chord(new Note("A", "b"), Chord.minorSeventh);
/*
Chord {
base: Note { pitch: 'A', accidental: 'b', octave: null },
intervals: [
Interval { quality: 'm', size: 3 },
Interval { quality: 'M', size: 3 },
Interval { quality: 'm', size: 3 }
]
}
*/

Scale

Generate a B dorian scale.

const s = new Scale(new Note("B"), Scale.dorian);
/*
Scale {
root: Note { pitch: 'B', accidental: '', octave: null },
configuration: [
Interval { quality: 'M', size: 2 },
Interval { quality: 'm', size: 2 },
Interval { quality: 'M', size: 2 },
Interval { quality: 'M', size: 2 },
Interval { quality: 'M', size: 2 },
Interval { quality: 'm', size: 2 },
Interval { quality: 'M', size: 2 }
]
}
*/

We can also collect scales into a note array.

const ss = [...s];
/*
[
Note { pitch: 'B', accidental: '', octave: null },
Note { pitch: 'C', accidental: '#', octave: null },
Note { pitch: 'D', accidental: '', octave: null },
Note { pitch: 'E', accidental: '', octave: null },
Note { pitch: 'F', accidental: '#', octave: null },
Note { pitch: 'G', accidental: '#', octave: null },
Note { pitch: 'A', accidental: '', octave: null },
Note { pitch: 'B', accidental: '', octave: null }
]
*/

Development

After cloning, install the dev dependencies with:

npm install

Run the tests with:

npm run test # one time
npm run test:watch # continuously

Generate docs and coverage report with:

npm run doc
npm run test:coverage

Build the project with:

npm run build:ts
npm run watch:ts # continuously rebuild the project