Debian Codegraph @

contrib/tkrplay/tkrplay

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 "/usr/local/lib/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 -geometry 20x20 \
84 -setgrid yes
85 bind .sounds.list <Control-q> {destroy .}
86 bind .sounds.list <Control-c> {destroy .}
87 bind .sounds.list <Double-Button-1> {foreach i [selection get] {doit "play" $i}}
88 pack .sounds.list -side top -fill both -expand yes
89 pack .sounds -side top -fill both
90
91 #
92 # Create the sound action buttons.
93 #
94 frame .buttons
95 button .buttons.play -text "Play" -command \
96 { foreach i [.sounds.list curselection] { doit "play" [.sounds.list get $i] } }
97 button .buttons.stop -text "Stop" -command \
98 { foreach i [.sounds.list curselection] { doit "stop" [.sounds.list get $i] } }
99 button .buttons.pause -text "Pause" -command \
100 { foreach i [.sounds.list curselection] { doit "pause" [.sounds.list get $i] } }
101 button .buttons.continue -text "Continue" -command \
102 { foreach i [.sounds.list curselection] { doit "continue" [.sounds.list get $i] } }
103 button .buttons.prev -bitmap @/usr/include/X11/bitmaps/RotateLeft -command { cd ..; load }
104 button .buttons.next -bitmap @/usr/include/X11/bitmaps/Excl -command { stop "#0" }
105 pack .buttons.prev .buttons.play .buttons.stop .buttons.pause \
106 .buttons.continue .buttons.next -side left -expand yes
107 pack .buttons -side bottom -fill both
108
109 #
110 # Create the "Configure" window.
111 #
112 proc config {} {
113 global host
114 global volume
115 global hvolume
116 global priority
117
118 catch {destroy .config}
119 toplevel .config
120 wm title .config "tkrplay configure"
121
122 frame .config.host
123 entry .config.host.e -relief sunken -width 40
124 pack .config.host.e -side right
125 .config.host.e insert 0 $host
126 label .config.host.l
127 pack .config.host.l -side left
128 .config.host.l config -text "Sound Host:"
129 pack .config.host -fill x
130
131 frame .config.hvolume -relief raised -borderwidth 2
132 label .config.hvolume.l -text "Host Volume"
133 scale .config.hvolume.s -from 0 -to 255 -length 10c -orient horizontal -tickinterval 50
134 .config.hvolume.s set $hvolume
135 pack .config.hvolume.l .config.hvolume.s
136 pack .config.hvolume
137
138 frame .config.volume -relief raised -borderwidth 2
139 label .config.volume.l -text "Sound Volume"
140 scale .config.volume.s -from 0 -to 255 -length 10c -orient horizontal -tickinterval 50
141 .config.volume.s set $volume
142 pack .config.volume.l .config.volume.s
143 pack .config.volume
144
145 frame .config.priority -relief raised -borderwidth 2
146 label .config.priority.l -text "Sound Priority"
147 scale .config.priority.s -from 0 -to 255 -length 10c -orient horizontal -tickinterval 50
148 .config.priority.s set $priority
149 pack .config.priority.l .config.priority.s
150 pack .config.priority
151
152 button .config.apply -text "Apply" -command {
153 set host [.config.host.e get]
154 set hvolume [.config.hvolume.s get]
155 set volume [.config.volume.s get]
156 set priority [.config.priority.s get]
157
158 set hvolume [lindex [split [exec rptp -h $host volume $hvolume] =] 1]
159 .config.hvolume.s set $hvolume
160 }
161 button .config.reset -text "Reset" -command {
162 set volume $default_volume
163 .config.volume.s set $default_volume
164 set priority $default_priority
165 .config.priority.s set $default_priority
166 set host $default_host
167 .config.host.e delete 0 end
168 .config.host.e insert 0 $default_host
169
170 set hvolume [lindex [split [exec rptp -h $host volume] =] 1]
171 .config.hvolume.s set $hvolume
172 }
173 button .config.cancel -text "Cancel" -command "destroy .config"
174 pack .config.apply .config.reset .config.cancel -side left -expand yes
175 }
176
177 #
178 # Play a sound.
179 #
180 proc play args {
181 global host
182 global priority
183 global volume
184 exec rplay -h $host -P $priority -v $volume $args
185 }
186
187 #
188 # Pause a sound.
189 #
190 proc pause args {
191 global host
192 global priority
193 global volume
194 exec rplay -h $host -P $priority -v $volume -p $args
195 }
196
197 #
198 # Continue a sound.
199 #
200 proc continue args {
201 global host
202 global priority
203 global volume
204 exec rplay -h $host -P $priority -v $volume -c $args
205 }
206
207 #
208 # Stop a sound.
209 #
210 proc stop args {
211 global host
212 global priority
213 global volume
214 exec rplay -h $host -P $priority -v $volume -s $args
215 }
216
217 #
218 # Load a list of the current directories' sounds. Only .au, .wav, .aiff, and
219 # directories are displayed.
220 #
221 proc load {} {
222 global dir
223 set dir [pwd]
224 .pwd.entry delete 0 end
225 .pwd.entry insert 0 $dir
226 .sounds.list delete 0 [.sounds.list size]
227 foreach i [exec ls -a] {
228 if [file isdirectory $i] {
229 if {[string compare $i "."] != 0 && [string compare $i ".."] != 0} {
230 .sounds.list insert end $i
231 }
232 } else {
233 if {[string match *.au $i] || [string match *.wav $i] || [string match *.aiff $i]} {
234 .sounds.list insert end $i
235 }
236 }
237 }
238 }
239
240 #
241 # Change working directory or perform a sound action.
242 #
243 proc doit {action file} {
244 global dir
245 if [file isdirectory $file] {
246 cd $file
247 load
248 } else {
249 case $action in {
250 { play } { play $dir/$file }
251 { stop } { stop $dir/$file }
252 { pause } { pause $dir/$file }
253 { continue } { continue $dir/$file }
254 }
255 }
256 }
257
258 #
259 # Here's where everything starts.
260 #
261 focus .sounds.list
262 if $argc>0 {set dir [lindex $argv 0]} else {set dir $sound_dir}
263 cd $dir
264 load