diff options
author | Joris | 2022-07-09 17:35:15 +0200 |
---|---|---|
committer | Joris | 2022-07-09 17:35:15 +0200 |
commit | fadee0cda55b4b328dbe778a5d511f9222e7d50c (patch) | |
tree | ddb2bc6c4f12a365c815c0a5ad913479f05341ba /src/chord.ts | |
parent | 56dd2ec807eda8dc328a92e1c8cf88fcaf786037 (diff) | |
download | chords-fadee0cda55b4b328dbe778a5d511f9222e7d50c.tar.gz chords-fadee0cda55b4b328dbe778a5d511f9222e7d50c.tar.bz2 chords-fadee0cda55b4b328dbe778a5d511f9222e7d50c.zip |
Add seventh chords
Diffstat (limited to 'src/chord.ts')
-rw-r--r-- | src/chord.ts | 22 |
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' ] |