Skip to content

Instantly share code, notes, and snippets.

@bikewheat
Created June 23, 2012 09:38
Show Gist options
  • Save bikewheat/2977725 to your computer and use it in GitHub Desktop.
Save bikewheat/2977725 to your computer and use it in GitHub Desktop.
mode scale search in different keys
def showScale( key, mode)
scale = ["C","#C/bD","D","#D/bE","E","F","#F/bG","G","#G/bA","A","#A/bB","B"]
mode_hash = {
# 1 means a semitone and 2 means two semitone
"Ionian" => [2,2,1,2,2,2,1],
"Dorian" => [2,1,2,2,2,1,2],
"Phrygian" => [1,2,2,2,1,2,2],
"Lydian" => [2,2,2,1,2,2,1],
"Mixolydian"=> [2,2,1,2,2,1,2],
"Aeolian" => [2,1,2,2,1,2,2],
"Locrian" => [1,2,2,1,2,2,2]
}
# ==============================
pos = scale.index(key)
for i in (0..6)
print scale[pos] + ' '
pos += (mode_hash[mode]).at(i)
pos %= 12
end
puts scale[pos]
# ==============================
end
# Ionian scale in different keys
p "Ionian scale in different keys"
showScale("C","Ionian")
showScale("D","Ionian")
showScale("E","Ionian")
showScale("F","Ionian")
showScale("G","Ionian")
showScale("A","Ionian")
showScale("B","Ionian")
puts
puts
# Mixolydian scale in different keys
p "Mixolydian scale in different keys"
showScale("C","Mixolydian")
showScale("D","Mixolydian")
showScale("E","Mixolydian")
showScale("F","Mixolydian")
showScale("G","Mixolydian")
showScale("A","Mixolydian")
showScale("B","Mixolydian")
=begin
//output:
"Ionian scale in different keys"
C D E F G A B C
D E #F/bG G A B #C/bD D
E #F/bG #G/bA A B #C/bD #D/bE E
F G A #A/bB C D E F
G A B C D E #F/bG G
A B #C/bD D E #F/bG #G/bA A
B #C/bD #D/bE E #F/bG #G/bA #A/bB B
"Mixolydian scale in different keys"
C D E F G A #A/bB C
D E #F/bG G A B C D
E #F/bG #G/bA A B #C/bD D E
F G A #A/bB C D #D/bE F
G A B C D E F G
A B #C/bD D E #F/bG G A
B #C/bD #D/bE E #F/bG #G/bA A B
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment