2313
|
1 /* Audacious
|
|
2 * Copyright (C) 2005-2007 Audacious team
|
|
3 *
|
|
4 * XMMS - Cross-platform multimedia player
|
|
5 * Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas,
|
|
6 * Thomas Nilsson and 4Front Technologies
|
|
7 * Copyright (C) 1999-2003 Haavard Kvaalen
|
|
8 *
|
|
9 * This program is free software; you can redistribute it and/or modify
|
|
10 * it under the terms of the GNU General Public License as published by
|
|
11 * the Free Software Foundation; under version 2 of the License.
|
|
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
21 */
|
|
22
|
|
23 #ifdef HAVE_CONFIG_H
|
|
24 # include "config.h"
|
|
25 #endif
|
|
26
|
|
27 #include <glib.h>
|
|
28 #include <sys/types.h>
|
|
29 #include <sys/stat.h>
|
|
30 #include <sys/socket.h>
|
|
31 #include <sys/un.h>
|
|
32 #include <arpa/inet.h>
|
|
33 #include <netdb.h>
|
|
34 #include <errno.h>
|
|
35 #include <stdio.h>
|
|
36 #include <stdlib.h>
|
|
37 #include <string.h>
|
|
38 #include "beepctrl.h"
|
|
39 #include "audacious/controlsocket.h"
|
|
40 #include "libaudacious/configdb.h"
|
|
41
|
|
42 #include <netdb.h>
|
|
43 #include <netinet/in.h>
|
|
44 #include <unistd.h>
|
|
45 #include <grp.h>
|
|
46 #include <sys/time.h>
|
|
47 #include <sys/wait.h>
|
|
48 #include <sys/resource.h>
|
|
49 #include <sys/socket.h>
|
|
50 #include <fcntl.h>
|
|
51 #include <arpa/inet.h>
|
|
52
|
|
53 /* overrides audacious_get_session_uri(). */
|
|
54 gchar *audacious_session_uri = NULL;
|
|
55 gint audacious_session_type = 0;
|
|
56
|
|
57 #ifdef HAVE_UNISTD_H
|
|
58 #include <unistd.h>
|
|
59 #endif
|
|
60
|
|
61 static gpointer
|
|
62 remote_read_packet(gint fd)
|
|
63 {
|
|
64 gpointer data = NULL;
|
|
65 ServerPktHeader pkt_hdr = { 0, 0 };
|
|
66
|
|
67 if (read(fd, &pkt_hdr, sizeof(ServerPktHeader)) ==
|
|
68 sizeof(ServerPktHeader))
|
|
69 {
|
|
70 if (pkt_hdr.version == XMMS_PROTOCOL_VERSION &&
|
|
71 pkt_hdr.data_length > 0)
|
|
72 {
|
|
73 size_t data_length = pkt_hdr.data_length;
|
|
74 data = g_malloc0(data_length);
|
|
75 if ((size_t)read(fd, data, data_length) < data_length)
|
|
76 {
|
|
77 g_free(data);
|
|
78 data = NULL;
|
|
79 }
|
|
80 }
|
|
81 }
|
|
82
|
|
83 return data;
|
|
84 }
|
|
85
|
|
86 static void
|
|
87 remote_read_ack(gint fd)
|
|
88 {
|
|
89 gpointer data;
|
|
90
|
|
91 data = remote_read_packet(fd);
|
|
92 if (data)
|
|
93 g_free(data);
|
|
94
|
|
95 }
|
|
96
|
|
97 static void
|
|
98 remote_send_packet(gint fd, guint32 command, gpointer data,
|
|
99 guint32 data_length)
|
|
100 {
|
|
101 ClientPktHeader pkt_hdr;
|
|
102
|
|
103 memset(&pkt_hdr, '\0', sizeof(ClientPktHeader));
|
|
104
|
|
105 pkt_hdr.version = XMMS_PROTOCOL_VERSION;
|
|
106 pkt_hdr.command = command;
|
|
107 pkt_hdr.data_length = data_length;
|
|
108 if ((size_t)write(fd, &pkt_hdr, sizeof(ClientPktHeader)) < sizeof(pkt_hdr))
|
|
109 return;
|
|
110 if (data_length && data)
|
|
111 write(fd, data, data_length);
|
|
112 }
|
|
113
|
|
114 static void
|
|
115 remote_send_guint32(gint session, guint32 cmd, guint32 val)
|
|
116 {
|
|
117 gint fd;
|
|
118
|
|
119 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
120 return;
|
|
121 remote_send_packet(fd, cmd, &val, sizeof(guint32));
|
|
122 remote_read_ack(fd);
|
|
123 close(fd);
|
|
124 }
|
|
125
|
|
126 static void
|
|
127 remote_send_boolean(gint session, guint32 cmd, gboolean val)
|
|
128 {
|
|
129 gint fd;
|
|
130
|
|
131 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
132 return;
|
|
133 remote_send_packet(fd, cmd, &val, sizeof(gboolean));
|
|
134 remote_read_ack(fd);
|
|
135 close(fd);
|
|
136 }
|
|
137
|
|
138 static void
|
|
139 remote_send_gfloat(gint session, guint32 cmd, gfloat value)
|
|
140 {
|
|
141 gint fd;
|
|
142
|
|
143 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
144 return;
|
|
145 remote_send_packet(fd, cmd, &value, sizeof(gfloat));
|
|
146 remote_read_ack(fd);
|
|
147 close(fd);
|
|
148 }
|
|
149
|
|
150 static void
|
|
151 remote_send_string(gint session, guint32 cmd, gchar * string)
|
|
152 {
|
|
153 gint fd;
|
|
154
|
|
155 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
156 return;
|
|
157 remote_send_packet(fd, cmd, string, string ? strlen(string) + 1 : 0);
|
|
158 remote_read_ack(fd);
|
|
159 close(fd);
|
|
160 }
|
|
161
|
|
162 static gboolean
|
|
163 remote_cmd(gint session, guint32 cmd)
|
|
164 {
|
|
165 gint fd;
|
|
166
|
|
167 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
168 return FALSE;
|
|
169 remote_send_packet(fd, cmd, NULL, 0);
|
|
170 remote_read_ack(fd);
|
|
171 close(fd);
|
|
172
|
|
173 return TRUE;
|
|
174 }
|
|
175
|
|
176 static gboolean
|
|
177 remote_get_gboolean(gint session, gint cmd)
|
|
178 {
|
|
179 gboolean ret = FALSE;
|
|
180 gpointer data;
|
|
181 gint fd;
|
|
182
|
|
183 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
184 return ret;
|
|
185 remote_send_packet(fd, cmd, NULL, 0);
|
|
186 data = remote_read_packet(fd);
|
|
187 if (data) {
|
|
188 ret = *((gboolean *) data);
|
|
189 g_free(data);
|
|
190 }
|
|
191 remote_read_ack(fd);
|
|
192 close(fd);
|
|
193
|
|
194 return ret;
|
|
195 }
|
|
196
|
|
197 static guint32
|
|
198 remote_get_gint(gint session, gint cmd)
|
|
199 {
|
|
200 gpointer data;
|
|
201 gint fd, ret = 0;
|
|
202
|
|
203 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
204 return ret;
|
|
205 remote_send_packet(fd, cmd, NULL, 0);
|
|
206 data = remote_read_packet(fd);
|
|
207 if (data) {
|
|
208 ret = *((gint *) data);
|
|
209 g_free(data);
|
|
210 }
|
|
211 remote_read_ack(fd);
|
|
212 close(fd);
|
|
213 return ret;
|
|
214 }
|
|
215
|
|
216 static gfloat
|
|
217 remote_get_gfloat(gint session, gint cmd)
|
|
218 {
|
|
219 gpointer data;
|
|
220 gint fd;
|
|
221 gfloat ret = 0.0;
|
|
222
|
|
223 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
224 return ret;
|
|
225 remote_send_packet(fd, cmd, NULL, 0);
|
|
226 data = remote_read_packet(fd);
|
|
227 if (data) {
|
|
228 ret = *((gfloat *) data);
|
|
229 g_free(data);
|
|
230 }
|
|
231 remote_read_ack(fd);
|
|
232 close(fd);
|
|
233 return ret;
|
|
234 }
|
|
235
|
|
236 gchar *
|
|
237 remote_get_string(gint session, gint cmd)
|
|
238 {
|
|
239 gpointer data;
|
|
240 gint fd;
|
|
241
|
|
242 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
243 return NULL;
|
|
244 remote_send_packet(fd, cmd, NULL, 0);
|
|
245 data = remote_read_packet(fd);
|
|
246 remote_read_ack(fd);
|
|
247 close(fd);
|
|
248 return data;
|
|
249 }
|
|
250
|
|
251 gchar *
|
|
252 remote_get_string_pos(gint session, gint cmd, guint32 pos)
|
|
253 {
|
|
254 gpointer data;
|
|
255 gint fd;
|
|
256
|
|
257 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
258 return NULL;
|
|
259 remote_send_packet(fd, cmd, &pos, sizeof(guint32));
|
|
260 data = remote_read_packet(fd);
|
|
261 remote_read_ack(fd);
|
|
262 close(fd);
|
|
263 return data;
|
|
264 }
|
|
265
|
|
266 /**
|
|
267 * audacious_set_session_uri:
|
|
268 * @uri: The session URI to set the client API to.
|
|
269 *
|
|
270 * Sets the Session URI where Audacious can be reached at.
|
|
271 **/
|
|
272 void
|
|
273 audacious_set_session_uri(gchar *uri)
|
|
274 {
|
|
275 audacious_session_uri = uri;
|
|
276 }
|
|
277
|
|
278 /**
|
|
279 * audacious_get_session_uri:
|
|
280 * @session: Legacy XMMS session id (usually 0).
|
|
281 *
|
|
282 * Attempts to determine what the Session URI may be.
|
|
283 *
|
|
284 * Return value: A session URI.
|
|
285 **/
|
|
286 gchar *
|
|
287 audacious_get_session_uri(gint session)
|
|
288 {
|
|
289 ConfigDb *db;
|
|
290 gchar *value = NULL;
|
|
291
|
|
292 if (audacious_session_uri != NULL)
|
|
293 {
|
|
294 return g_strdup(audacious_session_uri);
|
|
295 }
|
|
296
|
|
297 if (audacious_session_type != AUDACIOUS_TYPE_UNIX)
|
|
298 {
|
|
299 db = bmp_cfg_db_open();
|
|
300
|
|
301 bmp_cfg_db_get_string(db, NULL, "listen_uri_base", &value);
|
|
302
|
|
303 bmp_cfg_db_close(db);
|
|
304 }
|
|
305
|
|
306 if (value == NULL)
|
|
307 return g_strdup_printf("unix://localhost/%s/%s_%s.%d", g_get_tmp_dir(),
|
|
308 CTRLSOCKET_NAME, g_get_user_name(), session);
|
|
309
|
|
310 audacious_session_uri = value;
|
|
311
|
|
312 return value;
|
|
313 }
|
|
314
|
|
315 /**
|
|
316 * audacious_set_session_type:
|
|
317 * @type: The type to set the session type to.
|
|
318 *
|
|
319 * Sets the type of session used by the audacious server.
|
|
320 **/
|
|
321 void
|
|
322 audacious_set_session_type(gint type)
|
|
323 {
|
|
324 audacious_session_type = type;
|
|
325 }
|
|
326
|
|
327 /**
|
|
328 * audacious_determine_session_type:
|
|
329 * @session: Legacy XMMS session id (usually 0).
|
|
330 *
|
|
331 * Attempts to determine what the session type may be.
|
|
332 **/
|
|
333 gint
|
|
334 audacious_determine_session_type(gint session)
|
|
335 {
|
|
336 gchar *uri = NULL;
|
|
337
|
|
338 if (audacious_session_type != 0)
|
|
339 {
|
|
340 return audacious_session_type;
|
|
341 }
|
|
342
|
|
343 uri = audacious_get_session_uri(session);
|
|
344
|
|
345 if (!g_strncasecmp(uri, "tcp://", 6))
|
|
346 audacious_session_type = AUDACIOUS_TYPE_TCP;
|
|
347 else
|
|
348 audacious_session_type = AUDACIOUS_TYPE_UNIX;
|
|
349
|
|
350 if (audacious_session_type == 0)
|
|
351 audacious_session_type = AUDACIOUS_TYPE_UNIX;
|
|
352
|
|
353 /* memory leak! */
|
|
354 g_free(uri);
|
|
355
|
|
356 return audacious_session_type;
|
|
357 }
|
|
358
|
|
359 /* tcp://192.168.100.1:5900/zyzychynxi389xvmfewqaxznvnw */
|
|
360
|
|
361 /**
|
|
362 * audacious_decode_tcp_uri:
|
|
363 * @session: The legacy XMMS session id (usually 0).
|
|
364 * @in: A TCP:// Session URI to decode.
|
|
365 * @host: Pointer to a host buffer.
|
|
366 * @port: Pointer to the TCP port.
|
|
367 * @key: Pointer to a security key buffer.
|
|
368 *
|
|
369 * Decodes a tcp:// session URI.
|
|
370 **/
|
|
371 void
|
|
372 audacious_decode_tcp_uri(gint session, gchar *in, gchar **host, gint *port, gchar **key)
|
|
373 {
|
|
374 static gchar *workbuf, *keybuf;
|
|
375 gint iport;
|
|
376 gchar *tmp = g_strdup(in);
|
|
377
|
|
378 /* split out the host/port and key */
|
|
379 workbuf = tmp;
|
|
380 workbuf += 6;
|
|
381
|
|
382 keybuf = strchr(workbuf, '/');
|
|
383 *keybuf++ = '\0';
|
|
384
|
|
385 *key = g_strdup(keybuf);
|
|
386
|
|
387 if (strchr(workbuf, ':') == NULL)
|
|
388 {
|
|
389 *host = g_strdup(workbuf);
|
|
390 *port = 37370 + session;
|
|
391 }
|
|
392 else
|
|
393 {
|
|
394 gchar *hostbuf = NULL;
|
|
395 sscanf(workbuf, "%s:%d", hostbuf, &iport);
|
|
396
|
|
397 *port = iport + session;
|
|
398 }
|
|
399
|
|
400 g_free(tmp);
|
|
401 }
|
|
402
|
|
403 /* unix://localhost/tmp/audacious_nenolod.0 */
|
|
404
|
|
405 /**
|
|
406 * audacious_decode_unix_uri:
|
|
407 * @session: The legacy XMMS session id (usually 0).
|
|
408 * @in: A UNIX:// Session URI to decode.
|
|
409 * @key: Pointer to a UNIX path buffer.
|
|
410 *
|
|
411 * Decodes a unix:// session URI.
|
|
412 **/
|
|
413 void
|
|
414 audacious_decode_unix_uri(gint session, gchar *in, gchar **key)
|
|
415 {
|
|
416 static gchar *workbuf, *keybuf;
|
|
417 gchar *tmp = g_strdup(in);
|
|
418
|
|
419 /* split out the host/port and key */
|
|
420 workbuf = tmp;
|
|
421 workbuf += 7;
|
|
422
|
|
423 keybuf = strchr(workbuf, '/');
|
|
424 *keybuf++ = '\0';
|
|
425
|
|
426 *key = g_strdup(keybuf);
|
|
427
|
|
428 g_free(tmp);
|
|
429 }
|
|
430
|
|
431 /**
|
|
432 * xmms_connect_to_session:
|
|
433 * @session: Legacy XMMS-style session identifier.
|
|
434 *
|
|
435 * Connects to an audacious server.
|
|
436 *
|
|
437 * Return value: an FD on success, otherwise -1.
|
|
438 **/
|
|
439 gint
|
|
440 xmms_connect_to_session(gint session)
|
|
441 {
|
|
442 gint fd;
|
|
443 gint type = audacious_determine_session_type(session);
|
|
444 gchar *uri = audacious_get_session_uri(session);
|
|
445
|
|
446 if (type == AUDACIOUS_TYPE_UNIX)
|
|
447 {
|
|
448 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1)
|
|
449 {
|
|
450 uid_t stored_uid, euid;
|
|
451 struct sockaddr_un saddr;
|
|
452 gchar *path;
|
|
453
|
|
454 saddr.sun_family = AF_UNIX;
|
|
455 stored_uid = getuid();
|
|
456 euid = geteuid();
|
|
457 setuid(euid);
|
|
458
|
|
459 audacious_decode_unix_uri(session, uri, &path);
|
|
460
|
|
461 g_strlcpy(saddr.sun_path, path, 108);
|
|
462 g_free(path);
|
|
463 setreuid(stored_uid, euid);
|
|
464
|
|
465 g_free(uri);
|
|
466
|
|
467 if (connect(fd, (struct sockaddr *) &saddr, sizeof(saddr)) != -1)
|
|
468 return fd;
|
|
469 }
|
|
470 }
|
|
471 else
|
|
472 {
|
|
473 if ((fd = socket(AF_INET, SOCK_STREAM, 0)) != -1)
|
|
474 {
|
|
475 struct hostent *hp;
|
|
476 struct sockaddr_in saddr;
|
|
477 gchar *host, *key;
|
|
478 gint port;
|
|
479
|
|
480 audacious_decode_tcp_uri(session, uri, &host, &port, &key);
|
|
481
|
|
482 /* resolve it */
|
|
483 if ((hp = gethostbyname(host)) == NULL)
|
|
484 {
|
|
485 close(fd);
|
|
486 return -1;
|
|
487 }
|
|
488
|
|
489 memset(&saddr, '\0', sizeof(saddr));
|
|
490 saddr.sin_family = AF_INET;
|
|
491 saddr.sin_port = htons(port);
|
|
492 memcpy(&saddr.sin_addr, hp->h_addr, hp->h_length);
|
|
493
|
|
494 g_free(host);
|
|
495 g_free(key);
|
|
496
|
|
497 g_free(uri);
|
|
498
|
|
499 if (connect(fd, (struct sockaddr *) &saddr, sizeof(saddr)) != -1)
|
|
500 return fd;
|
|
501 }
|
|
502 }
|
|
503
|
|
504 close(fd);
|
|
505 return -1;
|
|
506 }
|
|
507
|
|
508 /**
|
|
509 * xmms_remote_playlist:
|
|
510 * @session: Legacy XMMS-style session identifier.
|
|
511 * @list: A list of URIs to play.
|
|
512 * @num: Number of URIs to play.
|
|
513 * @enqueue: Whether or not the new playlist should be added on, or replace the current playlist.
|
|
514 *
|
|
515 * Sends a playlist to audacious.
|
|
516 **/
|
|
517 void
|
|
518 xmms_remote_playlist(gint session, gchar ** list, gint num, gboolean enqueue)
|
|
519 {
|
|
520 gint fd, i;
|
|
521 gchar *data, *ptr;
|
|
522 gint data_length;
|
|
523 guint32 len;
|
|
524
|
|
525 g_return_if_fail(list != NULL);
|
|
526 g_return_if_fail(num > 0);
|
|
527
|
|
528 if (!enqueue)
|
|
529 xmms_remote_playlist_clear(session);
|
|
530
|
|
531 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
532 return;
|
|
533
|
|
534 for (i = 0, data_length = 0; i < num; i++)
|
|
535 data_length += (((strlen(list[i]) + 1) + 3) / 4) * 4 + 4;
|
|
536 if (data_length) {
|
|
537 data_length += 4;
|
|
538 data = g_malloc(data_length);
|
|
539 for (i = 0, ptr = data; i < num; i++) {
|
|
540 len = strlen(list[i]) + 1;
|
|
541 *((guint32 *) ptr) = len;
|
|
542 ptr += 4;
|
|
543 memcpy(ptr, list[i], len);
|
|
544 ptr += ((len + 3) / 4) * 4;
|
|
545 }
|
|
546 *((guint32 *) ptr) = 0;
|
|
547 remote_send_packet(fd, CMD_PLAYLIST_ADD, data, data_length);
|
|
548 remote_read_ack(fd);
|
|
549 close(fd);
|
|
550 g_free(data);
|
|
551 }
|
|
552
|
|
553 if (!enqueue)
|
|
554 xmms_remote_play(session);
|
|
555 }
|
|
556
|
|
557 /**
|
|
558 * xmms_remote_get_version:
|
|
559 * @session: Legacy XMMS-style session identifier.
|
|
560 *
|
|
561 * Queries audacious for it's protocol version.
|
|
562 *
|
|
563 * Return value: The protocol version used by Audacious.
|
|
564 **/
|
|
565 gint
|
|
566 xmms_remote_get_version(gint session)
|
|
567 {
|
|
568 return remote_get_gint(session, CMD_GET_VERSION);
|
|
569 }
|
|
570
|
|
571 /**
|
|
572 * xmms_remote_play_files:
|
|
573 * @session: Legacy XMMS-style session identifier.
|
|
574 * @list: A GList of URIs to play.
|
|
575 *
|
|
576 * Sends a list of URIs to Audacious to play.
|
|
577 **/
|
|
578 void
|
|
579 xmms_remote_play_files(gint session, GList * list)
|
|
580 {
|
|
581 g_return_if_fail(list != NULL);
|
|
582
|
|
583 xmms_remote_playlist_clear(session);
|
|
584 xmms_remote_playlist_add(session, list);
|
|
585 xmms_remote_play(session);
|
|
586 }
|
|
587
|
|
588 /**
|
|
589 * xmms_remote_playlist_add:
|
|
590 * @session: Legacy XMMS-style session identifier.
|
|
591 * @list: A GList of URIs to add to the playlist.
|
|
592 *
|
|
593 * Sends a list of URIs to Audacious to add to the playlist.
|
|
594 **/
|
|
595 void
|
|
596 xmms_remote_playlist_add(gint session, GList * list)
|
|
597 {
|
|
598 gchar **str_list;
|
|
599 GList *node;
|
|
600 gint i, num;
|
|
601
|
|
602 g_return_if_fail(list != NULL);
|
|
603
|
|
604 num = g_list_length(list);
|
|
605 str_list = g_malloc0(num * sizeof(gchar *));
|
|
606 for (i = 0, node = list; i < num && node; i++, node = g_list_next(node))
|
|
607 str_list[i] = node->data;
|
|
608
|
|
609 xmms_remote_playlist(session, str_list, num, TRUE);
|
|
610 g_free(str_list);
|
|
611 }
|
|
612
|
|
613 /**
|
|
614 * xmms_remote_playlist_delete:
|
|
615 * @session: Legacy XMMS-style session identifier.
|
|
616 * @pos: The playlist position to delete.
|
|
617 *
|
|
618 * Deletes a playlist entry.
|
|
619 **/
|
|
620 void
|
|
621 xmms_remote_playlist_delete(gint session, gint pos)
|
|
622 {
|
|
623 remote_send_guint32(session, CMD_PLAYLIST_DELETE, pos);
|
|
624 }
|
|
625
|
|
626 /**
|
|
627 * xmms_remote_play:
|
|
628 * @session: Legacy XMMS-style session identifier.
|
|
629 *
|
|
630 * Tells audacious to begin playback.
|
|
631 **/
|
|
632 void
|
|
633 xmms_remote_play(gint session)
|
|
634 {
|
|
635 remote_cmd(session, CMD_PLAY);
|
|
636 }
|
|
637
|
|
638 /**
|
|
639 * xmms_remote_pause:
|
|
640 * @session: Legacy XMMS-style session identifier.
|
|
641 *
|
|
642 * Tells audacious to pause.
|
|
643 **/
|
|
644 void
|
|
645 xmms_remote_pause(gint session)
|
|
646 {
|
|
647 remote_cmd(session, CMD_PAUSE);
|
|
648 }
|
|
649
|
|
650 /**
|
|
651 * xmms_remote_stop:
|
|
652 * @session: Legacy XMMS-style session identifier.
|
|
653 *
|
|
654 * Tells audacious to stop.
|
|
655 **/
|
|
656 void
|
|
657 xmms_remote_stop(gint session)
|
|
658 {
|
|
659 remote_cmd(session, CMD_STOP);
|
|
660 }
|
|
661
|
|
662 /**
|
|
663 * xmms_remote_play_pause:
|
|
664 * @session: Legacy XMMS-style session identifier.
|
|
665 *
|
|
666 * Tells audacious to either play or pause.
|
|
667 **/
|
|
668 void
|
|
669 xmms_remote_play_pause(gint session)
|
|
670 {
|
|
671 remote_cmd(session, CMD_PLAY_PAUSE);
|
|
672 }
|
|
673
|
|
674 /**
|
|
675 * xmms_remote_is_playing:
|
|
676 * @session: Legacy XMMS-style session identifier.
|
|
677 *
|
|
678 * Queries audacious about whether it is playing or not.
|
|
679 *
|
|
680 * Return value: TRUE if playing, FALSE otherwise.
|
|
681 **/
|
|
682 gboolean
|
|
683 xmms_remote_is_playing(gint session)
|
|
684 {
|
|
685 return remote_get_gboolean(session, CMD_IS_PLAYING);
|
|
686 }
|
|
687
|
|
688 /**
|
|
689 * xmms_remote_is_paused:
|
|
690 * @session: Legacy XMMS-style session identifier.
|
|
691 *
|
|
692 * Queries audacious about whether it is paused or not.
|
|
693 *
|
|
694 * Return value: TRUE if playing, FALSE otherwise.
|
|
695 **/
|
|
696 gboolean
|
|
697 xmms_remote_is_paused(gint session)
|
|
698 {
|
|
699 return remote_get_gboolean(session, CMD_IS_PAUSED);
|
|
700 }
|
|
701
|
|
702 /**
|
|
703 * xmms_remote_get_playlist_pos:
|
|
704 * @session: Legacy XMMS-style session identifier.
|
|
705 *
|
|
706 * Queries audacious about the current playlist position.
|
|
707 *
|
|
708 * Return value: The current playlist position.
|
|
709 **/
|
|
710 gint
|
|
711 xmms_remote_get_playlist_pos(gint session)
|
|
712 {
|
|
713 return remote_get_gint(session, CMD_GET_PLAYLIST_POS);
|
|
714 }
|
|
715
|
|
716 /**
|
|
717 * xmms_remote_set_playlist_pos:
|
|
718 * @session: Legacy XMMS-style session identifier.
|
|
719 * @pos: Playlist position to jump to.
|
|
720 *
|
|
721 * Tells audacious to jump to a different playlist position.
|
|
722 **/
|
|
723 void
|
|
724 xmms_remote_set_playlist_pos(gint session, gint pos)
|
|
725 {
|
|
726 remote_send_guint32(session, CMD_SET_PLAYLIST_POS, pos);
|
|
727 }
|
|
728
|
|
729 /**
|
|
730 * xmms_remote_get_playlist_length:
|
|
731 * @session: Legacy XMMS-style session identifier.
|
|
732 *
|
|
733 * Queries audacious about the current playlist length.
|
|
734 *
|
|
735 * Return value: The amount of entries in the playlist.
|
|
736 **/
|
|
737 gint
|
|
738 xmms_remote_get_playlist_length(gint session)
|
|
739 {
|
|
740 return remote_get_gint(session, CMD_GET_PLAYLIST_LENGTH);
|
|
741 }
|
|
742
|
|
743 /**
|
|
744 * xmms_remote_playlist_clear:
|
|
745 * @session: Legacy XMMS-style session identifier.
|
|
746 *
|
|
747 * Clears the playlist.
|
|
748 **/
|
|
749 void
|
|
750 xmms_remote_playlist_clear(gint session)
|
|
751 {
|
|
752 remote_cmd(session, CMD_PLAYLIST_CLEAR);
|
|
753 }
|
|
754
|
|
755 /**
|
|
756 * xmms_remote_get_output_time:
|
|
757 * @session: Legacy XMMS-style session identifier.
|
|
758 *
|
|
759 * Queries audacious about the current output position.
|
|
760 *
|
|
761 * Return value: The current output position.
|
|
762 **/
|
|
763 gint
|
|
764 xmms_remote_get_output_time(gint session)
|
|
765 {
|
|
766 return remote_get_gint(session, CMD_GET_OUTPUT_TIME);
|
|
767 }
|
|
768
|
|
769 /**
|
|
770 * xmms_remote_jump_to_time:
|
|
771 * @session: Legacy XMMS-style session identifier.
|
|
772 * @pos: The time (in milliseconds) to jump to.
|
|
773 *
|
|
774 * Tells audacious to seek to a new time position.
|
|
775 **/
|
|
776 void
|
|
777 xmms_remote_jump_to_time(gint session, gint pos)
|
|
778 {
|
|
779 remote_send_guint32(session, CMD_JUMP_TO_TIME, pos);
|
|
780 }
|
|
781
|
|
782 /**
|
|
783 * xmms_remote_get_volume:
|
|
784 * @session: Legacy XMMS-style session identifier.
|
|
785 * @vl: Pointer to integer containing the left channel's volume.
|
|
786 * @vr: Pointer to integer containing the right channel's volume.
|
|
787 *
|
|
788 * Queries audacious about the current volume.
|
|
789 **/
|
|
790 void
|
|
791 xmms_remote_get_volume(gint session, gint * vl, gint * vr)
|
|
792 {
|
|
793 gint fd;
|
|
794 gpointer data;
|
|
795
|
|
796 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
797 return;
|
|
798
|
|
799 remote_send_packet(fd, CMD_GET_VOLUME, NULL, 0);
|
|
800 data = remote_read_packet(fd);
|
|
801 if (data) {
|
|
802 *vl = ((guint32 *) data)[0];
|
|
803 *vr = ((guint32 *) data)[1];
|
|
804 g_free(data);
|
|
805 }
|
|
806 remote_read_ack(fd);
|
|
807 close(fd);
|
|
808 }
|
|
809
|
|
810 /**
|
|
811 * xmms_remote_get_main_volume:
|
|
812 * @session: Legacy XMMS-style session identifier.
|
|
813 *
|
|
814 * Queries audacious about the current volume.
|
|
815 *
|
|
816 * Return value: The current volume.
|
|
817 **/
|
|
818 gint
|
|
819 xmms_remote_get_main_volume(gint session)
|
|
820 {
|
|
821 gint vl, vr;
|
|
822
|
|
823 xmms_remote_get_volume(session, &vl, &vr);
|
|
824
|
|
825 return (vl > vr) ? vl : vr;
|
|
826 }
|
|
827
|
|
828 /**
|
|
829 * xmms_remote_get_balance:
|
|
830 * @session: Legacy XMMS-style session identifier.
|
|
831 *
|
|
832 * Queries audacious about the current balance.
|
|
833 *
|
|
834 * Return value: The current balance.
|
|
835 **/
|
|
836 gint
|
|
837 xmms_remote_get_balance(gint session)
|
|
838 {
|
|
839 return remote_get_gint(session, CMD_GET_BALANCE);
|
|
840 }
|
|
841
|
|
842 /**
|
|
843 * xmms_remote_set_volume:
|
|
844 * @session: Legacy XMMS-style session identifier.
|
|
845 * @vl: The volume for the left channel.
|
|
846 * @vr: The volume for the right channel.
|
|
847 *
|
|
848 * Sets the volume for the left and right channels in Audacious.
|
|
849 **/
|
|
850 void
|
|
851 xmms_remote_set_volume(gint session, gint vl, gint vr)
|
|
852 {
|
|
853 gint fd;
|
|
854 guint32 v[2];
|
|
855
|
|
856 if (vl < 0)
|
|
857 vl = 0;
|
|
858 if (vl > 100)
|
|
859 vl = 100;
|
|
860 if (vr < 0)
|
|
861 vr = 0;
|
|
862 if (vr > 100)
|
|
863 vr = 100;
|
|
864
|
|
865 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
866 return;
|
|
867 v[0] = vl;
|
|
868 v[1] = vr;
|
|
869 remote_send_packet(fd, CMD_SET_VOLUME, v, 2 * sizeof(guint32));
|
|
870 remote_read_ack(fd);
|
|
871 close(fd);
|
|
872 }
|
|
873
|
|
874 /**
|
|
875 * xmms_remote_set_main_volume:
|
|
876 * @session: Legacy XMMS-style session identifier.
|
|
877 * @v: The volume to set.
|
|
878 *
|
|
879 * Sets the volume in Audacious.
|
|
880 **/
|
|
881 void
|
|
882 xmms_remote_set_main_volume(gint session, gint v)
|
|
883 {
|
|
884 gint b, vl, vr;
|
|
885
|
|
886 b = xmms_remote_get_balance(session);
|
|
887
|
|
888 if (b < 0) {
|
|
889 vl = v;
|
|
890 vr = (v * (100 - abs(b))) / 100;
|
|
891 }
|
|
892 else if (b > 0) {
|
|
893 vl = (v * (100 - b)) / 100;
|
|
894 vr = v;
|
|
895 }
|
|
896 else
|
|
897 vl = vr = v;
|
|
898 xmms_remote_set_volume(session, vl, vr);
|
|
899 }
|
|
900
|
|
901 /**
|
|
902 * xmms_remote_set_balance:
|
|
903 * @session: Legacy XMMS-style session identifier.
|
|
904 * @b: The balance to set.
|
|
905 *
|
|
906 * Sets the balance in Audacious.
|
|
907 **/
|
|
908 void
|
|
909 xmms_remote_set_balance(gint session, gint b)
|
|
910 {
|
|
911 gint v, vl, vr;
|
|
912
|
|
913 if (b < -100)
|
|
914 b = -100;
|
|
915 if (b > 100)
|
|
916 b = 100;
|
|
917
|
|
918 v = xmms_remote_get_main_volume(session);
|
|
919
|
|
920 if (b < 0) {
|
|
921 vl = v;
|
|
922 vr = (v * (100 - abs(b))) / 100;
|
|
923 }
|
|
924 else if (b > 0) {
|
|
925 vl = (v * (100 - b)) / 100;
|
|
926 vr = v;
|
|
927 }
|
|
928 else
|
|
929 vl = vr = v;
|
|
930 xmms_remote_set_volume(session, vl, vr);
|
|
931 }
|
|
932
|
|
933 /**
|
|
934 * xmms_remote_get_skin:
|
|
935 * @session: Legacy XMMS-style session identifier.
|
|
936 *
|
|
937 * Queries Audacious about it's skin.
|
|
938 *
|
|
939 * Return value: A path to the currently selected skin.
|
|
940 **/
|
|
941 gchar *
|
|
942 xmms_remote_get_skin(gint session)
|
|
943 {
|
|
944 return remote_get_string(session, CMD_GET_SKIN);
|
|
945 }
|
|
946
|
|
947 /**
|
|
948 * xmms_remote_set_skin:
|
|
949 * @session: Legacy XMMS-style session identifier.
|
|
950 * @skinfile: Path to a skinfile to use with Audacious.
|
|
951 *
|
|
952 * Tells audacious to start using the skinfile provided.
|
|
953 **/
|
|
954 void
|
|
955 xmms_remote_set_skin(gint session, gchar * skinfile)
|
|
956 {
|
|
957 remote_send_string(session, CMD_SET_SKIN, skinfile);
|
|
958 }
|
|
959
|
|
960 /**
|
|
961 * xmms_remote_get_playlist_file:
|
|
962 * @session: Legacy XMMS-style session identifier.
|
|
963 * @pos: The playlist position to query for.
|
|
964 *
|
|
965 * Queries Audacious about a playlist entry's file.
|
|
966 *
|
|
967 * Return value: A path to the file in the playlist at %pos position.
|
|
968 **/
|
|
969 gchar *
|
|
970 xmms_remote_get_playlist_file(gint session, gint pos)
|
|
971 {
|
|
972 return remote_get_string_pos(session, CMD_GET_PLAYLIST_FILE, pos);
|
|
973 }
|
|
974
|
|
975 /**
|
|
976 * xmms_remote_get_playlist_title:
|
|
977 * @session: Legacy XMMS-style session identifier.
|
|
978 * @pos: The playlist position to query for.
|
|
979 *
|
|
980 * Queries Audacious about a playlist entry's title.
|
|
981 *
|
|
982 * Return value: The title for the entry in the playlist at %pos position.
|
|
983 **/
|
|
984 gchar *
|
|
985 xmms_remote_get_playlist_title(gint session, gint pos)
|
|
986 {
|
|
987 return remote_get_string_pos(session, CMD_GET_PLAYLIST_TITLE, pos);
|
|
988 }
|
|
989
|
|
990 /**
|
|
991 * xmms_remote_get_playlist_time:
|
|
992 * @session: Legacy XMMS-style session identifier.
|
|
993 * @pos: The playlist position to query for.
|
|
994 *
|
|
995 * Queries Audacious about a playlist entry's length.
|
|
996 *
|
|
997 * Return value: The length of the entry in the playlist at %pos position.
|
|
998 **/
|
|
999 gint
|
|
1000 xmms_remote_get_playlist_time(gint session, gint pos)
|
|
1001 {
|
|
1002 gpointer data;
|
|
1003 gint fd, ret = 0;
|
|
1004 guint32 p = pos;
|
|
1005
|
|
1006 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
1007 return ret;
|
|
1008 remote_send_packet(fd, CMD_GET_PLAYLIST_TIME, &p, sizeof(guint32));
|
|
1009 data = remote_read_packet(fd);
|
|
1010 if (data) {
|
|
1011 ret = *((gint *) data);
|
|
1012 g_free(data);
|
|
1013 }
|
|
1014 remote_read_ack(fd);
|
|
1015 close(fd);
|
|
1016 return ret;
|
|
1017 }
|
|
1018
|
|
1019 /**
|
|
1020 * xmms_remote_get_info:
|
|
1021 * @session: Legacy XMMS-style session identifier.
|
|
1022 * @rate: Pointer to an integer containing the bitrate.
|
|
1023 * @freq: Pointer to an integer containing the frequency.
|
|
1024 * @nch: Pointer to an integer containing the number of channels.
|
|
1025 *
|
|
1026 * Queries Audacious about the current audio format.
|
|
1027 **/
|
|
1028 void
|
|
1029 xmms_remote_get_info(gint session, gint * rate, gint * freq, gint * nch)
|
|
1030 {
|
|
1031 gint fd;
|
|
1032 gpointer data;
|
|
1033
|
|
1034 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
1035 return;
|
|
1036 remote_send_packet(fd, CMD_GET_INFO, NULL, 0);
|
|
1037 data = remote_read_packet(fd);
|
|
1038 if (data) {
|
|
1039 *rate = ((guint32 *) data)[0];
|
|
1040 *freq = ((guint32 *) data)[1];
|
|
1041 *nch = ((guint32 *) data)[2];
|
|
1042 g_free(data);
|
|
1043 }
|
|
1044 remote_read_ack(fd);
|
|
1045 close(fd);
|
|
1046 }
|
|
1047
|
|
1048 /**
|
|
1049 * xmms_remote_get_eq_data:
|
|
1050 * @session: Legacy XMMS-style session identifier.
|
|
1051 *
|
|
1052 * Not implemented, present for compatibility with libxmms API.
|
|
1053 **/
|
|
1054 void
|
|
1055 xmms_remote_get_eq_data(gint session)
|
|
1056 {
|
|
1057 /* Obsolete */
|
|
1058 }
|
|
1059
|
|
1060 /**
|
|
1061 * xmms_remote_set_eq_data:
|
|
1062 * @session: Legacy XMMS-style session identifier.
|
|
1063 *
|
|
1064 * Not implemented, present for compatibility with libxmms API.
|
|
1065 **/
|
|
1066 void
|
|
1067 xmms_remote_set_eq_data(gint session)
|
|
1068 {
|
|
1069 /* Obsolete */
|
|
1070 }
|
|
1071
|
|
1072 /**
|
|
1073 * xmms_remote_pl_win_toggle:
|
|
1074 * @session: Legacy XMMS-style session identifier.
|
|
1075 * @show: Whether or not to show the playlist window.
|
|
1076 *
|
|
1077 * Toggles the playlist window's visibility.
|
|
1078 **/
|
|
1079 void
|
|
1080 xmms_remote_pl_win_toggle(gint session, gboolean show)
|
|
1081 {
|
|
1082 remote_send_boolean(session, CMD_PL_WIN_TOGGLE, show);
|
|
1083 }
|
|
1084
|
|
1085 /**
|
|
1086 * xmms_remote_eq_win_toggle:
|
|
1087 * @session: Legacy XMMS-style session identifier.
|
|
1088 * @show: Whether or not to show the equalizer window.
|
|
1089 *
|
|
1090 * Toggles the equalizer window's visibility.
|
|
1091 **/
|
|
1092 void
|
|
1093 xmms_remote_eq_win_toggle(gint session, gboolean show)
|
|
1094 {
|
|
1095 remote_send_boolean(session, CMD_EQ_WIN_TOGGLE, show);
|
|
1096 }
|
|
1097
|
|
1098 /**
|
|
1099 * xmms_remote_main_win_toggle:
|
|
1100 * @session: Legacy XMMS-style session identifier.
|
|
1101 * @show: Whether or not to show the main window.
|
|
1102 *
|
|
1103 * Toggles the main window's visibility.
|
|
1104 **/
|
|
1105 void
|
|
1106 xmms_remote_main_win_toggle(gint session, gboolean show)
|
|
1107 {
|
|
1108 remote_send_boolean(session, CMD_MAIN_WIN_TOGGLE, show);
|
|
1109 }
|
|
1110
|
|
1111 /**
|
|
1112 * xmms_remote_is_main_win:
|
|
1113 * @session: Legacy XMMS-style session identifier.
|
|
1114 *
|
|
1115 * Queries Audacious about the main window's visibility.
|
|
1116 *
|
|
1117 * Return value: TRUE if visible, FALSE otherwise.
|
|
1118 **/
|
|
1119 gboolean
|
|
1120 xmms_remote_is_main_win(gint session)
|
|
1121 {
|
|
1122 return remote_get_gboolean(session, CMD_IS_MAIN_WIN);
|
|
1123 }
|
|
1124
|
|
1125 /**
|
|
1126 * xmms_remote_is_pl_win:
|
|
1127 * @session: Legacy XMMS-style session identifier.
|
|
1128 *
|
|
1129 * Queries Audacious about the playlist window's visibility.
|
|
1130 *
|
|
1131 * Return value: TRUE if visible, FALSE otherwise.
|
|
1132 **/
|
|
1133 gboolean
|
|
1134 xmms_remote_is_pl_win(gint session)
|
|
1135 {
|
|
1136 return remote_get_gboolean(session, CMD_IS_PL_WIN);
|
|
1137 }
|
|
1138
|
|
1139 /**
|
|
1140 * xmms_remote_is_eq_win:
|
|
1141 * @session: Legacy XMMS-style session identifier.
|
|
1142 *
|
|
1143 * Queries Audacious about the equalizer window's visibility.
|
|
1144 *
|
|
1145 * Return value: TRUE if visible, FALSE otherwise.
|
|
1146 **/
|
|
1147 gboolean
|
|
1148 xmms_remote_is_eq_win(gint session)
|
|
1149 {
|
|
1150 return remote_get_gboolean(session, CMD_IS_EQ_WIN);
|
|
1151 }
|
|
1152
|
|
1153 /**
|
|
1154 * xmms_remote_show_prefs_box:
|
|
1155 * @session: Legacy XMMS-style session identifier.
|
|
1156 *
|
|
1157 * Tells audacious to show the preferences pane.
|
|
1158 **/
|
|
1159 void
|
|
1160 xmms_remote_show_prefs_box(gint session)
|
|
1161 {
|
|
1162 remote_cmd(session, CMD_SHOW_PREFS_BOX);
|
|
1163 }
|
|
1164
|
|
1165 /**
|
|
1166 * xmms_remote_show_jtf_box:
|
|
1167 * @session: Legacy XMMS-style session identifier.
|
|
1168 *
|
|
1169 * Tells audacious to show the Jump-to-File pane.
|
|
1170 **/
|
|
1171 void
|
|
1172 xmms_remote_show_jtf_box(gint session)
|
|
1173 {
|
|
1174 remote_cmd(session, CMD_SHOW_JTF_BOX);
|
|
1175 }
|
|
1176
|
|
1177 /**
|
|
1178 * xmms_remote_toggle_aot:
|
|
1179 * @session: Legacy XMMS-style session identifier.
|
|
1180 * @ontop: Whether or not Audacious should be always-on-top.
|
|
1181 *
|
|
1182 * Tells audacious to toggle the always-on-top feature.
|
|
1183 **/
|
|
1184 void
|
|
1185 xmms_remote_toggle_aot(gint session, gboolean ontop)
|
|
1186 {
|
|
1187 remote_send_boolean(session, CMD_TOGGLE_AOT, ontop);
|
|
1188 }
|
|
1189
|
|
1190 /**
|
|
1191 * xmms_remote_show_about_box:
|
|
1192 * @session: Legacy XMMS-style session identifier.
|
|
1193 *
|
|
1194 * Tells audacious to show the about pane.
|
|
1195 **/
|
|
1196 void
|
|
1197 xmms_remote_show_about_box(gint session)
|
|
1198 {
|
|
1199 remote_cmd(session, CMD_SHOW_ABOUT_BOX);
|
|
1200 }
|
|
1201
|
|
1202 /**
|
|
1203 * xmms_remote_eject:
|
|
1204 * @session: Legacy XMMS-style session identifier.
|
|
1205 *
|
|
1206 * Tells audacious to display the open files pane.
|
|
1207 **/
|
|
1208 void
|
|
1209 xmms_remote_eject(gint session)
|
|
1210 {
|
|
1211 remote_cmd(session, CMD_EJECT);
|
|
1212 }
|
|
1213
|
|
1214 /**
|
|
1215 * xmms_remote_playlist_prev:
|
|
1216 * @session: Legacy XMMS-style session identifier.
|
|
1217 *
|
|
1218 * Tells audacious to move backwards in the playlist.
|
|
1219 **/
|
|
1220 void
|
|
1221 xmms_remote_playlist_prev(gint session)
|
|
1222 {
|
|
1223 remote_cmd(session, CMD_PLAYLIST_PREV);
|
|
1224 }
|
|
1225
|
|
1226 /**
|
|
1227 * xmms_remote_playlist_next:
|
|
1228 * @session: Legacy XMMS-style session identifier.
|
|
1229 *
|
|
1230 * Tells audacious to move forward in the playlist.
|
|
1231 **/
|
|
1232 void
|
|
1233 xmms_remote_playlist_next(gint session)
|
|
1234 {
|
|
1235 remote_cmd(session, CMD_PLAYLIST_NEXT);
|
|
1236 }
|
|
1237
|
|
1238 /**
|
|
1239 * xmms_remote_playlist_add_url_string:
|
|
1240 * @session: Legacy XMMS-style session identifier.
|
|
1241 * @string: The URI to add.
|
|
1242 *
|
|
1243 * Tells audacious to add an URI to the playlist.
|
|
1244 **/
|
|
1245 void
|
|
1246 xmms_remote_playlist_add_url_string(gint session, gchar * string)
|
|
1247 {
|
|
1248 g_return_if_fail(string != NULL);
|
|
1249 remote_send_string(session, CMD_PLAYLIST_ADD_URL_STRING, string);
|
|
1250 }
|
|
1251
|
|
1252 /**
|
|
1253 * xmms_remote_playlist_enqueue_to_temp:
|
|
1254 * @session: Legacy XMMS-style session identifier.
|
|
1255 * @string: The URI to enqueue to a temporary playlist.
|
|
1256 *
|
|
1257 * Tells audacious to add an URI to a temporary playlist.
|
|
1258 **/
|
|
1259 void
|
|
1260 xmms_remote_playlist_enqueue_to_temp(gint session, gchar * string)
|
|
1261 {
|
|
1262 g_return_if_fail(string != NULL);
|
|
1263 remote_send_string(session, CMD_PLAYLIST_ENQUEUE_TO_TEMP, string);
|
|
1264 }
|
|
1265
|
|
1266 /**
|
|
1267 * xmms_remote_playlist_ins_url_string:
|
|
1268 * @session: Legacy XMMS-style session identifier.
|
|
1269 * @string: The URI to add.
|
|
1270 * @pos: The position to add the URI at.
|
|
1271 *
|
|
1272 * Tells audacious to add an URI to the playlist at a specific position.
|
|
1273 **/
|
|
1274 void
|
|
1275 xmms_remote_playlist_ins_url_string(gint session, gchar * string, gint pos)
|
|
1276 {
|
|
1277 gint fd, size;
|
|
1278 gchar *packet;
|
|
1279
|
|
1280 g_return_if_fail(string != NULL);
|
|
1281
|
|
1282 size = strlen(string) + 1 + sizeof(gint);
|
|
1283
|
|
1284 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
1285 return;
|
|
1286
|
|
1287 packet = g_malloc0(size);
|
|
1288 *((gint *) packet) = pos;
|
|
1289 strcpy(packet + sizeof(gint), string);
|
|
1290 remote_send_packet(fd, CMD_PLAYLIST_INS_URL_STRING, packet, size);
|
|
1291 remote_read_ack(fd);
|
|
1292 close(fd);
|
|
1293 g_free(packet);
|
|
1294 }
|
|
1295
|
|
1296 /**
|
|
1297 * xmms_remote_is_running:
|
|
1298 * @session: Legacy XMMS-style session identifier.
|
|
1299 *
|
|
1300 * Checks to see if an Audacious server is running.
|
|
1301 *
|
|
1302 * Return value: TRUE if yes, otherwise FALSE.
|
|
1303 **/
|
|
1304 gboolean
|
|
1305 xmms_remote_is_running(gint session)
|
|
1306 {
|
|
1307 return remote_cmd(session, CMD_PING);
|
|
1308 }
|
|
1309
|
|
1310 /**
|
|
1311 * xmms_remote_toggle_repeat:
|
|
1312 * @session: Legacy XMMS-style session identifier.
|
|
1313 *
|
|
1314 * Tells audacious to toggle the repeat feature.
|
|
1315 **/
|
|
1316 void
|
|
1317 xmms_remote_toggle_repeat(gint session)
|
|
1318 {
|
|
1319 remote_cmd(session, CMD_TOGGLE_REPEAT);
|
|
1320 }
|
|
1321
|
|
1322 /**
|
|
1323 * xmms_remote_toggle_shuffle:
|
|
1324 * @session: Legacy XMMS-style session identifier.
|
|
1325 *
|
|
1326 * Tells audacious to toggle the shuffle feature.
|
|
1327 **/
|
|
1328 void
|
|
1329 xmms_remote_toggle_shuffle(gint session)
|
|
1330 {
|
|
1331 remote_cmd(session, CMD_TOGGLE_SHUFFLE);
|
|
1332 }
|
|
1333
|
|
1334 /**
|
|
1335 * xmms_remote_toggle_advance:
|
|
1336 * @session: Legacy XMMS-style session identifier.
|
|
1337 *
|
|
1338 * Tells audacious to toggle the no-playlist-advance feature.
|
|
1339 **/
|
|
1340 void
|
|
1341 xmms_remote_toggle_advance(int session)
|
|
1342 {
|
|
1343 remote_cmd(session, CMD_TOGGLE_ADVANCE);
|
|
1344 }
|
|
1345
|
|
1346 /**
|
|
1347 * xmms_remote_is_repeat:
|
|
1348 * @session: Legacy XMMS-style session identifier.
|
|
1349 *
|
|
1350 * Queries audacious about whether or not the repeat feature is active.
|
|
1351 *
|
|
1352 * Return value: TRUE if yes, otherwise FALSE.
|
|
1353 **/
|
|
1354 gboolean
|
|
1355 xmms_remote_is_repeat(gint session)
|
|
1356 {
|
|
1357 return remote_get_gboolean(session, CMD_IS_REPEAT);
|
|
1358 }
|
|
1359
|
|
1360 /**
|
|
1361 * xmms_remote_is_shuffle:
|
|
1362 * @session: Legacy XMMS-style session identifier.
|
|
1363 *
|
|
1364 * Queries audacious about whether or not the shuffle feature is active.
|
|
1365 *
|
|
1366 * Return value: TRUE if yes, otherwise FALSE.
|
|
1367 **/
|
|
1368 gboolean
|
|
1369 xmms_remote_is_shuffle(gint session)
|
|
1370 {
|
|
1371 return remote_get_gboolean(session, CMD_IS_SHUFFLE);
|
|
1372 }
|
|
1373
|
|
1374 /**
|
|
1375 * xmms_remote_is_advance:
|
|
1376 * @session: Legacy XMMS-style session identifier.
|
|
1377 *
|
|
1378 * Queries audacious about whether or not the no-playlist-advance feature is active.
|
|
1379 *
|
|
1380 * Return value: TRUE if yes, otherwise FALSE.
|
|
1381 **/
|
|
1382 gboolean
|
|
1383 xmms_remote_is_advance(gint session)
|
|
1384 {
|
|
1385 return remote_get_gboolean(session, CMD_IS_ADVANCE);
|
|
1386 }
|
|
1387
|
|
1388 /**
|
|
1389 * xmms_remote_playqueue_add:
|
|
1390 * @session: Legacy XMMS-style session identifier.
|
|
1391 * @pos: The playlist position to add to the queue.
|
|
1392 *
|
|
1393 * Tells audacious to add a playlist entry to the playqueue.
|
|
1394 **/
|
|
1395 void
|
|
1396 xmms_remote_playqueue_add(gint session, gint pos)
|
|
1397 {
|
|
1398 remote_send_guint32(session, CMD_PLAYQUEUE_ADD, pos);
|
|
1399 }
|
|
1400
|
|
1401 /**
|
|
1402 * xmms_remote_playqueue_remove:
|
|
1403 * @session: Legacy XMMS-style session identifier.
|
|
1404 * @pos: The playlist position to remove from the queue.
|
|
1405 *
|
|
1406 * Tells audacious to remove a playlist entry from the playqueue.
|
|
1407 **/
|
|
1408 void
|
|
1409 xmms_remote_playqueue_remove(gint session, gint pos)
|
|
1410 {
|
|
1411 remote_send_guint32(session, CMD_PLAYQUEUE_REMOVE, pos);
|
|
1412 }
|
|
1413
|
|
1414 /**
|
|
1415 * xmms_remote_playqueue_clear:
|
|
1416 * @session: Legacy XMMS-style session identifier.
|
|
1417 *
|
|
1418 * Tells audacious to clear the playqueue.
|
|
1419 **/
|
|
1420 void
|
|
1421 xmms_remote_playqueue_clear(gint session)
|
|
1422 {
|
|
1423 remote_cmd(session, CMD_PLAYQUEUE_CLEAR);
|
|
1424 }
|
|
1425
|
|
1426 /**
|
|
1427 * xmms_remote_get_playqueue_length:
|
|
1428 * @session: Legacy XMMS-style session identifier.
|
|
1429 *
|
|
1430 * Queries audacious about the playqueue's length.
|
|
1431 *
|
|
1432 * Return value: The number of entries in the playqueue.
|
|
1433 **/
|
|
1434 gint
|
|
1435 xmms_remote_get_playqueue_length(gint session)
|
|
1436 {
|
|
1437 return remote_get_gint(session, CMD_GET_PLAYQUEUE_LENGTH);
|
|
1438 }
|
|
1439
|
|
1440 /**
|
|
1441 * xmms_remote_playqueue_is_queued:
|
|
1442 * @session: Legacy XMMS-style session identifier.
|
|
1443 * @pos: Position to check queue for.
|
|
1444 *
|
|
1445 * Queries audacious about whether or not a playlist entry is in the playqueue.
|
|
1446 *
|
|
1447 * Return value: TRUE if yes, FALSE otherwise.
|
|
1448 **/
|
|
1449 gboolean
|
|
1450 xmms_remote_playqueue_is_queued(gint session, gint pos)
|
|
1451 {
|
|
1452 gpointer data;
|
|
1453 gint fd, ret = 0;
|
|
1454 guint32 p = pos;
|
|
1455
|
|
1456 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
1457 return ret;
|
|
1458 remote_send_packet(fd, CMD_PLAYQUEUE_IS_QUEUED, &p, sizeof(guint32));
|
|
1459 data = remote_read_packet(fd);
|
|
1460 if (data) {
|
|
1461 ret = *((gint *) data);
|
|
1462 g_free(data);
|
|
1463 }
|
|
1464 remote_read_ack(fd);
|
|
1465 close(fd);
|
|
1466 return ret;
|
|
1467 }
|
|
1468
|
|
1469 /**
|
|
1470 * xmms_remote_get_playqueue_position:
|
|
1471 * @session: Legacy XMMS-style session identifier.
|
|
1472 * @pos: Position to check queue for.
|
|
1473 *
|
|
1474 * Queries audacious about what the playqueue position is for a playlist entry.
|
|
1475 *
|
|
1476 * Return value: TRUE if yes, FALSE otherwise.
|
|
1477 **/
|
|
1478 gint
|
|
1479 xmms_remote_get_playqueue_position(gint session, gint pos)
|
|
1480 {
|
|
1481 gpointer data;
|
|
1482 gint fd, ret = 0;
|
|
1483 guint32 p = pos;
|
|
1484
|
|
1485 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
1486 return ret;
|
|
1487 remote_send_packet(fd, CMD_PLAYQUEUE_GET_POS, &p, sizeof(guint32));
|
|
1488 data = remote_read_packet(fd);
|
|
1489 if (data) {
|
|
1490 ret = *((gint *) data);
|
|
1491 g_free(data);
|
|
1492 }
|
|
1493 remote_read_ack(fd);
|
|
1494 close(fd);
|
|
1495 return ret;
|
|
1496 }
|
|
1497
|
|
1498 /**
|
|
1499 * xmms_remote_get_playqueue_queue_position:
|
|
1500 * @session: Legacy XMMS-style session identifier.
|
|
1501 * @pos: Position to check queue for.
|
|
1502 *
|
|
1503 * Queries audacious about what the playlist position is for a playqueue entry.
|
|
1504 *
|
|
1505 * Return value: TRUE if yes, FALSE otherwise.
|
|
1506 **/
|
|
1507 gint
|
|
1508 xmms_remote_get_playqueue_queue_position(gint session, gint pos)
|
|
1509 {
|
|
1510 gpointer data;
|
|
1511 gint fd, ret = 0;
|
|
1512 guint32 p = pos;
|
|
1513
|
|
1514 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
1515 return ret;
|
|
1516 remote_send_packet(fd, CMD_PLAYQUEUE_GET_QPOS, &p, sizeof(guint32));
|
|
1517 data = remote_read_packet(fd);
|
|
1518 if (data) {
|
|
1519 ret = *((gint *) data);
|
|
1520 g_free(data);
|
|
1521 }
|
|
1522 remote_read_ack(fd);
|
|
1523 close(fd);
|
|
1524 return ret;
|
|
1525 }
|
|
1526
|
|
1527 /**
|
|
1528 * xmms_remote_get_eq:
|
|
1529 * @session: Legacy XMMS-style session identifier.
|
|
1530 * @preamp: Pointer to value for preamp setting.
|
|
1531 * @bands: Pointer to array of band settings.
|
|
1532 *
|
|
1533 * Queries audacious about the equalizer settings.
|
|
1534 **/
|
|
1535 void
|
|
1536 xmms_remote_get_eq(gint session, gfloat * preamp, gfloat ** bands)
|
|
1537 {
|
|
1538 gint fd;
|
|
1539 gpointer data;
|
|
1540
|
|
1541 if (preamp)
|
|
1542 *preamp = 0.0;
|
|
1543
|
|
1544 if (bands)
|
|
1545 *bands = NULL;
|
|
1546
|
|
1547 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
1548 return;
|
|
1549 remote_send_packet(fd, CMD_GET_EQ, NULL, 0);
|
|
1550 data = remote_read_packet(fd);
|
|
1551 if (data) {
|
|
1552 if (preamp)
|
|
1553 *preamp = *((gfloat *) data);
|
|
1554 if (bands)
|
|
1555 *bands =
|
|
1556 (gfloat *) g_memdup((gfloat *) data + 1,
|
|
1557 10 * sizeof(gfloat));
|
|
1558 g_free(data);
|
|
1559 }
|
|
1560 remote_read_ack(fd);
|
|
1561 close(fd);
|
|
1562 }
|
|
1563
|
|
1564 /**
|
|
1565 * xmms_remote_get_eq_preamp:
|
|
1566 * @session: Legacy XMMS-style session identifier.
|
|
1567 *
|
|
1568 * Queries audacious about the equalizer preamp's setting.
|
|
1569 *
|
|
1570 * Return value: The equalizer preamp's setting.
|
|
1571 **/
|
|
1572 gfloat
|
|
1573 xmms_remote_get_eq_preamp(gint session)
|
|
1574 {
|
|
1575 return remote_get_gfloat(session, CMD_GET_EQ_PREAMP);
|
|
1576 }
|
|
1577
|
|
1578 /**
|
|
1579 * xmms_remote_get_eq_band:
|
|
1580 * @session: Legacy XMMS-style session identifier.
|
|
1581 * @band: Which band to lookup the value for.
|
|
1582 *
|
|
1583 * Queries audacious about an equalizer band's value.
|
|
1584 *
|
|
1585 * Return value: The equalizer band's value.
|
|
1586 **/
|
|
1587 gfloat
|
|
1588 xmms_remote_get_eq_band(gint session, gint band)
|
|
1589 {
|
|
1590 gint fd;
|
|
1591 gpointer data;
|
|
1592 gfloat val = 0.0;
|
|
1593
|
|
1594 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
1595 return val;
|
|
1596 remote_send_packet(fd, CMD_GET_EQ_BAND, &band, sizeof(band));
|
|
1597 data = remote_read_packet(fd);
|
|
1598 if (data) {
|
|
1599 val = *((gfloat *) data);
|
|
1600 g_free(data);
|
|
1601 }
|
|
1602 remote_read_ack(fd);
|
|
1603 close(fd);
|
|
1604 return val;
|
|
1605 }
|
|
1606
|
|
1607 /**
|
|
1608 * xmms_remote_set_eq:
|
|
1609 * @session: Legacy XMMS-style session identifier.
|
|
1610 * @preamp: Value for preamp setting.
|
|
1611 * @bands: Array of band settings.
|
|
1612 *
|
|
1613 * Tells audacious to set the equalizer up using the provided values.
|
|
1614 **/
|
|
1615 void
|
|
1616 xmms_remote_set_eq(gint session, gfloat preamp, gfloat * bands)
|
|
1617 {
|
|
1618 gint fd, i;
|
|
1619 gfloat data[11];
|
|
1620
|
|
1621 g_return_if_fail(bands != NULL);
|
|
1622
|
|
1623 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
1624 return;
|
|
1625 data[0] = preamp;
|
|
1626 for (i = 0; i < 10; i++)
|
|
1627 data[i + 1] = bands[i];
|
|
1628 remote_send_packet(fd, CMD_SET_EQ, data, sizeof(data));
|
|
1629 remote_read_ack(fd);
|
|
1630 close(fd);
|
|
1631 }
|
|
1632
|
|
1633 /**
|
|
1634 * xmms_remote_set_eq_preamp:
|
|
1635 * @session: Legacy XMMS-style session identifier.
|
|
1636 * @preamp: Value for preamp setting.
|
|
1637 *
|
|
1638 * Tells audacious to set the equalizer's preamp setting.
|
|
1639 **/
|
|
1640 void
|
|
1641 xmms_remote_set_eq_preamp(gint session, gfloat preamp)
|
|
1642 {
|
|
1643 remote_send_gfloat(session, CMD_SET_EQ_PREAMP, preamp);
|
|
1644 }
|
|
1645
|
|
1646 /**
|
|
1647 * xmms_remote_set_eq_band:
|
|
1648 * @session: Legacy XMMS-style session identifier.
|
|
1649 * @band: The band to set the value for.
|
|
1650 * @value: The value to set that band to.
|
|
1651 *
|
|
1652 * Tells audacious to set an equalizer band's setting.
|
|
1653 **/
|
|
1654 void
|
|
1655 xmms_remote_set_eq_band(gint session, gint band, gfloat value)
|
|
1656 {
|
|
1657 gint fd;
|
|
1658 gchar data[sizeof(gint) + sizeof(gfloat)];
|
|
1659
|
|
1660 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
1661 return;
|
|
1662 *((gint *) data) = band;
|
|
1663 *((gfloat *) (data + sizeof(gint))) = value;
|
|
1664 remote_send_packet(fd, CMD_SET_EQ_BAND, data, sizeof(data));
|
|
1665 remote_read_ack(fd);
|
|
1666 close(fd);
|
|
1667 }
|
|
1668
|
|
1669 /**
|
|
1670 * xmms_remote_quit:
|
|
1671 * @session: Legacy XMMS-style session identifier.
|
|
1672 *
|
|
1673 * Tells audacious to quit.
|
|
1674 **/
|
|
1675 void
|
|
1676 xmms_remote_quit(gint session)
|
|
1677 {
|
|
1678 gint fd;
|
|
1679
|
|
1680 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
1681 return;
|
|
1682 remote_send_packet(fd, CMD_QUIT, NULL, 0);
|
|
1683 remote_read_ack(fd);
|
|
1684 close(fd);
|
|
1685 }
|
|
1686
|
|
1687 /**
|
|
1688 * xmms_remote_activate:
|
|
1689 * @session: Legacy XMMS-style session identifier.
|
|
1690 *
|
|
1691 * Tells audacious to display the main window and become the selected window.
|
|
1692 **/
|
|
1693 void
|
|
1694 xmms_remote_activate(gint session)
|
|
1695 {
|
|
1696 gint fd;
|
|
1697
|
|
1698 if ((fd = xmms_connect_to_session(session)) == -1)
|
|
1699 return;
|
|
1700 remote_send_packet(fd, CMD_ACTIVATE, NULL, 0);
|
|
1701 remote_read_ack(fd);
|
|
1702 close(fd);
|
|
1703 }
|