#!/usr/local/bin/wish8.4
#
package require -exact sound 2.2

proc UpdateValues { x } {
    if { $::balance > 0 } {
	set ::lev_l  [ expr $::level - $::balance ]
	set ::lev_r  $::level
    } else {
	set ::lev_r  [ expr $::level + $::balance ]
	set ::lev_l  $::level
    }
}

frame .f -relief raised -borderwidth 2
pack .f -padx 3 -pady 3

label .lb -text "Balance"
label .ll -text "Volume"
    
if { $tcl_platform(platform)=="windows"} {
    snack::mixer volume Play ::lev_l  ::lev_r
} elseif { $tcl_platform(platform)=="unix"} {
    snack::mixer volume Vol ::lev_l  ::lev_r
} else {
    puts "Unsupported platform."
    exit
}

snack::mixer update 
if { $::lev_l > $::lev_r } {
    set ::level $::lev_l
} else {
    set ::level $::lev_r
}
set ::balance [ expr $::lev_r - $::lev_l ]
scale .sb -orient horizontal -variable ::balance -from -100 -to 100 -showvalue no -length 80 \
    -command UpdateValues
scale .sl -orient vertical -variable ::level -to 0 -from 100 -showvalue no \
    -command UpdateValues
    
pack .lb .sb .ll .sl -side top -in .f
button .b -text "Close" -command "destroy ."
pack .b  -side bottom -padx 3 -pady 3

focus .b

update idletasks

bind . <F10> "destroy ."