Create and manipulate pitch class sets
npm install tonal-pcsettonal-pcset is a collection of functions to work with pitch class sets, oriented
to make comparations (isEqual, isSubset, isSuperset)
This is part of tonal music theory library.
You can install via npm: npm i --save tonal-pcset
``js
// es6
import PcSet from "tonal-pcset"
var PcSet = require("tonal-pcset")
PcSet.isEqual("c2 d5 e6", "c6 e3 d1") // => true
`
* PcSet
* .chroma(set) ⇒ string
* .chromas() ⇒ Array
* .modes(set, normalize) ⇒ Array.<String>
* .isChroma(chroma) ⇒ Boolean
* .intervals(pcset) ⇒ Array
* .isEqual(set1, set2) ⇒ Boolean
* .isSubsetOf(set, notes) ⇒ boolean
* .isSupersetOf(set, notes) ⇒ boolean
* .includes(set, note) ⇒ Boolean
* .filter(set, notes) ⇒ Array
⇒ stringNote that this function accepts a chroma as parameter and return it
without modification.
Kind: static method of PcSet
Returns: string - a binary representation of the pitch class set
| Param | Type | Description |
| --- | --- | --- |
| set | Array \| String | the pitch class set |
Example
`js`
PcSet.chroma(["C", "D", "E"]) // => "1010100000000"
⇒ ArrayKind: static method of PcSet
Returns: Array - an array of possible chromas from '10000000000' to '11111111111'
⇒ Array.<String>This is used, for example, to get all the modes of a scale.
Kind: static method of PcSet
Returns: Array.<String> - an array with all the modes of the chroma
| Param | Type | Description |
| --- | --- | --- |
| set | Array \| String | the list of notes or pitchChr of the set |
| normalize | Boolean | (Optional, true by default) remove all the rotations that starts with "0" |
Example
`js`
PcSet.modes(["C", "D", "E"]).map(PcSet.intervals)
⇒ BooleanKind: static method of PcSet
Returns: Boolean - true if its a valid pcset chroma
| Param | Type | Description |
| --- | --- | --- |
| chroma | string | the pitch class set chroma |
Example
`js`
PcSet.isChroma("101010101010") // => true
PcSet.isChroma("101001") // => false
⇒ ArrayKind: static method of PcSet
Returns: Array - intervals or empty array if not valid pcset
| Param | Type | Description |
| --- | --- | --- |
| pcset | String \| Array | the pitch class set (notes or chroma) |
Example
`js`
PcSet.intervals("1010100000000") => ["1P", "2M", "3M"]
⇒ BooleanKind: static method of PcSet
Returns: Boolean - true if they are equal
| Param | Type | Description |
| --- | --- | --- |
| set1 | Array \| String | one of the pitch class sets |
| set2 | Array \| String | the other pitch class set |
Example
`js`
PcSet.isEqual(["c2", "d3"], ["c5", "d2"]) // => true
⇒ booleanThe function can be partially applied
Kind: static method of PcSet
Returns: boolean - true if notes is a subset of set, false otherwise
| Param | Type | Description |
| --- | --- | --- |
| set | Array \| String | an array of notes or a chroma set string to test against |
| notes | Array \| String | an array of notes or a chroma set |
Example
`js`
const inCMajor = PcSet.isSubsetOf(["C", "E", "G"])
inCMajor(["e6", "c4"]) // => true
inCMajor(["e6", "c4", "d3"]) // => false
⇒ booleanKind: static method of PcSet
Returns: boolean - true if notes is a superset of set, false otherwise
| Param | Type | Description |
| --- | --- | --- |
| set | Array \| String | an array of notes or a chroma set string to test against |
| notes | Array \| String | an array of notes or a chroma set |
Example
`js`
const extendsCMajor = PcSet.isSupersetOf(["C", "E", "G"])
extendsCMajor(["e6", "a", "c4", "g2"]) // => true
extendsCMajor(["c6", "e4", "g3"]) // => false
⇒ BooleanKind: static method of PcSet
Returns: Boolean - true if the note is included in the pcset
| Param | Type | Description |
| --- | --- | --- |
| set | Array \| String | the base set to test against |
| note | String \| Pitch | the note to test |
Example
`js`
PcSet.includes(["C", "D", "E"], "C4") // => true
PcSet.includes(["C", "D", "E"], "C#4") // => false
⇒ ArrayKind: static method of PcSet
Returns: Array - the filtered notes
| Param | Type | Description |
| --- | --- | --- |
| set | Array \| String | the pitch class set notes |
| notes | Array \| String | the note list to be filtered |
Example
`js``
PcSet.filter(["C", "D", "E"], ["c2", "c#2", "d2", "c3", "c#3", "d3"]) // => [ "c2", "d2", "c3", "d3" ])
PcSet.filter(["C2"], ["c2", "c#2", "d2", "c3", "c#3", "d3"]) // => [ "c2", "c3" ])