For the musicians amoungst you the lower case refers to the inversion. i.e.
none = root, b = first and c of course = second
Pardon? You prior post discussed transposing the KEY of a piece.
This one is talking about chord inversions... But so far as I
know, a "C in 1st inversion" is /still/ a C chord -- instead of "CEG"
one is playing "EGC".
It is also confusing as, in the absence of musical notation, "b"
is often used to represent a "flat".
Assuming a key transposition, my take is:
-=-=-=-=-=-=-=-=-=-=-=-=-
# The following table should be expanded to include all the
accidentals
# that may occur... The key "C" needs C#/Db, D#, F#/Gb, G#/Ab, and A#
# and the others need the relevant mapping (which could lead to double
# sharps or double flats to make each key list the same length
# Note: I tried to derive the circle of keys from memory, may be
# some mistakes in the system
# MAJOR KEY arrangement
# half-steps 2 2 1 2 2 2 1
Keys = { "C" : ["C", "D", "E", "F", "G", "A", "B"], # no # or b
"G" : ["G", "A", "B", "C", "D", "E", "F#"], # one #
"D" : ["D", "E", "F#", "G", "A", "B", "C#"], # two #
"A" : ["A", "B", "C#", "D", "E", "F#", "G#"], # three #
"E" : ["E", "F#", "G#", "A", "B", "C#", "D#"], # four #
"B" : ["B", "C#", "D#", "E", "F#", "G#", "A#"], # five #
"F#" : ["F#", "G#", "A#", "B", "C#", "D#", "E#"], # six #
"C#" : ["C#", "D#", "E#", "F#", "G#", "A#", "B#"], #same notes
as "Db"
"F" : ["F", "G", "A", "Bb", "C", "D", "E"], # one b
"Bb" : ["Bb", "C", "D", "Eb", "F", "G", "A"], # two b
"Eb" : ["Eb", "F", "G", "Ab", "Bb", "C", "D"], # three b
"Ab" : ["Ab", "Bb", "C", "Db", "Eb", "F", "G"], # four b
"Db" : ["Db", "Eb", "F", "Gb", "Ab", "Bb", "C"], # five b
"Gb" : ["Gb", "Ab", "Bb", "Cb", "Db", "Eb", "F"], # six b
"Cb" : ["Cb", "Db", "Eb", "Fb", "Gb", "Ab", "Bb"], #same notes
as "B"
}
def Transpose(in_key, out_key, notes):
in_key = in_key[0].upper() + in_key[1:]
if Keys.has_key(in_key):
in_notes = Keys[in_key]
else:
raise "Invalid Key Signature", in_key
# Yes, it's a deprecated string exception!
out_key = out_key[0].upper() + out_key[1:]
if Keys.has_key(out_key):
out_notes = Keys[out_key]
else:
raise "Invalid Key Signature", out_key
out_list = []
for n in notes.split():
n = n[0].upper() + n[1:]
if n in in_notes:
out_list.append(out_notes[in_notes.index(n)])
else:
out_list.append("<'%s' invalid note>" % n)
return " ".join(out_list)
while 1:
print "\n"
print "For minor keys, enter the relative major key\n"
inkey = raw_input("Enter the starting key> ")
if not inkey: break
outkey = raw_input("Enter the output key> ")
if not outkey: break
print "\nEnter base chord/note sequence (separated by spaces)"
print "DO NOT enter maj, min, 7th, sus, etc. modifiers"
inchords = raw_input("Notes> ")
if not inchords: break
print Transpose(inkey, outkey, inchords)
-=-=-=-=-=-=-=-=-=-=-
From your prior post
As I said in the lists I have shown so far the transpose works. The problem
is is that a melody could be say ['C', 'E', 'B', 'F'], which should
transpose in the key of G to ['G', 'B', 'F#', 'D'] or in the key of F to
['F', 'A', 'E', 'Bb']
Hmmm, one of us has a mistake on the key of G
F:\Mail Attachments>python transpose.py
For minor keys, enter the relative major key
Enter the starting key> c
Enter the output key> g
Enter base chord/note sequence (separated by spaces)
DO NOT enter maj, min, 7th, sus, etc. modifiers
Notes> c e b f
G B F# C
For minor keys, enter the relative major key
Enter the starting key> c
Enter the output key> f
Enter base chord/note sequence (separated by spaces)
DO NOT enter maj, min, 7th, sus, etc. modifiers
Notes> c e b f
F A E Bb
For minor keys, enter the relative major key
Enter the starting key>
F:\Mail Attachments>
--