#! /bin/sh
# the next line restarts using wish \
exec wish "$0" "$@"

# this is free software
# you can use, modify and redistribute it under the terms and conditions of the Gnu General Public License (http://www.gnu.org/licenses/gpl.html)
# fmsfrontend comes without warranty of any kind

checkbutton .fade -text "fade"
scale  .freq -from 1 -to 1000 -label "Hz"
# -from = Startwert, -to = Endwert
scale  .time -from  10 -to 2000 -label "ms"
scale  .vol  -from  1  -to  100 -label "Vol."
.freq set 440
# Wert, auf den der Schieberegler von Anfang an gesetzt ist
.time set 1000
.vol  set 100
button .sine -text "Sine"       -command {sine $fade} -background #a0a000 -activebackground #ffff00
button .tri  -text "Triangular" -command {tri $fade}  -background #6060a0 -activebackground #6060ff
button .saw  -text "Saw"        -command {saw $fade}  -background #a00000 -activebackground #ff0000
button .exit -text "Exit"       -command really_quit  -background #efefef -activebackground #ffffff
grid .freq -row 0 -rowspan 4 -column 1
# -rowspan 4 = 4 Reihen hoch
grid .time -row 0 -rowspan 4 -column 2
grid .vol  -row 0 -rowspan 4 -column 3
grid .sine -row 0 -column 0
grid .saw  -row 1 -column 0
grid .tri  -row 2 -column 0
grid .exit -row 3 -column 0
grid .fade -row 4 -column 1

proc sine {fade} {
	set a [.freq get]
	set b [.time get]
	set c [.vol  get]
	switch -- $fade {
		0
			{exec fmplay sin -f $a -t [expr $b / 1000.0] -V $c}
		1
			{exec fmplay sin -f $a -t [expr $b / 1000.0] -V $c -H midi/attack}
	}
}

proc saw  {fade} {
	set a [.freq get]
	set b [.time get]
	set c [.vol  get]
	switch -- $fade {
		0
			{exec fmplay saw -f $a -t [expr $b / 1000.0] -V $c}
		1
			{exec fmplay saw -f $a -t [expr $b / 1000.0] -V $c -H midi/attack}
	}
}

proc tri  {fade} {
	set a [.freq get]
	set b [.time get]
	set c [.vol  get]
	switch -- $fade {
		0
			{exec fmplay tri -f $a -t [expr $b / 1000.0] -V $c}
		1
			{exec fmplay tri -f $a -t [expr $b / 1000.0] -V $c -H midi/attack}
	}
}

proc really_quit {} {
	bell
	set answer [tk_messageBox -message "Really quit?" -type yesno -icon question]
	switch -- $answer {
		yes exit
	}
}

