Camelot Codes to Keys
For a brief time, back when I was radio DJ, a station I worked at experimented with using "key segues", whereby a recorded sounder would transition from a song played in one key to a song in another. Thus: Song in C fades -> sounder transitions from C to A minor -> seg next Song in A minor.
It was horrendous.
Anyway. Since I was an Actual Musician (few and far between in radio), it was my job to assign the correct key for each song we played. Which essentially meant that I sat in a studio a couple of times a week with a CD player and a Casio keyboard and diddled around until I determined the key of each song we added that week.
Nowadays, a lot of DJs use the musical key of the tracks they play to create "harmonic mixes"; tracks are mixed or segued according to harmonic rules. Some DJs probably aren't musically inclined either, so there is software and databases and such that can supply the key for their tracks. Then all they have to do is check the Camelot chart to see what might sound good.
(This, of course, is not perfect, since pitches can vary. Which is what made my old station's experiments with key segues so cringey. We had CD players that could adjust for pitch, but nobody wanted to spend that much time on creating perfectly harmonic segues. But, whatever.)
I heard from a Correspondent who uses this system. He has the Camelot codes in his iTunes tracks' Comments tags. These are codes that represent 24 musical keys and look like this: 1A, 2A, 3A...10B, 11B, 12B:
Courtesy of harmonic-mixing.com
He wants to convert the Camelot codes to the actual key. So here is a script that will do that:
set camCodes to {"1A", "2A", "3A", "4A", "5A", "6A", ¬
"7A", "8A", "9A", "10A", "11A", "12A", ¬
"1B", "2B", "3B", "4B", "5B", "6B", ¬
"7B", "8B", "9B", "10B", "11B", "12B"}
set keyCodes to {"G#min", "D#min", "A#min", "Fmin", "Cmin", "Gmin", ¬
"Dmin", "Amin", "Emin", "Bmin", "F#min", "C#min", ¬
"Bmaj", "F#maj", "C#maj", "G#maj", "D#maj", "A#maj", ¬
"Fmaj", "Cmaj", "Gmaj", "Dmaj", "Amaj", "Emaj"}
(*
Replace "keyCodes" variable in the code below with "keyCodesEnharmonic"
if you prefer the enharmonic key combinations
*)
set keyCodesEnharmonic to {"G#min/Abmin", "D#min/Ebmin", "A#min/Bbmin", "Fmin", "Cmin", "Gmin", ¬
"Dmin", "Amin", "Emin", "Bmin", "F#min/Gbmin", "C#min/Dbmin", ¬
"Bmaj", "F#maj/Gbmaj", "C#maj/Dbmaj", "G#maj/Abmaj", "D#maj/Ebmaj", "A#maj/Bbmaj", ¬
"Fmaj", "Cmaj", "Gmaj", "Dmaj", "Amaj", "Emaj"}
-- just to see:
repeat with i from 1 to 24
log ((item i of camCodes) & " = " & (item i of keyCodes) & " | " & (item i of keyCodesEnharmonic)) as text
end repeat
tell application "iTunes"
set sel to selection
if sel is {} then return
repeat with aTrack in sel
set theComment to (get comment of aTrack)
-- use reverse order to replace occurrences of 12X, 11X _first_
-- and avoid ambiguity with 2X, 1X
repeat with i from 24 to 1 by -1
considering case
try
if theComment contains (item i of camCodes) then
tell aTrack to set comment to my replaceChars(theComment, (item i of camCodes), (item i of keyCodes))
exit repeat
end if
end try
end considering
end repeat
end repeat
end tell
on replaceChars(txt, srch, repl)
set text item delimiters to srch
set item_list to every text item of txt
set text item delimiters to repl
set txt to item_list as string
set text item delimiters to ""
return txt
end replaceChars
Open this in Script Editor by clicking the little little script icon. Save it named whatever you like with the Format "Script" (.scpt) in your ~/Library/iTunes/Scripts/ folder so that it will be listed in the iTunes Script menu. Select the tracks which contain Camelot codes in the comments. Launch the script and in a few moments, the Camelot codes, if they do exist in a selected track's Comments tag, will be replaced with the keys.
If it bugs you that, for example, the key of G# is not (technically) exactly the same as Ab, you can replace occurrences of the keyCodes variable with the keyCodesEnharmonic variable so that both enharmonic keys are used per code.
Also, I used "#" and "b" instead of Unicode # and ♭ because some software may not take kindly to non-ASCII text.