Skip to content

Instantly share code, notes, and snippets.

@SethVandebrooke
Created April 3, 2020 16:13
Show Gist options
  • Save SethVandebrooke/9f4966f3b65e5fa7280cbb993bd74c19 to your computer and use it in GitHub Desktop.
Save SethVandebrooke/9f4966f3b65e5fa7280cbb993bd74c19 to your computer and use it in GitHub Desktop.
function random(a, b) {
if(Array.isArray(a)){
return a[random(a.length)];
}
if (typeof a === "object") {
var key = random(Object.keys(a));
return b === "key" ? key : b === "both" ? {key:key,value:a[key]} : a[key];
}
if (typeof a === "string" && !!a) {
return (a.toLowerCase() === "bool") ? (Math.floor(Math.random()*2) == 1) : random(a.split(''));
}
if (typeof a === "number"){
if(typeof b === "number"){
return random(b-a)+a;
}
return Math.floor(Math.random()*a);
}
return false;
};
function getMajorScaleChordLabels(key, chordNumbers) {
var notes = ['C','C#','D','D#','E','F','F#','G','G#','A','A#','B'];
var chordMap = {
1: { position: 0, shape: 'Maj' },
2: { position: 2, shape: 'm' },
3: { position: 4, shape: 'm' },
4: { position: 5, shape: 'Maj' },
5: { position: 7, shape: 'Maj' },
6: { position: 9, shape: 'm' },
7: { position: 11, shape: 'Dim' }
};
var chords = [];
for (var i = 0; i < chordNumbers.length; i++) {
var chord = chordMap[chordNumbers[i]];
var typeExtension = chord.shape == 'Maj' ? '' : chord.shape;
chords.push(notes[((key + chord.position) % notes.length)] + typeExtension);
}
return chords;
}
function randomProgression() {
var chords = [1];
for (var i = 0; i < 3; i++) {
chords.push(random(1,6));
}
return chords;
}
// getMajorScaleChordLabels(random(0,11),randomProgression())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment