aboutsummaryrefslogtreecommitdiff
path: root/src/chord.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/chord.ts')
-rw-r--r--src/chord.ts40
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)]
+}