Mercurial > audlegacy
annotate libaudacious/beepctrl.c @ 1105:4be4d74db123 trunk
[svn] automatic character encoding detector for id3 metadata. --enable-chardet enables this feature.
author | yaz |
---|---|
date | Sat, 27 May 2006 11:02:08 -0700 |
parents | bcd1ebd0a7c1 |
children | c70b68bcf527 |
rev | line source |
---|---|
0 | 1 /* XMMS - Cross-platform multimedia player |
2 * Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas, | |
3 * Thomas Nilsson and 4Front Technologies | |
4 * Copyright (C) 1999-2003 Haavard Kvaalen | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
19 */ | |
20 | |
21 #ifdef HAVE_CONFIG_H | |
22 # include "config.h" | |
23 #endif | |
24 | |
25 #include <glib.h> | |
26 #include <sys/types.h> | |
27 #include <sys/stat.h> | |
28 #include <sys/socket.h> | |
29 #include <sys/un.h> | |
30 #include <errno.h> | |
31 #include <stdio.h> | |
32 #include <stdlib.h> | |
33 #include <string.h> | |
34 #include "beepctrl.h" | |
35 #include "audacious/controlsocket.h" | |
36 | |
37 | |
38 #ifdef HAVE_UNISTD_H | |
39 #include <unistd.h> | |
40 #endif | |
41 | |
42 static gint | |
43 read_all(gint fd, gpointer buf, size_t count) | |
44 { | |
45 size_t left = count; | |
46 GTimer *timer; | |
47 gulong usec; | |
48 gint r; | |
49 | |
50 timer = g_timer_new(); | |
51 | |
52 do { | |
53 if ((r = read(fd, buf, left)) < 0) { | |
54 count = -1; | |
55 break; | |
56 } | |
57 left -= r; | |
58 buf = (gchar *) buf + r; | |
59 g_timer_elapsed(timer, &usec); | |
60 } | |
61 while (left > 0 && usec <= CTRLSOCKET_IO_TIMEOUT_USEC); | |
62 | |
63 g_timer_destroy(timer); | |
64 return count - left; | |
65 } | |
66 | |
67 static gint | |
68 write_all(gint fd, gconstpointer buf, size_t count) | |
69 { | |
70 size_t left = count; | |
71 GTimer *timer; | |
72 gulong usec; | |
73 gint written; | |
74 | |
75 timer = g_timer_new(); | |
76 | |
77 do { | |
78 if ((written = write(fd, buf, left)) < 0) { | |
79 count = -1; | |
80 break; | |
81 } | |
82 left -= written; | |
83 buf = (gchar *) buf + written; | |
84 g_timer_elapsed(timer, &usec); | |
85 } | |
86 while (left > 0 && usec <= CTRLSOCKET_IO_TIMEOUT_USEC); | |
87 | |
88 g_timer_destroy(timer); | |
89 return count - left; | |
90 } | |
91 | |
92 static gpointer | |
93 remote_read_packet(gint fd, ServerPktHeader * pkt_hdr) | |
94 { | |
95 gpointer data = NULL; | |
96 | |
97 if (read_all(fd, pkt_hdr, sizeof(ServerPktHeader)) == | |
98 sizeof(ServerPktHeader)) { | |
99 if (pkt_hdr->data_length) { | |
100 size_t data_length = pkt_hdr->data_length; | |
101 data = g_malloc0(data_length); | |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
0
diff
changeset
|
102 if ((size_t)read_all(fd, data, data_length) < data_length) { |
0 | 103 g_free(data); |
104 data = NULL; | |
105 } | |
106 } | |
107 } | |
108 return data; | |
109 } | |
110 | |
111 static void | |
112 remote_read_ack(gint fd) | |
113 { | |
114 gpointer data; | |
115 ServerPktHeader pkt_hdr; | |
116 | |
117 data = remote_read_packet(fd, &pkt_hdr); | |
118 if (data) | |
119 g_free(data); | |
120 | |
121 } | |
122 | |
123 static void | |
124 remote_send_packet(gint fd, guint32 command, gpointer data, | |
125 guint32 data_length) | |
126 { | |
127 ClientPktHeader pkt_hdr; | |
128 | |
129 pkt_hdr.version = XMMS_PROTOCOL_VERSION; | |
130 pkt_hdr.command = command; | |
131 pkt_hdr.data_length = data_length; | |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
0
diff
changeset
|
132 if ((size_t)write_all(fd, &pkt_hdr, sizeof(ClientPktHeader)) < sizeof(pkt_hdr)) |
0 | 133 return; |
134 if (data_length && data) | |
135 write_all(fd, data, data_length); | |
136 } | |
137 | |
138 static void | |
139 remote_send_guint32(gint session, guint32 cmd, guint32 val) | |
140 { | |
141 gint fd; | |
142 | |
143 if ((fd = xmms_connect_to_session(session)) == -1) | |
144 return; | |
145 remote_send_packet(fd, cmd, &val, sizeof(guint32)); | |
146 remote_read_ack(fd); | |
147 close(fd); | |
148 } | |
149 | |
150 static void | |
151 remote_send_boolean(gint session, guint32 cmd, gboolean val) | |
152 { | |
153 gint fd; | |
154 | |
155 if ((fd = xmms_connect_to_session(session)) == -1) | |
156 return; | |
157 remote_send_packet(fd, cmd, &val, sizeof(gboolean)); | |
158 remote_read_ack(fd); | |
159 close(fd); | |
160 } | |
161 | |
162 static void | |
163 remote_send_gfloat(gint session, guint32 cmd, gfloat value) | |
164 { | |
165 gint fd; | |
166 | |
167 if ((fd = xmms_connect_to_session(session)) == -1) | |
168 return; | |
169 remote_send_packet(fd, cmd, &value, sizeof(gfloat)); | |
170 remote_read_ack(fd); | |
171 close(fd); | |
172 } | |
173 | |
174 static void | |
175 remote_send_string(gint session, guint32 cmd, gchar * string) | |
176 { | |
177 gint fd; | |
178 | |
179 if ((fd = xmms_connect_to_session(session)) == -1) | |
180 return; | |
181 remote_send_packet(fd, cmd, string, string ? strlen(string) + 1 : 0); | |
182 remote_read_ack(fd); | |
183 close(fd); | |
184 } | |
185 | |
186 static gboolean | |
187 remote_cmd(gint session, guint32 cmd) | |
188 { | |
189 gint fd; | |
190 | |
191 if ((fd = xmms_connect_to_session(session)) == -1) | |
192 return FALSE; | |
193 remote_send_packet(fd, cmd, NULL, 0); | |
194 remote_read_ack(fd); | |
195 close(fd); | |
196 | |
197 return TRUE; | |
198 } | |
199 | |
200 static gboolean | |
201 remote_get_gboolean(gint session, gint cmd) | |
202 { | |
203 ServerPktHeader pkt_hdr; | |
204 gboolean ret = FALSE; | |
205 gpointer data; | |
206 gint fd; | |
207 | |
208 if ((fd = xmms_connect_to_session(session)) == -1) | |
209 return ret; | |
210 remote_send_packet(fd, cmd, NULL, 0); | |
211 data = remote_read_packet(fd, &pkt_hdr); | |
212 if (data) { | |
213 ret = *((gboolean *) data); | |
214 g_free(data); | |
215 } | |
216 remote_read_ack(fd); | |
217 close(fd); | |
218 | |
219 return ret; | |
220 } | |
221 | |
222 static guint32 | |
223 remote_get_gint(gint session, gint cmd) | |
224 { | |
225 ServerPktHeader pkt_hdr; | |
226 gpointer data; | |
227 gint fd, ret = 0; | |
228 | |
229 if ((fd = xmms_connect_to_session(session)) == -1) | |
230 return ret; | |
231 remote_send_packet(fd, cmd, NULL, 0); | |
232 data = remote_read_packet(fd, &pkt_hdr); | |
233 if (data) { | |
234 ret = *((gint *) data); | |
235 g_free(data); | |
236 } | |
237 remote_read_ack(fd); | |
238 close(fd); | |
239 return ret; | |
240 } | |
241 | |
242 static gfloat | |
243 remote_get_gfloat(gint session, gint cmd) | |
244 { | |
245 ServerPktHeader pkt_hdr; | |
246 gpointer data; | |
247 gint fd; | |
248 gfloat ret = 0.0; | |
249 | |
250 if ((fd = xmms_connect_to_session(session)) == -1) | |
251 return ret; | |
252 remote_send_packet(fd, cmd, NULL, 0); | |
253 data = remote_read_packet(fd, &pkt_hdr); | |
254 if (data) { | |
255 ret = *((gfloat *) data); | |
256 g_free(data); | |
257 } | |
258 remote_read_ack(fd); | |
259 close(fd); | |
260 return ret; | |
261 } | |
262 | |
263 gchar * | |
264 remote_get_string(gint session, gint cmd) | |
265 { | |
266 ServerPktHeader pkt_hdr; | |
267 gpointer data; | |
268 gint fd; | |
269 | |
270 if ((fd = xmms_connect_to_session(session)) == -1) | |
271 return NULL; | |
272 remote_send_packet(fd, cmd, NULL, 0); | |
273 data = remote_read_packet(fd, &pkt_hdr); | |
274 remote_read_ack(fd); | |
275 close(fd); | |
276 return data; | |
277 } | |
278 | |
279 gchar * | |
280 remote_get_string_pos(gint session, gint cmd, guint32 pos) | |
281 { | |
282 ServerPktHeader pkt_hdr; | |
283 gpointer data; | |
284 gint fd; | |
285 | |
286 if ((fd = xmms_connect_to_session(session)) == -1) | |
287 return NULL; | |
288 remote_send_packet(fd, cmd, &pos, sizeof(guint32)); | |
289 data = remote_read_packet(fd, &pkt_hdr); | |
290 remote_read_ack(fd); | |
291 close(fd); | |
292 return data; | |
293 } | |
294 | |
295 gint | |
296 xmms_connect_to_session(gint session) | |
297 { | |
298 gint fd; | |
299 uid_t stored_uid, euid; | |
300 struct sockaddr_un saddr; | |
301 | |
302 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1) { | |
303 saddr.sun_family = AF_UNIX; | |
304 stored_uid = getuid(); | |
305 euid = geteuid(); | |
306 setuid(euid); | |
307 g_snprintf(saddr.sun_path, 108, "%s/%s_%s.%d", g_get_tmp_dir(), | |
308 CTRLSOCKET_NAME, g_get_user_name(), session); | |
309 setreuid(stored_uid, euid); | |
310 if (connect(fd, (struct sockaddr *) &saddr, sizeof(saddr)) != -1) | |
311 return fd; | |
312 } | |
313 close(fd); | |
314 return -1; | |
315 } | |
316 | |
317 void | |
318 xmms_remote_playlist(gint session, gchar ** list, gint num, gboolean enqueue) | |
319 { | |
320 gint fd, i; | |
321 gchar *data, *ptr; | |
322 gint data_length; | |
323 guint32 len; | |
324 | |
325 g_return_if_fail(list != NULL); | |
326 g_return_if_fail(num > 0); | |
327 | |
328 if (!enqueue) | |
329 xmms_remote_playlist_clear(session); | |
330 | |
331 if ((fd = xmms_connect_to_session(session)) == -1) | |
332 return; | |
333 | |
334 for (i = 0, data_length = 0; i < num; i++) | |
335 data_length += (((strlen(list[i]) + 1) + 3) / 4) * 4 + 4; | |
336 if (data_length) { | |
337 data_length += 4; | |
338 data = g_malloc(data_length); | |
339 for (i = 0, ptr = data; i < num; i++) { | |
340 len = strlen(list[i]) + 1; | |
341 *((guint32 *) ptr) = len; | |
342 ptr += 4; | |
343 memcpy(ptr, list[i], len); | |
344 ptr += ((len + 3) / 4) * 4; | |
345 } | |
346 *((guint32 *) ptr) = 0; | |
347 remote_send_packet(fd, CMD_PLAYLIST_ADD, data, data_length); | |
348 remote_read_ack(fd); | |
349 close(fd); | |
350 g_free(data); | |
351 } | |
352 | |
353 if (!enqueue) | |
354 xmms_remote_play(session); | |
355 } | |
356 | |
357 gint | |
358 xmms_remote_get_version(gint session) | |
359 { | |
360 return remote_get_gint(session, CMD_GET_VERSION); | |
361 } | |
362 | |
363 void | |
364 xmms_remote_play_files(gint session, GList * list) | |
365 { | |
366 g_return_if_fail(list != NULL); | |
367 | |
368 xmms_remote_playlist_clear(session); | |
369 xmms_remote_add_files(session, list); | |
370 xmms_remote_play(session); | |
371 } | |
372 | |
373 void | |
374 xmms_remote_playlist_add(gint session, GList * list) | |
375 { | |
376 gchar **str_list; | |
377 GList *node; | |
378 gint i, num; | |
379 | |
380 g_return_if_fail(list != NULL); | |
381 | |
382 num = g_list_length(list); | |
383 str_list = g_malloc0(num * sizeof(gchar *)); | |
384 for (i = 0, node = list; i < num && node; i++, node = g_list_next(node)) | |
385 str_list[i] = node->data; | |
386 | |
387 xmms_remote_playlist(session, str_list, num, TRUE); | |
388 g_free(str_list); | |
389 } | |
390 | |
391 void | |
392 xmms_remote_playlist_delete(gint session, gint pos) | |
393 { | |
394 remote_send_guint32(session, CMD_PLAYLIST_DELETE, pos); | |
395 } | |
396 | |
397 void | |
398 xmms_remote_play(gint session) | |
399 { | |
400 remote_cmd(session, CMD_PLAY); | |
401 } | |
402 | |
403 void | |
404 xmms_remote_pause(gint session) | |
405 { | |
406 remote_cmd(session, CMD_PAUSE); | |
407 } | |
408 | |
409 void | |
410 xmms_remote_stop(gint session) | |
411 { | |
412 remote_cmd(session, CMD_STOP); | |
413 } | |
414 | |
415 void | |
416 xmms_remote_play_pause(gint session) | |
417 { | |
418 remote_cmd(session, CMD_PLAY_PAUSE); | |
419 } | |
420 | |
421 gboolean | |
422 xmms_remote_is_playing(gint session) | |
423 { | |
424 return remote_get_gboolean(session, CMD_IS_PLAYING); | |
425 } | |
426 | |
427 gboolean | |
428 xmms_remote_is_paused(gint session) | |
429 { | |
430 return remote_get_gboolean(session, CMD_IS_PAUSED); | |
431 } | |
432 | |
433 gint | |
434 xmms_remote_get_playlist_pos(gint session) | |
435 { | |
436 return remote_get_gint(session, CMD_GET_PLAYLIST_POS); | |
437 } | |
438 | |
439 void | |
440 xmms_remote_set_playlist_pos(gint session, gint pos) | |
441 { | |
442 remote_send_guint32(session, CMD_SET_PLAYLIST_POS, pos); | |
443 } | |
444 | |
445 gint | |
446 xmms_remote_get_playlist_length(gint session) | |
447 { | |
448 return remote_get_gint(session, CMD_GET_PLAYLIST_LENGTH); | |
449 } | |
450 | |
451 void | |
452 xmms_remote_playlist_clear(gint session) | |
453 { | |
454 remote_cmd(session, CMD_PLAYLIST_CLEAR); | |
455 } | |
456 | |
457 gint | |
458 xmms_remote_get_output_time(gint session) | |
459 { | |
460 return remote_get_gint(session, CMD_GET_OUTPUT_TIME); | |
461 } | |
462 | |
463 void | |
464 xmms_remote_jump_to_time(gint session, gint pos) | |
465 { | |
466 remote_send_guint32(session, CMD_JUMP_TO_TIME, pos); | |
467 } | |
468 | |
469 void | |
470 xmms_remote_get_volume(gint session, gint * vl, gint * vr) | |
471 { | |
472 ServerPktHeader pkt_hdr; | |
473 gint fd; | |
474 gpointer data; | |
475 | |
476 if ((fd = xmms_connect_to_session(session)) == -1) | |
477 return; | |
478 | |
479 remote_send_packet(fd, CMD_GET_VOLUME, NULL, 0); | |
480 data = remote_read_packet(fd, &pkt_hdr); | |
481 if (data) { | |
482 *vl = ((guint32 *) data)[0]; | |
483 *vr = ((guint32 *) data)[1]; | |
484 g_free(data); | |
485 } | |
486 remote_read_ack(fd); | |
487 close(fd); | |
488 } | |
489 | |
490 gint | |
491 xmms_remote_get_main_volume(gint session) | |
492 { | |
493 gint vl, vr; | |
494 | |
495 xmms_remote_get_volume(session, &vl, &vr); | |
496 | |
497 return (vl > vr) ? vl : vr; | |
498 } | |
499 | |
500 gint | |
501 xmms_remote_get_balance(gint session) | |
502 { | |
503 return remote_get_gint(session, CMD_GET_BALANCE); | |
504 } | |
505 | |
506 void | |
507 xmms_remote_set_volume(gint session, gint vl, gint vr) | |
508 { | |
509 gint fd; | |
510 guint32 v[2]; | |
511 | |
512 if (vl < 0) | |
513 vl = 0; | |
514 if (vl > 100) | |
515 vl = 100; | |
516 if (vr < 0) | |
517 vr = 0; | |
518 if (vr > 100) | |
519 vr = 100; | |
520 | |
521 if ((fd = xmms_connect_to_session(session)) == -1) | |
522 return; | |
523 v[0] = vl; | |
524 v[1] = vr; | |
525 remote_send_packet(fd, CMD_SET_VOLUME, v, 2 * sizeof(guint32)); | |
526 remote_read_ack(fd); | |
527 close(fd); | |
528 } | |
529 | |
530 void | |
531 xmms_remote_set_main_volume(gint session, gint v) | |
532 { | |
533 gint b, vl, vr; | |
534 | |
535 b = xmms_remote_get_balance(session); | |
536 | |
537 if (b < 0) { | |
538 vl = v; | |
539 vr = (v * (100 - abs(b))) / 100; | |
540 } | |
541 else if (b > 0) { | |
542 vl = (v * (100 - b)) / 100; | |
543 vr = v; | |
544 } | |
545 else | |
546 vl = vr = v; | |
547 xmms_remote_set_volume(session, vl, vr); | |
548 } | |
549 | |
550 void | |
551 xmms_remote_set_balance(gint session, gint b) | |
552 { | |
553 gint v, vl, vr; | |
554 | |
555 if (b < -100) | |
556 b = -100; | |
557 if (b > 100) | |
558 b = 100; | |
559 | |
560 v = xmms_remote_get_main_volume(session); | |
561 | |
562 if (b < 0) { | |
563 vl = v; | |
564 vr = (v * (100 - abs(b))) / 100; | |
565 } | |
566 else if (b > 0) { | |
567 vl = (v * (100 - b)) / 100; | |
568 vr = v; | |
569 } | |
570 else | |
571 vl = vr = v; | |
572 xmms_remote_set_volume(session, vl, vr); | |
573 } | |
574 | |
575 gchar * | |
576 xmms_remote_get_skin(gint session) | |
577 { | |
578 return remote_get_string(session, CMD_GET_SKIN); | |
579 } | |
580 | |
581 void | |
582 xmms_remote_set_skin(gint session, gchar * skinfile) | |
583 { | |
584 remote_send_string(session, CMD_SET_SKIN, skinfile); | |
585 } | |
586 | |
587 gchar * | |
588 xmms_remote_get_playlist_file(gint session, gint pos) | |
589 { | |
590 return remote_get_string_pos(session, CMD_GET_PLAYLIST_FILE, pos); | |
591 } | |
592 | |
593 gchar * | |
594 xmms_remote_get_playlist_title(gint session, gint pos) | |
595 { | |
596 return remote_get_string_pos(session, CMD_GET_PLAYLIST_TITLE, pos); | |
597 } | |
598 | |
599 gint | |
600 xmms_remote_get_playlist_time(gint session, gint pos) | |
601 { | |
602 ServerPktHeader pkt_hdr; | |
603 gpointer data; | |
604 gint fd, ret = 0; | |
605 guint32 p = pos; | |
606 | |
607 if ((fd = xmms_connect_to_session(session)) == -1) | |
608 return ret; | |
609 remote_send_packet(fd, CMD_GET_PLAYLIST_TIME, &p, sizeof(guint32)); | |
610 data = remote_read_packet(fd, &pkt_hdr); | |
611 if (data) { | |
612 ret = *((gint *) data); | |
613 g_free(data); | |
614 } | |
615 remote_read_ack(fd); | |
616 close(fd); | |
617 return ret; | |
618 } | |
619 | |
620 void | |
621 xmms_remote_get_info(gint session, gint * rate, gint * freq, gint * nch) | |
622 { | |
623 ServerPktHeader pkt_hdr; | |
624 gint fd; | |
625 gpointer data; | |
626 | |
627 if ((fd = xmms_connect_to_session(session)) == -1) | |
628 return; | |
629 remote_send_packet(fd, CMD_GET_INFO, NULL, 0); | |
630 data = remote_read_packet(fd, &pkt_hdr); | |
631 if (data) { | |
632 *rate = ((guint32 *) data)[0]; | |
633 *freq = ((guint32 *) data)[1]; | |
634 *nch = ((guint32 *) data)[2]; | |
635 g_free(data); | |
636 } | |
637 remote_read_ack(fd); | |
638 close(fd); | |
639 } | |
640 | |
641 void | |
642 xmms_remote_get_eq_data(gint session) | |
643 { | |
644 /* Obsolete */ | |
645 } | |
646 | |
647 void | |
648 xmms_remote_set_eq_data(gint session) | |
649 { | |
650 /* Obsolete */ | |
651 } | |
652 | |
653 void | |
654 xmms_remote_pl_win_toggle(gint session, gboolean show) | |
655 { | |
656 remote_send_boolean(session, CMD_PL_WIN_TOGGLE, show); | |
657 } | |
658 | |
659 void | |
660 xmms_remote_eq_win_toggle(gint session, gboolean show) | |
661 { | |
662 remote_send_boolean(session, CMD_EQ_WIN_TOGGLE, show); | |
663 } | |
664 | |
665 void | |
666 xmms_remote_main_win_toggle(gint session, gboolean show) | |
667 { | |
668 remote_send_boolean(session, CMD_MAIN_WIN_TOGGLE, show); | |
669 } | |
670 | |
671 gboolean | |
672 xmms_remote_is_main_win(gint session) | |
673 { | |
674 return remote_get_gboolean(session, CMD_IS_MAIN_WIN); | |
675 } | |
676 | |
677 gboolean | |
678 xmms_remote_is_pl_win(gint session) | |
679 { | |
680 return remote_get_gboolean(session, CMD_IS_PL_WIN); | |
681 } | |
682 | |
683 gboolean | |
684 xmms_remote_is_eq_win(gint session) | |
685 { | |
686 return remote_get_gboolean(session, CMD_IS_EQ_WIN); | |
687 } | |
688 | |
689 void | |
690 xmms_remote_show_prefs_box(gint session) | |
691 { | |
692 remote_cmd(session, CMD_SHOW_PREFS_BOX); | |
693 } | |
694 | |
695 void | |
984 | 696 xmms_remote_show_jtf_box(gint session) |
697 { | |
698 remote_cmd(session, CMD_SHOW_JTF_BOX); | |
699 } | |
700 | |
701 void | |
0 | 702 xmms_remote_toggle_aot(gint session, gboolean ontop) |
703 { | |
704 remote_send_boolean(session, CMD_TOGGLE_AOT, ontop); | |
705 } | |
706 | |
707 void | |
708 xmms_remote_show_about_box(gint session) | |
709 { | |
710 remote_cmd(session, CMD_SHOW_ABOUT_BOX); | |
711 } | |
712 | |
713 void | |
714 xmms_remote_eject(gint session) | |
715 { | |
716 remote_cmd(session, CMD_EJECT); | |
717 } | |
718 | |
719 void | |
720 xmms_remote_playlist_prev(gint session) | |
721 { | |
722 remote_cmd(session, CMD_PLAYLIST_PREV); | |
723 } | |
724 | |
725 void | |
726 xmms_remote_playlist_next(gint session) | |
727 { | |
728 remote_cmd(session, CMD_PLAYLIST_NEXT); | |
729 } | |
730 | |
731 void | |
732 xmms_remote_playlist_add_url_string(gint session, gchar * string) | |
733 { | |
734 g_return_if_fail(string != NULL); | |
735 remote_send_string(session, CMD_PLAYLIST_ADD_URL_STRING, string); | |
736 } | |
737 | |
738 void | |
739 xmms_remote_playlist_ins_url_string(gint session, gchar * string, gint pos) | |
740 { | |
741 gint fd, size; | |
742 gchar *packet; | |
743 | |
744 g_return_if_fail(string != NULL); | |
745 | |
746 size = strlen(string) + 1 + sizeof(gint); | |
747 | |
748 if ((fd = xmms_connect_to_session(session)) == -1) | |
749 return; | |
750 | |
751 packet = g_malloc0(size); | |
752 *((gint *) packet) = pos; | |
753 strcpy(packet + sizeof(gint), string); | |
754 remote_send_packet(fd, CMD_PLAYLIST_INS_URL_STRING, packet, size); | |
755 remote_read_ack(fd); | |
756 close(fd); | |
757 g_free(packet); | |
758 } | |
759 | |
760 gboolean | |
761 xmms_remote_is_running(gint session) | |
762 { | |
763 return remote_cmd(session, CMD_PING); | |
764 } | |
765 | |
766 void | |
767 xmms_remote_toggle_repeat(gint session) | |
768 { | |
769 remote_cmd(session, CMD_TOGGLE_REPEAT); | |
770 } | |
771 | |
772 void | |
773 xmms_remote_toggle_shuffle(gint session) | |
774 { | |
775 remote_cmd(session, CMD_TOGGLE_SHUFFLE); | |
776 } | |
777 | |
778 void | |
779 xmms_remote_toggle_advance(int session) | |
780 { | |
781 remote_cmd(session, CMD_TOGGLE_ADVANCE); | |
782 } | |
783 | |
784 gboolean | |
785 xmms_remote_is_repeat(gint session) | |
786 { | |
787 return remote_get_gboolean(session, CMD_IS_REPEAT); | |
788 } | |
789 | |
790 gboolean | |
791 xmms_remote_is_shuffle(gint session) | |
792 { | |
793 return remote_get_gboolean(session, CMD_IS_SHUFFLE); | |
794 } | |
795 | |
796 gboolean | |
797 xmms_remote_is_advance(gint session) | |
798 { | |
799 return remote_get_gboolean(session, CMD_IS_ADVANCE); | |
800 } | |
801 | |
802 void | |
803 xmms_remote_playqueue_add(gint session, gint pos) | |
804 { | |
805 remote_send_guint32(session, CMD_PLAYQUEUE_ADD, pos); | |
806 } | |
807 | |
808 void | |
809 xmms_remote_playqueue_remove(gint session, gint pos) | |
810 { | |
811 remote_send_guint32(session, CMD_PLAYQUEUE_REMOVE, pos); | |
812 } | |
813 | |
984 | 814 void |
815 xmms_remote_playqueue_clear(gint session) | |
816 { | |
817 remote_cmd(session, CMD_PLAYQUEUE_CLEAR); | |
818 } | |
819 | |
0 | 820 gint |
821 xmms_remote_get_playqueue_length(gint session) | |
822 { | |
823 return remote_get_gint(session, CMD_GET_PLAYQUEUE_LENGTH); | |
824 } | |
825 | |
984 | 826 gboolean |
827 xmms_remote_playqueue_is_queued(gint session, gint pos) | |
828 { | |
829 ServerPktHeader pkt_hdr; | |
830 gpointer data; | |
831 gint fd, ret = 0; | |
832 guint32 p = pos; | |
833 | |
834 if ((fd = xmms_connect_to_session(session)) == -1) | |
835 return ret; | |
836 remote_send_packet(fd, CMD_PLAYQUEUE_IS_QUEUED, &p, sizeof(guint32)); | |
837 data = remote_read_packet(fd, &pkt_hdr); | |
838 if (data) { | |
839 ret = *((gint *) data); | |
840 g_free(data); | |
841 } | |
842 remote_read_ack(fd); | |
843 close(fd); | |
844 return ret; | |
845 } | |
846 | |
847 gint | |
848 xmms_remote_get_playqueue_position(gint session, gint pos) | |
849 { | |
850 ServerPktHeader pkt_hdr; | |
851 gpointer data; | |
852 gint fd, ret = 0; | |
853 guint32 p = pos; | |
854 | |
855 if ((fd = xmms_connect_to_session(session)) == -1) | |
856 return ret; | |
857 remote_send_packet(fd, CMD_PLAYQUEUE_GET_POS, &p, sizeof(guint32)); | |
858 data = remote_read_packet(fd, &pkt_hdr); | |
859 if (data) { | |
860 ret = *((gint *) data); | |
861 g_free(data); | |
862 } | |
863 remote_read_ack(fd); | |
864 close(fd); | |
865 return ret; | |
866 } | |
867 | |
868 gint | |
869 xmms_remote_get_playqueue_queue_position(gint session, gint pos) | |
870 { | |
871 ServerPktHeader pkt_hdr; | |
872 gpointer data; | |
873 gint fd, ret = 0; | |
874 guint32 p = pos; | |
875 | |
876 if ((fd = xmms_connect_to_session(session)) == -1) | |
877 return ret; | |
878 remote_send_packet(fd, CMD_PLAYQUEUE_GET_QPOS, &p, sizeof(guint32)); | |
879 data = remote_read_packet(fd, &pkt_hdr); | |
880 if (data) { | |
881 ret = *((gint *) data); | |
882 g_free(data); | |
883 } | |
884 remote_read_ack(fd); | |
885 close(fd); | |
886 return ret; | |
887 } | |
888 | |
0 | 889 void |
890 xmms_remote_get_eq(gint session, gfloat * preamp, gfloat ** bands) | |
891 { | |
892 ServerPktHeader pkt_hdr; | |
893 gint fd; | |
894 gpointer data; | |
895 | |
896 if (preamp) | |
897 *preamp = 0.0; | |
898 | |
899 if (bands) | |
900 *bands = NULL; | |
901 | |
902 if ((fd = xmms_connect_to_session(session)) == -1) | |
903 return; | |
904 remote_send_packet(fd, CMD_GET_EQ, NULL, 0); | |
905 data = remote_read_packet(fd, &pkt_hdr); | |
906 if (data) { | |
907 if (pkt_hdr.data_length >= 11 * sizeof(gfloat)) { | |
908 if (preamp) | |
909 *preamp = *((gfloat *) data); | |
910 if (bands) | |
911 *bands = | |
912 (gfloat *) g_memdup((gfloat *) data + 1, | |
913 10 * sizeof(gfloat)); | |
914 } | |
915 g_free(data); | |
916 } | |
917 remote_read_ack(fd); | |
918 close(fd); | |
919 } | |
920 | |
921 gfloat | |
922 xmms_remote_get_eq_preamp(gint session) | |
923 { | |
924 return remote_get_gfloat(session, CMD_GET_EQ_PREAMP); | |
925 } | |
926 | |
927 gfloat | |
928 xmms_remote_get_eq_band(gint session, gint band) | |
929 { | |
930 ServerPktHeader pkt_hdr; | |
931 gint fd; | |
932 gpointer data; | |
933 gfloat val = 0.0; | |
934 | |
935 if ((fd = xmms_connect_to_session(session)) == -1) | |
936 return val; | |
937 remote_send_packet(fd, CMD_GET_EQ_BAND, &band, sizeof(band)); | |
938 data = remote_read_packet(fd, &pkt_hdr); | |
939 if (data) { | |
940 val = *((gfloat *) data); | |
941 g_free(data); | |
942 } | |
943 remote_read_ack(fd); | |
944 close(fd); | |
945 return val; | |
946 } | |
947 | |
948 void | |
949 xmms_remote_set_eq(gint session, gfloat preamp, gfloat * bands) | |
950 { | |
951 gint fd, i; | |
952 gfloat data[11]; | |
953 | |
954 g_return_if_fail(bands != NULL); | |
955 | |
956 if ((fd = xmms_connect_to_session(session)) == -1) | |
957 return; | |
958 data[0] = preamp; | |
959 for (i = 0; i < 10; i++) | |
960 data[i + 1] = bands[i]; | |
961 remote_send_packet(fd, CMD_SET_EQ, data, sizeof(data)); | |
962 remote_read_ack(fd); | |
963 close(fd); | |
964 } | |
965 | |
966 void | |
967 xmms_remote_set_eq_preamp(gint session, gfloat preamp) | |
968 { | |
969 remote_send_gfloat(session, CMD_SET_EQ_PREAMP, preamp); | |
970 } | |
971 | |
972 void | |
973 xmms_remote_set_eq_band(gint session, gint band, gfloat value) | |
974 { | |
975 gint fd; | |
976 gchar data[sizeof(gint) + sizeof(gfloat)]; | |
977 | |
978 if ((fd = xmms_connect_to_session(session)) == -1) | |
979 return; | |
980 *((gint *) data) = band; | |
981 *((gfloat *) (data + sizeof(gint))) = value; | |
982 remote_send_packet(fd, CMD_SET_EQ_BAND, data, sizeof(data)); | |
983 remote_read_ack(fd); | |
984 close(fd); | |
985 } | |
986 | |
987 void | |
988 xmms_remote_quit(gint session) | |
989 { | |
990 gint fd; | |
991 | |
992 if ((fd = xmms_connect_to_session(session)) == -1) | |
993 return; | |
994 remote_send_packet(fd, CMD_QUIT, NULL, 0); | |
995 remote_read_ack(fd); | |
996 close(fd); | |
997 } | |
998 | |
999 void | |
1000 xmms_remote_activate(gint session) | |
1001 { | |
1002 gint fd; | |
1003 | |
1004 if ((fd = xmms_connect_to_session(session)) == -1) | |
1005 return; | |
1006 remote_send_packet(fd, CMD_ACTIVATE, NULL, 0); | |
1007 remote_read_ack(fd); | |
1008 close(fd); | |
1009 } |