Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: PcSet.notes #406

Merged
merged 4 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/pcset/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @tonaljs/pcset

## 4.9.0

### Minor Changes

- f21525b: Add `Pcset.notes()` function that returns the ordered pitch class notes of the given set

## 4.8.3

### Patch Changes
Expand Down
9 changes: 9 additions & 0 deletions packages/pcset/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ 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 currified:
Expand Down
6 changes: 6 additions & 0 deletions packages/pcset/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
deprecate,
interval,
note,
transpose,
} from "@tonaljs/core";

/**
Expand Down Expand Up @@ -157,6 +158,10 @@ export function chromaToIntervals(chroma: PcsetChroma): IntervalName[] {
return intervals;
}

export function notes(set: Set): NoteName[] {
return get(set).intervals.map((ivl) => transpose("C", ivl));
}

/**
* Get a list of all possible pitch class sets (all possible chromas) *having
* C as root*. There are 2048 different chromas. If you want them with another
Expand Down Expand Up @@ -310,6 +315,7 @@ export default {
isEqual,
filter,
modes,
notes,
// deprecated
pcset,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/pcset/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tonaljs/pcset",
"version": "4.8.3",
"version": "4.9.0",
"description": "Functions to work with midi numbers",
"keywords": [
"note",
Expand Down
10 changes: 10 additions & 0 deletions packages/pcset/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ describe("@tonaljs/pcset", () => {
expect(Pcset.filter($("c"))($("c2 c#2 d2 c3 c#3 d3"))).toEqual($("c2 c3"));
});

test("notes", () => {
expect(Pcset.notes($("c d e f g a b"))).toEqual($("C D E F G A B"));
expect(Pcset.notes($("b a g f e d c"))).toEqual($("C D E F G A B"));
expect(Pcset.notes($("D3 A3 Bb3 C4 D4 E4 F4 G4 A4"))).toEqual(
$("C D E F G A Bb"),
);
expect(Pcset.notes("101011010110")).toEqual($("C D E F G A Bb"));
expect(Pcset.notes(["blah", "x"])).toEqual([]);
});

test("modes", () => {
expect(Pcset.modes($("c d e f g a b"))).toEqual([
"101011010101",
Expand Down
11 changes: 11 additions & 0 deletions packages/tonal/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# tonal

## 5.2.0

### Minor Changes

- f21525b: Add `Pcset.notes()` function that returns the ordered pitch class notes of the given set

### Patch Changes

- Updated dependencies [f21525b]
- @tonaljs/[email protected]

## 5.1.3

### Patch Changes
Expand Down
2 changes: 2 additions & 0 deletions packages/tonal/__snapshots__/test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ exports[`tonal Modules exports functions 1`] = `
"isSubsetOf",
"isSupersetOf",
"modes",
"notes",
"num",
"pcset",
],
Expand All @@ -191,6 +192,7 @@ exports[`tonal Modules exports functions 1`] = `
"isSubsetOf",
"isSupersetOf",
"modes",
"notes",
"num",
"pcset",
],
Expand Down
2 changes: 1 addition & 1 deletion packages/tonal/browser/tonal.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/tonal/browser/tonal.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/tonal/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tonal",
"version": "5.1.3",
"version": "5.2.0",
"description": "tonaljs music theory library",
"keywords": [
"music",
Expand Down Expand Up @@ -28,7 +28,7 @@
"@tonaljs/midi": "^4.9.1",
"@tonaljs/mode": "^4.8.2",
"@tonaljs/note": "^4.10.1",
"@tonaljs/pcset": "^4.8.3",
"@tonaljs/pcset": "^4.9.0",
"@tonaljs/progression": "^4.8.2",
"@tonaljs/range": "^4.8.2",
"@tonaljs/roman-numeral": "^4.8.1",
Expand Down
Loading