aboutsummaryrefslogtreecommitdiff
path: root/src/chord.ts
blob: 9393e967943ecb5cea95e87da7dbc54cb1809dd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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 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♯' ]

export type Chords = Set<Chord>

export type GenerateParams = {
  major: Chords,
  minor: Chords,
  seventh: Chords,
  minorSeventh: Chords,
  majorSeventh: Chords,
}

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)]
}