0
|
1 /* BMP - Cross-platform multimedia player
|
|
2 * Copyright (C) 2003-2004 BMP development team.
|
|
3 *
|
|
4 * Based on XMMS:
|
|
5 * Copyright (C) 1998-2003 XMMS development team.
|
|
6 *
|
|
7 * This program is free software; you can redistribute it and/or modify
|
|
8 * it under the terms of the GNU General Public License as published by
|
|
9 * the Free Software Foundation; either version 2 of the License, or
|
|
10 * (at your option) any later version.
|
|
11 *
|
|
12 * This program is distributed in the hope that it will be useful,
|
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 * GNU General Public License for more details.
|
|
16 *
|
|
17 * You should have received a copy of the GNU General Public License
|
|
18 * along with this program; if not, write to the Free Software
|
|
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
20 */
|
|
21
|
|
22 #include "controlsocket.h"
|
|
23
|
|
24 #include <glib.h>
|
|
25 #include <stdlib.h>
|
|
26 #include <string.h>
|
|
27
|
|
28 #include <unistd.h>
|
|
29 #include <errno.h>
|
|
30 #include <sys/time.h>
|
|
31 #include <sys/types.h>
|
|
32 #include <sys/socket.h>
|
|
33 #include <sys/un.h>
|
|
34
|
|
35 #include "main.h"
|
|
36 #include "equalizer.h"
|
|
37 #include "mainwin.h"
|
|
38 #include "input.h"
|
|
39 #include "playback.h"
|
|
40 #include "playlist.h"
|
|
41 #include "playlistwin.h"
|
|
42 #include "prefswin.h"
|
|
43 #include "skin.h"
|
|
44 #include "libaudacious/beepctrl.h"
|
|
45
|
|
46
|
|
47 #define CTRLSOCKET_BACKLOG 100
|
|
48 #define CTRLSOCKET_TIMEOUT 100000
|
|
49
|
|
50
|
|
51 static gint session_id = 0;
|
|
52
|
|
53 static gint ctrl_fd = 0;
|
|
54 static gchar *socket_name = NULL;
|
|
55
|
|
56 static gpointer ctrlsocket_func(gpointer);
|
|
57 static GThread *ctrlsocket_thread;
|
|
58
|
|
59 static GList *packet_list = NULL;
|
|
60 static GMutex *packet_list_mutex = NULL;
|
|
61
|
|
62 static gboolean started = FALSE;
|
|
63 static gboolean going = TRUE;
|
|
64 static GCond *start_cond = NULL;
|
|
65 static GMutex *status_mutex = NULL;
|
|
66
|
|
67
|
|
68 static void
|
|
69 ctrlsocket_start_thread(void)
|
|
70 {
|
|
71 start_cond = g_cond_new();
|
|
72 status_mutex = g_mutex_new();
|
|
73 packet_list_mutex = g_mutex_new();
|
|
74
|
|
75 ctrlsocket_thread = g_thread_create(ctrlsocket_func, NULL, TRUE, NULL);
|
|
76 }
|
|
77
|
|
78 gboolean
|
|
79 ctrlsocket_setup(void)
|
|
80 {
|
|
81 struct sockaddr_un saddr;
|
|
82 gint i;
|
|
83 gint fd;
|
|
84
|
|
85 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
|
|
86 g_critical("ctrlsocket_setup(): Failed to open socket: %s",
|
|
87 strerror(errno));
|
|
88 return FALSE;
|
|
89 }
|
|
90
|
|
91 for (i = 0;; i++) {
|
|
92 saddr.sun_family = AF_UNIX;
|
|
93 g_snprintf(saddr.sun_path, sizeof(saddr.sun_path),
|
|
94 "%s/%s_%s.%d", g_get_tmp_dir(),
|
|
95 CTRLSOCKET_NAME, g_get_user_name(), i);
|
|
96
|
|
97 if (xmms_remote_is_running(i)) {
|
|
98 if (cfg.allow_multiple_instances)
|
|
99 continue;
|
|
100 break;
|
|
101 }
|
|
102
|
|
103 if ((unlink(saddr.sun_path) == -1) && errno != ENOENT) {
|
|
104 g_critical
|
|
105 ("ctrlsocket_setup(): Failed to unlink %s (Error: %s)",
|
|
106 saddr.sun_path, strerror(errno));
|
|
107 break;
|
|
108 }
|
|
109
|
|
110 if (bind(fd, (struct sockaddr *) &saddr, sizeof(saddr)) == -1) {
|
|
111 g_critical
|
|
112 ("ctrlsocket_setup(): Failed to assign %s to a socket (Error: %s)",
|
|
113 saddr.sun_path, strerror(errno));
|
|
114 break;
|
|
115 }
|
|
116
|
|
117 listen(fd, CTRLSOCKET_BACKLOG);
|
|
118
|
|
119 socket_name = g_strdup(saddr.sun_path);
|
|
120 ctrl_fd = fd;
|
|
121 session_id = i;
|
|
122 going = TRUE;
|
|
123
|
|
124 ctrlsocket_start_thread();
|
|
125
|
|
126 return TRUE;
|
|
127 }
|
|
128
|
|
129 close(fd);
|
|
130
|
|
131 return FALSE;
|
|
132 }
|
|
133
|
|
134 gint
|
|
135 ctrlsocket_get_session_id(void)
|
|
136 {
|
|
137 return session_id;
|
|
138 }
|
|
139
|
|
140 void
|
|
141 ctrlsocket_cleanup(void)
|
|
142 {
|
|
143 if (ctrl_fd) {
|
|
144 g_mutex_lock(status_mutex);
|
|
145 going = FALSE;
|
|
146 g_cond_signal(start_cond);
|
|
147 g_mutex_unlock(status_mutex);
|
|
148
|
|
149 /* wait for ctrlsocket_thread to terminate */
|
|
150 g_thread_join(ctrlsocket_thread);
|
|
151
|
|
152 /* close and remove socket */
|
|
153 close(ctrl_fd);
|
|
154 ctrl_fd = 0;
|
|
155 unlink(socket_name);
|
|
156 g_free(socket_name);
|
|
157
|
|
158 g_cond_free(start_cond);
|
|
159 g_mutex_free(status_mutex);
|
|
160 g_mutex_free(packet_list_mutex);
|
|
161 }
|
|
162 }
|
|
163
|
|
164 void
|
|
165 ctrlsocket_start(void)
|
|
166 {
|
|
167 /* tell control socket thread to go 'live' i.e. start handling
|
|
168 * packets */
|
|
169 g_mutex_lock(status_mutex);
|
|
170 started = TRUE;
|
|
171 g_cond_signal(start_cond);
|
|
172 g_mutex_unlock(status_mutex);
|
|
173 }
|
|
174
|
|
175 static gint
|
|
176 write_all(gint fd, gconstpointer buf, size_t count)
|
|
177 {
|
|
178 size_t left = count;
|
|
179 GTimer *timer;
|
|
180 gulong usec;
|
|
181 gint written;
|
|
182
|
|
183 timer = g_timer_new();
|
|
184
|
|
185 do {
|
|
186 if ((written = write(fd, buf, left)) < 0) {
|
|
187 count = -1;
|
|
188 break;
|
|
189 }
|
|
190 left -= written;
|
|
191 buf = (gchar *) buf + written;
|
|
192 g_timer_elapsed(timer, &usec);
|
|
193 }
|
|
194 while (left > 0 && usec <= CTRLSOCKET_IO_TIMEOUT_USEC);
|
|
195
|
|
196 g_timer_destroy(timer);
|
|
197 return count - left;
|
|
198 }
|
|
199
|
|
200 static void
|
|
201 ctrl_write_packet(gint fd, gpointer data, gint length)
|
|
202 {
|
|
203 ServerPktHeader pkthdr;
|
|
204
|
|
205 pkthdr.version = XMMS_PROTOCOL_VERSION;
|
|
206 pkthdr.data_length = length;
|
|
207 if (write_all(fd, &pkthdr, sizeof(ServerPktHeader)) < sizeof(pkthdr))
|
|
208 return;
|
|
209 if (data && length > 0)
|
|
210 write_all(fd, data, length);
|
|
211 }
|
|
212
|
|
213 static void
|
|
214 ctrl_write_gint(gint fd, gint val)
|
|
215 {
|
|
216 ctrl_write_packet(fd, &val, sizeof(gint));
|
|
217 }
|
|
218
|
|
219 static void
|
|
220 ctrl_write_gfloat(gint fd, gfloat val)
|
|
221 {
|
|
222 ctrl_write_packet(fd, &val, sizeof(gfloat));
|
|
223 }
|
|
224
|
|
225 static void
|
|
226 ctrl_write_gboolean(gint fd, gboolean bool)
|
|
227 {
|
|
228 ctrl_write_packet(fd, &bool, sizeof(gboolean));
|
|
229 }
|
|
230
|
|
231 static void
|
|
232 ctrl_write_string(gint fd, gchar * string)
|
|
233 {
|
|
234 ctrl_write_packet(fd, string, string ? strlen(string) + 1 : 0);
|
|
235 }
|
|
236
|
|
237 static void
|
|
238 ctrl_ack_packet(PacketNode * pkt)
|
|
239 {
|
|
240 ctrl_write_packet(pkt->fd, NULL, 0);
|
|
241 close(pkt->fd);
|
|
242 if (pkt->data)
|
|
243 g_free(pkt->data);
|
|
244 g_free(pkt);
|
|
245 }
|
|
246
|
|
247 static gint
|
|
248 read_all(gint fd, gpointer buf, size_t count)
|
|
249 {
|
|
250 size_t left = count;
|
|
251 GTimer *timer;
|
|
252 gulong usec;
|
|
253 gint r;
|
|
254
|
|
255 timer = g_timer_new();
|
|
256
|
|
257 do {
|
|
258 if ((r = read(fd, buf, left)) < 0) {
|
|
259 count = -1;
|
|
260 break;
|
|
261 }
|
|
262 left -= r;
|
|
263 buf = (gchar *) buf + r;
|
|
264 g_timer_elapsed(timer, &usec);
|
|
265 }
|
|
266 while (left > 0 && usec <= CTRLSOCKET_IO_TIMEOUT_USEC);
|
|
267
|
|
268 g_timer_destroy(timer);
|
|
269 return count - left;
|
|
270 }
|
|
271
|
|
272 static gboolean
|
|
273 ctrlsocket_is_going(void)
|
|
274 {
|
|
275 gboolean result;
|
|
276
|
|
277 g_mutex_lock(status_mutex);
|
|
278 result = going;
|
|
279 g_mutex_unlock(status_mutex);
|
|
280
|
|
281 return result;
|
|
282 }
|
|
283
|
|
284 static gpointer
|
|
285 ctrlsocket_func(gpointer arg)
|
|
286 {
|
|
287 fd_set set;
|
|
288 struct timeval tv;
|
|
289 struct sockaddr_un saddr;
|
|
290 gint fd, b, i;
|
|
291 guint32 info[3];
|
|
292 gint32 v[2];
|
|
293 PacketNode *pkt;
|
|
294 socklen_t len;
|
|
295 gfloat fval[11];
|
|
296
|
|
297 g_mutex_lock(status_mutex);
|
|
298 while (!started && going)
|
|
299 g_cond_wait(start_cond, status_mutex);
|
|
300 g_mutex_unlock(status_mutex);
|
|
301
|
|
302 while (ctrlsocket_is_going()) {
|
|
303 FD_ZERO(&set);
|
|
304 FD_SET(ctrl_fd, &set);
|
|
305 tv.tv_sec = 0;
|
|
306 tv.tv_usec = CTRLSOCKET_TIMEOUT;
|
|
307 len = sizeof(saddr);
|
|
308 if (select(ctrl_fd + 1, &set, NULL, NULL, &tv) <= 0)
|
|
309 continue;
|
|
310 if ((fd = accept(ctrl_fd, (struct sockaddr *) &saddr, &len)) == -1)
|
|
311 continue;
|
|
312
|
|
313 pkt = g_new0(PacketNode, 1);
|
|
314 if (read_all(fd, &pkt->hdr, sizeof(ClientPktHeader))
|
|
315 < sizeof(ClientPktHeader)) {
|
|
316 g_free(pkt);
|
|
317 continue;
|
|
318 }
|
|
319
|
|
320 if (pkt->hdr.data_length) {
|
|
321 size_t data_length = pkt->hdr.data_length;
|
|
322 pkt->data = g_malloc0(data_length);
|
|
323 if (read_all(fd, pkt->data, data_length) < data_length) {
|
|
324 g_free(pkt->data);
|
|
325 g_free(pkt);
|
|
326 g_warning("ctrlsocket_func(): Incomplete data packet dropped");
|
|
327 continue;
|
|
328 }
|
|
329 }
|
|
330
|
|
331 pkt->fd = fd;
|
|
332 switch (pkt->hdr.command) {
|
|
333 case CMD_GET_VERSION:
|
|
334 ctrl_write_gint(pkt->fd, 0x09a3);
|
|
335 ctrl_ack_packet(pkt);
|
|
336 break;
|
|
337 case CMD_IS_PLAYING:
|
|
338 ctrl_write_gboolean(pkt->fd, bmp_playback_get_playing());
|
|
339 ctrl_ack_packet(pkt);
|
|
340 break;
|
|
341 case CMD_IS_PAUSED:
|
|
342 ctrl_write_gboolean(pkt->fd, bmp_playback_get_paused());
|
|
343 ctrl_ack_packet(pkt);
|
|
344 break;
|
|
345 case CMD_GET_PLAYLIST_POS:
|
|
346 ctrl_write_gint(pkt->fd, playlist_get_position());
|
|
347 ctrl_ack_packet(pkt);
|
|
348 break;
|
|
349 case CMD_GET_PLAYLIST_LENGTH:
|
|
350 ctrl_write_gint(pkt->fd, playlist_get_length());
|
|
351 ctrl_ack_packet(pkt);
|
|
352 break;
|
|
353 case CMD_GET_PLAYQUEUE_LENGTH:
|
|
354 ctrl_write_gint(pkt->fd, playlist_queue_get_length());
|
|
355 ctrl_ack_packet(pkt);
|
|
356 break;
|
|
357 case CMD_GET_OUTPUT_TIME:
|
|
358 if (bmp_playback_get_playing())
|
|
359 ctrl_write_gint(pkt->fd, bmp_playback_get_time());
|
|
360 else
|
|
361 ctrl_write_gint(pkt->fd, 0);
|
|
362 ctrl_ack_packet(pkt);
|
|
363 break;
|
|
364 case CMD_GET_VOLUME:
|
|
365 input_get_volume(&v[0], &v[1]);
|
|
366 ctrl_write_packet(pkt->fd, v, sizeof(v));
|
|
367 ctrl_ack_packet(pkt);
|
|
368 break;
|
|
369 case CMD_GET_BALANCE:
|
|
370 input_get_volume(&v[0], &v[1]);
|
|
371 if (v[0] < 0 || v[1] < 0)
|
|
372 b = 0;
|
|
373 else if (v[0] > v[1])
|
|
374 b = -100 + ((v[1] * 100) / v[0]);
|
|
375 else if (v[1] > v[0])
|
|
376 b = 100 - ((v[0] * 100) / v[1]);
|
|
377 else
|
|
378 b = 0;
|
|
379 ctrl_write_gint(pkt->fd, b);
|
|
380 ctrl_ack_packet(pkt);
|
|
381 break;
|
|
382 case CMD_GET_SKIN:
|
|
383 ctrl_write_string(pkt->fd, bmp_active_skin->path);
|
|
384 ctrl_ack_packet(pkt);
|
|
385 break;
|
|
386 case CMD_GET_PLAYLIST_FILE:
|
|
387 if (pkt->data) {
|
|
388 gchar *filename;
|
|
389 filename = playlist_get_filename(*((guint32 *) pkt->data));
|
|
390 ctrl_write_string(pkt->fd, filename);
|
|
391 g_free(filename);
|
|
392 }
|
|
393 else
|
|
394 ctrl_write_string(pkt->fd, NULL);
|
|
395 ctrl_ack_packet(pkt);
|
|
396 break;
|
|
397 case CMD_GET_PLAYLIST_TITLE:
|
|
398 if (pkt->data) {
|
|
399 gchar *title;
|
|
400 title = playlist_get_songtitle(*((guint32 *) pkt->data));
|
|
401 ctrl_write_string(pkt->fd, title);
|
|
402 g_free(title);
|
|
403 }
|
|
404 else
|
|
405 ctrl_write_string(pkt->fd, NULL);
|
|
406 ctrl_ack_packet(pkt);
|
|
407 break;
|
|
408 case CMD_GET_PLAYLIST_TIME:
|
|
409 if (pkt->data)
|
|
410 ctrl_write_gint(pkt->fd,
|
|
411 playlist_get_songtime(*
|
|
412 ((guint32 *) pkt->
|
|
413 data)));
|
|
414 else
|
|
415 ctrl_write_gint(pkt->fd, -1);
|
|
416
|
|
417 ctrl_ack_packet(pkt);
|
|
418 break;
|
|
419 case CMD_GET_INFO:
|
|
420 playback_get_sample_params(&info[0], &info[1], &info[2]);
|
|
421 ctrl_write_packet(pkt->fd, info, 3 * sizeof(gint));
|
|
422 ctrl_ack_packet(pkt);
|
|
423 break;
|
|
424 case CMD_GET_EQ_DATA:
|
|
425 case CMD_SET_EQ_DATA:
|
|
426 /* obsolete */
|
|
427 ctrl_ack_packet(pkt);
|
|
428 break;
|
|
429 case CMD_PING:
|
|
430 ctrl_ack_packet(pkt);
|
|
431 break;
|
|
432 case CMD_PLAYLIST_ADD:
|
|
433 if (pkt->data) {
|
|
434 guint32 *dataptr = pkt->data;
|
|
435 while ((len = *dataptr) > 0) {
|
|
436 gchar *filename;
|
|
437
|
|
438 dataptr++;
|
|
439 filename = g_malloc0(len);
|
|
440 memcpy(filename, dataptr, len);
|
|
441
|
|
442 GDK_THREADS_ENTER();
|
|
443 playlist_add_url(filename);
|
|
444 GDK_THREADS_LEAVE();
|
|
445
|
|
446 g_free(filename);
|
|
447 dataptr += (len + 3) / 4;
|
|
448 }
|
|
449 }
|
|
450 ctrl_ack_packet(pkt);
|
|
451 break;
|
|
452 case CMD_PLAYLIST_ADD_URL_STRING:
|
|
453 GDK_THREADS_ENTER();
|
|
454 playlist_add_url(pkt->data);
|
|
455 GDK_THREADS_LEAVE();
|
|
456
|
|
457 ctrl_ack_packet(pkt);
|
|
458 break;
|
|
459 case CMD_PLAYLIST_INS_URL_STRING:
|
|
460 if (pkt->data) {
|
|
461 gint pos = *(gint *) pkt->data;
|
|
462 gchar *ptr = pkt->data;
|
|
463 ptr += sizeof(gint);
|
|
464 playlist_ins_url(ptr, pos);
|
|
465 }
|
|
466 ctrl_ack_packet(pkt);
|
|
467 break;
|
|
468 case CMD_PLAYLIST_DELETE:
|
|
469 GDK_THREADS_ENTER();
|
|
470 playlist_delete_index(*((guint32 *) pkt->data));
|
|
471 GDK_THREADS_LEAVE();
|
|
472 ctrl_ack_packet(pkt);
|
|
473 break;
|
|
474 case CMD_PLAYLIST_CLEAR:
|
|
475 GDK_THREADS_ENTER();
|
|
476 playlist_clear();
|
|
477 mainwin_clear_song_info();
|
|
478 mainwin_set_info_text();
|
|
479 GDK_THREADS_LEAVE();
|
|
480 ctrl_ack_packet(pkt);
|
|
481 break;
|
|
482 case CMD_IS_MAIN_WIN:
|
|
483 ctrl_write_gboolean(pkt->fd, cfg.player_visible);
|
|
484 ctrl_ack_packet(pkt);
|
|
485 break;
|
|
486 case CMD_IS_PL_WIN:
|
|
487 ctrl_write_gboolean(pkt->fd, cfg.playlist_visible);
|
|
488 ctrl_ack_packet(pkt);
|
|
489 break;
|
|
490 case CMD_IS_EQ_WIN:
|
|
491 ctrl_write_gboolean(pkt->fd, cfg.equalizer_visible);
|
|
492 ctrl_ack_packet(pkt);
|
|
493 break;
|
|
494 case CMD_IS_REPEAT:
|
|
495 ctrl_write_gboolean(pkt->fd, cfg.repeat);
|
|
496 ctrl_ack_packet(pkt);
|
|
497 break;
|
|
498 case CMD_IS_SHUFFLE:
|
|
499 ctrl_write_gboolean(pkt->fd, cfg.shuffle);
|
|
500 ctrl_ack_packet(pkt);
|
|
501 break;
|
|
502 case CMD_IS_ADVANCE:
|
|
503 ctrl_write_gboolean(pkt->fd, !cfg.no_playlist_advance);
|
|
504 ctrl_ack_packet(pkt);
|
|
505 break;
|
|
506 case CMD_GET_EQ:
|
|
507 fval[0] = equalizerwin_get_preamp();
|
|
508 for (i = 0; i < 10; i++)
|
|
509 fval[i + 1] = equalizerwin_get_band(i);
|
|
510 ctrl_write_packet(pkt->fd, fval, 11 * sizeof(gfloat));
|
|
511 ctrl_ack_packet(pkt);
|
|
512 break;
|
|
513 case CMD_GET_EQ_PREAMP:
|
|
514 ctrl_write_gfloat(pkt->fd, equalizerwin_get_preamp());
|
|
515 ctrl_ack_packet(pkt);
|
|
516 break;
|
|
517 case CMD_GET_EQ_BAND:
|
|
518 i = *((guint32 *) pkt->data);
|
|
519 ctrl_write_gfloat(pkt->fd, equalizerwin_get_band(i));
|
|
520 ctrl_ack_packet(pkt);
|
|
521 break;
|
|
522 default:
|
|
523 g_mutex_lock(packet_list_mutex);
|
|
524 packet_list = g_list_append(packet_list, pkt);
|
|
525 ctrl_write_packet(pkt->fd, NULL, 0);
|
|
526 close(pkt->fd);
|
|
527 g_mutex_unlock(packet_list_mutex);
|
|
528 break;
|
|
529 }
|
|
530 }
|
|
531 g_thread_exit(NULL);
|
|
532
|
|
533 /* Used to suppress GCC warnings. Sometimes you'd wish C has
|
|
534 native threading support :p */
|
|
535 return NULL;
|
|
536 }
|
|
537
|
|
538 void
|
|
539 ctrlsocket_check(void)
|
|
540 {
|
|
541 GList *pkt_list, *next;
|
|
542 PacketNode *pkt;
|
|
543 gpointer data;
|
|
544 guint32 v[2], i, num;
|
|
545 gboolean tbool;
|
|
546 gfloat *fval, f;
|
|
547
|
|
548 g_mutex_lock(packet_list_mutex);
|
|
549 for (pkt_list = packet_list; pkt_list; pkt_list = next) {
|
|
550 pkt = pkt_list->data;
|
|
551 data = pkt->data;
|
|
552
|
|
553 switch (pkt->hdr.command) {
|
|
554 case CMD_PLAY:
|
|
555 if (bmp_playback_get_paused())
|
|
556 bmp_playback_pause();
|
|
557 else if (playlist_get_length())
|
|
558 bmp_playback_initiate();
|
|
559 else
|
|
560 mainwin_eject_pushed();
|
|
561 break;
|
|
562 case CMD_PAUSE:
|
|
563 bmp_playback_pause();
|
|
564 break;
|
|
565 case CMD_STOP:
|
|
566 bmp_playback_stop();
|
|
567 mainwin_clear_song_info();
|
|
568 break;
|
|
569 case CMD_PLAY_PAUSE:
|
|
570 if (bmp_playback_get_playing())
|
|
571 bmp_playback_pause();
|
|
572 else
|
|
573 bmp_playback_initiate();
|
|
574 break;
|
|
575 case CMD_PLAYQUEUE_ADD:
|
|
576 num = *((guint32 *) data);
|
|
577 if (num < playlist_get_length())
|
|
578 playlist_queue_position(num);
|
|
579 break;
|
|
580 case CMD_PLAYQUEUE_REMOVE:
|
|
581 num = *((guint32 *) data);
|
|
582 if (num < playlist_get_length())
|
|
583 playlist_queue_remove(num);
|
|
584 break;
|
|
585 case CMD_SET_PLAYLIST_POS:
|
|
586 num = *((guint32 *) data);
|
|
587 if (num < playlist_get_length())
|
|
588 playlist_set_position(num);
|
|
589 break;
|
|
590 case CMD_JUMP_TO_TIME:
|
|
591 num = *((guint32 *) data);
|
|
592 if (playlist_get_current_length() > 0 &&
|
|
593 num < playlist_get_current_length())
|
|
594 bmp_playback_seek(num / 1000);
|
|
595 break;
|
|
596 case CMD_SET_VOLUME:
|
|
597 v[0] = ((guint32 *) data)[0];
|
|
598 v[1] = ((guint32 *) data)[1];
|
|
599 for (i = 0; i < 2; i++) {
|
|
600 if (v[i] > 100)
|
|
601 v[i] = 100;
|
|
602 }
|
|
603 input_set_volume(v[0], v[1]);
|
|
604 break;
|
|
605 case CMD_SET_SKIN:
|
|
606 bmp_active_skin_load(data);
|
|
607 break;
|
|
608 case CMD_PL_WIN_TOGGLE:
|
|
609 tbool = *((gboolean *) data);
|
|
610 if (tbool)
|
|
611 playlistwin_show();
|
|
612 else
|
|
613 playlistwin_hide();
|
|
614 break;
|
|
615 case CMD_EQ_WIN_TOGGLE:
|
|
616 tbool = *((gboolean *) data);
|
|
617 equalizerwin_show(!!tbool);
|
|
618 break;
|
|
619 case CMD_SHOW_PREFS_BOX:
|
|
620 show_prefs_window();
|
|
621 break;
|
|
622 case CMD_TOGGLE_AOT:
|
|
623 tbool = *((gboolean *) data);
|
|
624 mainwin_set_always_on_top(tbool);
|
|
625 break;
|
|
626 case CMD_SHOW_ABOUT_BOX:
|
|
627 break;
|
|
628 case CMD_EJECT:
|
|
629 mainwin_eject_pushed();
|
|
630 break;
|
|
631 case CMD_PLAYLIST_PREV:
|
|
632 playlist_prev();
|
|
633 break;
|
|
634 case CMD_PLAYLIST_NEXT:
|
|
635 playlist_next();
|
|
636 break;
|
|
637 case CMD_TOGGLE_REPEAT:
|
|
638 mainwin_repeat_pushed(!cfg.repeat);
|
|
639 break;
|
|
640 case CMD_TOGGLE_SHUFFLE:
|
|
641 mainwin_shuffle_pushed(!cfg.shuffle);
|
|
642 break;
|
|
643 case CMD_TOGGLE_ADVANCE:
|
|
644 /* FIXME: to be implemented */
|
|
645 break;
|
|
646 case CMD_MAIN_WIN_TOGGLE:
|
|
647 tbool = *((gboolean *) data);
|
|
648 mainwin_show(!!tbool);
|
|
649 break;
|
|
650 case CMD_SET_EQ:
|
|
651 if (pkt->hdr.data_length >= 11 * sizeof(gfloat)) {
|
|
652 fval = (gfloat *) data;
|
|
653 equalizerwin_set_preamp(fval[0]);
|
|
654 for (i = 0; i < 10; i++)
|
|
655 equalizerwin_set_band(i, fval[i + 1]);
|
|
656 }
|
|
657 break;
|
|
658 case CMD_SET_EQ_PREAMP:
|
|
659 f = *((gfloat *) data);
|
|
660 equalizerwin_set_preamp(f);
|
|
661 break;
|
|
662 case CMD_SET_EQ_BAND:
|
|
663 if (pkt->hdr.data_length >= sizeof(gint) + sizeof(gfloat)) {
|
|
664 i = *((gint *) data);
|
|
665 f = *((gfloat *) ((gchar *) data + sizeof(gint)));
|
|
666 equalizerwin_set_band(i, f);
|
|
667 }
|
|
668 break;
|
|
669 case CMD_QUIT:
|
|
670 /*
|
|
671 * We unlock the packet_list_mutex to
|
|
672 * avoid that cleanup_ctrlsocket() can
|
|
673 * deadlock, mainwin_quit_cb() will
|
|
674 * never return anyway, so this will
|
|
675 * work ok.
|
|
676 */
|
|
677 g_mutex_unlock(packet_list_mutex);
|
|
678 mainwin_quit_cb();
|
|
679 break;
|
|
680 case CMD_ACTIVATE:
|
|
681 gtk_window_present(GTK_WINDOW(mainwin));
|
|
682 break;
|
|
683 default:
|
|
684 g_message("Unknown socket command received");
|
|
685 break;
|
|
686 }
|
|
687 next = g_list_next(pkt_list);
|
|
688 packet_list = g_list_remove_link(packet_list, pkt_list);
|
|
689 g_list_free_1(pkt_list);
|
|
690 if (pkt->data)
|
|
691 g_free(pkt->data);
|
|
692 g_free(pkt);
|
|
693 }
|
|
694 g_mutex_unlock(packet_list_mutex);
|
|
695 }
|