Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

frankus's scratchpad

by frankus (Priest)
on Jun 03, 2004 at 20:01 UTC ( #360443=scratchpad: print w/replies, xml ) Need Help??

A guitar scale thingy
#!/usr/local/bin/perl -w use strict; use CGI; my @notes = ('a','a#','b','c','c#','d','d#','e','f','f#','g','g#'); my %scales = ( major => '0,2,4,5,7,9,11', minor => '0,2,3,5,7,9,11',); my %f = ( key=>'a', scale=>'major', 1=>'e', 2=>'a', 3=>'d', 4=>'g', 5= +>'b', 6=>'e' ); my $cgi = CGI->new(); $f{$_} = $cgi->param($_) for $cgi->param; sub findstr{my $i=0;++$i while $notes[$i] ne $f{$_[0]};$i} sub selbox($$@) { qq:<select name="$_[0]">:.join('',map{my $a=/^$_[1]$ +/?'selected':'';"<option $a>$_</option>"}@_[2..$#_]).'</select>'} sub row{'<tr>'.join('',map{qq{<td align="center" valign="center">$_</t +d>}}@_).'</tr>'} my $offset = findstr('key'); %scales = map{ $_ =>{ map{my $a=$notes[($_+$offset)%12];$a=>$_}split/, +/,$scales{$_} } } keys %scales; print $cgi->header(); print '<html><head><title>Guitar Fretboard</title></head><body><table +align="center" bgcolor="#FFFFFF" cellspacing="0" cellpadding="0" bord +er="1">'; print '<form name="foo" method="post"><tr><td colspan="1">' . selbox(' +key',$f{'key'},@notes) . '</td><td colspan="5">'; print selbox('scale',$f{'scale'},keys %scales) . '</td></tr><tr><td co +lspan="6"><input type="submit" value="update"/>&nbsp;Notes:<input val +ue="'; print join(',', sort keys %{ $scales{ $f{scale} } } ) . '"/></td></tr> +' . row( reverse map{ selbox( $_, $f{$_}, @notes )}1..6 ); my @strings = map{ findstr($_) }reverse(1..6); for ( 1 ..24 ) { print row( map{ $_=@notes[($strings[$_]++)%12]; my $c = $_; if ( exists( $scales{$f{scale}}->{$_} ) ) { $_ = ( $_ eq $f{key} ) ? 'root' : 'not +e'; } else { $_ = 'blank'; } qq{<img src="$_. +gif" alt="$c">}; }(0..$#strings) ); print '<tr><td colspan="6" bgcolor="black"><img src="http://ww" height="2"></td></tr>'; } print '</form></table></body></html>';

The plan is to link it to a mysql database that holds lots of loverly scales like the Gai-Gaku-Ritu Sen Poi Scale and the like.

Log In?

What's my password?
Create A New User
[nysus]: What happened to the submit button? All I have is a preview button.
[erix]: perlmonks has become read-only ?
[marto]: erix unlikely, we've had posts within the last few minutes ;)
[ambrus]: nysus: make sure you enter at least two lines for the title and then preview, and read warnings the preview form prints

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (16)
As of 2017-12-15 11:29 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (431 votes). Check out past polls.