# @tonaljs/pcset

> Functions to work with midi numbers

Latest version **4.10.1** (published 2025-01-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install @tonaljs/pcset
pnpm add @tonaljs/pcset
yarn add @tonaljs/pcset
bun add @tonaljs/pcset
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.10.1 |
| Published | 2025-01-03 |
| First published | 2019-06-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 54 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | danigb@gmail.com |
| Maintainers | danigb |
| Keywords | note, midi, music, theory, music-theory |

## Links

- npm: https://www.npmjs.com/package/@tonaljs/pcset
- npm.io page: https://npm.io/package/@tonaljs/pcset

## Dependencies (5)

- [@tonaljs/pitch](https://npm.io/package/@tonaljs/pitch.md) 5.0.2
- [@tonaljs/collection](https://npm.io/package/@tonaljs/collection.md) 4.9.0
- [@tonaljs/pitch-note](https://npm.io/package/@tonaljs/pitch-note.md) 6.1.0
- [@tonaljs/pitch-distance](https://npm.io/package/@tonaljs/pitch-distance.md) 5.0.5
- [@tonaljs/pitch-interval](https://npm.io/package/@tonaljs/pitch-interval.md) 6.1.0

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 4.10.1 (latest) — 2025-01-03
- 4.10.0 — 2024-07-23
- 4.9.2 — 2024-02-03
- 4.9.1 — 2024-02-03
- 4.9.0 — 2024-01-15
- 4.8.3 — 2024-01-04
- 4.8.2 — 2023-06-13
- 4.8.1 — 2023-01-19
- 4.8.0 — 2022-11-29
- 4.7.3 — 2022-11-29
- 4.7.2 — 2022-11-29
- 4.7.1 — 2022-11-29
- 4.7.0 — 2022-11-28
- 4.6.10 — 2022-11-18
- 4.6.5 — 2021-09-05
- … 16 more at https://npm.io/package/@tonaljs/pcset/versions

## README

# @tonaljs/pcset ![tonal](https://img.shields.io/badge/@tonaljs-pcset-yellow.svg?style=flat-square) [![npm version](https://img.shields.io/npm/v/@tonaljs/pcset.svg?style=flat-square)](https://www.npmjs.com/package/@tonaljs/pcset)

> 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:

```js
import { Pcset } from "tonal";
```

nodejs:

```js
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:

```js
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:

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

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

```js
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`:

```js
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:

```js
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 curried:

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

Keep in mind that enharmonics are included:

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

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

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

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

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

## 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?

```js
import { chromas, pcset } from "@tonaljs/pcset";
import { transposeFrom } from "@tonaljs/note";

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

---
_Source: https://npm.io/package/@tonaljs/pcset · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
