http://qs1969.pair.com?node_id=59104

I started playing bass a while ago, and now I am getting into the music theory part. Since I got tired of figuring out the keys/modes myself, I wrote some perl to do it.

The scripts takes two command line arguments, the key and then the mode. If the key is not specified, C is assumed, and if the mode is not specified, major is assumed. See the source for valid keys.

Update: I fixed a bug in the notes array (had "G G", instead of "G G#"). Thanks for the msg jeffa.
Update Again: I fixed the bug where invalid keys/modes weren't recognized.
Yet Another Update: Added ionian (instead of just "major").

Things that still need to be fixed:

  • Ouput flats (b). See the first comment below. I have no idea how to do this properly, as saying something like A# or Bb is just "known", there aren't any progmatic rules for it.
  • Recognize flats on the command line. el-moe suggested adding "rocker keys", which have flats (Ab, Bb, Eb, Gb).
      Maybe I'll fix it when I get the time. Our maybe one of you could do it ;-).
#!/usr/bin/perl $key = uc(shift || "C"); $mode = lc(shift || "major"); @notes = qw(A A# B C C# D D# E F F# G G# A A# B C C# D D# E F F# G G#) +; %modes = ("major", -1, "ionian", -1, "dorian", 0, "phrygian", 1, "lydi +an", 2, "mixolydian", 3, "aeolian", 4, "locrian", 5); @steps = qw(2 2 1 2 2 2 1); $notematch = join "|", @notes; if (($key !~ /($notematch)/) || !(exists $modes{$mode})) {die "Invalid + key or mode!\n"} while ($notes[0] ne $key) { push(@notes, shift(@notes)); } for (0 .. $modes{"$mode"}) { push(@steps, shift(@steps)); } unshift(@steps, 0); foreach $i (@steps) { $index += $i; print $notes[$index] . " "; }