tonal-pcset
Version:
Create and manipulate pitch class sets
128 lines (127 loc) • 4.69 kB
TypeScript
type Binary = "0" | "1";
type Chroma = string;
type Interval = 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.
*
* @param {Array|String} set - the pitch class set
* @return {string} a binary representation of the pitch class set
* @example
* PcSet.chroma(["C", "D", "E"]) // => "1010100000000"
*/
export declare function chroma(set: string | Chroma[]): string;
/**
* Get a list of all possible chromas (all possible scales)
* More information: http://allthescales.org/
* @return {Array} an array of possible chromas from '10000000000' to '11111111111'
*
*/
export declare function chromas(numberOfNotes: number): 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.
*
* @param {Array|String} set - the list of notes or pitchChr of the set
* @param {Boolean} normalize - (Optional, true by default) remove all
* the rotations that starts with "0"
* @return {Array<String>} an array with all the modes of the chroma
*
* @example
* PcSet.modes(["C", "D", "E"]).map(PcSet.intervals)
*/
export declare function modes(
set: string | string[],
normalize?: boolean
): string[];
/**
* Test if the given string is a pitch class set chroma.
* @param {string} chroma - the pitch class set chroma
* @return {Boolean} true if its a valid pcset chroma
* @example
* PcSet.isChroma("101010101010") // => true
* PcSet.isChroma("101001") // => false
*/
export declare function isChroma(set: Chroma | any): boolean;
/**
* Given a pcset (notes or chroma) return it"s intervals
* @param {String|Array} pcset - the pitch class set (notes or chroma)
* @return {Array} intervals or empty array if not valid pcset
* @example
* PcSet.intervals("1010100000000") => ["1P", "2M", "3M"]
*/
export declare function intervals(set: string | string[]): Interval[];
/**
* Test if two pitch class sets are identical
*
* @param {Array|String} set1 - one of the pitch class sets
* @param {Array|String} set2 - the other pitch class set
* @return {Boolean} true if they are equal
* @example
* PcSet.isEqual(["c2", "d3"], ["c5", "d2"]) // => true
*/
export declare function isEqual(s1: string, s2: string): boolean;
/**
* Create a function that test if a collection of notes is a
* subset of a given set
*
* The function can be partially applied
*
* @param {Array|String} set - an array of notes or a chroma set string to test against
* @param {Array|String} notes - an array of notes or a chroma set
* @return {boolean} true if notes is a subset of set, false otherwise
* @example
* const inCMajor = PcSet.isSubsetOf(["C", "E", "G"])
* inCMajor(["e6", "c4"]) // => true
* inCMajor(["e6", "c4", "d3"]) // => false
*/
export declare function isSubsetOf(
set: string | string[],
notes: string | string[]
): 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)
*
* @param {Array|String} set - an array of notes or a chroma set string to test against
* @param {Array|String} notes - an array of notes or a chroma set
* @return {boolean} true if notes is a superset of set, false otherwise
* @example
* const extendsCMajor = PcSet.isSupersetOf(["C", "E", "G"])
* extendsCMajor(["e6", "a", "c4", "g2"]) // => true
* extendsCMajor(["c6", "e4", "g3"]) // => false
*/
export declare function isSupersetOf(
set: string | string[],
notes: string | string[]
): boolean;
/**
* Test if a given pitch class set includes a note
* @param {Array|String} set - the base set to test against
* @param {String|Pitch} note - the note to test
* @return {Boolean} true if the note is included in the pcset
* @example
* PcSet.includes(["C", "D", "E"], "C4") // => true
* PcSet.includes(["C", "D", "E"], "C#4") // => false
*/
export declare function includes(set: string | string[], note: string): boolean;
/**
* Filter a list with a pitch class set
*
* @param {Array|String} set - the pitch class set notes
* @param {Array|String} notes - the note list to be filtered
* @return {Array} the filtered notes
*
* @example
* 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" ])
*/
export declare function filter(
set: string | string[],
notes: string | string[]
): string[];