Created
October 21, 2009 00:51
-
-
Save parabuzzle/214755 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
#!ruby | |
# | |
# A simple script to figure out the key of a song based on the scale that fits | |
# Probably many better ways of doing this but it works | |
#Setup Major scales | |
@keys = Hash.new | |
@keys.store('c_major',["a","b","c","d","e","f","g"]) | |
@keys.store('g_major',["a","b","c","d","e","fs","g"]) | |
@keys.store('d_major',["a","b","cs","d","e","fs","g"]) | |
@keys.store('a_major',["a","b","cs","d","e","fs","gs"]) | |
@keys.store('e_major',["a","b","cs","ds","e","fs","gs"]) | |
@keys.store('b_major',["as","b","cs","ds","e","fs","gs"]) | |
@keys.store('fsharp_major',["as","b","cs","ds","es","fs","gs"]) | |
@keys.store('csharp_major',["as","bs","cs","ds","es","fs","gs"]) | |
#flats | |
@keys.store('f_major',["a","bf","c","d","e","f","g"]) | |
@keys.store('bflat_major',["a","bf","c","d","ef","f","g"]) | |
@keys.store('eflat_major',["af","bf","c","d","ef","f","g"]) | |
@keys.store('aflat_major',["af","bf","c","df","ef","f","g"]) | |
@keys.store('dflat_major',["af","bf","c","df","ef","f","gf"]) | |
@keys.store('gflat_major',["af","bf","cf","df","ef","f","gf"]) | |
@keys.store('cflat_major',["af","bf","cf","df","ef","ff","gf"]) | |
#Setup Minor scales | |
@keys.store('a_minor',["a","b","c","d","e","f","g"]) | |
@keys.store('e_minor',["a","b","c","d","e","fs","g"]) | |
@keys.store('b_minor',["a","b","cs","d","e","fs","g"]) | |
@keys.store('fsharp_minor',["a","b","cs","d","e","fs","gs"]) | |
@keys.store('csharp_minor',["a","b","cs","ds","e","fs","gs"]) | |
@keys.store('gsharp_minor',["as","b","cs","ds","e","fs","gs"]) | |
@keys.store('dsharp_minor',["as","b","cs","ds","es","fs","gs"]) | |
@keys.store('asharp_minor',["as","bs","cs","ds","es","fs","gs"]) | |
#flats | |
@keys.store('d_minor',["a","bf","c","d","e","f","g"]) | |
@keys.store('g_minor',["a","bf","c","d","ef","f","g"]) | |
@keys.store('c_minor',["af","bf","c","d","ef","f","g"]) | |
@keys.store('f_minor',["af","bf","c","df","ef","f","g"]) | |
@keys.store('bflat_minor',["af","bf","c","df","ef","f","gf"]) | |
@keys.store('eflat_minor',["af","bf","cf","df","ef","f","gf"]) | |
@keys.store('aflat_minor',["af","bf","cf","df","ef","ff","gf"]) | |
def whatkeys?(array) | |
key = Hash.new | |
array.each do |note| | |
@keys.each do |k,n| | |
if n == array.sort | |
key.store(k,n) | |
end | |
end | |
end | |
return key | |
end | |
test = ["c","bf","a","ef","d","f","g"] | |
key = whatkeys?(test) | |
key.each do |k,v| | |
puts k | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment