You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.1KB

  1. # A simple Tcl/Tk example script
  2. # Set initial control values
  3. set pitch 64.0
  4. set press 64.0
  5. # Configure main window
  6. wm title . "A Simple GUI"
  7. wm iconname . "simple"
  8. . config -bg black
  9. # Configure a "note-on" button
  10. frame .noteOn -bg black
  11. button .noteOn.on -text NoteOn -bg grey66 -command { noteOn $pitch $press }
  12. pack .noteOn.on -side left -padx 5
  13. pack .noteOn
  14. # Configure sliders
  15. frame .slider -bg black
  16. scale .slider.pitch -from 0 -to 128 -length 200 \
  17. -command {changePitch } -variable pitch \
  18. -orient horizontal -label "MIDI Note Number" \
  19. -tickinterval 32 -showvalue true -bg grey66
  20. pack .slider.pitch -padx 10 -pady 10
  21. pack .slider -side left
  22. # Bind an X windows "close" event with the Exit routine
  23. bind . <Destroy> +myExit
  24. proc myExit {} {
  25. global pitch outID
  26. puts [format "NoteOff 0.0 1 %f 127" $pitch ]
  27. flush stdout
  28. puts [format "ExitProgram"]
  29. flush stdout
  30. close stdout
  31. exit
  32. }
  33. proc noteOn {pitchVal pressVal} {
  34. puts [format "NoteOn 0.0 1 %f %f" $pitchVal $pressVal]
  35. flush stdout
  36. }
  37. proc changePitch {value} {
  38. puts [format "PitchChange 0.0 1 %.3f" $value]
  39. flush stdout
  40. }
  41. bind . <Configure> {+ center_the_toplevel %W }
  42. proc center_the_toplevel { w } {
  43. # Callback on the <Configure> event for a toplevel
  44. # that should be centered on the screen
  45. # Make sure that we aren't configuring a child window
  46. if { [string equal $w [winfo toplevel $w]] } {
  47. # Calculate the desired geometry
  48. set width [winfo reqwidth $w]
  49. set height [winfo reqheight $w]
  50. set x [expr { ( [winfo vrootwidth $w] - $width ) / 2 }]
  51. set y [expr { ( [winfo vrootheight $w] - $height ) / 2 }]
  52. #set y 0
  53. # Hand the geometry off to the window manager
  54. wm geometry $w ${width}x${height}+${x}+${y}
  55. # Unbind <Configure> so that this procedure is
  56. # not called again when the window manager finishes
  57. # centering the window. Also, revert geometry management
  58. # to internal default for subsequent size changes.
  59. bind $w <Configure> {}
  60. wm geometry $w ""
  61. }
  62. return
  63. }