Skip to content

Instantly share code, notes, and snippets.

@tomhodgins
Last active July 29, 2019 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomhodgins/57593797a2284b9bb86557444249443b to your computer and use it in GitHub Desktop.
Save tomhodgins/57593797a2284b9bb86557444249443b to your computer and use it in GitHub Desktop.
Generating combinations of Major/minor chord progressions with JavaScript

minor → minor

C D♯ G → C♯ E G♯

C D♯ G → D F A

C D♯ G → D♯ F♯ A♯

C D♯ G → E G B

C D♯ G → F G♯ C

C D♯ G → F♯ A C♯

C D♯ G → G A♯ D

C D♯ G → G♯ B D♯

C D♯ G → A C E

C D♯ G → A♯ C♯ F

C D♯ G → B D F♯

Major → minor

C E G → C♯ E G♯

C E G → D F A

C E G → D♯ F♯ A♯

C E G → E G B

C E G → F G♯ C

C E G → F♯ A C♯

C E G → G A♯ D

C E G → G♯ B D♯

C E G → A C E

C E G → A♯ C♯ F

C E G → B D F♯

minor → Major

C D♯ G → C♯ F G♯

C D♯ G → D F♯ A

C D♯ G → D♯ G A♯

C D♯ G → E G♯ B

C D♯ G → F A C

C D♯ G → F♯ A♯ C♯

C D♯ G → G B D

C D♯ G → G♯ C D♯

C D♯ G → A C♯ E

C D♯ G → A♯ D F

C D♯ G → B D♯ F♯

Major → Major

C E G → C♯ F G♯

C E G → D F♯ A

C E G → D♯ G A♯

C E G → E G♯ B

C E G → F A C

C E G → F♯ A♯ C♯

C E G → G B D

C E G → G♯ C D♯

C E G → A C♯ E

C E G → A♯ D F

C E G → B D♯ F♯

const scale = [
['c-0', 16.35],
['c-s-0', 17.32],
['d-0', 18.35],
['d-s-0', 19.45],
['e-0', 20.6],
['f-0', 21.83],
['f-s-0', 23.12],
['g-0', 24.5],
['g-s-0', 25.96],
['a-0', 27.5],
['a-s-0', 29.14],
['b-0', 30.87],
['c-1', 32.7],
['c-s-1', 34.65],
['d-1', 36.71],
['d-s-1', 38.89],
['e-1', 41.2],
['f-1', 43.65],
['f-s-1', 46.25],
['g-1', 49],
['g-s-1', 51.91],
['a-1', 55],
['a-s-1', 58.27],
['b-1', 61.74],
['c-2', 65.41],
['c-s-2', 69.3],
['d-2', 73.42],
['d-s-2', 77.78],
['e-2', 82.41],
['f-2', 87.31],
['f-s-2', 92.5],
['g-2', 98],
['g-s-2', 103.83],
['a-2', 110],
['a-s-2', 116.54],
['b-2', 123.47],
['c-3', 130.81],
['c-s-3', 138.59],
['d-3', 146.83],
['d-s-3', 155.56],
['e-3', 164.81],
['f-3', 174.61],
['f-s-3', 185],
['g-3', 196],
['g-s-3', 207.65],
['a-3', 220],
['a-s-3', 233.08],
['b-3', 246.94],
['c-4', 261.63],
['c-s-4', 277.18],
['d-4', 293.66],
['d-s-4', 311.13],
['e-4', 329.63],
['f-4', 349.23],
['f-s-4', 369.99],
['g-4', 392],
['g-s-4', 415.3],
['a-4', 440],
['a-s-4', 466.16],
['b-4', 493.88],
['c-5', 523.25],
['c-s-5', 554.37],
['d-5', 587.33],
['d-s-5', 622.25],
['e-5', 659.25],
['f-5', 698.46],
['f-s-5', 739.99],
['g-5', 783.99],
['g-s-5', 830.61],
['a-5', 880],
['a-s-5', 932.33],
['b-5', 987.77],
['c-6', 1046.5],
['c-s-6', 1108.73],
['d-6', 1174.66],
['d-s-6', 1244.51],
['e-6', 1318.51],
['f-6', 1396.91],
['f-s-6', 1479.98],
['g-6', 1567.98],
['g-s-6', 1661.22],
['a-6', 1760],
['a-s-6', 1864.66],
['b-6', 1975.53],
['c-7', 2093],
['c-s-7', 2217.46],
['d-7', 2349.32],
['d-s-7', 2489.02],
['e-7', 2637.02],
['f-7', 2793.83],
['f-s-7', 2959.96],
['g-7', 3135.96],
['g-s-7', 3322.44],
['a-7', 3520],
['a-s-7', 3729.31],
['b-7', 3951.07],
['c-8', 4186.01],
['c-s-8', 4434.92],
['d-8', 4698.63],
['d-s-8', 4978.03],
['e-8', 5274.04],
['f-8', 5587.65],
['f-s-8', 5919.91],
['g-8', 6271.93],
['g-s-8', 6644.88],
['a-8', 7040],
['a-s-8', 7458.62],
['b-8', 7902.13]
]
const chord = {
Major: root => [scale[root], scale[root + 4], scale[root + 7]],
minor: root => [scale[root], scale[root + 3], scale[root + 7]]
}
const rootNote = string => scale.findIndex(([name, freq]) => name === string)
const nameOnly = ([name, freq]) => name.toUpperCase().replace('-S', '♯').replace(/-\d/, '')
const freqOnly = ([name, freq]) => freq
const variations = [
['minor', 'minor'],
['Major', 'minor'],
['minor', 'Major'],
['Major', 'Major']
]
// Log minor chord with root of C-4
console.log(
chord.minor(rootNote('c-4'))
)
// Log all possible chord progressions
console.log(
variations.map(([first, second]) => {
let chords = []
for (let offset = 1; offset < 12; offset++) {
chords.push([
chord[first](rootNote('c-4')),
chord[second](rootNote('c-4') + offset)
])
}
return `# ${first} → ${second}\n\n${
chords
.map(([start, end]) => `${start.map(nameOnly).join(' ')} → ${end.map(nameOnly).join(' ')}`)
.join('\n\n')
}\n\n`
})
.join('')
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment