Last active
October 5, 2019 17:00
-
-
Save walmik/de21deccfb0aea88725bbd9262e9a443 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pickOne = arr => | |
arr.length > 1 ? arr[Math.round(Math.random())] : arr[0]; | |
const dice = () => !!Math.round(Math.random()); | |
const getProgFactory = ({ T, P, D }) => { | |
return (count = 4) => { | |
const chords = []; | |
// Push root/tonic | |
chords.push(pickOne(T)); | |
let i = 1; | |
// Pick a predominant | |
if (i < count - 1) { | |
chords.push(pickOne(P)); | |
i++; | |
} | |
// Try another predominant | |
if (i < count - 1 && dice()) { | |
chords.push(pickOne(P)); | |
i++; | |
} | |
/////////4 or more////////// | |
if (i < count - 1) { | |
// Pick a dominant | |
chords.push(pickOne(D)); | |
i++; | |
} | |
if (i < count - 1) { | |
// Pick a predominant | |
chords.push(pickOne(P)); | |
i++; | |
} | |
if (i < count - 1) { | |
// Pick a dominant | |
chords.push(pickOne(D)); | |
i++; | |
} | |
// Pick a predominant if possible | |
if (i < count - 1 && dice()) { | |
chords.push(pickOne(P)); | |
i++; | |
} | |
//////////////////////////// | |
// Fill the rest with dominant | |
while (i < count) { | |
chords.push(pickOne(D)); | |
i++; | |
} | |
return chords; | |
}; | |
}; | |
const M = getProgFactory({ T: ['I', 'vi'], P: ['ii', 'IV'], D: ['V'] }); | |
const m = getProgFactory({ T: ['i', 'VI'], P: ['ii', 'iv'], D: ['V'] }); | |
console.log(M(4)); | |
console.log(M(8)); | |
console.log(m(4)); | |
console.log(m(8)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment