#################################
# The Option Module
#
# Part of the SharpeSound Editor
# by Paul D. Sharpe
# A 3rd Year Project at the University of Leeds;
# Department of Electronic and Electrical Engineering.
# Date: 17/2/95
#
# Revision:2
# Date: 7/3/95  


####################################################################
# LoadSettings
# This procedure loads in the defaults from the configuration
# file. 
proc LoadSettings { } {
   global ConfigInfo
   global FILE 

   set ColourFile "$FILE(CFG)"
	
   if {![file exists $ColourFile] } {
	#Create a Config file if non-existent
	SaveSettings		
   }

   # Open Configuration file.
   set fd [open $ColourFile r]

   # Retrieve configuration Data.
   while  {[gets $fd line]>=0} {
	# The lines containing data only have 3 list items.
	if {[llength $line]==3} {
		# Sort out in which global to store data
		GetArrayName [lindex $line 0] VarName subscript
		eval global $VarName

		# Store data in global
		set $VarName\($subscript) [join [lindex $line 1]]

		# Store the additional info
		set ConfigInfo([join [lindex $line 0]]) [join [lindex $line 2]]
	    }
	}
   # Close the configuration file.
   close $fd
}

####################################################################
# GetArrayName
# This procedure sorts out the array name for configuration data,
# based on the first letter in the array subscript given in "cfg". 
# In the case where no value is given in cfg, but an array name is given
# in "var" then the first letter that should be used as the first 
# letter in the subscripts of that array is returned in the varible
# given in "sub".
# The parameters are as follows;
# cfg : this contains the array subscript or an empty string.
# var : This is the name of a variable to contain the returned variable
#	name string. The contents of the given variable are ignored unless
#	cfg is an empty string.
# sub : The varaible name of a variable to contain the returned letter for
#	subscripts.
proc GetArrayName { cfg var sub } {
   upvar $sub subs
   upvar $var VarName
   if {$cfg!=""} {
	set what [string range $cfg 0 0]
	switch $what {
			f {set VarName FLAG; set i 1	}
			m {set VarName MIXER; set i 1	}
			default { set VarName ConfigSet; set i 0 }			
	}
	set subs [string range $cfg $i end]
   } else {
		
	switch $VarName {
		FLAG { set subs f}
		MIXER { set subs m}
		default { set subs ""}
	}		
   }	
}

###################################################################
# SetInitially 	
# This procedure that sets the configuration settings.
# Used in the case that a configuaration file is not present.
proc SetInitially { } {
   global ConfigSet PACK
   global ConfigInfo

   # Make a list of the array subscripts to be contained in the 
   # configuration file. The first letter determines the array
   # in which it will be stored. See GetArrayName.
   set var 	{cBG1  cBG2 cBG3 \
		cFG1 cFG2 cFG3	\
		cABG cAFG cDFG \
	 	FNT_S FNT_L\
		REL BDW mnoshow}


   # Set the values corresponding to the above 'var' list.
   set val {grey grey LightGrey \
		blue black blue\
		LightGrey black LightGrey \
		-Adobe-Helvetica-Medium-R-Normal--*-100-*\
		-Adobe-Helvetica-Medium-R-Normal--*-120-*\
		ridge 4 {-1 -1 -1 -1 3 4 5 -1 -1 8 9 10 11 12} }


   # Set the textual description corresponding to the 'var' list.
   set label { {Window Background Colour} \
		 {Button Colour}\
		 {Editor Background Colour} \
		 {Label Text Colour}\
		 {Button Text Colour} \
		 {Editor Foreground Colour}\
		 {Active Button Colour}\
		 {Active Button Text Colour}\
		 {Disabled Button Text Colour}\
		 {Button Font}\
		 {Label Font}\
		 {Border Type} \
		 {Border Width of Sections}\
		 { Mixer Sliders Not to be shown } }
		   
   # Add Viewing Flags
   # Packlist contains the items that maybe shown
   foreach item $PACK(list) {
		lappend var fVw_$item
		lappend val 1
		lappend label "Flag for Viewing $item"
   }
	
   # Store the above values into the corresponding globals.	  
   set n 0
   foreach i $var {
	# Get the array name.
	GetArrayName $i VarName subscript

	# Make the array have global access.
	eval global $VarName
	
	# Store the value into the global.
	set $VarName\($subscript) [lindex $val $n]

	# Store the textual description.
	set ConfigInfo($i) [lindex $label $n]
	incr n
   }
}


###################################################################
# SaveSettings
# This procedure saves the current configuration data into a
# configuration file. 
# The parameter "option" specifies what group of configuraion data is
# to be stored. By default it is "all", which means all configuration 
# data is stored as it is currently in memory. Otherwise, if 'option'
# contains the single character which distiguishes the groups of data, then
# the relevant group of data only is stored as it is currently in memory.
proc SaveSettings { {option all} } {
   global ConfigSet
   global ConfigInfo
   global FILE	

   set ColourFile "$FILE(CFG)"
         
   # Check for configuration file, if non-existent
   # get some initial values, to make one.
   if {![file exists $ColourFile]} {
	SetInitially
   }
	
   if {$option=="all"} {

	# Open configuration file for writing.	
       	set fd [open $ColourFile w]
	# Save introductory lines (must not have three words in line).
	puts $fd "ConfigSet File for the SharpeSound Studio"
	puts $fd "by Paul D. Sharpe; 3rd Year project"
	puts $fd "University of Leeds, 1994-1995"
	puts $fd "----------------------------------------------"
	
	# Store the configuration data.
	foreach var [array names ConfigInfo] {

		# Get the data from the corresponding global array.
		GetArrayName $var VarName subscript
		eval global $VarName

		# Write data to file.
		eval set data $$VarName\($subscript)
		puts $fd [format \
		 "{$var}\t{$data}\t{$ConfigInfo($var)}"]
	}

	# Close the configuration file.
	close $fd
   } else {
	
	# Store the current contents of the configuarion file.

	# Open configuration file for reading.
	set fd [open $ColourFile r]
		
	# Loop through the file.
	while {![eof $fd]} {
	  # Get the current line.
	  gets $fd line

	  # Store the first item in the line.
	  set var [lindex $line 0]
	
	  # Only do the following if it is a data line.	
	  if {[llength $line] ==3} {
	  	#Get the global name 
	  	GetArrayName $var VarName subscript
	  	eval global $VarName
		# Store the contents of that array item.
	  	eval set item $$VarName\($subscript)
	  }
	  # Get first letter
	  set char [string range $var 0 0]
	  if {$char==$option} {
		# Create new data line.
		lappend data [format \
		 "{$var}\t{$item}\t{$ConfigInfo($var)}"]
	  } else {
		# Keep old data line.
		lappend data $line
	  }
	}
	close $fd

	# Store the configuration data.		
	set fd [open $ColourFile w]
	foreach item $data {
		puts $fd $item
	}
	close $fd
   }
}

###################################################################
# ListBoxFill
# This Procedure fills a listbox with a list.
# options are:  Append, to add items to the list; 
#		Create, to delete and then append to the list.
#		Delete, to delete all items in the list.
# list : contains the list items to be added to the listbox.
# listBoxPath : The path name of the listbox widget to be be appended.
proc ListBoxFill { listboxPath list option } {

   if {[winfo exists $listboxPath]} {
  	set option [string tolower [string index $option 0]]
  	if {$option =="c" || $option =="d" } {
	  $listboxPath delete 0 end
  	}
	if {$option =="c" || $option =="a" } {
	  foreach item $list {
			$listboxPath insert end $item
		}
	}
   } else {
	puts $stderr "Invalid ListBox Path" 
   }
}

###################################################################
# Info2Set
# This Procedure takes a info label of ConfigInfo and returns the 
# corresponding value of ConfigSet.
# If a value is given that value is stored inthe ConfigSet array
proc Info2Set { label {Value ""} } {
   global ConfigSet
   global ConfigInfo
	
   set list [array names ConfigSet]
   set i [expr [array size ConfigSet]-1]
   while { $i>=0 && $ConfigInfo([lindex $list $i])!=$label} {
	incr i -1
   }
   if {$i>=0 && $Value =="" } {
	return $ConfigSet([lindex $list $i])	
   }\
   else {  
	if {$Value !=""} {
		set ConfigSet([lindex $list $i]) $Value
	}
  	return ""
   }
}


########################################################
# Setter 
# Creates a toplevel box for selection.
# list1 is a list of options with their current values
#	 (eg. {{background black}...})
# list 2 is a list of possible values for the contents of list 1
# option : currently only colour option is available. It shows a 
#	   preview of the colour in  a box. If list2 is not colours then
#	   the option may be ommited.
#
# Returns: A list containing a. a flag (ok,mkdefault,cancel) and
#		b. the a list which is list1 with new values(if not cancel)
# in global OPT_LIST
 
proc Setter { Title list1 list2 {option  ""} } {
  global ConfigSet
  global ConfigInfo
  global FILE(CFG)
  



  #------------------------------
  #LOCAL PROCEDURES START
  




  # MatchList
  # This procedure searches a listbox for an item and returns the index.
  proc MatchList { listboxPath label } {
	global ConfigSet
	global ConfigInfo
	if {[winfo exists $listboxPath]} {
	  if {[winfo class $listboxPath] == "Listbox" } {
		set i [expr [$listboxPath size ]-1]
		while { $i>=0 && [$listboxPath get $i]!=$label} {
			incr i -1
		}
		if {$i>=0} {
			return $i
		}\
		else { 
			return 0
		}	
	  }
	}	 
  }


 

  # Preview
  # This procedure sets the colour in .main to be that stored in the
  # defaults. Callback to selecting an option, from .selec.list

  proc Preview { option {index 0}  } {	
	global CURR_SET CURR_INDEX OPT_LIST
 	set CCol [lindex [lindex $OPT_LIST $CURR_INDEX] 1]
	set CURR_SET [.setter.setting.selec.sl.list get $index]
 	if {$option=="colour"} {.setter.setting.main.prev config  -bg $CCol}
	set Index2 [ MatchList .setter.setting.main.list $CCol ]

	.setter.setting.main.list yview $Index2
   }

   # CreateWidgets
   # This procedure creates the widgets for the toplevel.
   # option is 'init' to set up widgets, or reset to reconfigure the widgets.  
   proc CreateWidgets {{option init}} {  
	global ConfigSet
	global ConfigInfo
	upvar 1 option opt
	upvar 1 list1 list1
	upvar 1 list2 list2

   	switch $option {
    	init {
		global CURR_INDEX
		set CURR_INDEX 0

		# The Overall Frame
		frame .setter.setting -bg $ConfigSet(cBG1)

	  	# ------------------------------
  		# 1. .main  
	
  		# The frame.
  		frame .setter.setting.main -bg $ConfigSet(cBG1)

	  	# The Instruction label.
  		label .setter.setting.main.label \
				-bg $ConfigSet(cBG1) \
				-fg $ConfigSet(cFG1) \
				-font $ConfigSet(FNT_S) \
				-text "Select a colour" \
				-anchor w 
 
 		#  The preview button
  		button .setter.setting.main.prev -relief groove \
				-bg $ConfigSet(cBG1)\
				-fg $ConfigSet(cFG1) \
				-background $ConfigSet(cBG1) \
				-foreground $ConfigSet(cFG1)\
				-activeforeground $ConfigSet(cFG1)\
				-activebackground $ConfigSet(cFG1) \
				-font $ConfigSet(FNT_L) \
				-text "" \
				-command { puts preview }
  		# The Listbox.
  		listbox .setter.setting.main.list -relief sunken\
				-bg $ConfigSet(cBG1) \
				-fg $ConfigSet(cFG1) \
				-selectbackground $ConfigSet(cABG) \
				-selectforeground $ConfigSet(cAFG)\
				-font $ConfigSet(FNT_L) \
				-yscrollcommand \
					".setter.setting.main.scroll set"\
				-selectmode single

  		# Fill the list box with the settings
		ListBoxFill .setter.setting.main.list $list2 create
 

	  	# The ScrollBar.
  		scrollbar .setter.setting.main.scroll \
				-bg $ConfigSet(cBG1)\
				-activebackground $ConfigSet(cABG)\
				-command ".setter.setting.main.list yview"\
				-relief sunken

	 	# Pack the .main widgets.
  		pack .setter.setting.main.label .setter.setting.main.prev\
			 -fill x -expand 1
	  	pack .setter.setting.main.list \
			 -fill both -expand 1 -side left
  		pack  .setter.setting.main.scroll\
			 -fill both -expand 1 -side right



	 	# ------------------------------
  		# 2. .selec  

	  	# The frame.
  		frame .setter.setting.selec -bg $ConfigSet(cBG1)

	  	# The Instruction label.
  		label .setter.setting.selec.label -bg $ConfigSet(cBG1)\
				-fg $ConfigSet(cFG1) \
				-font $ConfigSet(FNT_S) \
				-text "Select an option" \
				-anchor w

	  	# The label showing the selection 
  		label  .setter.setting.selec.set\
				-bg $ConfigSet(cABG)\
				-fg $ConfigSet(cAFG) \
				-font $ConfigSet(FNT_L) \
				-anchor w \
				-relief sunken \
				-textvariable CURR_SET

		#--------------------------
		# The frame to contain the listbox and scrollbar
		frame .setter.setting.selec.sl -bg $ConfigSet(cBG1)

	 	# The Listbox.
 		listbox .setter.setting.selec.sl.list \
				-relief sunken\
				-bg $ConfigSet(cBG1) \
				-fg $ConfigSet(cFG1) \
				-selectbackground $ConfigSet(cABG) \
				-selectforeground $ConfigSet(cAFG)\
				-font $ConfigSet(FNT_L) \
				-yscrollcommand\
				   ".setter.setting.selec.sl.scroll set"\
				-width 25\
				-height 5\
				-selectmode single

  		# Fill the list box with the options
		foreach item $list1 {
			lappend newlist [lindex $item 0]
		}
	  	ListBoxFill .setter.setting.selec.sl.list $newlist create

	  	# The ScrollBar.
  		scrollbar .setter.setting.selec.sl.scroll \
				-bg $ConfigSet(cBG1)\
				-activebackground $ConfigSet(cABG)\
				-command ".setter.setting.selec.sl.list yview"\
				-relief sunken

		# Pack the Scroll/List widgets.
		pack .setter.setting.selec.sl.list  \
			-fill both -expand 1 -side left
  	   	pack  .setter.setting.selec.sl.scroll\
			 -fill both -expand 1 -side right

 		# ---------------------------
  		# Frame to contain the buttons

		# The Frame.
  		frame .setter.setting.selec.but -bg $ConfigSet(cBG1)

	  	# The OK Button
  		button .setter.setting.selec.but.ok \
			-bg $ConfigSet(cBG1) -fg $ConfigSet(cFG1) \
			-activeforeground $ConfigSet(cAFG)\
			-activebackground $ConfigSet(cABG)\
			-disabledforeground $ConfigSet(cDFG) \
			-command {
				global OPT_LIST CURR_INDEX CURR_SET
			        set OPT_LIST [list ok $OPT_LIST]
				unset  CURR_INDEX CURR_SET
				destroy .setter
				}\
			-text Apply

		# The Cancel Button.
  		button .setter.setting.selec.but.cancel -text Cancel \
			-bg $ConfigSet(cBG1) -fg $ConfigSet(cFG1) \
			-activeforeground $ConfigSet(cAFG)\
			-activebackground $ConfigSet(cABG)\
			-disabledforeground $ConfigSet(cDFG) \
			-command {
				global OPT_LIST CURR_INDEX CURR_SET
			        set OPT_LIST cancel
				unset  CURR_INDEX CURR_SET
				destroy .setter
				}

	 	# The Make Default button
  		button .setter.setting.selec.but.default \
			-bg $ConfigSet(cBG1) -fg $ConfigSet(cFG1) \
			-activeforeground $ConfigSet(cAFG)\
			-activebackground $ConfigSet(cABG)\
			-disabledforeground $ConfigSet(cDFG) \
			-command {
				global OPT_LIST CURR_INDEX CURR_SET
			        set OPT_LIST [list mkdefault $OPT_LIST]
				unset  CURR_INDEX CURR_SET
				destroy .setter	
			}\
			-text "Make Default"

		#pack the Buttons
  		foreach button [winfo children .setter.setting.selec.but] {
			pack $button -fill x -padx 30 -pady 3 -expand 1
  		}	

	  	# Pack the .selec widgets.
  		pack  .setter.setting.selec.label .setter.setting.selec.set\
			.setter.setting.selec.sl .setter.setting.selec.but \
			-fill x -expand 1

		#Pack the frames containing widgets
  		pack .setter.setting.main .setter.setting.selec \
			 -side right -anchor n



		# Select the 1st item in list2, a get a preview 
	  	Preview $opt 

		# ----------------------------
		# BINDINGS
		# Bind .main.list to give a preview of color/font.
		bind .setter.setting.main.list <Any-Button-1> { 
			global CURR_INDEX OPT_LIST opt
			set index [.setter.setting.main.list nearest %y]
			set col [.setter.setting.main.list get $index ]
			if {$opt=="colour"} {
			   .setter.setting.main.prev config -background $col
			}
			set OPT_LIST  [lreplace $OPT_LIST \
	  		 $CURR_INDEX $CURR_INDEX\
			 [lreplace [lindex $OPT_LIST $CURR_INDEX] 1 1 "$col"]]
		}
	


		# Bind selection list to display the current option,
		# and preview the current setting.
		bind .setter.setting.selec.sl.list <Any-Button-1> { 
			global CURR_SET CURR_INDEX
			set index [.setter.setting.selec.sl.list nearest %y]
			set CURR_INDEX $index
			set CURR_SET [.setter.setting.selec.sl.list get $index ]
		
			Preview $opt $index
		}

		#Pack the overall frame
		pack .setter.setting -expand 1 -fill both
  	}
  reset {
	destroy .setter.setting
	CreateWidgets init
  }
 }
}

   # LOCAL PROCEDURES END
   #------------------------------


   # Create toplevel .setter .
   toplevel .setter -bg $ConfigSet(cBG1)
   wm title .setter $Title
   # Link to master toplevel as a servant.
   wm transient .setter .
   # Stop entry from the main window. (grab).
   catch { grab .setter }

  
   global OPT_LIST
   set OPT_LIST $list1
   global opt
   set opt $option
 
   # Create and Pack widgets and enter event loop
   CreateWidgets
}


###################################################################
# ColourList
# This procedure returns a list with the X preset color names.
proc ColourList {} {

	# Open the file containing the presets.
	set fd [open /usr/lib/X11/rgb.txt]

	# Store the list.
	while {[gets $fd line]>=0} {
		lappend colours [lrange $line 3 end]
	}
	close $fd

 	#Sort and enter into listbox.
	set colours [lsort $colours]
	return $colours
}

###################################################################
# Colours
# This procedure is the callback to the Options-Colours menu item.
# It produces a dialog box allowing the setting of the various colour
# options.
proc Colours {} {
   global OPT_LIST ConfigSet ConfigInfo

   # Create a list containig the textual description and values for all
   # the colour options.
   foreach name [array names ConfigSet] {
	  if {[string range $name 0 0]=="c"} {
	    lappend collist [list $ConfigInfo($name) $ConfigSet($name)]
	  }
   }
   # Sort the list
   set collist [lsort $collist]

   # Create the dialog box.
   Setter "Colour Settings" $collist [ColourList] colour

   # Wait for the dialog box to be destroyed.
   tkwait window .setter

   # Store the return value.
   set test $OPT_LIST
   unset OPT_LIST 

   # Store the new settings according to the button pressed.
   set list1 [lindex $test 1]
   switch [lindex $test 0] {
		mkdefault {
			foreach item $list1 {
			  Info2Set [lindex $item 0] [lindex $item 1]
			  }
			SaveSettings c
			Resetter
		}
		ok 	{
			foreach item $list1 {
			  Info2Set [lindex $item 0] [lindex $item 1]
			 }
			Resetter
		}
		cancel {}
   }
}


###################################################################
# Resetter
# This procedure causes all the sections of Sound Studio to be 
# reconfigured with the current configuration options.
proc Resetter {} {
   global ConfigSet DialogCfg

   # Fix the window size.
   HoldWindow .

   # Reinitialise all sections.
   MenuBar init
   PlayPanel init
   PlotBox init
   EffectBar init
   InfoBar init
   Mixer init
   # Change the editing plot foreground colours.
   catch {FillPlot}

   . config -bg $ConfigSet(cBG1)

   # Set a global to contain the color list
   # required by dialog and filebrowser procedures.
   set DialogCfg [list $ConfigSet(cBG1) $ConfigSet(cFG1)\
		$ConfigSet(cABG) $ConfigSet(cAFG)\
		$ConfigSet(FNT_L)]

}

###################################################################
# Settings
# This procedure is the callback to the Options-Set Parameters menu item,
# or a button-3 press on the recording button.
# It creates a dialog box to set the sample parameters. If there is no
# sample loaded then the limits are set by the contraints of the card, 
# (for recording). Otherwise, the limits are those of sox, thus allowing
# conversions.
proc Settings {} {

   global SAMPLE CARD ConfigSet FLAG
   
   if {!$FLAG(Loaded) } {
	
   	# Get Limits of sampling rates based on how many channels are set
   	set min [lindex $CARD(Minrates) [expr $SAMPLE(chnl)-1]]
   	set max [lindex $CARD(Maxrates) [expr $SAMPLE(chnl)-1]]
   	set channels $CARD(Chnnls)
   	set bits $CARD(Bits)
   } else {

	# Limits of sox
	set max 50000
	set min 100
	set channels "1 2 4"
	set bits "8 16 32"
   }

   # Create the dialog box.
   toplevel .set -bg $ConfigSet(cBG1)
   wm title .set "Card Settings"
   # Set window as a pop-up child of the root window.
   wm transient .set .
   # Stop entry from the main window. (grab).
   catch { grab .set }

   # Create the overall frame.	
   frame .set.main -bg $ConfigSet(cBG1)
   label .set.main.label \
			-bg $ConfigSet(cBG1)\
			-fg $ConfigSet(cFG1)\
			-text "Recording/PlayBack Parameters"\
			-font $ConfigSet(FNT_S) \
 			-anchor w
   
   frame .set.main.chnl -bg $ConfigSet(cBG1)\
			  -relief groove\
			  -bd 2
   label .set.main.chnl.label \
			-bg $ConfigSet(cBG1)\
			-fg $ConfigSet(cFG1)\
			-text "Channel Settings"\
			-font $ConfigSet(FNT_S) \
 			-anchor w
   pack .set.main.chnl.label -fill x -expand 1

   # General setup for Radio Buttons -channels
   set list { "" "Mono" "Stereo" "" "Quad" } 
   set ButtWidth 10
   foreach ch $channels {
	set item [lindex $list $ch]
	set path [string tolower $item]
	radiobutton .set.main.chnl.$path \
			-foreground $ConfigSet(cFG2) \
			-background $ConfigSet(cBG2) \
			-activebackground $ConfigSet(cABG) \
			-activeforeground $ConfigSet(cAFG) \
			-disabledforeground $ConfigSet(cDFG) \
 			-text $item\
			-width $ButtWidth \
			-selectcolor $ConfigSet(cAFG)\
			-anchor w\
			-variable SAMPLE(chnl)\
			-value $ch\
			-relief groove\
			-command SETscaleLim
	pack .set.main.chnl.$path -side left -padx 3m -pady 3m\
				-fill x -expand 1
   }

   # Callback to channel radio button to adjust scale limits
   proc SETscaleLim {} {
      global CARD SAMPLE FLAG
      if {!$FLAG(Loaded)} {
        # Get Limits of sampling rates based on how many channels are set
        set min [lindex $CARD(Minrates) [expr $SAMPLE(chnl)-1]]
        set max [lindex $CARD(Maxrates) [expr $SAMPLE(chnl)-1]]
        .set.main.smpl.scale config -from $min -to $max
      }
   }

   frame .set.main.bit -bg $ConfigSet(cBG1)\
			  -relief groove\
			  -bd 2
   label .set.main.bit.label \
			-bg $ConfigSet(cBG1)\
			-fg $ConfigSet(cFG1)\
			-text "Bit Resolution Settings"\
			-font $ConfigSet(FNT_S) \
 			-anchor w
   pack .set.main.bit.label -fill x -expand 1

   # General setup for Radio Buttons - Bits
   set ButtWidth 10
   foreach item $bits {
	set path [string tolower $item]
	radiobutton .set.main.bit.$path \
			-foreground $ConfigSet(cFG2) \
			-background $ConfigSet(cBG2) \
			-activebackground $ConfigSet(cABG) \
			-activeforeground $ConfigSet(cAFG) \
			-disabledforeground $ConfigSet(cDFG) \
 			-text "$item Bit"\
			-width $ButtWidth \
			-selectcolor $ConfigSet(cAFG)\
			-anchor w\
			-variable SAMPLE(bit)\
			-value $item\
			-relief groove
	pack .set.main.bit.$path -side left -padx 3m -pady 3m\
				-fill x -expand 1
   }


   # Scale for Sample Rate
   frame .set.main.smpl -bg $ConfigSet(cBG1) \
			  -relief groove\
			  -bd 2 

   label .set.main.smpl.instr \
			-bg $ConfigSet(cBG1)\
			-fg $ConfigSet(cFG1)\
			-text "Sampling Rate (Hz)"\
			-font $ConfigSet(FNT_S) \
 			-anchor w

   entry .set.main.smpl.label \
			-bg $ConfigSet(cBG1)\
			-fg $ConfigSet(cFG1)\
			-textvariable "SAMPLE(rate)"\
			-font $ConfigSet(FNT_S) \
			-width 5\
			-insertbackground $ConfigSet(cFG1)\
			-selectforeground $ConfigSet(cAFG)\
			-selectbackground $ConfigSet(cABG)\
			-cursor arrow
   # Bind the entry with special characteristics.
   bindScale .set.main.smpl .set.main.done.butt
		 
   scale .set.main.smpl.scale\
			-showvalue 0\
			-bg $ConfigSet(cBG1)\
			-fg $ConfigSet(cFG1)\
			-activebackground $ConfigSet(cABG)\
			-from $min -to $max \
			-width 10 -length 300\
			-orient horizontal\
			-command "set SAMPLE(rate)"

   .set.main.smpl.scale set $SAMPLE(rate)

   pack .set.main.smpl.instr -fill x -expand 1\
					-anchor w
   pack .set.main.smpl.scale\
	.set.main.smpl.label \
	  -side left -fill x -expand 1

   # Done Button
   frame .set.main.done -bg $ConfigSet(cBG1)\
			  -relief groove\
			  -bd 2
   button .set.main.done.butt \
			-foreground $ConfigSet(cFG2) \
			-background $ConfigSet(cBG2) \
			-activebackground $ConfigSet(cABG) \
			-activeforeground $ConfigSet(cAFG) \
			-disabledforeground $ConfigSet(cDFG) \
 			-text Done\
			-command { InfoFill
				destroy .set}
   pack .set.main.done.butt -expand 1 -ipadx 2m -pady 3m
   bind .set.main.done.butt <Return> { .set.main.done.butt invoke }
   focus .set.main.done.butt

   pack .set.main.label .set.main.smpl .set.main.bit .set.main.chnl\
	.set.main.done \
	-fill both -expand 1 -side top
   pack .set.main -fill both -expand 1	
}


###################################################################
# The followin procedures prefixed with 'v' are callbacks to a selection
# in the Option-View cascaded menu. They toggle the relevant sections
# of sound studio in and out of view.
proc vPlot {} {
   global FLAG
   if {$FLAG(Vw_PlotBox)} {
	OrderPacking
	PlotBox show
   } else {
	PlotBox noshow
   }
}

proc vInfo {} {
   global FLAG
   if {$FLAG(Vw_InfoBar)} {
	OrderPacking
	InfoBar show
   } else {
	InfoBar noshow
   }
}

proc vMixer {} {
   global FLAG
   if {$FLAG(Vw_Mixer)} {
	OrderPacking
	Mixer show
   } else {
 	Mixer noshow
   }
}

proc vEffects {} {
   global FLAG
   if {$FLAG(Vw_EffectBar)} {
 	OrderPacking
	EffectBar show
   } else {
 	EffectBar noshow
   }
}
