Debian Codegraph @

contrib/tkrplay/foo

raw
1 #!/usr/local/bin/wish -f
2 #
3 # Copyright (C) 1994-95 Mark Boyns <[email protected]>
4 #
5 # tkrplay
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #
21
22 #
23 # Usage: tkrplay <sound_dir>
24 #
25
26 # -- Begin configuration options ---
27
28 set default_host "localhost"
29 set default_volume 127
30 set default_priority 0
31 set sound_dir "/opt/sounds"
32
33 # --- End configuration options ---
34
35 set host $default_host
36 set volume $default_volume
37 set priority $default_priority
38 set hvolume [lindex [split [exec rptp -h $host volume] =] 1]
39 set version "1.1"
40
41 #
42 # Set window manager parameters.
43 #
44 wm title . "tkrplay $version"
45 wm iconname . "tkrplay $version"
46 wm minsize . 1 1
47
48 #
49 # Create the Quit and Configure buttons.
50 #
51 frame .menu -relief raise -borderwidth 2
52 pack .menu -side top -fill x
53 menubutton .menu.file -text "File" -menu .menu.file.m -underline 0 -relief raise
54 menu .menu.file.m
55 .menu.file.m add command -label "Quit" -command "destroy ." -underline 0
56 button .menu.config -text "Configure" -command "config" -relief raised
57 pack .menu.file -side left
58 pack .menu.config -side right
59
60 #
61 # Create the current directory entry.
62 #
63 frame .pwd
64 entry .pwd.entry -relief sunken -width 40
65 label .pwd.label
66 pack .pwd.entry -side right
67 pack .pwd.label -side left
68 bind .pwd.entry <Return> {
69 if [file isdirectory [.pwd.entry get]] {
70 cd [.pwd.entry get]
71 load
72 }
73 }
74 .pwd.label config -text Directory:
75 pack .pwd
76
77 #
78 # Create the sounds list.
79 #
80 frame .sounds
81 scrollbar .sounds.scroll -command ".sounds.list yview"
82 pack .sounds.scroll -side right -fill y
83 listbox .sounds.list -yscroll ".sounds.scroll set" -relief sunken -setgrid yes
84 bind .sounds.list <Control-q> {destroy .}
85 bind .sounds.list <Control-c> {destroy .}
86 bind .sounds.list <Double-Button-1> {foreach i [selection get] {doit "play" $i}}
87 pack .sounds.list -side top -fill both -expand yes
88 pack .sounds -side top -fill both
89
90 #
91 # Create the sound action buttons.
92 #
93 frame .buttons
94 button .buttons.play -text "Play" -command \
95 { foreach i [.sounds.list curselection] { doit "play" [.sounds.list get $i] } }
96 button .buttons.stop -text "Stop" -command \
97 { foreach i [.sounds.list curselection] { doit "stop" [.sounds.list get $i] } }
98 button .buttons.pause -text "Pause" -command \
99 { foreach i [.sounds.list curselection] { doit "pause" [.sounds.list get $i] } }
100 button .buttons.continue -text "Continue" -command \
101 { foreach i [.sounds.list curselection] { doit "continue" [.sounds.list get $i] } }
102 button .buttons.prev -bitmap @/opt/X11R6/include/X11/bitmaps/RotateLeft -command { cd ..; load }
103 button .buttons.next -bitmap @/opt/X11R6/include/X11/bitmaps/Excl -command { stop "#0" }
104 pack .buttons.prev .buttons.play .buttons.stop .buttons.pause \
105 .buttons.continue .buttons.next -side left -expand yes
106 pack .buttons -side bottom -fill both
107
108 #
109 # Create the "Configure" window.
110 #
111 proc config {} {
112 global host
113 global volume
114 global hvolume
115 global priority
116
117 catch {destroy .config}
118 toplevel .config
119 wm title .config "tkrplay configure"
120
121 frame .config.host
122 entry .config.host.e -relief sunken -width 40
123 pack .config.host.e -side right
124 .config.host.e insert 0 $host
125 label .config.host.l
126 pack .config.host.l -side left
127 .config.host.l config -text "Sound Host:"
128 pack .config.host -fill x
129
130 frame .config.hvolume -relief raised -borderwidth 2
131 label .config.hvolume.l -text "Host Volume"
132 scale .config.hvolume.s -from 0 -to 255 -length 10c -orient horizontal -tickinterval 50
133 .config.hvolume.s set $hvolume
134 pack .config.hvolume.l .config.hvolume.s
135 pack .config.hvolume
136
137 frame .config.volume -relief raised -borderwidth 2
138 label .config.volume.l -text "Sound Volume"
139 scale .config.volume.s -from 0 -to 255 -length 10c -orient horizontal -tickinterval 50
140 .config.volume.s set $volume
141 pack .config.volume.l .config.volume.s
142 pack .config.volume
143
144 frame .config.priority -relief raised -borderwidth 2
145 label .config.priority.l -text "Sound Priority"
146 scale .config.priority.s -from 0 -to 255 -length 10c -orient horizontal -tickinterval 50
147 .config.priority.s set $priority
148 pack .config.priority.l .config.priority.s
149 pack .config.priority
150
151 button .config.apply -text "Apply" -command {
152 set host [.config.host.e get]
153 set hvolume [.config.hvolume.s get]
154 set volume [.config.volume.s get]
155 set priority [.config.priority.s get]
156
157 set hvolume [lindex [split [exec rptp -h $host volume $hvolume] =] 1]
158 .config.hvolume.s set $hvolume
159 }
160 button .config.reset -text "Reset" -command {
161 set volume $default_volume
162 .config.volume.s set $default_volume
163 set priority $default_priority
164 .config.priority.s set $default_priority
165 set host $default_host
166 .config.host.e delete 0 end
167 .config.host.e insert 0 $default_host
168
169 set hvolume [lindex [split [exec rptp -h $host volume] =] 1]
170 .config.hvolume.s set $hvolume
171 }
172 button .config.cancel -text "Cancel" -command "destroy .config"
173 pack .config.apply .config.reset .config.cancel -side left -expand yes
174 }
175
176 #
177 # Play a sound.
178 #
179 proc play args {
180 global host
181 global priority
182 global volume
183 exec rplay -h $host -P $priority -v $volume $args
184 }
185
186 #
187 # Pause a sound.
188 #
189 proc pause args {
190 global host
191 global priority
192 global volume
193 exec rplay -h $host -P $priority -v $volume -p $args
194 }
195
196 #
197 # Continue a sound.
198 #
199 proc continue args {
200 global host
201 global priority
202 global volume
203 exec rplay -h $host -P $priority -v $volume -c $args
204 }
205
206 #
207 # Stop a sound.
208 #
209 proc stop args {
210 global host
211 global priority
212 global volume
213 exec rplay -h $host -P $priority -v $volume -s $args
214 }
215
216 #
217 # Load a list of the current directories' sounds. Only .au, .wav, .aiff, and
218 # directories are displayed.
219 #
220 proc load {} {
221 global dir
222 set dir [pwd]
223 .pwd.entry delete 0 end
224 .pwd.entry insert 0 $dir
225 .sounds.list delete 0 [.sounds.list size]
226 foreach i [exec ls -a] {
227 if [file isdirectory $i] {
228 if {[string compare $i "."] != 0 && [string compare $i ".."] != 0} {
229 .sounds.list insert end $i
230 }
231 } else {
232 if {[string match *.au $i] || [string match *.wav $i] || [string match *.aiff $i]} {
233 .sounds.list insert end $i
234 }
235 }
236 }
237 }
238
239 #
240 # Change working directory or perform a sound action.
241 #
242 proc doit {action file} {
243 global dir
244 if [file isdirectory $file] {
245 cd $file
246 load
247 } else {
248 case $action in {
249 { play } { play $dir/$file }
250 { stop } { stop $dir/$file }
251 { pause } { pause $dir/$file }
252 { continue } { continue $dir/$file }
253 }
254 }
255 }
256
257 #
258 # Here's where everything starts.
259 #
260 focus .sounds.list
261 if $argc>0 {set dir [lindex $argv 0]} else {set dir $sound_dir}
262 cd $dir
263 load