aboutsummaryrefslogtreecommitdiff
path: root/src/chord.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/chord.ts')
-rw-r--r--src/chord.ts22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/chord.ts b/src/chord.ts
index b2645e2..0584727 100644
--- a/src/chord.ts
+++ b/src/chord.ts
@@ -1,14 +1,24 @@
export type Options = {
major: boolean,
- minor: boolean
+ minor: boolean,
+ seventh: boolean,
+ minorSeventh: boolean,
+ majorSeventh: boolean,
}
-export function generate({ major, minor }: Options): string {
- let choices: string[] = []
- if (major) choices = choices.concat(all)
- if (minor) choices = choices.concat(all.map(chord => `${chord}m`))
+export function generate(o: Options): [string, string] {
- return choices[Math.floor(Math.random() * choices.length)]
+ let base = all[Math.floor(Math.random() * all.length)]
+
+
+ let alterations: string[] = []
+ 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')
+
+ return [base, alterations[Math.floor(Math.random() * alterations.length)]]
}
const all: string[] = [ 'C', 'D♭', 'D', 'E♭', 'E', 'F', 'G♭', 'G', 'A♭', 'A', 'B♭', 'B' ]