annotate mservtk.tcl @ 1:c36994199c5e MSERVTK_0_1

Initial revision
author darius
date Wed, 03 May 2000 12:20:47 +0000
parents
children 4343bc7f829a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
c36994199c5e Initial revision
darius
parents:
diff changeset
1 #!/usr/bin/env wish8.0
c36994199c5e Initial revision
darius
parents:
diff changeset
2
c36994199c5e Initial revision
darius
parents:
diff changeset
3 #
c36994199c5e Initial revision
darius
parents:
diff changeset
4 # This software is copyright Daniel O'Connor (darius@dons.net.au) 2000
c36994199c5e Initial revision
darius
parents:
diff changeset
5 #
c36994199c5e Initial revision
darius
parents:
diff changeset
6 # Redistribution and use in source and binary forms, with or without
c36994199c5e Initial revision
darius
parents:
diff changeset
7 # modification, are permitted provided that the following conditions
c36994199c5e Initial revision
darius
parents:
diff changeset
8 # are met:
c36994199c5e Initial revision
darius
parents:
diff changeset
9 # 1. Redistributions of source code must retain the above copyright
c36994199c5e Initial revision
darius
parents:
diff changeset
10 # notice, this list of conditions and the following disclaimer.
c36994199c5e Initial revision
darius
parents:
diff changeset
11 # 2. Redistributions in binary form must reproduce the above copyright
c36994199c5e Initial revision
darius
parents:
diff changeset
12 # notice, this list of conditions and the following disclaimer in the
c36994199c5e Initial revision
darius
parents:
diff changeset
13 # documentation and/or other materials provided with the distribution.
c36994199c5e Initial revision
darius
parents:
diff changeset
14 # 3. Neither the name Daniel O'Connor nor the names of its contributors
c36994199c5e Initial revision
darius
parents:
diff changeset
15 # may be used to endorse or promote products derived from this software
c36994199c5e Initial revision
darius
parents:
diff changeset
16 # without specific prior written permission.
c36994199c5e Initial revision
darius
parents:
diff changeset
17 #
c36994199c5e Initial revision
darius
parents:
diff changeset
18 # THIS SOFTWARE IS PROVIDED BY DANIEL O'CONNOR AND CONTRIBUTORS ``AS IS'' AND
c36994199c5e Initial revision
darius
parents:
diff changeset
19 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
c36994199c5e Initial revision
darius
parents:
diff changeset
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
c36994199c5e Initial revision
darius
parents:
diff changeset
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
c36994199c5e Initial revision
darius
parents:
diff changeset
22 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
c36994199c5e Initial revision
darius
parents:
diff changeset
23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
c36994199c5e Initial revision
darius
parents:
diff changeset
24 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
c36994199c5e Initial revision
darius
parents:
diff changeset
25 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
c36994199c5e Initial revision
darius
parents:
diff changeset
26 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
c36994199c5e Initial revision
darius
parents:
diff changeset
27 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
c36994199c5e Initial revision
darius
parents:
diff changeset
28 # SUCH DAMAGE.
c36994199c5e Initial revision
darius
parents:
diff changeset
29 #
c36994199c5e Initial revision
darius
parents:
diff changeset
30
c36994199c5e Initial revision
darius
parents:
diff changeset
31 proc main {} {
c36994199c5e Initial revision
darius
parents:
diff changeset
32 global argv0 argv state albums songs;
c36994199c5e Initial revision
darius
parents:
diff changeset
33
c36994199c5e Initial revision
darius
parents:
diff changeset
34 set state(exit) 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
35 set state(host) "lot";
c36994199c5e Initial revision
darius
parents:
diff changeset
36 set state(port) "4444";
c36994199c5e Initial revision
darius
parents:
diff changeset
37 set state(user) "Darius";
c36994199c5e Initial revision
darius
parents:
diff changeset
38 set state(pass) "Fnordish";
c36994199c5e Initial revision
darius
parents:
diff changeset
39 set state(sortmode) "Title";
c36994199c5e Initial revision
darius
parents:
diff changeset
40 set state(tmpphrase) "";
c36994199c5e Initial revision
darius
parents:
diff changeset
41
c36994199c5e Initial revision
darius
parents:
diff changeset
42 gui_build;
c36994199c5e Initial revision
darius
parents:
diff changeset
43
c36994199c5e Initial revision
darius
parents:
diff changeset
44 con_mserv;
c36994199c5e Initial revision
darius
parents:
diff changeset
45
c36994199c5e Initial revision
darius
parents:
diff changeset
46 con_getalbums albums;
c36994199c5e Initial revision
darius
parents:
diff changeset
47 con_getsongs songs albums;
c36994199c5e Initial revision
darius
parents:
diff changeset
48
c36994199c5e Initial revision
darius
parents:
diff changeset
49 gui_updatesongs;
c36994199c5e Initial revision
darius
parents:
diff changeset
50 gui_updatequeue;
c36994199c5e Initial revision
darius
parents:
diff changeset
51
c36994199c5e Initial revision
darius
parents:
diff changeset
52 update_timer;
c36994199c5e Initial revision
darius
parents:
diff changeset
53
c36994199c5e Initial revision
darius
parents:
diff changeset
54 while {1} {
c36994199c5e Initial revision
darius
parents:
diff changeset
55 vwait state(exit);
c36994199c5e Initial revision
darius
parents:
diff changeset
56
c36994199c5e Initial revision
darius
parents:
diff changeset
57 if {$state(exit) == 1} {
c36994199c5e Initial revision
darius
parents:
diff changeset
58 exit;
c36994199c5e Initial revision
darius
parents:
diff changeset
59 }
c36994199c5e Initial revision
darius
parents:
diff changeset
60 }
c36994199c5e Initial revision
darius
parents:
diff changeset
61 }
c36994199c5e Initial revision
darius
parents:
diff changeset
62
c36994199c5e Initial revision
darius
parents:
diff changeset
63 proc quit_now {} {
c36994199c5e Initial revision
darius
parents:
diff changeset
64 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
65
c36994199c5e Initial revision
darius
parents:
diff changeset
66 set state(exit) 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
67 }
c36994199c5e Initial revision
darius
parents:
diff changeset
68
c36994199c5e Initial revision
darius
parents:
diff changeset
69 proc gui_build {} {
c36994199c5e Initial revision
darius
parents:
diff changeset
70 # create the toplevel
c36994199c5e Initial revision
darius
parents:
diff changeset
71 eval destroy [winfo child .];
c36994199c5e Initial revision
darius
parents:
diff changeset
72 wm title . "MServ-Tk";
c36994199c5e Initial revision
darius
parents:
diff changeset
73 wm minsize . 600 500;
c36994199c5e Initial revision
darius
parents:
diff changeset
74 wm geometry . 600x500;
c36994199c5e Initial revision
darius
parents:
diff changeset
75
c36994199c5e Initial revision
darius
parents:
diff changeset
76 # Let's have a menubar
c36994199c5e Initial revision
darius
parents:
diff changeset
77 frame .menubar -relief raised -bd 2;
c36994199c5e Initial revision
darius
parents:
diff changeset
78 pack .menubar -side top -fill x;
c36994199c5e Initial revision
darius
parents:
diff changeset
79
c36994199c5e Initial revision
darius
parents:
diff changeset
80 # Add the File menu
c36994199c5e Initial revision
darius
parents:
diff changeset
81 menubutton .menubar.file -text "File" -menu .menubar.file.m -underline 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
82 menu .menubar.file.m -tearoff 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
83 .menubar.file.m add command -label " Quit" -command "quit_now" \
c36994199c5e Initial revision
darius
parents:
diff changeset
84 -underline 2 -accelerator "Alt-q";
c36994199c5e Initial revision
darius
parents:
diff changeset
85 pack .menubar.file -side left;
c36994199c5e Initial revision
darius
parents:
diff changeset
86
c36994199c5e Initial revision
darius
parents:
diff changeset
87 # Add the Rate menu
c36994199c5e Initial revision
darius
parents:
diff changeset
88 menubutton .menubar.rate -text "Rate" -menu .menubar.rate.m -underline 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
89 menu .menubar.rate.m -tearoff 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
90 .menubar.rate.m add command -label " Superb" -command "rate_song SUPERB";
c36994199c5e Initial revision
darius
parents:
diff changeset
91 .menubar.rate.m add command -label " Good" -command "rate_song GOOD";
c36994199c5e Initial revision
darius
parents:
diff changeset
92 .menubar.rate.m add command -label " Neutral" -command "rate_song NEUTRAL";
c36994199c5e Initial revision
darius
parents:
diff changeset
93 .menubar.rate.m add command -label " Bad" -command "rate_song BAD";
c36994199c5e Initial revision
darius
parents:
diff changeset
94 .menubar.rate.m add command -label " Awful" -command "rate_song AWFUL";
c36994199c5e Initial revision
darius
parents:
diff changeset
95
c36994199c5e Initial revision
darius
parents:
diff changeset
96 pack .menubar.rate -side left;
c36994199c5e Initial revision
darius
parents:
diff changeset
97
c36994199c5e Initial revision
darius
parents:
diff changeset
98 # Add the Control menu
c36994199c5e Initial revision
darius
parents:
diff changeset
99 menubutton .menubar.control -text "Control" -menu .menubar.control.m -underline 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
100 menu .menubar.control.m -tearoff 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
101 .menubar.control.m add command -label " Next" -command "control_player NEXT";
c36994199c5e Initial revision
darius
parents:
diff changeset
102 .menubar.control.m add command -label " Pause" -command "control_player PAUSE";
c36994199c5e Initial revision
darius
parents:
diff changeset
103 .menubar.control.m add command -label " Stop" -command "control_player STOP"
c36994199c5e Initial revision
darius
parents:
diff changeset
104 .menubar.control.m add command -label " Play" -command "control_player PLAY";
c36994199c5e Initial revision
darius
parents:
diff changeset
105
c36994199c5e Initial revision
darius
parents:
diff changeset
106 pack .menubar.control -side left;
c36994199c5e Initial revision
darius
parents:
diff changeset
107
c36994199c5e Initial revision
darius
parents:
diff changeset
108 # Add the Volume menu
c36994199c5e Initial revision
darius
parents:
diff changeset
109 menubutton .menubar.vol -text "Volume" -menu .menubar.vol.m -underline 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
110 menu .menubar.vol.m -tearoff 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
111 .menubar.vol.m add command -label " Increase" -command "set_vol +3" \
c36994199c5e Initial revision
darius
parents:
diff changeset
112 -accelerator "+";
c36994199c5e Initial revision
darius
parents:
diff changeset
113 .menubar.vol.m add command -label " Decrease" -command "set_vol -3" \
c36994199c5e Initial revision
darius
parents:
diff changeset
114 -accelerator "-";
c36994199c5e Initial revision
darius
parents:
diff changeset
115 .menubar.vol.m add separator;
c36994199c5e Initial revision
darius
parents:
diff changeset
116 .menubar.vol.m add command -label " 100%" -command "set_vol 100";
c36994199c5e Initial revision
darius
parents:
diff changeset
117 .menubar.vol.m add command -label " 90%" -command "set_vol 90";
c36994199c5e Initial revision
darius
parents:
diff changeset
118 .menubar.vol.m add command -label " 80%" -command "set_vol 80";
c36994199c5e Initial revision
darius
parents:
diff changeset
119 .menubar.vol.m add command -label " 70%" -command "set_vol 70";
c36994199c5e Initial revision
darius
parents:
diff changeset
120 .menubar.vol.m add command -label " 60%" -command "set_vol 60";
c36994199c5e Initial revision
darius
parents:
diff changeset
121 .menubar.vol.m add command -label " 50%" -command "set_vol 50";
c36994199c5e Initial revision
darius
parents:
diff changeset
122 .menubar.vol.m add command -label " 40%" -command "set_vol 40";
c36994199c5e Initial revision
darius
parents:
diff changeset
123 .menubar.vol.m add command -label " 30%" -command "set_vol 30";
c36994199c5e Initial revision
darius
parents:
diff changeset
124 .menubar.vol.m add command -label " 20%" -command "set_vol 20";
c36994199c5e Initial revision
darius
parents:
diff changeset
125 .menubar.vol.m add command -label " 10%" -command "set_vol 10";
c36994199c5e Initial revision
darius
parents:
diff changeset
126 .menubar.vol.m add command -label " 0%" -command "set_vol 0";
c36994199c5e Initial revision
darius
parents:
diff changeset
127
c36994199c5e Initial revision
darius
parents:
diff changeset
128 pack .menubar.vol -side left;
c36994199c5e Initial revision
darius
parents:
diff changeset
129
c36994199c5e Initial revision
darius
parents:
diff changeset
130 # Add the Sort menu
c36994199c5e Initial revision
darius
parents:
diff changeset
131 menubutton .menubar.sort -text "Sort" -menu .menubar.sort.m -underline 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
132 menu .menubar.sort.m -tearoff 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
133 .menubar.sort.m add command -label " Artist" \
c36994199c5e Initial revision
darius
parents:
diff changeset
134 -command "global state; set state(sortmode) Artist; gui_updatesongs";
c36994199c5e Initial revision
darius
parents:
diff changeset
135 .menubar.sort.m add command -label " Title" \
c36994199c5e Initial revision
darius
parents:
diff changeset
136 -command "global state; set state(sortmode) Title; gui_updatesongs";
c36994199c5e Initial revision
darius
parents:
diff changeset
137 .menubar.sort.m add command -label " Album" \
c36994199c5e Initial revision
darius
parents:
diff changeset
138 -command "global state; set state(sortmode) Album; gui_updatesongs";
c36994199c5e Initial revision
darius
parents:
diff changeset
139
c36994199c5e Initial revision
darius
parents:
diff changeset
140 pack .menubar.sort -side left;
c36994199c5e Initial revision
darius
parents:
diff changeset
141
c36994199c5e Initial revision
darius
parents:
diff changeset
142 # Add the Help menu
c36994199c5e Initial revision
darius
parents:
diff changeset
143 menubutton .menubar.help -text "Help" -menu .menubar.help.m -underline 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
144 menu .menubar.help.m -tearoff 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
145 .menubar.help.m add command -label " About" -command "about_box" \
c36994199c5e Initial revision
darius
parents:
diff changeset
146 -underline 2;
c36994199c5e Initial revision
darius
parents:
diff changeset
147 pack .menubar.help -side right;
c36994199c5e Initial revision
darius
parents:
diff changeset
148
c36994199c5e Initial revision
darius
parents:
diff changeset
149 # Top frame holding tracklist and trackinfo frames
c36994199c5e Initial revision
darius
parents:
diff changeset
150 frame .top -relief raised -bd 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
151 pack .top -fill both -expand 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
152
c36994199c5e Initial revision
darius
parents:
diff changeset
153 # Tracklist
c36994199c5e Initial revision
darius
parents:
diff changeset
154 frame .top.tlist -relief raised -bd 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
155 pack .top.tlist -side left -fill both -expand 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
156 label .top.tlist.label -text "Track List";
c36994199c5e Initial revision
darius
parents:
diff changeset
157 pack .top.tlist.label -side top -expand 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
158 listbox .top.tlist.list -relief raised -borderwidth 2 \
c36994199c5e Initial revision
darius
parents:
diff changeset
159 -yscrollcommand ".top.tlist.scr set";
c36994199c5e Initial revision
darius
parents:
diff changeset
160 pack .top.tlist.list -side left -fill both -expand 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
161 scrollbar .top.tlist.scr -command ".top.tlist.list yview";
c36994199c5e Initial revision
darius
parents:
diff changeset
162 pack .top.tlist.scr -side right -fill y;
c36994199c5e Initial revision
darius
parents:
diff changeset
163 bind .top.tlist.list <Double-Button-1> {
c36994199c5e Initial revision
darius
parents:
diff changeset
164 queue_song [.top.tlist.list curselection];
c36994199c5e Initial revision
darius
parents:
diff changeset
165 }
c36994199c5e Initial revision
darius
parents:
diff changeset
166
c36994199c5e Initial revision
darius
parents:
diff changeset
167 # Trackinfo
c36994199c5e Initial revision
darius
parents:
diff changeset
168 frame .top.tinfo -relief raised -bd 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
169 pack .top.tinfo -side right -fill both -expand 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
170 label .top.tinfo.label -text "Track Info";
c36994199c5e Initial revision
darius
parents:
diff changeset
171 pack .top.tinfo.label -side top -expand 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
172 frame .top.tinfo.sub -relief raised -bd 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
173 pack .top.tinfo.sub -side right -fill both -expand 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
174 label .top.tinfo.sub.author -text "Author:";
c36994199c5e Initial revision
darius
parents:
diff changeset
175 pack .top.tinfo.sub.author -side top -expand 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
176 label .top.tinfo.sub.title -text "Title:";
c36994199c5e Initial revision
darius
parents:
diff changeset
177 pack .top.tinfo.sub.title -side top -expand 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
178 label .top.tinfo.sub.length -text "Length:";
c36994199c5e Initial revision
darius
parents:
diff changeset
179 pack .top.tinfo.sub.length -side top -expand 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
180 label .top.tinfo.sub.time -text "Time:";
c36994199c5e Initial revision
darius
parents:
diff changeset
181 pack .top.tinfo.sub.time -side top -expand 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
182 label .top.tinfo.sub.album -text "Album:";
c36994199c5e Initial revision
darius
parents:
diff changeset
183 pack .top.tinfo.sub.album -side top -expand 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
184 label .top.tinfo.sub.trackno -text "Misc:";
c36994199c5e Initial revision
darius
parents:
diff changeset
185 pack .top.tinfo.sub.trackno -side top -expand 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
186 label .top.tinfo.sub.vol -text "Volume:";
c36994199c5e Initial revision
darius
parents:
diff changeset
187 pack .top.tinfo.sub.vol -side top -expand 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
188
c36994199c5e Initial revision
darius
parents:
diff changeset
189 # Queue (and the frame holding it)
c36994199c5e Initial revision
darius
parents:
diff changeset
190 frame .bot -relief raised -bd 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
191 pack .bot -fill both -expand 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
192 label .bot.qlabel -text "Queue";
c36994199c5e Initial revision
darius
parents:
diff changeset
193 pack .bot.qlabel -side top -expand 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
194 frame .bot.queue;
c36994199c5e Initial revision
darius
parents:
diff changeset
195 pack .bot.queue -fill both -expand 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
196 listbox .bot.queue.list -relief raised -borderwidth 2 \
c36994199c5e Initial revision
darius
parents:
diff changeset
197 -yscrollcommand ".bot.queue.scr set";
c36994199c5e Initial revision
darius
parents:
diff changeset
198 pack .bot.queue.list -side left -fill both -expand 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
199 scrollbar .bot.queue.scr -command ".bot.queue.list yview";
c36994199c5e Initial revision
darius
parents:
diff changeset
200 pack .bot.queue.scr -side right -fill y;
c36994199c5e Initial revision
darius
parents:
diff changeset
201 bind .bot.queue.list <Double-Button-1> {
c36994199c5e Initial revision
darius
parents:
diff changeset
202 gui_delqueue [.bot.queue.list curselection];
c36994199c5e Initial revision
darius
parents:
diff changeset
203 }
c36994199c5e Initial revision
darius
parents:
diff changeset
204
c36994199c5e Initial revision
darius
parents:
diff changeset
205 bind . <Destroy> {quit_now};
c36994199c5e Initial revision
darius
parents:
diff changeset
206 bind all <Alt-q> {quit_now};
c36994199c5e Initial revision
darius
parents:
diff changeset
207
c36994199c5e Initial revision
darius
parents:
diff changeset
208 bind all <KP_Add> {set_vol +3};
c36994199c5e Initial revision
darius
parents:
diff changeset
209 bind all <KP_Subtract> {set_vol -3};
c36994199c5e Initial revision
darius
parents:
diff changeset
210 bind all <plus> {set_vol +3};
c36994199c5e Initial revision
darius
parents:
diff changeset
211 bind all <equal> {set_vol +3};
c36994199c5e Initial revision
darius
parents:
diff changeset
212 bind all <minus> {set_vol -3};
c36994199c5e Initial revision
darius
parents:
diff changeset
213 bind all <F1> {set_vol 10};
c36994199c5e Initial revision
darius
parents:
diff changeset
214 bind all <F2> {set_vol 20};
c36994199c5e Initial revision
darius
parents:
diff changeset
215 bind all <F3> {set_vol 30};
c36994199c5e Initial revision
darius
parents:
diff changeset
216 bind all <F4> {set_vol 40};
c36994199c5e Initial revision
darius
parents:
diff changeset
217 bind all <F5> {set_vol 50};
c36994199c5e Initial revision
darius
parents:
diff changeset
218 bind all <F6> {set_vol 60};
c36994199c5e Initial revision
darius
parents:
diff changeset
219 bind all <F7> {set_vol 70};
c36994199c5e Initial revision
darius
parents:
diff changeset
220 bind all <F8> {set_vol 80};
c36994199c5e Initial revision
darius
parents:
diff changeset
221 bind all <F9> {set_vol 90};
c36994199c5e Initial revision
darius
parents:
diff changeset
222 bind all <F10> {set_vol 100};
c36994199c5e Initial revision
darius
parents:
diff changeset
223
c36994199c5e Initial revision
darius
parents:
diff changeset
224 bind all <Pause> {control_player PAUSE};
c36994199c5e Initial revision
darius
parents:
diff changeset
225 bind all <End> {control_player NEXT};
c36994199c5e Initial revision
darius
parents:
diff changeset
226 bind all <Delete> {control_player STOP};
c36994199c5e Initial revision
darius
parents:
diff changeset
227 bind all <Home> {control_player PLAY};
c36994199c5e Initial revision
darius
parents:
diff changeset
228
c36994199c5e Initial revision
darius
parents:
diff changeset
229 update;
c36994199c5e Initial revision
darius
parents:
diff changeset
230 }
c36994199c5e Initial revision
darius
parents:
diff changeset
231
c36994199c5e Initial revision
darius
parents:
diff changeset
232 proc queue_song {id} {
c36994199c5e Initial revision
darius
parents:
diff changeset
233 global songs state;
c36994199c5e Initial revision
darius
parents:
diff changeset
234
c36994199c5e Initial revision
darius
parents:
diff changeset
235 set tmp [lindex [lindex [array get songs *:listid:$id] 1] 0];
c36994199c5e Initial revision
darius
parents:
diff changeset
236 log "%s" "Queue - '$songs($tmp:name)' by '$songs($tmp:author)' ($tmp)";
c36994199c5e Initial revision
darius
parents:
diff changeset
237
c36994199c5e Initial revision
darius
parents:
diff changeset
238 n_write "QUEUE [split $tmp {:}]";
c36994199c5e Initial revision
darius
parents:
diff changeset
239 n_getrtn rtn;
c36994199c5e Initial revision
darius
parents:
diff changeset
240
c36994199c5e Initial revision
darius
parents:
diff changeset
241 if {$rtn(code) != 247} {
c36994199c5e Initial revision
darius
parents:
diff changeset
242 if {$rtn(code) == 510} {
c36994199c5e Initial revision
darius
parents:
diff changeset
243 msg_box "Queue" "You can't have the same\nsong in the queue twice!";
c36994199c5e Initial revision
darius
parents:
diff changeset
244 } else {
c36994199c5e Initial revision
darius
parents:
diff changeset
245 log "Failed to queue track ($rtn(code) $rtn(data))";
c36994199c5e Initial revision
darius
parents:
diff changeset
246 }
c36994199c5e Initial revision
darius
parents:
diff changeset
247 }
c36994199c5e Initial revision
darius
parents:
diff changeset
248 }
c36994199c5e Initial revision
darius
parents:
diff changeset
249
c36994199c5e Initial revision
darius
parents:
diff changeset
250 proc msg_box {title msg} {
c36994199c5e Initial revision
darius
parents:
diff changeset
251 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
252
c36994199c5e Initial revision
darius
parents:
diff changeset
253 catch {destroy .msg};
c36994199c5e Initial revision
darius
parents:
diff changeset
254
c36994199c5e Initial revision
darius
parents:
diff changeset
255 toplevel .msg -class Dialog;
c36994199c5e Initial revision
darius
parents:
diff changeset
256 wm title .msg $title;
c36994199c5e Initial revision
darius
parents:
diff changeset
257 wm iconname .msg $title;
c36994199c5e Initial revision
darius
parents:
diff changeset
258
c36994199c5e Initial revision
darius
parents:
diff changeset
259 # text region
c36994199c5e Initial revision
darius
parents:
diff changeset
260 frame .msg.frame;
c36994199c5e Initial revision
darius
parents:
diff changeset
261 pack .msg.frame -side top -fill both -expand yes;
c36994199c5e Initial revision
darius
parents:
diff changeset
262 text .msg.frame.text -font fixed -height 10 -width 40 -yscroll ".msg.frame.scroll set" \
c36994199c5e Initial revision
darius
parents:
diff changeset
263 -wrap none;
c36994199c5e Initial revision
darius
parents:
diff changeset
264 scrollbar .msg.frame.scroll -command ".msg.frame.text yview";
c36994199c5e Initial revision
darius
parents:
diff changeset
265 pack .msg.frame.text -side left -expand y -fill both;
c36994199c5e Initial revision
darius
parents:
diff changeset
266 pack .msg.frame.scroll -side right -fill y;
c36994199c5e Initial revision
darius
parents:
diff changeset
267
c36994199c5e Initial revision
darius
parents:
diff changeset
268 # close button
c36994199c5e Initial revision
darius
parents:
diff changeset
269 button .msg.close -text "Close" -command "destroy .msg";
c36994199c5e Initial revision
darius
parents:
diff changeset
270 pack .msg.close -side bottom -fill x;
c36994199c5e Initial revision
darius
parents:
diff changeset
271
c36994199c5e Initial revision
darius
parents:
diff changeset
272 # read text into the text widget
c36994199c5e Initial revision
darius
parents:
diff changeset
273 .msg.frame.text insert end $msg;
c36994199c5e Initial revision
darius
parents:
diff changeset
274 }
c36994199c5e Initial revision
darius
parents:
diff changeset
275
c36994199c5e Initial revision
darius
parents:
diff changeset
276 proc about_box {} {
c36994199c5e Initial revision
darius
parents:
diff changeset
277 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
278
c36994199c5e Initial revision
darius
parents:
diff changeset
279 catch {destroy .about};
c36994199c5e Initial revision
darius
parents:
diff changeset
280
c36994199c5e Initial revision
darius
parents:
diff changeset
281 toplevel .about -class Dialog;
c36994199c5e Initial revision
darius
parents:
diff changeset
282 wm title .about "About...";
c36994199c5e Initial revision
darius
parents:
diff changeset
283 wm iconname .about "About";
c36994199c5e Initial revision
darius
parents:
diff changeset
284
c36994199c5e Initial revision
darius
parents:
diff changeset
285 # text region
c36994199c5e Initial revision
darius
parents:
diff changeset
286 frame .about.frame;
c36994199c5e Initial revision
darius
parents:
diff changeset
287 pack .about.frame -side top -fill both -expand yes;
c36994199c5e Initial revision
darius
parents:
diff changeset
288 text .about.frame.text -font fixed -height 10 -width 40 -yscroll ".about.frame.scroll set" \
c36994199c5e Initial revision
darius
parents:
diff changeset
289 -wrap none;
c36994199c5e Initial revision
darius
parents:
diff changeset
290 scrollbar .about.frame.scroll -command ".about.frame.text yview";
c36994199c5e Initial revision
darius
parents:
diff changeset
291 pack .about.frame.text -side left -expand y;
c36994199c5e Initial revision
darius
parents:
diff changeset
292 pack .about.frame.scroll -side right -fill y;
c36994199c5e Initial revision
darius
parents:
diff changeset
293
c36994199c5e Initial revision
darius
parents:
diff changeset
294 # close button
c36994199c5e Initial revision
darius
parents:
diff changeset
295 button .about.close -text "Close" -command "destroy .about";
c36994199c5e Initial revision
darius
parents:
diff changeset
296 pack .about.close -side bottom -fill x;
c36994199c5e Initial revision
darius
parents:
diff changeset
297
c36994199c5e Initial revision
darius
parents:
diff changeset
298 # read text into the text widget
c36994199c5e Initial revision
darius
parents:
diff changeset
299 .about.frame.text insert end "Mserv Client\n";
c36994199c5e Initial revision
darius
parents:
diff changeset
300 .about.frame.text insert end "Copyright Daniel O'Connor 2000\n";
c36994199c5e Initial revision
darius
parents:
diff changeset
301 .about.frame.text insert end "\n";
c36994199c5e Initial revision
darius
parents:
diff changeset
302 .about.frame.text insert end "http://www.dons.net.au/~darius/\n";
c36994199c5e Initial revision
darius
parents:
diff changeset
303 }
c36994199c5e Initial revision
darius
parents:
diff changeset
304
c36994199c5e Initial revision
darius
parents:
diff changeset
305 proc set_vol {vol} {
c36994199c5e Initial revision
darius
parents:
diff changeset
306 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
307
c36994199c5e Initial revision
darius
parents:
diff changeset
308 n_write "VOLUME $vol"
c36994199c5e Initial revision
darius
parents:
diff changeset
309 n_getrtn rtn;
c36994199c5e Initial revision
darius
parents:
diff changeset
310
c36994199c5e Initial revision
darius
parents:
diff changeset
311 if {$rtn(code) != 255} {
c36994199c5e Initial revision
darius
parents:
diff changeset
312 log "%s" "Couldn't set volume ($rtn(code) $rtn(data))";
c36994199c5e Initial revision
darius
parents:
diff changeset
313 }
c36994199c5e Initial revision
darius
parents:
diff changeset
314 }
c36994199c5e Initial revision
darius
parents:
diff changeset
315
c36994199c5e Initial revision
darius
parents:
diff changeset
316 proc rate_song {rate} {
c36994199c5e Initial revision
darius
parents:
diff changeset
317 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
318
c36994199c5e Initial revision
darius
parents:
diff changeset
319 n_write "RATE $rate";
c36994199c5e Initial revision
darius
parents:
diff changeset
320 n_getrtn rtn;
c36994199c5e Initial revision
darius
parents:
diff changeset
321
c36994199c5e Initial revision
darius
parents:
diff changeset
322 if {$rtn(code) != 270} {
c36994199c5e Initial revision
darius
parents:
diff changeset
323 log "%s" "Failed to get rate song ($rtn(code) $rtn(data))";
c36994199c5e Initial revision
darius
parents:
diff changeset
324 }
c36994199c5e Initial revision
darius
parents:
diff changeset
325
c36994199c5e Initial revision
darius
parents:
diff changeset
326 }
c36994199c5e Initial revision
darius
parents:
diff changeset
327
c36994199c5e Initial revision
darius
parents:
diff changeset
328 proc control_player {cmd} {
c36994199c5e Initial revision
darius
parents:
diff changeset
329 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
330
c36994199c5e Initial revision
darius
parents:
diff changeset
331 n_write "$cmd";
c36994199c5e Initial revision
darius
parents:
diff changeset
332 n_getrtn rtn;
c36994199c5e Initial revision
darius
parents:
diff changeset
333
c36994199c5e Initial revision
darius
parents:
diff changeset
334 log "%s" "Control Got $rtn(code) $rtn(data)";
c36994199c5e Initial revision
darius
parents:
diff changeset
335 }
c36994199c5e Initial revision
darius
parents:
diff changeset
336
c36994199c5e Initial revision
darius
parents:
diff changeset
337 proc gui_updatesongs {} {
c36994199c5e Initial revision
darius
parents:
diff changeset
338 global state songs;
c36994199c5e Initial revision
darius
parents:
diff changeset
339
c36994199c5e Initial revision
darius
parents:
diff changeset
340 .top.tlist.list delete 0 end;
c36994199c5e Initial revision
darius
parents:
diff changeset
341
c36994199c5e Initial revision
darius
parents:
diff changeset
342 set tmp "";
c36994199c5e Initial revision
darius
parents:
diff changeset
343
c36994199c5e Initial revision
darius
parents:
diff changeset
344 foreach tag [array names songs "*:id"] {
c36994199c5e Initial revision
darius
parents:
diff changeset
345 set a $songs($tag);
c36994199c5e Initial revision
darius
parents:
diff changeset
346 lappend tmp [list $a $songs($a:name) $songs($a:author) $songs($a:albumname)];
c36994199c5e Initial revision
darius
parents:
diff changeset
347 }
c36994199c5e Initial revision
darius
parents:
diff changeset
348
c36994199c5e Initial revision
darius
parents:
diff changeset
349 switch -- $state(sortmode) {
c36994199c5e Initial revision
darius
parents:
diff changeset
350 "Title" {
c36994199c5e Initial revision
darius
parents:
diff changeset
351 set idx 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
352 }
c36994199c5e Initial revision
darius
parents:
diff changeset
353
c36994199c5e Initial revision
darius
parents:
diff changeset
354 "Artist" {
c36994199c5e Initial revision
darius
parents:
diff changeset
355 set idx 2;
c36994199c5e Initial revision
darius
parents:
diff changeset
356 }
c36994199c5e Initial revision
darius
parents:
diff changeset
357
c36994199c5e Initial revision
darius
parents:
diff changeset
358 "Album" {
c36994199c5e Initial revision
darius
parents:
diff changeset
359 set idx 3;
c36994199c5e Initial revision
darius
parents:
diff changeset
360 }
c36994199c5e Initial revision
darius
parents:
diff changeset
361
c36994199c5e Initial revision
darius
parents:
diff changeset
362 default {
c36994199c5e Initial revision
darius
parents:
diff changeset
363 set idx 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
364 }
c36994199c5e Initial revision
darius
parents:
diff changeset
365 }
c36994199c5e Initial revision
darius
parents:
diff changeset
366 set tmp [lsort -dictionary -index $idx $tmp];
c36994199c5e Initial revision
darius
parents:
diff changeset
367
c36994199c5e Initial revision
darius
parents:
diff changeset
368 foreach a [array names songs *:listid:*] {
c36994199c5e Initial revision
darius
parents:
diff changeset
369 unset songs($a);
c36994199c5e Initial revision
darius
parents:
diff changeset
370 }
c36994199c5e Initial revision
darius
parents:
diff changeset
371
c36994199c5e Initial revision
darius
parents:
diff changeset
372 set i 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
373 foreach a $tmp {
c36994199c5e Initial revision
darius
parents:
diff changeset
374 .top.tlist.list insert end "'[lindex $a 1]' by '[lindex $a 2]' on '[lindex $a 3]'"
c36994199c5e Initial revision
darius
parents:
diff changeset
375 set songs([lindex $a 0]:listid:$i) $a;
c36994199c5e Initial revision
darius
parents:
diff changeset
376 incr i;
c36994199c5e Initial revision
darius
parents:
diff changeset
377 }
c36994199c5e Initial revision
darius
parents:
diff changeset
378 }
c36994199c5e Initial revision
darius
parents:
diff changeset
379
c36994199c5e Initial revision
darius
parents:
diff changeset
380 proc gui_updatequeue {} {
c36994199c5e Initial revision
darius
parents:
diff changeset
381 global state songs queue;
c36994199c5e Initial revision
darius
parents:
diff changeset
382
c36994199c5e Initial revision
darius
parents:
diff changeset
383 if {[info exists state(queuelock)]} {
c36994199c5e Initial revision
darius
parents:
diff changeset
384 return;
c36994199c5e Initial revision
darius
parents:
diff changeset
385 }
c36994199c5e Initial revision
darius
parents:
diff changeset
386
c36994199c5e Initial revision
darius
parents:
diff changeset
387 set state(queuelock) "";
c36994199c5e Initial revision
darius
parents:
diff changeset
388
c36994199c5e Initial revision
darius
parents:
diff changeset
389 log "%s" "Updating queue";
c36994199c5e Initial revision
darius
parents:
diff changeset
390
c36994199c5e Initial revision
darius
parents:
diff changeset
391 .bot.queue.list delete 0 end;
c36994199c5e Initial revision
darius
parents:
diff changeset
392
c36994199c5e Initial revision
darius
parents:
diff changeset
393 con_getqueue queue;
c36994199c5e Initial revision
darius
parents:
diff changeset
394
c36994199c5e Initial revision
darius
parents:
diff changeset
395 foreach tag [lsort [array names queue]] {
c36994199c5e Initial revision
darius
parents:
diff changeset
396 .bot.queue.list insert end "'$songs($queue($tag):name)' by '$songs($queue($tag):author)' on '$songs($queue($tag):albumname)'";
c36994199c5e Initial revision
darius
parents:
diff changeset
397 }
c36994199c5e Initial revision
darius
parents:
diff changeset
398
c36994199c5e Initial revision
darius
parents:
diff changeset
399 unset state(queuelock);
c36994199c5e Initial revision
darius
parents:
diff changeset
400 }
c36994199c5e Initial revision
darius
parents:
diff changeset
401
c36994199c5e Initial revision
darius
parents:
diff changeset
402 proc gui_delqueue {id} {
c36994199c5e Initial revision
darius
parents:
diff changeset
403 global queue;
c36994199c5e Initial revision
darius
parents:
diff changeset
404
c36994199c5e Initial revision
darius
parents:
diff changeset
405 if {$id == ""} {
c36994199c5e Initial revision
darius
parents:
diff changeset
406 return;
c36994199c5e Initial revision
darius
parents:
diff changeset
407 }
c36994199c5e Initial revision
darius
parents:
diff changeset
408
c36994199c5e Initial revision
darius
parents:
diff changeset
409 n_write "UNQUEUE [split $queue($id) {:}]";
c36994199c5e Initial revision
darius
parents:
diff changeset
410 n_getrtn rtn;
c36994199c5e Initial revision
darius
parents:
diff changeset
411
c36994199c5e Initial revision
darius
parents:
diff changeset
412 if {$rtn(code) != 254} {
c36994199c5e Initial revision
darius
parents:
diff changeset
413 log "%s" "Failed to remove $id ($queue($id))";
c36994199c5e Initial revision
darius
parents:
diff changeset
414 msg_box "Queue" "Failed to dequeue the song";
c36994199c5e Initial revision
darius
parents:
diff changeset
415 }
c36994199c5e Initial revision
darius
parents:
diff changeset
416 }
c36994199c5e Initial revision
darius
parents:
diff changeset
417
c36994199c5e Initial revision
darius
parents:
diff changeset
418 proc gui_updateinfo {} {
c36994199c5e Initial revision
darius
parents:
diff changeset
419 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
420
c36994199c5e Initial revision
darius
parents:
diff changeset
421 n_write "VOLUME";
c36994199c5e Initial revision
darius
parents:
diff changeset
422 n_getrtn rtn;
c36994199c5e Initial revision
darius
parents:
diff changeset
423
c36994199c5e Initial revision
darius
parents:
diff changeset
424 if {$rtn(code) != 235} {
c36994199c5e Initial revision
darius
parents:
diff changeset
425 set vol "??";
c36994199c5e Initial revision
darius
parents:
diff changeset
426 } else {
c36994199c5e Initial revision
darius
parents:
diff changeset
427 set vol "[lindex [lindex $rtn(lines) 0] 0]";
c36994199c5e Initial revision
darius
parents:
diff changeset
428 }
c36994199c5e Initial revision
darius
parents:
diff changeset
429
c36994199c5e Initial revision
darius
parents:
diff changeset
430 n_write "INFO";
c36994199c5e Initial revision
darius
parents:
diff changeset
431 n_getrtn rtn;
c36994199c5e Initial revision
darius
parents:
diff changeset
432
c36994199c5e Initial revision
darius
parents:
diff changeset
433 if {$rtn(code) == 246} {
c36994199c5e Initial revision
darius
parents:
diff changeset
434 set data [split [lindex $rtn(lines) 0] "\t"];
c36994199c5e Initial revision
darius
parents:
diff changeset
435 set author [lindex $data 4];
c36994199c5e Initial revision
darius
parents:
diff changeset
436 set title [lindex $data 5];
c36994199c5e Initial revision
darius
parents:
diff changeset
437 set length [lindex $data 14];
c36994199c5e Initial revision
darius
parents:
diff changeset
438 set album [lindex $data 3];
c36994199c5e Initial revision
darius
parents:
diff changeset
439 set tnum [lindex $data 15];
c36994199c5e Initial revision
darius
parents:
diff changeset
440 } else {
c36994199c5e Initial revision
darius
parents:
diff changeset
441 set author "N/A";
c36994199c5e Initial revision
darius
parents:
diff changeset
442 set title "N/A";
c36994199c5e Initial revision
darius
parents:
diff changeset
443 set length "N/A";
c36994199c5e Initial revision
darius
parents:
diff changeset
444 set album "N/A";
c36994199c5e Initial revision
darius
parents:
diff changeset
445 set tnum "N/A";
c36994199c5e Initial revision
darius
parents:
diff changeset
446 if {$rtn(code) != 401} {
c36994199c5e Initial revision
darius
parents:
diff changeset
447 log "%s" "Failed to get track info ($rtn(code) $rtn(data))";
c36994199c5e Initial revision
darius
parents:
diff changeset
448 }
c36994199c5e Initial revision
darius
parents:
diff changeset
449 }
c36994199c5e Initial revision
darius
parents:
diff changeset
450
c36994199c5e Initial revision
darius
parents:
diff changeset
451
c36994199c5e Initial revision
darius
parents:
diff changeset
452
c36994199c5e Initial revision
darius
parents:
diff changeset
453 n_write "STATUS";
c36994199c5e Initial revision
darius
parents:
diff changeset
454 n_getrtn rtn;
c36994199c5e Initial revision
darius
parents:
diff changeset
455
c36994199c5e Initial revision
darius
parents:
diff changeset
456 if {$rtn(code) != 222} {
c36994199c5e Initial revision
darius
parents:
diff changeset
457 set left "x:xx";
c36994199c5e Initial revision
darius
parents:
diff changeset
458 set played "x:xx";
c36994199c5e Initial revision
darius
parents:
diff changeset
459 } else {
c36994199c5e Initial revision
darius
parents:
diff changeset
460 set played [lindex [split [lindex $rtn(lines) 0] "\t"] 8];
c36994199c5e Initial revision
darius
parents:
diff changeset
461
c36994199c5e Initial revision
darius
parents:
diff changeset
462 # scan $played "%d:%d" played_m played_s;
c36994199c5e Initial revision
darius
parents:
diff changeset
463 # set played [expr ($played_m * 60) + $played_s];
c36994199c5e Initial revision
darius
parents:
diff changeset
464 # scan $length "%d:%f" len_m len_s;
c36994199c5e Initial revision
darius
parents:
diff changeset
465 # set len [expr ($len_m * 60) + $len_s];
c36994199c5e Initial revision
darius
parents:
diff changeset
466
c36994199c5e Initial revision
darius
parents:
diff changeset
467 # set left [expr $len - $played];
c36994199c5e Initial revision
darius
parents:
diff changeset
468 # set left_m [expr int($left / 60)];
c36994199c5e Initial revision
darius
parents:
diff changeset
469 # set left [format "%02d:%02d" $left_m [expr int($left - ($left_m * 60))]];
c36994199c5e Initial revision
darius
parents:
diff changeset
470 }
c36994199c5e Initial revision
darius
parents:
diff changeset
471
c36994199c5e Initial revision
darius
parents:
diff changeset
472 .top.tinfo.sub.author configure -text "Author: $author";
c36994199c5e Initial revision
darius
parents:
diff changeset
473 .top.tinfo.sub.title configure -text "Title: $title";
c36994199c5e Initial revision
darius
parents:
diff changeset
474 .top.tinfo.sub.length configure -text "Length: $length";
c36994199c5e Initial revision
darius
parents:
diff changeset
475 .top.tinfo.sub.time configure -text "Time: $played";
c36994199c5e Initial revision
darius
parents:
diff changeset
476 .top.tinfo.sub.album configure -text "Album: $album";
c36994199c5e Initial revision
darius
parents:
diff changeset
477 .top.tinfo.sub.trackno configure -text "Misc: $tnum";
c36994199c5e Initial revision
darius
parents:
diff changeset
478 .top.tinfo.sub.vol configure -text "Volume: $vol";
c36994199c5e Initial revision
darius
parents:
diff changeset
479 }
c36994199c5e Initial revision
darius
parents:
diff changeset
480
c36994199c5e Initial revision
darius
parents:
diff changeset
481 proc con_getqueue {queuevar} {
c36994199c5e Initial revision
darius
parents:
diff changeset
482 upvar $queuevar queue;
c36994199c5e Initial revision
darius
parents:
diff changeset
483
c36994199c5e Initial revision
darius
parents:
diff changeset
484 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
485
c36994199c5e Initial revision
darius
parents:
diff changeset
486 catch {unset queue};
c36994199c5e Initial revision
darius
parents:
diff changeset
487
c36994199c5e Initial revision
darius
parents:
diff changeset
488 n_write "QUEUE"
c36994199c5e Initial revision
darius
parents:
diff changeset
489 n_getrtn rtn;
c36994199c5e Initial revision
darius
parents:
diff changeset
490
c36994199c5e Initial revision
darius
parents:
diff changeset
491 if {$rtn(code) == 225} {
c36994199c5e Initial revision
darius
parents:
diff changeset
492 set i 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
493 foreach line $rtn(lines) {
c36994199c5e Initial revision
darius
parents:
diff changeset
494 set foo [split $line \011];
c36994199c5e Initial revision
darius
parents:
diff changeset
495 set id "[lindex $foo 1]:[lindex $foo 2]";
c36994199c5e Initial revision
darius
parents:
diff changeset
496
c36994199c5e Initial revision
darius
parents:
diff changeset
497 set queue($i) $id;
c36994199c5e Initial revision
darius
parents:
diff changeset
498 incr i;
c36994199c5e Initial revision
darius
parents:
diff changeset
499 }
c36994199c5e Initial revision
darius
parents:
diff changeset
500 } elseif {$rtn(code) == 404} {
c36994199c5e Initial revision
darius
parents:
diff changeset
501 log "%s" "Queue empty";
c36994199c5e Initial revision
darius
parents:
diff changeset
502 } else {
c36994199c5e Initial revision
darius
parents:
diff changeset
503 log "%s" "Failed to get queue ($rtn(code) $rtn(data))";
c36994199c5e Initial revision
darius
parents:
diff changeset
504 }
c36994199c5e Initial revision
darius
parents:
diff changeset
505 }
c36994199c5e Initial revision
darius
parents:
diff changeset
506
c36994199c5e Initial revision
darius
parents:
diff changeset
507 proc con_getsongs {songsvar albumsvar} {
c36994199c5e Initial revision
darius
parents:
diff changeset
508 upvar $songsvar songs;
c36994199c5e Initial revision
darius
parents:
diff changeset
509 upvar $albumsvar albums;
c36994199c5e Initial revision
darius
parents:
diff changeset
510
c36994199c5e Initial revision
darius
parents:
diff changeset
511 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
512
c36994199c5e Initial revision
darius
parents:
diff changeset
513 catch { unset songs };
c36994199c5e Initial revision
darius
parents:
diff changeset
514
c36994199c5e Initial revision
darius
parents:
diff changeset
515 foreach i [array names albums "*:"] {
c36994199c5e Initial revision
darius
parents:
diff changeset
516 n_write "TRACKS $albums($i)";
c36994199c5e Initial revision
darius
parents:
diff changeset
517 n_getrtn rtn;
c36994199c5e Initial revision
darius
parents:
diff changeset
518 if {$rtn(code) != "228"} {
c36994199c5e Initial revision
darius
parents:
diff changeset
519 error "Got bogus response to track request ($rtn(code) $rtn(data))";
c36994199c5e Initial revision
darius
parents:
diff changeset
520 }
c36994199c5e Initial revision
darius
parents:
diff changeset
521
c36994199c5e Initial revision
darius
parents:
diff changeset
522 foreach trk $rtn(lines) {
c36994199c5e Initial revision
darius
parents:
diff changeset
523 set foo [split $trk \011];
c36994199c5e Initial revision
darius
parents:
diff changeset
524 if {[llength $foo] != 6} {
c36994199c5e Initial revision
darius
parents:
diff changeset
525 continue;
c36994199c5e Initial revision
darius
parents:
diff changeset
526 }
c36994199c5e Initial revision
darius
parents:
diff changeset
527
c36994199c5e Initial revision
darius
parents:
diff changeset
528 set albid [lindex $foo 0];
c36994199c5e Initial revision
darius
parents:
diff changeset
529 set num [lindex $foo 1]
c36994199c5e Initial revision
darius
parents:
diff changeset
530 set songs($albid:$num:id) "$albid:$num";
c36994199c5e Initial revision
darius
parents:
diff changeset
531 set songs($albid:$num:author) [lindex $foo 2];
c36994199c5e Initial revision
darius
parents:
diff changeset
532 set songs($albid:$num:name) [lindex $foo 3];
c36994199c5e Initial revision
darius
parents:
diff changeset
533 set songs($albid:$num:rating) [lindex $foo 4];
c36994199c5e Initial revision
darius
parents:
diff changeset
534 set songs($albid:$num:length) [lindex $foo 5];
c36994199c5e Initial revision
darius
parents:
diff changeset
535 set songs($albid:$num:albumname) $albums($albid:name);
c36994199c5e Initial revision
darius
parents:
diff changeset
536 }
c36994199c5e Initial revision
darius
parents:
diff changeset
537 }
c36994199c5e Initial revision
darius
parents:
diff changeset
538
c36994199c5e Initial revision
darius
parents:
diff changeset
539 }
c36994199c5e Initial revision
darius
parents:
diff changeset
540
c36994199c5e Initial revision
darius
parents:
diff changeset
541 proc con_getalbums {albumsvar} {
c36994199c5e Initial revision
darius
parents:
diff changeset
542 upvar $albumsvar albums;
c36994199c5e Initial revision
darius
parents:
diff changeset
543
c36994199c5e Initial revision
darius
parents:
diff changeset
544 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
545
c36994199c5e Initial revision
darius
parents:
diff changeset
546 catch {unset albums};
c36994199c5e Initial revision
darius
parents:
diff changeset
547
c36994199c5e Initial revision
darius
parents:
diff changeset
548 n_write "ALBUMS";
c36994199c5e Initial revision
darius
parents:
diff changeset
549 n_getrtn rtn;
c36994199c5e Initial revision
darius
parents:
diff changeset
550 if {$rtn(code) != 227} {
c36994199c5e Initial revision
darius
parents:
diff changeset
551 error "Server gave bogus response to album request ($rtn(code) $rtn(data))";
c36994199c5e Initial revision
darius
parents:
diff changeset
552 }
c36994199c5e Initial revision
darius
parents:
diff changeset
553
c36994199c5e Initial revision
darius
parents:
diff changeset
554 foreach alb $rtn(lines) {
c36994199c5e Initial revision
darius
parents:
diff changeset
555 set foo [split $alb \011];
c36994199c5e Initial revision
darius
parents:
diff changeset
556 set id [lindex $foo 0];
c36994199c5e Initial revision
darius
parents:
diff changeset
557 set albums($id:) [lindex $foo 0];
c36994199c5e Initial revision
darius
parents:
diff changeset
558 set albums($id:author) [lindex $foo 1];
c36994199c5e Initial revision
darius
parents:
diff changeset
559 set albums($id:name) [lindex $foo 2];
c36994199c5e Initial revision
darius
parents:
diff changeset
560
c36994199c5e Initial revision
darius
parents:
diff changeset
561 # log "%s" "Album $i, ID $albums($i:id) called $albums($i:name) by $albums($i:author)";
c36994199c5e Initial revision
darius
parents:
diff changeset
562 }
c36994199c5e Initial revision
darius
parents:
diff changeset
563 }
c36994199c5e Initial revision
darius
parents:
diff changeset
564
c36994199c5e Initial revision
darius
parents:
diff changeset
565 proc update_timer {} {
c36994199c5e Initial revision
darius
parents:
diff changeset
566
c36994199c5e Initial revision
darius
parents:
diff changeset
567 gui_updateinfo;
c36994199c5e Initial revision
darius
parents:
diff changeset
568
c36994199c5e Initial revision
darius
parents:
diff changeset
569 after 900 update_timer;
c36994199c5e Initial revision
darius
parents:
diff changeset
570 }
c36994199c5e Initial revision
darius
parents:
diff changeset
571
c36994199c5e Initial revision
darius
parents:
diff changeset
572 proc con_mserv {} {
c36994199c5e Initial revision
darius
parents:
diff changeset
573 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
574
c36994199c5e Initial revision
darius
parents:
diff changeset
575 # Close old FD
c36994199c5e Initial revision
darius
parents:
diff changeset
576 catch {close state(serv_fd)};
c36994199c5e Initial revision
darius
parents:
diff changeset
577 catch {unset state(serv_fd)};
c36994199c5e Initial revision
darius
parents:
diff changeset
578
c36994199c5e Initial revision
darius
parents:
diff changeset
579 catch {fileevent $state(serv_fd) readable ""};
c36994199c5e Initial revision
darius
parents:
diff changeset
580 set state(serv_fd) [ socket $state(host) $state(port) ];
c36994199c5e Initial revision
darius
parents:
diff changeset
581 set state(pushbuf) "";
c36994199c5e Initial revision
darius
parents:
diff changeset
582 fileevent $state(serv_fd) readable n_rtinput;
c36994199c5e Initial revision
darius
parents:
diff changeset
583 fconfigure $state(serv_fd) -blocking 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
584
c36994199c5e Initial revision
darius
parents:
diff changeset
585 # Greeting from server
c36994199c5e Initial revision
darius
parents:
diff changeset
586 n_getrtn rtn;
c36994199c5e Initial revision
darius
parents:
diff changeset
587 puts $rtn(data);
c36994199c5e Initial revision
darius
parents:
diff changeset
588 if {$rtn(code) != "200"} {
c36994199c5e Initial revision
darius
parents:
diff changeset
589 error "Server failed to send greeting";
c36994199c5e Initial revision
darius
parents:
diff changeset
590 }
c36994199c5e Initial revision
darius
parents:
diff changeset
591
c36994199c5e Initial revision
darius
parents:
diff changeset
592 # Login
c36994199c5e Initial revision
darius
parents:
diff changeset
593 n_write "USER $state(user)"
c36994199c5e Initial revision
darius
parents:
diff changeset
594 n_getrtn rtn;
c36994199c5e Initial revision
darius
parents:
diff changeset
595 if {$rtn(code) != "201"} {
c36994199c5e Initial revision
darius
parents:
diff changeset
596 error "Server failed to send password request";
c36994199c5e Initial revision
darius
parents:
diff changeset
597 }
c36994199c5e Initial revision
darius
parents:
diff changeset
598
c36994199c5e Initial revision
darius
parents:
diff changeset
599 n_write "PASS $state(pass) RTCOMPUTER";
c36994199c5e Initial revision
darius
parents:
diff changeset
600 n_getrtn rtn;
c36994199c5e Initial revision
darius
parents:
diff changeset
601 if {$rtn(code) == "507"} {
c36994199c5e Initial revision
darius
parents:
diff changeset
602 error "Server rejected our credentials";
c36994199c5e Initial revision
darius
parents:
diff changeset
603 }
c36994199c5e Initial revision
darius
parents:
diff changeset
604
c36994199c5e Initial revision
darius
parents:
diff changeset
605 if {$rtn(code) != "202"} {
c36994199c5e Initial revision
darius
parents:
diff changeset
606 error "Unknown response to PASS command - $rtn(code) $rtn(data)"
c36994199c5e Initial revision
darius
parents:
diff changeset
607 }
c36994199c5e Initial revision
darius
parents:
diff changeset
608
c36994199c5e Initial revision
darius
parents:
diff changeset
609 log "%s" "Logged in";
c36994199c5e Initial revision
darius
parents:
diff changeset
610 }
c36994199c5e Initial revision
darius
parents:
diff changeset
611
c36994199c5e Initial revision
darius
parents:
diff changeset
612 proc n_write {text} {
c36994199c5e Initial revision
darius
parents:
diff changeset
613 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
614
c36994199c5e Initial revision
darius
parents:
diff changeset
615 puts $state(serv_fd) $text;
c36994199c5e Initial revision
darius
parents:
diff changeset
616 # log "%s" "Wrote - $text";
c36994199c5e Initial revision
darius
parents:
diff changeset
617
c36994199c5e Initial revision
darius
parents:
diff changeset
618 flush $state(serv_fd);
c36994199c5e Initial revision
darius
parents:
diff changeset
619 }
c36994199c5e Initial revision
darius
parents:
diff changeset
620
c36994199c5e Initial revision
darius
parents:
diff changeset
621 proc n_rthandler {code data} {
c36994199c5e Initial revision
darius
parents:
diff changeset
622 global songs;
c36994199c5e Initial revision
darius
parents:
diff changeset
623
c36994199c5e Initial revision
darius
parents:
diff changeset
624 log "%s" "Got RT - $code $data";
c36994199c5e Initial revision
darius
parents:
diff changeset
625
c36994199c5e Initial revision
darius
parents:
diff changeset
626 switch -- $code {
c36994199c5e Initial revision
darius
parents:
diff changeset
627 600 {
c36994199c5e Initial revision
darius
parents:
diff changeset
628 log "%s" "User '$data' connected";
c36994199c5e Initial revision
darius
parents:
diff changeset
629 }
c36994199c5e Initial revision
darius
parents:
diff changeset
630
c36994199c5e Initial revision
darius
parents:
diff changeset
631 601 {
c36994199c5e Initial revision
darius
parents:
diff changeset
632 log "%s" "User '$data' disconnected";
c36994199c5e Initial revision
darius
parents:
diff changeset
633 }
c36994199c5e Initial revision
darius
parents:
diff changeset
634
c36994199c5e Initial revision
darius
parents:
diff changeset
635 618 -
c36994199c5e Initial revision
darius
parents:
diff changeset
636 619 -
c36994199c5e Initial revision
darius
parents:
diff changeset
637 622 -
c36994199c5e Initial revision
darius
parents:
diff changeset
638 627 -
c36994199c5e Initial revision
darius
parents:
diff changeset
639 623 {
c36994199c5e Initial revision
darius
parents:
diff changeset
640 after idle gui_updatequeue;
c36994199c5e Initial revision
darius
parents:
diff changeset
641 }
c36994199c5e Initial revision
darius
parents:
diff changeset
642 }
c36994199c5e Initial revision
darius
parents:
diff changeset
643 }
c36994199c5e Initial revision
darius
parents:
diff changeset
644
c36994199c5e Initial revision
darius
parents:
diff changeset
645 proc n_rtinput {} {
c36994199c5e Initial revision
darius
parents:
diff changeset
646 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
647
c36994199c5e Initial revision
darius
parents:
diff changeset
648 set rth "";
c36994199c5e Initial revision
darius
parents:
diff changeset
649
c36994199c5e Initial revision
darius
parents:
diff changeset
650 set line [gets $state(serv_fd)];
c36994199c5e Initial revision
darius
parents:
diff changeset
651 # log "%s" "Read - $line";
c36994199c5e Initial revision
darius
parents:
diff changeset
652
c36994199c5e Initial revision
darius
parents:
diff changeset
653 # Check for RT text
c36994199c5e Initial revision
darius
parents:
diff changeset
654 set foo [split $line "\t"];
c36994199c5e Initial revision
darius
parents:
diff changeset
655 if {[string index $line 0] == "="} {
c36994199c5e Initial revision
darius
parents:
diff changeset
656 set rth [list [string range [lindex $foo 0] 1 3] [lrange $foo 1 end]];
c36994199c5e Initial revision
darius
parents:
diff changeset
657 } else {
c36994199c5e Initial revision
darius
parents:
diff changeset
658 lappend state(tmpphrase) $line
c36994199c5e Initial revision
darius
parents:
diff changeset
659 if {$line == "."} {
c36994199c5e Initial revision
darius
parents:
diff changeset
660 set state(pushbuf) [linsert $state(pushbuf) 0 $state(tmpphrase)];
c36994199c5e Initial revision
darius
parents:
diff changeset
661 set state(tmpphrase) "";
c36994199c5e Initial revision
darius
parents:
diff changeset
662 }
c36994199c5e Initial revision
darius
parents:
diff changeset
663 }
c36994199c5e Initial revision
darius
parents:
diff changeset
664
c36994199c5e Initial revision
darius
parents:
diff changeset
665 if {$rth != ""} {
c36994199c5e Initial revision
darius
parents:
diff changeset
666 n_rthandler [lindex $rth 0] [lindex $rth 1];
c36994199c5e Initial revision
darius
parents:
diff changeset
667 }
c36994199c5e Initial revision
darius
parents:
diff changeset
668 }
c36994199c5e Initial revision
darius
parents:
diff changeset
669
c36994199c5e Initial revision
darius
parents:
diff changeset
670 proc n_getrtn {var} {
c36994199c5e Initial revision
darius
parents:
diff changeset
671 upvar $var rtn;
c36994199c5e Initial revision
darius
parents:
diff changeset
672 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
673
c36994199c5e Initial revision
darius
parents:
diff changeset
674 set gotcode 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
675 catch {unset rtn(code)};
c36994199c5e Initial revision
darius
parents:
diff changeset
676 catch {unset rtn(data)};
c36994199c5e Initial revision
darius
parents:
diff changeset
677 catch {unset rtn(lines)}
c36994199c5e Initial revision
darius
parents:
diff changeset
678
c36994199c5e Initial revision
darius
parents:
diff changeset
679 while {[llength $state(pushbuf)] == 0} {
c36994199c5e Initial revision
darius
parents:
diff changeset
680 vwait state(pushbuf);
c36994199c5e Initial revision
darius
parents:
diff changeset
681 }
c36994199c5e Initial revision
darius
parents:
diff changeset
682
c36994199c5e Initial revision
darius
parents:
diff changeset
683 set buf [lindex $state(pushbuf) 0];
c36994199c5e Initial revision
darius
parents:
diff changeset
684 set state(pushbuf) [lrange $state(pushbuf) 1 end];
c36994199c5e Initial revision
darius
parents:
diff changeset
685
c36994199c5e Initial revision
darius
parents:
diff changeset
686 while {1} {
c36994199c5e Initial revision
darius
parents:
diff changeset
687 if {[llength $buf] == 0} {
c36994199c5e Initial revision
darius
parents:
diff changeset
688 break;
c36994199c5e Initial revision
darius
parents:
diff changeset
689 }
c36994199c5e Initial revision
darius
parents:
diff changeset
690
c36994199c5e Initial revision
darius
parents:
diff changeset
691 set line [lindex $buf 0];
c36994199c5e Initial revision
darius
parents:
diff changeset
692 set buf [lrange $buf 1 end];
c36994199c5e Initial revision
darius
parents:
diff changeset
693
c36994199c5e Initial revision
darius
parents:
diff changeset
694 if {[string index $line 0] == "."} {
c36994199c5e Initial revision
darius
parents:
diff changeset
695 break;
c36994199c5e Initial revision
darius
parents:
diff changeset
696 }
c36994199c5e Initial revision
darius
parents:
diff changeset
697
c36994199c5e Initial revision
darius
parents:
diff changeset
698 if {$gotcode == 0} {
c36994199c5e Initial revision
darius
parents:
diff changeset
699 set rtn(code) [string range $line 0 2];
c36994199c5e Initial revision
darius
parents:
diff changeset
700 set rtn(data) [string range $line 4 end];
c36994199c5e Initial revision
darius
parents:
diff changeset
701 set gotcode 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
702 continue;
c36994199c5e Initial revision
darius
parents:
diff changeset
703 }
c36994199c5e Initial revision
darius
parents:
diff changeset
704
c36994199c5e Initial revision
darius
parents:
diff changeset
705 lappend rtn(lines) $line;
c36994199c5e Initial revision
darius
parents:
diff changeset
706 }
c36994199c5e Initial revision
darius
parents:
diff changeset
707
c36994199c5e Initial revision
darius
parents:
diff changeset
708 if {$gotcode == 0} {
c36994199c5e Initial revision
darius
parents:
diff changeset
709 log "%s" "Failed to parse phrase (got . before server responce)";
c36994199c5e Initial revision
darius
parents:
diff changeset
710 }
c36994199c5e Initial revision
darius
parents:
diff changeset
711 }
c36994199c5e Initial revision
darius
parents:
diff changeset
712
c36994199c5e Initial revision
darius
parents:
diff changeset
713 ##################################################################
c36994199c5e Initial revision
darius
parents:
diff changeset
714 # Log a message to stderr
c36994199c5e Initial revision
darius
parents:
diff changeset
715 #
c36994199c5e Initial revision
darius
parents:
diff changeset
716 proc log {format args} {
c36994199c5e Initial revision
darius
parents:
diff changeset
717 # Extract the calling function's name
c36994199c5e Initial revision
darius
parents:
diff changeset
718 set fname [lindex [info level -1] 0];
c36994199c5e Initial revision
darius
parents:
diff changeset
719
c36994199c5e Initial revision
darius
parents:
diff changeset
720 # Evaluate the supplied format string and arguments
c36994199c5e Initial revision
darius
parents:
diff changeset
721 if {[catch {set csm [eval format {$format} $args]} msg]} {
c36994199c5e Initial revision
darius
parents:
diff changeset
722 set csm "bad log message. format='$format' args='$args'";
c36994199c5e Initial revision
darius
parents:
diff changeset
723 }
c36994199c5e Initial revision
darius
parents:
diff changeset
724
c36994199c5e Initial revision
darius
parents:
diff changeset
725 # Emit the message
c36994199c5e Initial revision
darius
parents:
diff changeset
726 puts stderr "[clock format [clock seconds] -format {%y/%m/%d %H:%M:%S} -gmt yes]:$fname: $csm";
c36994199c5e Initial revision
darius
parents:
diff changeset
727 flush stderr;
c36994199c5e Initial revision
darius
parents:
diff changeset
728 }
c36994199c5e Initial revision
darius
parents:
diff changeset
729
c36994199c5e Initial revision
darius
parents:
diff changeset
730 main;