diff options
| author | Joris | 2023-02-19 14:39:02 +0100 | 
|---|---|---|
| committer | Joris | 2023-02-19 14:39:02 +0100 | 
| commit | e0699eed72c5682bd2395ba4299ff69933c83d48 (patch) | |
| tree | b5601a32492b70ec9458738a64bac6d6e15802cc /src/chord.ts | |
| parent | bb058d35c7110dcffe31b4e7afabbe26673a43a8 (diff) | |
Diffstat (limited to 'src/chord.ts')
| -rw-r--r-- | src/chord.ts | 40 | 
1 files changed, 23 insertions, 17 deletions
diff --git a/src/chord.ts b/src/chord.ts index 118f146..9393e96 100644 --- a/src/chord.ts +++ b/src/chord.ts @@ -1,22 +1,28 @@ -export type Options = { -  major: boolean, -  minor: boolean, -  seventh: boolean, -  minorSeventh: boolean, -  majorSeventh: boolean, -} +export type Chord +  = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' +  | 'A♭' | 'B♭' | 'C♭' | 'D♭' | 'E♭' | 'F♭' | 'G♭' +  | 'A♯' | 'B♯' | 'C♯' | 'D♯' | 'E♯' | 'F♯' | 'G♯' -export function generate(o: Options): [string, string] { -  let base = all[Math.floor(Math.random() * all.length)] -  let alterations: string[] = [] +export let plains: Array<Chord> = [ 'A', 'B', 'C', 'D', 'E', 'F', 'G' ] +export let bemols: Array<Chord> = [ 'A♭', 'B♭', 'C♭', 'D♭', 'E♭', 'F♭', 'G♭' ] +export let sharps: Array<Chord> = [ 'A♯', 'B♯', 'C♯', 'D♯', 'E♯', 'F♯', 'G♯' ] -  if (o.major) alterations = alterations.concat('') -  if (o.minor) alterations = alterations.concat('-') -  if (o.seventh) alterations = alterations.concat('7') -  if (o.minorSeventh) alterations = alterations.concat('-7') -  if (o.majorSeventh) alterations = alterations.concat('7') +export type Chords = Set<Chord> -  return [base, alterations[Math.floor(Math.random() * alterations.length)]] +export type GenerateParams = { +  major: Chords, +  minor: Chords, +  seventh: Chords, +  minorSeventh: Chords, +  majorSeventh: Chords,  } -const all: string[] = [ 'C', 'D♭', 'D', 'E♭', 'E', 'F', 'G♭', 'G', 'A♭', 'A', 'B♭', 'B' ] +export function generate(o: GenerateParams): [string, string] { +  const major: Array<[string, string]> = [...o.major].map(c => [c, '']) +  const minor: Array<[string, string]> = [...o.minor].map(c => [c, '-']) +  const seventh: Array<[string, string]> = [...o.seventh].map(c => [c, '7']) +  const minorSeventh: Array<[string, string]> = [...o.minorSeventh].map(c => [c, '-7']) +  const majorSeventh: Array<[string, string]> = [...o.majorSeventh].map(c => [c, '7']) +  const all = [...major, ...minor, ...seventh, ...minorSeventh, ...majorSeventh] +  return all[Math.floor(Math.random() * all.length)] +}  | 
