pcset
tonal-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
var pcset = require('tonal-pcset')
pcset.isEqual('c2 d5 e6', 'c6 e3 d1')
API documentation
pcset.chroma(set)
⇒ String
Get chroma of a pitch class set. A chroma identifies each set uniquely.
It's a 12-digit binary each presenting one semitone of the octave.
Note 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
pcset.chroma(["C", "D", "E"])
pcset.modes(set, normalize)
⇒ Array.<String>
Given a a list of notes or a pcset chroma, produce the rotations
of the chroma discarding the ones that starts with '0'
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
pcset.modes(["C", "D", "E"]).map(pcset.intervals)
pcset.isChroma(chroma)
⇒ Boolean
Test if the given string is a pitch class set chroma.
Kind: static method of pcset
Returns: Boolean
- true if its a valid pcset chroma
Param | Type | Description |
---|
chroma | String | the pitch class set chroma |
Example
pcset.isChroma('101010101010')
pcset.isChroma('101001')
pcset.intervals(pcset)
⇒ Array
Given a pcset (notes or chroma) return it's intervals
Kind: 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
pcset.intervals('1010100000000') => ["1P", "2M", "3M"]
pcset.isEqual(set1, set2)
⇒ Boolean
Test if two pitch class sets are identical
Kind: 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
pcset.isEqual(["c2", "d3"], ["c5", "d2"])
pcset.isSubsetOf(set, notes)
⇒ boolean
Create a function that test if a collection of notes is a
subset of a given set
The 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
const inCMajor = pcset.isSubsetOf(["C", "E", "G"])
inCMajor(["e6", "c4"])
inCMajor(["e6", "c4", "d3"])
pcset.isSupersetOf(set, notes)
⇒ boolean
Create a function that test if a collectio of notes is a
superset of a given set (it contains all notes and at least one more)
Kind: 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
const extendsCMajor = pcset.isSupersetOf(["C", "E", "G"])
extendsCMajor(["e6", "a", "c4", "g2"])
extendsCMajor(["c6", "e4", "g3"])
pcset.includes(set, note)
⇒ Boolean
Test if a given pitch class set includes a note
Kind: 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
pcset.includes(["C", "D", "E"], 'C4')
pcset.includes(["C", "D", "E"], 'C#4')
pcset.filter(set, notes)
⇒ Array
Filter a list with a pitch class set
Kind: 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
pcset.filter(["C", "D", "E"], ["c2", "c#2", "d2", "c3", "c#3", "d3"])
pcset.filter(["C2"], ["c2", "c#2", "d2", "c3", "c#3", "d3"])