📄 xsox
字号:
# play or convert a sound fileproc playorconvert {function} { global inputfile volumeenable volume inputfiletypeenable inputfiletype global inputsamplerateenable inputsamplerate inputsampletypeenable global inputsampletype inputsamplesizeenable global inputsamplesize inputchannelsenable inputchannels inputswapbytes global effect echodelay echovolume vibrospeed vibrodepth centerfreq global filterwidth noise outputfile global outputfile outputfiletypeenable outputfiletype global outputsamplerateenable outputsamplerate outputsampletypeenable global outputsampletype outputsamplesizeenable outputsamplesize global outputchannelsenable outputchannels outputswapbytes # make sure play/sox command exists if {![auto_execok $function]} { tk_dialog .oops "Error" "No `$function' command was found. Make sure you have the program installed and in your search path." error 0 Dismiss return } # make sure input file field is filled in if {$inputfile == ""} { tk_dialog .oops "Error" "No input file was specified. You need to enter an input filename using the Input Parameters menu." error 0 Dismiss return} # make sure file exists and is readable if {![file readable $inputfile]} { tk_dialog .oops "Error" "The input file `$inputfile' does not exist or is not readable. Enter a valid filename using the Input Parameters menu." error 0 Dismiss return } if {$function == "sox"} { # make sure output file field is filled in if {$outputfile == ""} { tk_dialog .oops "Error" "No output file was specified. You need to enter an output filename using the Output Parameters menu." error 0 Dismiss return } # make sure output directory exists and is writable set dir [file dirname $outputfile] if {![file writable $dir]} { tk_dialog .oops "Error" "The output directory `$dir' does not exist or is not writable. Enter a valid filename using the Output Parameters menu." error 0 Dismiss return } # confirm if file already exists if {[file exists $outputfile]} { set ans [tk_dialog .oops "Warning" "The output file `$outputfile' already exists. Continuing will overwrite the file." warning 0 Cancel Continue] if {$ans == 0} return } } # start building up the command line set command "" lappend command $function # get global options set globaloptions "" if {$volumeenable} { lappend command "-v" $volume } # get input options if {$inputfiletypeenable} {lappend command -t $inputfiletype} if {$inputsamplerateenable} {lappend command -r $inputsamplerate} if {$inputsampletypeenable} {lappend command $inputsampletype} if {$inputsamplesizeenable} {lappend command $inputsamplesize} if {$inputchannelsenable} {lappend command -c $inputchannels} if {$inputswapbytes} {lappend command -x} lappend command $inputfile # get output options if {$function == "sox"} { if {$outputfiletypeenable} {lappend command -t $outputfiletype} if {$outputsamplerateenable} {lappend command -r $outputsamplerate} if {$outputsampletypeenable} {lappend command $outputsampletype} if {$outputsamplesizeenable} {lappend command $outputsamplesize} if {$outputchannelsenable} {lappend command -c $outputchannels} if {$outputswapbytes} {lappend command -x} lappend command $outputfile } # get effects lappend command $effect switch $effect { echo {lappend command $echodelay $echovolume} vibro {lappend command $vibrospeed $vibrodepth} lowp - highp {lappend command $centerfreq} band { if $noise {lappend command -n} lappend command $centerfreq $filterwidth } } # run command set status [catch "exec $command" output] # handle errors if {$status != 0} { tk_dialog .oops Error $output error 0 Dismiss return } # handle warnings or other informational output if {$output != ""} { tk_dialog .oops "Output from Sox" $output info 0 Dismiss return }}# Procedure to handle dependencies between widgets. First argument is# a button variable, second is a list of widgets that are# enabled/disabled by it.proc widget_toggle {enable widgetlist} { if {$enable} { set state normal } else { set state disabled } foreach widget $widgetlist { $widget configure -state $state }}# routine to handle special dependencies in effects menuproc effects_toggle {state} { .effects.delay.entry1 configure -state disabled .effects.delay.entry2 configure -state disabled .effects.vibro.entry1 configure -state disabled .effects.vibro.entry2 configure -state disabled .effects.filter.entry1 configure -state disabled .effects.filter.entry2 configure -state disabled .effects.filter.noise configure -state disabled switch $state { echo { .effects.delay.entry1 configure -state normal .effects.delay.entry2 configure -state normal } vibro { .effects.vibro.entry1 configure -state normal .effects.vibro.entry2 configure -state normal } lowp - highp { .effects.filter.entry1 configure -state normal } band { .effects.filter.entry1 configure -state normal .effects.filter.entry2 configure -state normal .effects.filter.noise configure -state normal } }}# about popupproc AboutPopup {} { catch {destroy .aboutBox} toplevel .aboutBox wm title .aboutBox "About XSox" message .aboutBox.text -text "XSox Sound File ConversionUtilityversion 1.0Written by Jeff Tranter.Sox program written by LanceNorskog with enhancements forLinux by Greg Lee." button .aboutBox.ok -text Dismiss -command {destroy .aboutBox} pack .aboutBox.text pack .aboutBox.ok -fill x -padx 2 -pady 2}# help popupsproc HelpOnXsox {} { catch {destroy .helpOnXsox} toplevel .helpOnXsox wm title .helpOnXsox "Help On XSox" message .helpOnXsox.text -text "On XSox:XSox is a graphical interface to the sox sound fileconversion utility. You can use xsox to convert betweenall common sound file formats, change sound file parameters,and add special effects.XSox operates in two modes: convert and play.In convert mode an input sound file is analyzed, modified,and written out to an output file in a different format.In play mode a sound file is played through the audio device." button .helpOnXsox.ok -text Dismiss -command {destroy .helpOnXsox} pack .helpOnXsox.text pack .helpOnXsox.ok -fill x -padx 2 -pady 2}proc HelpOnBasics {} { catch {destroy .helpOnBasics} toplevel .helpOnBasics wm title .helpOnBasics "Help On Basics" message .helpOnBasics.text -text "To Convert A Sound File:1. Bring up Input Parameters menu, fill in input file name and any other desired parameters.2. Bring up Output Parameters menu, fill in output file name and any other desired parameters.3. Bring up global effects menu to set volume scaling (optional).4. Enable any effects using the Effects menu (optional)5. Hit the Convert button.To Play A Sound File:1. Bring up Input Parameters menu, fill in input file name and any other desired parameters.2. Bring up global effects menu to set volume scaling (optional).3. Enable any effects using the Effects menu (optional)4. Hit the Play button." button .helpOnBasics.ok -text Dismiss -command {destroy .helpOnBasics} pack .helpOnBasics.text pack .helpOnBasics.ok -fill x -padx 2 -pady 2}proc HelpOnInputParameters {} { catch {destroy .helpOnInputParameters} toplevel .helpOnInputParameters wm title .helpOnInputParameters "Help On Input Parameters" message .helpOnInputParameters.text -text "Input Parameters Menu:The input parameters menu is used to specify informationabout the input file.The input filename field is mandatory, all others are optional.To specify values for other parameters, enable the fieldusing the appropriate enable button.Some combinations of parameters are illegal. In this casethe sox program will produce a warning or error messagetelling you what is wrong.Feel free to experiment!" button .helpOnInputParameters.ok -text Dismiss \ -command {destroy .helpOnInputParameters} pack .helpOnInputParameters.text pack .helpOnInputParameters.ok -fill x -padx 2 -pady 2}proc HelpOnOutputParameters {} { catch {destroy .helpOnOutputParameters} toplevel .helpOnOutputParameters wm title .helpOnOutputParameters "Help On Output Parameters" message .helpOnOutputParameters.text -text "Output Parameters Menu:The Output parameters menu is used to specify informationabout the output file when performing a file conversion. Itis not used when playing a sound file.The output filename field is mandatory, all others are optional.To specify values for other parameters, enable the fieldusing the appropriate enable button.Some combinations of parameters are illegal. In this casethe sox program will produce a warning or error messagetelling you what is wrong.Feel free to experiment!" button .helpOnOutputParameters.ok -text Dismiss \ -command {destroy .helpOnOutputParameters} pack .helpOnOutputParameters.text pack .helpOnOutputParameters.ok -fill x -padx 2 -pady 2}proc HelpOnGlobalParameters {} { catch {destroy .helpOnGlobalParameters} toplevel .helpOnGlobalParameters wm title .helpOnGlobalParameters "Help On Global Parameters" message .helpOnGlobalParameters.text -text "Global Parameters Menu:The global parameters menu is used to specifyadditional file conversion parameters.Currently only one optional parameter is supported:volume scaling. Use this to scale the output (orplayed) file. Any floating point value can be used.Values less than 1.0 will reduce the overall volume;values greater than one will increase it. Using thestat effect you can determine what scaling value touse to achieve maximum volume without distortion." button .helpOnGlobalParameters.ok -text Dismiss \ -command {destroy .helpOnGlobalParameters} pack .helpOnGlobalParameters.text pack .helpOnGlobalParameters.ok -fill x -padx 2 -pady 2}proc HelpOnEffects {} { catch {destroy .helpOnEffects} toplevel .helpOnEffects wm title .helpOnEffects "Help On Effects" message .helpOnEffects.text -text "Effects Menu:The effects menu is used to produce special audioeffects.You can choose from one of 9 different audio effects.The default effect, copy, simply copies the input fileto the output.The echo, vibro, and filtering effects require additionalparameters to be given. The appropriate menu fields areenabled. All parameters take floating point values. Theband-pass filter also offers an optional noise filterselection." button .helpOnEffects.ok -text Dismiss \ -command {destroy .helpOnEffects} pack .helpOnEffects.text pack .helpOnEffects.ok -fill x -padx 2 -pady 2}# routine to validate numeric text entry fieldproc validate_entry {field} { set value [$field get] set status [catch {format "%f" $value} output] if {$status != 0} { tk_dialog .oops Error "Entry `$value' is not a number. Please re-enter." \ error 0 Dismiss }}### main program ###mainwindowmenubar menubargraphic logoinputoutput inputinputoutput outputglobals globalseffects effects
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -