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/pcset

v4.10.0

Published

Functions to work with midi numbers

Downloads

7,156

Readme

@tonaljs/pcset tonal npm version

Functions to create and manipulate musical pitch class sets

A pitch class set is a set (no repeated) of pitch classes (notes without octaves). Pitch classes are useful to identify musical structures (if two chords are related, for example)

Usage

ES6:

import { Pcset } from "tonal";

nodejs:

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

API

get(src: note[] | string | number)

Given a collection of notes, a pitch class chroma string or a pitch class number, it returns a properties object with the following attributes:

  • num: the set number. Each pitch class set can be represented by an unique name between 0 and 4096. Those are the possible combinations of 12 different elements (pitch classes)
  • chroma: the set number as binary string
  • intervals: the list of intervals starting from C
  • length: the number of notes

Example:

Pcset.get(["c", "d", "e"]);
// =>
// {
//   num: 2688,
//   chroma: "101010000000",
//   intervals: ["1P", "2M", "3M"],
//   length: 3
// }

It is possible to obtain the properties from chroma or set number. All this function calls returns the same object:

Pcset.get(["c", "d", "e"]);
Pcset.get(2688);
Pcset.get("101010000000");

Several shorthands (num, chroma, intervals`) are provided:

Pcset.chroma(["c", "d", "e"]); //=> "101010000000"
Pcset.num(["c", "d", "e"]); //=> 2192

// several set representations are accepted
Pcset.chroma(2192); //=> "101010000000"
Pcset.num("101010000000"); // => 2192

Intervals are always calculated from C:

Pcset.intervals(["c", "d", "e"]); // => ["1P", "5P", "7M"]
Pcset.intervals(["D", "F", "A"]); // => ["2M", "4P", "6M"]

notes(pcset: string | number | string[]) => string[]

Given a pcset or a list of notes, it returns the sorted pitch class notes:

Pcset.notes(["D3", "A3", "Bb3", "C4", "D4", "E4", "F4", "G4", "A4"]); // => ["C", "D", "E", "F", "G", "A", "Bb"]
Pcset.notes("101011010110"); // => ["C", "D", "E", "F", "G", "A", "Bb"]

isIncludedIn(parent: Set) => (note: string) => boolean

Test if a note is included in the given set. This function is currified:

const isInCTriad = isNoteIncludedIn(["C", "E", "G"]);
isInCTriad("C4"); // => true
isInCTriad("C#4"); // => false

Keep in mind that enharmonics are included:

isInCTriad("Fb"); // => true

isSubsetOf(parent: Set) => (subset: Set) => boolean

Test if a set is a subset of another. This function is currified

isSupersetOf(subset: Set) => (parent: Set) => boolean

Test if a set is a superset of another. This function is currified

Want more?

Take a look to @tonal/scale-type or @tonal/chord-type that are, in fact, dictionaries of pitch class sets.

FAQ

How do I get a list of all possible music scales?
import { chromas, pcset } from "@tonaljs/pcset";
import { transposeFrom } from "@tonaljs/note";

chromas().map((chroma) => pcset(chroma).intervals.map(transposeFrom("C")));