tonaljs / tonal

A functional music theory library for Javascript

Home Page:https://tonaljs.github.io/tonal/docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`Scale.scaleNotes` returns an array instead of a pcset.

elsherbini opened this issue · comments

/**
* Given an array of notes, return the scale: a pitch class set starting from
* the first note of the array
*
* @function
* @param {string[]} notes
* @return {string[]} pitch classes with same tonic
* @example
* scaleNotes(['C4', 'c3', 'C5', 'C4', 'c4']) // => ["C"]
* scaleNotes(['D4', 'c#5', 'A5', 'F#6']) // => ["D", "F#", "A", "C#"]
*/
export function scaleNotes(notes: NoteName[]) {
const pcset: string[] = notes.map((n) => note(n).pc).filter((x) => x);
const tonic = pcset[0];
const scale = sortedUniqNames(pcset);
return rotate(scale.indexOf(tonic), scale);
}

Also, Pcset doesn't have support for a tonic, so I guess its not really possible to return a pcset with the specified tonic as the comment suggests.

export interface Pcset extends Named {
readonly empty: boolean;
readonly setNum: number;
readonly chroma: PcsetChroma;
readonly normalized: PcsetChroma;
readonly intervals: IntervalName[];
}

commented

Don't understand exactly what is the problem to solve. The documentation says that it returns an array of notes: Scale.scaleNotes(notes: string[]) => string[] but also, conceptually, that collection of notes is a pitch class set, but not a pitch class set structure.

Any ideas on how to improve both code or docs are welcomed.

Got it. I read it expecting it to return an actual scale or Pcset structure that had the properties intervals, tonic, etc.

I was looking for some way in the library to define an arbitrary scale and get the intervals relative to the tonic without having to do everything relative to C, and reading the description I thought this was it!

So documentation-wise for this issue, maybe the description could be written:

"Given an array of notes, return an array of sorted note names starting from the first note name of the input array."

What do you think?