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:
#!/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] . " "; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Musical key/mode finder.
by Anonymous Monk on Mar 09, 2001 at 23:52 UTC |