Debian Codegraph @

contrib/rplaytool-1.1/rptp.c

raw symbols SCIP
1 /* $Id: rptp.c,v 1.2 1998/08/13 06:13:21 boyns Exp $ */
2
3 /*
4 * Copyright (C) 1995 Mark Boyns <[email protected]>
5 *
6 * This file is part of rplaytool.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "rptp.h"
24 #include "misc.h"
25
26 int rptp_fd = -1;
27 char *rptp_host = 0;
28
29 static void
30 callback (fd, action)
31 int fd;
32 int action;
33 {
34 switch (action)
35 {
36 case RPTP_ASYNC_ENABLE:
37 enable_notify_write (fd);
38 break;
39
40 case RPTP_ASYNC_DISABLE:
41 disable_notify_write (fd);
42 break;
43 }
44 }
45
46 int
47 do_rptp_open (host)
48 char *host;
49 {
50 char rptp_buf[RPTP_MAX_LINE];
51 extern void process_input ();
52
53 if (rptp_fd != -1)
54 {
55 rptp_close (rptp_fd);
56 }
57
58 rptp_fd = rptp_open (host, RPTP_PORT, rptp_buf, sizeof (rptp_buf));
59
60 rptp_async_register (rptp_fd, RPTP_ASYNC_WRITE, callback);
61 #if 0
62 rptp_async_notify (rptp_fd,
63 RPTP_EVENT_PLAY|RPTP_EVENT_PAUSE|RPTP_EVENT_CONTINUE|RPTP_EVENT_DONE
64 |RPTP_EVENT_STATE|RPTP_EVENT_OK|RPTP_EVENT_ERROR|RPTP_EVENT_CLOSE
65 |RPTP_EVENT_OTHER,
66 process_input);
67 #else
68 rptp_async_notify (rptp_fd, RPTP_EVENT_ALL, process_input);
69 #endif
70
71 if (rptp_host)
72 {
73 free (rptp_host);
74 }
75 rptp_host = (char *) strdup (host);
76
77 return 0;
78 }
79
80
81 int
82 do_rptp_pause (id, client_data)
83 int id;
84 char *client_data;
85 {
86 rptp_async_putline (rptp_fd, NULL, "pause id=#%d client-data=\"%d %s\"",
87 id, STATE_PAUSE, client_data);
88
89 return 0;
90 }
91
92
93 int
94 do_rptp_cont (id, client_data)
95 int id;
96 char *client_data;
97 {
98 rptp_async_putline (rptp_fd, NULL, "continue id=#%d client-data=\"%d %s\"",
99 id, STATE_CONTINUE, client_data);
100
101 return 0;
102 }
103
104
105 int
106 do_rptp_stop (id, client_data)
107 int id;
108 char *client_data;
109 {
110 rptp_async_putline (rptp_fd, NULL, "stop id=#%d client-data=\"%d %s\"",
111 id, STATE_STOP, client_data);
112
113 return 0;
114 }
115
116
117 int
118 do_rptp_volume (volume)
119 int volume;
120 {
121 rptp_async_putline (rptp_fd, NULL, "set volume=%d", volume);
122
123 return 0;
124 }
125
126
127 int
128 do_rptp_sounds ()
129 {
130 rptp_async_putline (rptp_fd, NULL, "list sounds");
131
132 return 0;
133 }
134
135
136 int
137 do_rptp_play (sound, client_data, args)
138 char *sound;
139 char *client_data;
140 char *args;
141 {
142 if (client_data)
143 {
144 rptp_async_putline (rptp_fd, NULL, "play client-data=\"%d %s\" %s sound=\"%s\"",
145 STATE_PLAY, client_data,
146 args ? args : "",
147 sound);
148 }
149 else
150 {
151 rptp_async_putline (rptp_fd, NULL, "play %s sound=%s",
152 args ? args : "",
153 sound);
154 }
155
156 return 0;
157 }
158
159
160 int
161 do_rptp_play_info (info, client_data)
162 INFO *info;
163 char *client_data;
164 {
165 char buf[RPTP_MAX_LINE];
166
167 buf[0] = '\0';
168
169 if (info->sample_rate != RPLAY_DEFAULT_SAMPLE_RATE)
170 {
171 sprintf (buf + strlen (buf), "sample-rate=%d ", info->sample_rate);
172 }
173
174 if (info->volume != RPLAY_DEFAULT_VOLUME)
175 {
176 sprintf (buf + strlen (buf), "volume=%d ", info->volume);
177 }
178
179 return do_rptp_play (info->filename, client_data, buf);
180 }