Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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
[Corion]: marto: Currently all well - work is even OK currently ;) I should start translating my WWW::Mechanize:: Chrome talk to English and recheck that my demos all work, but I have two weeks for that still :)
[Corion]: So, most things are looking good :-D
[Corion]: I should write some more code for my Jekyll clone, but I don't feel like it, so maybe I should just let that linger instead ;)
[karlgoethebier]: "...mein enemy..."
[marto]: it has finally stopped raining!
[Corion]: marto: Heh - we've got the rain here, now. But it's only intermittently, not permanent. But funny that you should complain about rain ;)
[Discipulus]: rain? i dont remember it..
[marto]: and good news all round, Flash will die come 2020!

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2017-07-26 10:50 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (390 votes). Check out past polls.