# An attempt to bring that chord-stuff into an Apache Perl module # # 9 Jan 01 Erich Rickheit KSC Created # package chord::chr; use Apache::Constants qw(:common); use strict; # hack my $uval = 0; # where are GIFs located? my $imgdir = '/~rickheit/chord'; # external program to generate chords my $chordprog = "/home/rickheit/public_html/chord/ch/ch"; # intervals between degrees of the scale my @intervals = qw(0 2 4 5 7 9 11 12 14 16 17 19 21 23 24 26 28 29 31 33 35 36); # names of the clasical modes, in order my @modes = qw(Ionian Dorian Phrygian Lydian Myxolydian Aeolian Locrian); # note names users can enter my @unotes = qw(x A B C D E F G A# B# C# D# E# F# G# Ab Bb Cb Db Eb Fb Gb); # map note names to numeric values my %nval = ( C => 0, D => 2, E => 4, F => 5, G => 7, A => 9, B => 11 ); # intervals in each chord my @chords = ( [ '', [ 4, 7 ] ], [ 'm', [ 3, 7 ] ], [ '+', [ 4, 8 ] ], [ 'mb5', [ 3, 6 ] ], [ '7', [ 4, 7, 10 ] ], [ 'maj7', [ 4, 7, 11 ] ], [ 'm7', [ 3, 7, 10 ] ], [ 'm(maj7)', [ 3, 7, 11 ] ], [ 'm7b5', [ 3, 6, 10 ] ], [ 'dim', [ 3, 6, 9 ] ], [ 'sus', [ 5, 7 ] ], ); # 'standard' chord patterns my %basic_chords = ( '[0]' => [ qw(x 3 2 0 1 0 1) ], '[0]+' => [ qw(x x 2 1 1 0 1) ], '[0]7' => [ qw(0 3 2 3 1 0 1) ], '[0]dim' => [ qw(x x 1 2 1 2 1) ], '[0]m' => [ qw(x 1 3 3 2 1 3) ], '[0]m(maj7)' => [ qw(1 1 3 2 2 1 3) ], '[0]m7' => [ qw(x 1 3 1 2 1 3) ], '[0]m7b5' => [ qw(x x 2 2 1 2 7) ], '[0]maj7' => [ qw(x 3 2 0 0 0 1) ], '[0]mb5' => [ qw(x x 3 4 3 1 2) ], '[0]sus' => [ qw(x x 3 0 1 3 1) ], '[1]' => [ qw(x x 3 1 2 1 1) ], '[1]+' => [ qw(x x 3 2 2 1 1) ], '[1]7' => [ qw(x x 3 4 2 4 1) ], '[1]dim' => [ qw(x x 2 3 2 3 1) ], '[1]m' => [ qw(x x 2 1 2 0 1) ], '[1]m(maj7)' => [ qw(1 1 3 2 2 1 4) ], '[1]m7' => [ qw(x x 2 4 2 4 1) ], '[1]m7b5' => [ qw(0 4 2 0 0 0 1) ], '[1]maj7' => [ qw(x 4 3 1 1 1 1) ], '[1]mb5' => [ qw(0 4 2 0 2 0 1) ], '[1]sus' => [ qw(x x 3 3 4 1 4) ], '[2]' => [ qw(x x 0 2 3 2 1) ], '[2]+' => [ qw(x x 0 3 3 2 1) ], '[2]7' => [ qw(x x 0 2 1 2 1) ], '[2]dim' => [ qw(x x 0 1 0 1 1) ], '[2]m' => [ qw(x x 0 2 3 1 1) ], '[2]m(maj7)' => [ qw(x 4 0 2 3 1 1) ], '[2]m7' => [ qw(x x 0 2 1 1 1) ], '[2]m7b5' => [ qw(x 3 0 1 1 1 1) ], '[2]maj7' => [ qw(x x 0 2 2 2 1) ], '[2]mb5' => [ qw(x x 0 1 3 1 1) ], '[2]sus' => [ qw(x x 0 2 3 3 1) ], '[3]' => [ qw(x x 3 1 2 1 3) ], '[3]+' => [ qw(x x 1 0 0 4 1) ], '[3]7' => [ qw(x x 1 3 2 3 1) ], '[3]dim' => [ qw(x x 1 2 1 2 1) ], '[3]m' => [ qw(x x 4 3 4 2 1) ], '[3]m(maj7)' => [ qw(x 4 0 2 3 1 2) ], '[3]m7' => [ qw(x x 1 3 2 2 1) ], '[3]m7b5' => [ qw(x 0 1 2 2 2 1) ], '[3]maj7' => [ qw(x x 1 3 3 3 1) ], '[3]mb5' => [ qw(x 0 1 2 4 2 1) ], '[3]sus' => [ qw(x x 1 3 4 4 1) ], '[4]' => [ qw(0 2 2 1 0 0 1) ], '[4]+' => [ qw(x x 2 1 1 0 1) ], '[4]7' => [ qw(0 2 2 1 3 0 1) ], '[4]dim' => [ qw(x x 2 3 2 3 1) ], '[4]m' => [ qw(0 2 2 0 0 0 1) ], '[4]m(maj7)' => [ qw(0 2 1 0 0 0 1) ], '[4]m7' => [ qw(0 2 2 0 3 0 1) ], '[4]m7b5' => [ qw(0 1 0 0 3 0 1) ], '[4]maj7' => [ qw(0 2 1 1 0 x 1) ], '[4]mb5' => [ qw(x x 1 2 4 2 2) ], '[4]sus' => [ qw(0 2 2 2 0 0 1) ], '[5]' => [ qw(1 3 3 2 1 1 1) ], '[5]+' => [ qw(x x 3 2 2 1 1) ], '[5]7' => [ qw(1 3 1 2 1 1 1) ], '[5]dim' => [ qw(x x 0 1 0 1 1) ], '[5]m' => [ qw(1 3 3 1 1 1 1) ], '[5]m(maj7)' => [ qw(0 3 3 1 1 1 1) ], '[5]m7' => [ qw(1 3 1 1 1 1 1) ], '[5]m7b5' => [ qw(1 2 1 1 4 1 1) ], '[5]maj7' => [ qw(x 3 3 2 1 0 1) ], '[5]mb5' => [ qw(x x 3 1 3 1 4) ], '[5]sus' => [ qw(x x 3 3 1 1 1) ], '[6]' => [ qw(2 4 4 3 2 2 1) ], '[6]+' => [ qw(x x 4 3 3 2 1) ], '[6]7' => [ qw(x x 4 3 2 0 1) ], '[6]dim' => [ qw(x x 1 2 1 2 1) ], '[6]m' => [ qw(2 4 4 2 2 2 1) ], '[6]m(maj7)' => [ qw(x 0 3 2 2 2 1) ], '[6]m7' => [ qw(x x 2 2 2 2 1) ], '[6]m7b5' => [ qw(0 0 4 2 1 0 1) ], '[6]maj7' => [ qw(x x 4 3 2 1 1) ], '[6]mb5' => [ qw(x 0 3 1 3 4 5) ], '[6]sus' => [ qw(x x 4 4 2 2 1) ], '[7]' => [ qw(3 2 0 0 0 3 1) ], '[7]+' => [ qw(x x 1 0 0 4 1) ], '[7]7' => [ qw(3 2 0 0 0 1 1) ], '[7]dim' => [ qw(x x 2 3 2 3 1) ], '[7]m' => [ qw(1 3 3 1 1 1 3) ], '[7]m(maj7)' => [ qw(2 1 0 0 3 3 1) ], '[7]m7' => [ qw(1 3 1 1 1 1 3) ], '[7]m7b5' => [ qw(x x 1 2 2 2 5) ], '[7]maj7' => [ qw(x x 4 3 2 1 2) ], '[7]mb5' => [ qw(x x 3 1 3 1 6) ], '[7]sus' => [ qw(x x 0 0 1 3 1) ], '[8]' => [ qw(1 3 3 2 1 1 4) ], '[8]+' => [ qw(x x 2 1 1 0 1) ], '[8]7' => [ qw(x x 1 1 1 2 1) ], '[8]dim' => [ qw(x x 0 1 0 1 1) ], '[8]m' => [ qw(1 3 3 1 1 1 4) ], '[8]m(maj7)' => [ qw(4 2 1 0 0 4 1) ], '[8]m7' => [ qw(x x 1 1 1 1 4) ], '[8]m7b5' => [ qw(x x 1 2 2 2 6) ], '[8]maj7' => [ qw(x x 1 1 1 3 1) ], '[8]mb5' => [ qw(4 2 0 1 0 4 1) ], '[8]sus' => [ qw(x x 1 1 2 4 1) ], '[9]' => [ qw(x 0 2 2 2 0 1) ], '[9]+' => [ qw(x 0 3 2 2 1 1) ], '[9]7' => [ qw(x 0 2 0 2 0 1) ], '[9]dim' => [ qw(x x 1 2 1 2 1) ], '[9]m' => [ qw(x 0 2 2 1 0 1) ], '[9]m(maj7)' => [ qw(0 0 2 1 1 0 1) ], '[9]m7' => [ qw(x 0 2 2 1 3 1) ], '[9]m7b5' => [ qw(x 0 3 3 2 1 3) ], '[9]maj7' => [ qw(x 0 2 1 2 0 1) ], '[9]mb5' => [ qw(x 0 4 2 1 2 4) ], '[9]sus' => [ qw(x x 2 2 3 0 1) ], '[10]' => [ qw(x 1 3 3 3 1 1) ], '[10]+' => [ qw(x x 0 3 3 2 1) ], '[10]7' => [ qw(x x 1 1 1 2 3) ], '[10]dim' => [ qw(x x 2 3 2 3 1) ], '[10]m' => [ qw(x 1 3 3 2 1 1) ], '[10]m(maj7)' => [ qw(1 1 3 2 2 1 1) ], '[10]m7' => [ qw(x 1 3 1 2 1 1) ], '[10]m7b5' => [ qw(x x 1 2 2 2 8) ], '[10]maj7' => [ qw(x 1 3 2 3 x 1) ], '[10]mb5' => [ qw(0 1 2 3 2 0 1) ], '[10]sus' => [ qw(x x 3 3 4 1 1) ], '[11]' => [ qw(x 2 4 4 4 2 1) ], '[11]+' => [ qw(x x 1 0 0 4 1) ], '[11]7' => [ qw(0 2 1 2 0 2 1) ], '[11]dim' => [ qw(x x 0 1 0 1 1) ], '[11]m' => [ qw(x 2 4 4 3 2 1) ], '[11]m(maj7)' => [ qw(2 2 4 3 3 2 1) ], '[11]m7' => [ qw(x 1 3 1 2 1 2) ], '[11]m7b5' => [ qw(1 0 0 2 0 1 1) ], '[11]maj7' => [ qw(x 2 4 3 4 x 1) ], '[11]mb5' => [ qw(1 2 0 4 0 1 1) ], '[11]sus' => [ qw(x x 3 3 4 1 2) ], ); sub modal { my ($r) = @_; my (%arg, $count, $res, $modelist, $keylist, @name, $prog); # fetch CGI-style arguments %arg = $r->args; %arg = $r->content unless %arg; $prog = $r->uri; # generate the form elements $count = 0; for (@modes) { $modelist .= qq(