4 iscmd(char *s, char *cmd)
9 return strncmp(s, cmd, len)==0 && (s[len]=='\0' || s[len]==' ' || s[len]=='\t' || s[len]=='\n');
13 skip(char *s, char *cmd)
16 while(*s==' ' || *s=='\t' || *s=='\n')
21 //#define PLAYSTRING "/^[0-9:]+>"
22 //#define PLAYSTRINGSPACE "/^[0-9:]+> ?"
23 //#define INITSTRING "0:00> "
25 #define INITSTRING "> "
26 #define PLAYSTRING "/^>"
27 #define PLAYSTRINGSPACE "/^> ?"
30 * find the playing string, leave in addr
31 * if q0, q1 are non-nil, set them to the addr of the string.
34 findplay(Window *w, char *s, ulong *q0, ulong *q1)
38 w->data = winopenfile(w, "data");
40 if(!winsetaddr(w, "#0", 1) || !winsetaddr(w, s, 1))
44 if(read(w->addr, xbuf, 24) != 24)
57 * find the playing string and replace the time
60 setplaytime(Window *w, char *new)
66 if(!findplay(w, PLAYSTRING, &q0, &q1))
70 sprint(buf, "#%lud,#%lud", q0, q1);
71 DPRINT(2, "setaddr %s\n", buf);
72 if(!winsetaddr(w, buf, 1))
75 if(write(w->data, new, strlen(new)) != strlen(new))
82 * find the playing string, and remove it.
83 * return the string at the beginning of hte next line in buf
84 * (presumably a track number).
87 unmarkplay(Window *w, char *buf, int n, ulong *q0, ulong *q1, ulong *qbegin)
91 if(!findplay(w, PLAYSTRINGSPACE, q0, q1))
94 if(write(w->data, "", 0) < 0 || !winsetaddr(w, "+1+#0", 1))
99 if(read(w->addr, xbuf, 24) != 24)
101 *qbegin = atoi(xbuf);
105 if((n = read(w->data, buf, n-1)) < 0)
115 markplay(Window *w, ulong q0)
120 w->data = winopenfile(w, "data");
122 sprint(buf, "#%lud", q0);
123 DPRINT(2, "addr %s\n", buf);
124 if(!winsetaddr(w, buf, 1) || !winsetaddr(w, "-0", 1))
126 if(write(w->data, INITSTRING, strlen(INITSTRING)) != strlen(INITSTRING))
131 /* return 1 if handled, 0 otherwise */
133 cdcommand(Window *w, Drive *d, char *s)
142 if(iscmd(s, "Stop")){
143 unmarkplay(w, nil, 0, nil, nil, nil);
147 if(iscmd(s, "Eject")){
148 unmarkplay(w, nil, 0, nil, nil, nil);
152 if(iscmd(s, "Ingest")){
153 unmarkplay(w, nil, 0, nil, nil, nil);
157 if(iscmd(s, "Pause")){
161 if(iscmd(s, "Resume")){
169 drawtoc(Window *w, Drive *d, Toc *t)
174 w->data = winopenfile(w, "data");
175 if(!winsetaddr(w, ",", 1))
178 fprint(w->data, "Title\n\n");
180 if(d->status.state == Splaying || d->status.state == Spaused)
181 playing = d->status.track-t->track0;
183 for(i=0; i<t->ntrack; i++)
184 fprint(w->data, "%s%d/ Track %d\n", i==playing ? "> " : "", i+1, i+1);
189 redrawtoc(Window *w, Toc *t)
195 w->data = winopenfile(w, "data");
197 if(winsetaddr(w, "/Title", 1))
198 write(w->data, t->title, strlen(t->title));
200 for(i=0; i<t->ntrack; i++) {
201 if(t->track[i].title) {
202 sprint(old, "/Track %d", i+1);
203 if(winsetaddr(w, old, 1))
204 write(w->data, t->track[i].title, strlen(t->track[i].title));
210 advancetrack(Drive *d, Window *w)
217 if(!unmarkplay(w, buf, sizeof(buf), &q0, &q1, &qnext)) {
218 DPRINT(2, "unmark: %r\n");
222 DPRINT(2, "buf: %s\n", buf);
223 if(strncmp(buf, "repeat", 6) == 0) {
224 if(!winsetaddr(w, "#0", 1) || !findplay(w, "/^[0-9]+\\/", &qnext, nil)) {
225 DPRINT(2, "set/find: %r\n");
229 w->data = winopenfile(w, "data");
230 if((n = read(w->data, buf, sizeof(buf)-1)) <= 0) {
231 DPRINT(2, "read %d: %r\n", n);
235 DPRINT(2, "buf: %s\n", buf);
238 if((n = atoi(buf)) == 0)
241 if(!markplay(w, qnext))
242 DPRINT(2, "err: %r");
244 playtrack(d, n-1, n-1);
248 acmeevent(Drive *d, Window *w, Event *e)
255 switch(e->c1){ /* origin of action */
258 fprint(2, "unknown message %c%c\n", e->c1, e->c2);
261 case 'E': /* write to body or tag; can't affect us */
264 case 'F': /* generated by our actions; ignore */
267 case 'K': /* type away; we don't care */
270 case 'M': /* mouse event */
271 switch(e->c2){ /* type of action */
272 case 'x': /* mouse: button 2 in tag */
273 case 'X': /* mouse: button 2 in body */
277 if(e->flag & 2){ /* null string with non-null expansion */
278 e2 = recvp(w->cevent);
282 if(e->flag & 8){ /* chorded argument */
283 ea = recvp(w->cevent); /* argument */
285 recvp(w->cevent); /* ignore origin */
289 /* append chorded arguments */
291 t = emalloc(strlen(s)+1+na+1);
292 sprint(t, "%s %s", s, ea->b);
295 /* if it's a known command, do it */
296 /* if it's a long message, it can't be for us anyway */
297 DPRINT(2, "exec: %s\n", s);
298 if(!cdcommand(w, d, s)) /* send it back */
304 case 'l': /* mouse: button 3 in tag */
305 case 'L': /* mouse: button 3 in body */
309 e2 = recvp(w->cevent);
313 if(eq->q1>eq->q0 && eq->nb==0){
314 buf = emalloc((eq->q1-eq->q0)*UTFmax+1);
315 winread(w, eq->q0, eq->q1, buf);
318 DPRINT(2, "load %s\n", s);
319 if((n = atoi(s)) != 0) {
320 DPRINT(2, "mark %d\n", n);
322 unmarkplay(w, nil, 0, &q0, &q1, nil);
324 /* adjust eq->q* for deletion */
329 if(!markplay(w, eq->q0))
330 DPRINT(2, "err: %r\n");
332 playtrack(d, n-1, n-1);
337 case 'i': /* mouse: text inserted in tag */
338 case 'I': /* mouse: text inserted in body */
339 case 'd': /* mouse: text deleted from tag */
340 case 'D': /* mouse: text deleted from body */