Last active
June 18, 2018 16:15
-
-
Save hotwatermorning/ee1adfe814f5cd45a7f090a9f70143b9 to your computer and use it in GitHub Desktop.
show major/minor scales
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
// https://wandbox.org/permlink/oFiLhUB4zQ73nxTx | |
const kCMajorScale = ["C", "D", "E", "F", "G", "A", "B"]; | |
const kAMinorScale = ["A", "B", "C", "D", "E", "F", "G"]; | |
const ScaleShiftDirection = { | |
kDominant: 0, | |
kSubdominant: 1, | |
} | |
function shiftScale(step, direction, isMajor) { | |
var tmp = (isMajor ? kCMajorScale : kAMinorScale).slice(); | |
console.assert(step <= 7); | |
for(var i = 0; i < step; ++i) { | |
if(direction == ScaleShiftDirection.kDominant) { | |
tmp = tmp.slice(4, 7).concat(tmp.slice(0, 4)); | |
tmp[(isMajor ? 6 : 1)] += "#"; | |
} else { | |
tmp = tmp.slice(3, 7).concat(tmp.slice(0, 3)); | |
tmp[(isMajor ? 3 : 5)] += "b"; | |
} | |
} | |
return tmp; | |
} | |
function showScales(isMajor) { | |
console.log(shiftScale(0, ScaleShiftDirection.kDominant, isMajor)); | |
console.log(shiftScale(1, ScaleShiftDirection.kDominant, isMajor)); | |
console.log(shiftScale(2, ScaleShiftDirection.kDominant, isMajor)); | |
console.log(shiftScale(3, ScaleShiftDirection.kDominant, isMajor)); | |
console.log(shiftScale(4, ScaleShiftDirection.kDominant, isMajor)); | |
console.log(shiftScale(5, ScaleShiftDirection.kDominant, isMajor)); | |
console.log(shiftScale(7, ScaleShiftDirection.kSubdominant, isMajor)); | |
console.log(shiftScale(6, ScaleShiftDirection.kDominant, isMajor)); | |
console.log(shiftScale(6, ScaleShiftDirection.kSubdominant, isMajor)); | |
console.log(shiftScale(7, ScaleShiftDirection.kDominant, isMajor)); | |
console.log(shiftScale(5, ScaleShiftDirection.kSubdominant, isMajor)); | |
console.log(shiftScale(4, ScaleShiftDirection.kSubdominant, isMajor)); | |
console.log(shiftScale(3, ScaleShiftDirection.kSubdominant, isMajor)); | |
console.log(shiftScale(2, ScaleShiftDirection.kSubdominant, isMajor)); | |
console.log(shiftScale(1, ScaleShiftDirection.kSubdominant, isMajor)); | |
} | |
showScales(true); | |
console.log(""); | |
showScales(false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment