#!/usr/bin/wish package require snack proc beep {freq} { global s if {[info exists s]} {$s stop} global newfreq global octave set freq [expr $freq*pow(2, $octave)] set newfreq "[format %.2f $freq]" set s [snack::sound -rate 22050] set f [snack::filter generator $freq 3000 0.0 sine -1] $s play -filter $f } # main frame frame .main pack .main -ipadx 2 -ipady 2 -padx 2 -pady 2 # two rows frame .main.up -border 2 frame .main.down -border 2 pack .main.up -ipadx 4 -ipady 4 -padx 2 -pady 2 -fill both pack .main.down -ipadx 2 -ipady 2 -padx 2 -pady 2 -fill both # note buttons set notes(a) [button .main.up.a -text A] set notes(ais) [button .main.up.ais -text A#] set notes(b) [button .main.up.b -text B] set notes(c) [button .main.up.c -text C] set notes(cis) [button .main.up.cis -text C#] set notes(d) [button .main.up.d -text D] set notes(dis) [button .main.up.dis -text D#] set notes(e) [button .main.up.e -text E] set notes(f) [button .main.up.f -text F] set notes(fis) [button .main.up.fis -text F#] set notes(g) [button .main.up.g -text G] set notes(gis) [button .main.up.gis -text G#] set mult 0 foreach note [lsort [array names notes]] { set freq [expr 440 * pow(1.05946, $mult)] $notes($note) configure -width 2 -command "beep $freq" -font "Lucida 9" pack $notes($note) -side left -padx 2 -ipadx 1 incr mult } # varios wiggets message .main.down.moct -text "Octave: " -width 200 -font "Lucida 9" spinbox .main.down.oct -width 2 -from -3 -to 3 -state readonly -textvariable octave -command "beep 0" -font "Lucida 9" message .main.down.freq -textvar newfreq -width 200 -font "Lucida 9" message .main.down.mfreq -text "Hz" -width 100 -font "Lucida 9" button .main.down.stop -text Stop -command "beep 0" -font "Lucida 9" button .main.down.quit -text Quit -command "destroy ." -font "Lucida 9" pack .main.down.moct -side left -padx 5 pack .main.down.oct -side left -padx 5 pack .main.down.freq -side left -padx 5 pack .main.down.mfreq -side left -padx 5 pack .main.down.stop -side left -padx 5 pack .main.down.quit -side left -padx 5 set newfreq 440.00 set octave 0 wm title . "Simple tuner"