comparison src/audtool/audtool.c @ 2313:3149d4b1a9a9 trunk

[svn] - objective-make autodepend fixes - move all sourcecode into src/ and adjust Makefiles accordingly
author nenolod
date Fri, 12 Jan 2007 11:43:40 -0800
parents
children 921b2d8d9b2e
comparison
equal deleted inserted replaced
2312:e1a5a66fb9cc 2313:3149d4b1a9a9
1 /* Audtool -- Audacious scripting tool
2 * Copyright (c) 2005-2007 Audacious development team
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #include <stdlib.h>
20 #include <glib.h>
21 #include <locale.h>
22 #include "libaudacious/beepctrl.h"
23 #include "audtool.h"
24
25 struct commandhandler handlers[] = {
26 {"<sep>", NULL, "Vital information"},
27 {"current-song", get_current_song, "returns current song title"},
28 {"current-song-filename", get_current_song_filename, "returns current song filename"},
29 {"current-song-length", get_current_song_length, "returns current song length"},
30 {"current-song-length-seconds", get_current_song_length_seconds, "returns current song length in seconds"},
31 {"current-song-length-frames", get_current_song_length_frames, "returns current song length in frames"},
32 {"current-song-output-length", get_current_song_output_length, "returns current song output length"},
33 {"current-song-output-length-seconds", get_current_song_output_length_seconds, "returns current song output length in seconds"},
34 {"current-song-output-length-frames", get_current_song_output_length_frames, "returns current song output length in frames"},
35 {"current-song-bitrate", get_current_song_bitrate, "returns current song bitrate in bits per second"},
36 {"current-song-bitrate-kbps", get_current_song_bitrate_kbps, "returns current song bitrate in kilobits per second"},
37 {"current-song-frequency", get_current_song_frequency, "returns current song frequency in hertz"},
38 {"current-song-frequency-khz", get_current_song_frequency_khz, "returns current song frequency in kilohertz"},
39 {"current-song-channels", get_current_song_channels, "returns current song channels"},
40 {"<sep>", NULL, "Playlist manipulation"},
41 {"playlist-advance", playlist_advance, "go to the next song in the playlist"},
42 {"playlist-reverse", playlist_reverse, "go to the previous song in the playlist"},
43 {"playlist-addurl", playlist_add_url_string, "adds a url to the playlist"},
44 {"playlist-delete", playlist_delete, "deletes a song from the playlist"},
45 {"playlist-length", playlist_length, "returns the total length of the playlist"},
46 {"playlist-song", playlist_song, "returns the title of a song in the playlist"},
47 {"playlist-song-filename", playlist_song_filename, "returns the filename of a song in the playlist"},
48 {"playlist-song-length", playlist_song_length, "returns the length of a song in the playlist"},
49 {"playlist-song-length-seconds", playlist_song_length_seconds, "returns the length of a song in the playlist in seconds"},
50 {"playlist-song-length-frames", playlist_song_length_frames, "returns the length of a song in the playlist in frames"},
51 {"playlist-display", playlist_display, "returns the entire playlist"},
52 {"playlist-position", playlist_position, "returns the position in the playlist"},
53 {"playlist-jump", playlist_jump, "jumps to a position in the playlist"},
54 {"playlist-clear", playlist_clear, "clears the playlist"},
55 {"playlist-repeat-status", playlist_repeat_status, "returns the status of playlist repeat"},
56 {"playlist-repeat-toggle", playlist_repeat_toggle, "toggles playlist repeat"},
57 {"playlist-shuffle-status", playlist_shuffle_status, "returns the status of playlist shuffle"},
58 {"playlist-shuffle-toggle", playlist_shuffle_toggle, "toggles playlist shuffle"},
59 {"<sep>", NULL, "Playqueue manipulation"},
60 {"playqueue-add", playqueue_add, "adds a song to the playqueue"},
61 {"playqueue-remove", playqueue_remove, "removes a song from the playqueue"},
62 {"playqueue-is-queued", playqueue_is_queued, "returns OK if a song is queued"},
63 {"playqueue-get-position", playqueue_get_position, "returns the queue position of a song in the playlist"},
64 {"playqueue-get-qposition", playqueue_get_qposition, "returns the playlist position of a song in the queue"},
65 {"playqueue-length", playqueue_length, "returns the length of the playqueue"},
66 {"playqueue-display", playqueue_display, "returns a list of currently-queued songs"},
67 {"playqueue-clear", playqueue_clear, "clears the playqueue"},
68 {"<sep>", NULL, "Playback manipulation"},
69 {"playback-play", playback_play, "starts/unpauses song playback"},
70 {"playback-pause", playback_pause, "(un)pauses song playback"},
71 {"playback-playpause", playback_playpause, "plays/(un)pauses song playback"},
72 {"playback-stop", playback_stop, "stops song playback"},
73 {"playback-playing", playback_playing, "returns OK if audacious is playing"},
74 {"playback-paused", playback_paused, "returns OK if audacious is paused"},
75 {"playback-stopped", playback_stopped, "returns OK if audacious is stopped"},
76 {"playback-status", playback_status, "returns the playback status"},
77 {"playback-seek", playback_seek, "performs an absolute seek"},
78 {"playback-seek-relative", playback_seek_relative, "performs a seek relative to the current position"},
79 {"<sep>", NULL, "Volume control"},
80 {"get-volume", get_volume, "returns the current volume level in percent"},
81 {"set-volume", set_volume, "sets the current volume level in percent"},
82 {"<sep>", NULL, "Miscellaneous"},
83 {"mainwin-show", mainwin_show, "shows/hides the main window"},
84 {"playlist-show", playlist_show, "shows/hides the playlist window"},
85 {"equalizer-show", equalizer_show, "shows/hides the equalizer window"},
86 {"preferences", show_preferences_window, "shows/hides the preferences window"},
87 {"jumptofile", show_jtf_window, "shows the jump to file window"},
88 {"shutdown", shutdown_audacious_server, "shuts down audacious"},
89 {"<sep>", NULL, "Help system"},
90 {"list-handlers", get_handlers_list, "shows handlers list"},
91 {"help", get_handlers_list, "shows handlers list"},
92 {NULL, NULL, NULL}
93 };
94
95 gint main(gint argc, gchar **argv)
96 {
97 gint i;
98 gchar *remote_uri;
99
100 setlocale(LC_CTYPE, "");
101
102 if (argc < 2)
103 {
104 g_print("%s: usage: %s <command>\n", argv[0], argv[0]);
105 g_print("%s: use `%s help' to get a listing of available commands.\n",
106 argv[0], argv[0]);
107 exit(-2);
108 }
109
110 remote_uri = getenv("AUDTOOL_REMOTE_URI");
111 audacious_set_session_uri(remote_uri);
112
113 if (!xmms_remote_is_running(0) && g_strcasecmp("help", argv[1])
114 && g_strcasecmp("list-handlers", argv[1]))
115 {
116 g_print("%s: audacious server is not running!\n", argv[0]);
117 exit(-1);
118 }
119
120 for (i = 0; handlers[i].name != NULL; i++)
121 {
122 if ((!g_strcasecmp(handlers[i].name, argv[1]) ||
123 !g_strcasecmp(g_strconcat("--", handlers[i].name, NULL), argv[1]))
124 && g_strcasecmp("<sep>", handlers[i].name))
125 {
126 handlers[i].handler(0, argc, argv);
127 exit(0);
128 }
129 }
130
131 g_print("%s: invalid command '%s'\n", argv[0], argv[1]);
132 g_print("%s: use `%s help' to get a listing of available commands.\n", argv[0], argv[0]);
133
134 return 0;
135 }
136
137 /*** MOVE TO HANDLERS.C ***/
138
139 void get_current_song(gint session, gint argc, gchar **argv)
140 {
141 gint playpos = xmms_remote_get_playlist_pos(session);
142 gchar *song = xmms_remote_get_playlist_title(session, playpos);
143
144 if (!song)
145 {
146 g_print("No song playing.\n");
147 return;
148 }
149
150 g_print("%s\n", song);
151 }
152
153 void get_current_song_filename(gint session, gint argc, gchar **argv)
154 {
155 gint playpos = xmms_remote_get_playlist_pos(session);
156
157 g_print("%s\n", xmms_remote_get_playlist_file(session, playpos));
158 }
159
160 void get_current_song_output_length(gint session, gint argc, gchar **argv)
161 {
162 gint frames = xmms_remote_get_output_time(session);
163 gint length = frames / 1000;
164
165 g_print("%d:%.2d\n", length / 60, length % 60);
166 }
167
168 void get_current_song_output_length_seconds(gint session, gint argc, gchar **argv)
169 {
170 gint frames = xmms_remote_get_output_time(session);
171 gint length = frames / 1000;
172
173 g_print("%d\n", length);
174 }
175
176 void get_current_song_output_length_frames(gint session, gint argc, gchar **argv)
177 {
178 gint frames = xmms_remote_get_output_time(session);
179
180 g_print("%d\n", frames);
181 }
182
183 void get_current_song_length(gint session, gint argc, gchar **argv)
184 {
185 gint playpos = xmms_remote_get_playlist_pos(session);
186 gint frames = xmms_remote_get_playlist_time(session, playpos);
187 gint length = frames / 1000;
188
189 g_print("%d:%.2d\n", length / 60, length % 60);
190 }
191
192 void get_current_song_length_seconds(gint session, gint argc, gchar **argv)
193 {
194 gint playpos = xmms_remote_get_playlist_pos(session);
195 gint frames = xmms_remote_get_playlist_time(session, playpos);
196 gint length = frames / 1000;
197
198 g_print("%d\n", length);
199 }
200
201 void get_current_song_length_frames(gint session, gint argc, gchar **argv)
202 {
203 gint playpos = xmms_remote_get_playlist_pos(session);
204 gint frames = xmms_remote_get_playlist_time(session, playpos);
205
206 g_print("%d\n", frames);
207 }
208
209 void get_current_song_bitrate(gint session, gint argc, gchar **argv)
210 {
211 gint rate, freq, nch;
212
213 xmms_remote_get_info(session, &rate, &freq, &nch);
214
215 g_print("%d\n", rate);
216 }
217
218 void get_current_song_bitrate_kbps(gint session, gint argc, gchar **argv)
219 {
220 gint rate, freq, nch;
221
222 xmms_remote_get_info(session, &rate, &freq, &nch);
223
224 g_print("%d\n", rate / 1000);
225 }
226
227 void get_current_song_frequency(gint session, gint argc, gchar **argv)
228 {
229 gint rate, freq, nch;
230
231 xmms_remote_get_info(session, &rate, &freq, &nch);
232
233 g_print("%d\n", freq);
234 }
235
236 void get_current_song_frequency_khz(gint session, gint argc, gchar **argv)
237 {
238 gint rate, freq, nch;
239
240 xmms_remote_get_info(session, &rate, &freq, &nch);
241
242 g_print("%0.1f\n", (gfloat) freq / 1000);
243 }
244
245 void get_current_song_channels(gint session, gint argc, gchar **argv)
246 {
247 gint rate, freq, nch;
248
249 xmms_remote_get_info(session, &rate, &freq, &nch);
250
251 g_print("%d\n", nch);
252 }
253
254 void playlist_reverse(gint session, gint argc, gchar **argv)
255 {
256 xmms_remote_playlist_prev(session);
257 }
258
259 void playlist_advance(gint session, gint argc, gchar **argv)
260 {
261 xmms_remote_playlist_next(session);
262 }
263
264 void playback_play(gint session, gint argc, gchar **argv)
265 {
266 xmms_remote_play(session);
267 }
268
269 void playback_pause(gint session, gint argc, gchar **argv)
270 {
271 xmms_remote_pause(session);
272 }
273
274 void playback_playpause(gint session, gint argc, gchar **argv)
275 {
276 if (xmms_remote_is_playing(session))
277 {
278 xmms_remote_pause(session);
279 }
280 else
281 {
282 xmms_remote_play(session);
283 }
284 }
285
286 void playback_stop(gint session, gint argc, gchar **argv)
287 {
288 xmms_remote_stop(session);
289 }
290
291 void playback_playing(gint session, gint argc, gchar **argv)
292 {
293 if (!xmms_remote_is_paused(session))
294 {
295 exit(!xmms_remote_is_playing(session));
296 }
297 else
298 {
299 exit(1);
300 }
301 }
302
303 void playback_paused(gint session, gint argc, gchar **argv)
304 {
305 exit(!xmms_remote_is_paused(session));
306 }
307
308 void playback_stopped(gint session, gint argc, gchar **argv)
309 {
310 if (!xmms_remote_is_playing(session) && !xmms_remote_is_paused(session))
311 {
312 exit(0);
313 }
314 else
315 {
316 exit(1);
317 }
318 }
319
320 void playback_status(gint session, gint argc, gchar **argv)
321 {
322 if (xmms_remote_is_paused(session))
323 {
324 g_print("paused\n");
325 return;
326 }
327 else if (xmms_remote_is_playing(session))
328 {
329 g_print("playing\n");
330 return;
331 }
332 else
333 {
334 g_print("stopped\n");
335 return;
336 }
337 }
338
339 void playback_seek(gint session, gint argc, gchar **argv)
340 {
341 if (argc < 3)
342 {
343 g_print("%s: invalid parameters for playback-seek.\n", argv[0]);
344 g_print("%s: syntax: %s playback-seek <position>\n", argv[0], argv[0]);
345 return;
346 }
347
348 xmms_remote_jump_to_time(session, atoi(argv[2]) * 1000);
349 }
350
351 void playback_seek_relative(gint session, gint argc, gchar **argv)
352 {
353 gint oldtime, newtime, diff;
354
355 if (argc < 3)
356 {
357 g_print("%s: invalid parameters for playback-seek-relative.\n", argv[0]);
358 g_print("%s: syntax: %s playback-seek <position>\n", argv[0], argv[0]);
359 return;
360 }
361
362 oldtime = xmms_remote_get_output_time(session);
363 diff = atoi(argv[2]) * 1000;
364 newtime = oldtime + diff;
365
366 xmms_remote_jump_to_time(session, newtime);
367 }
368
369 void playlist_add_url_string(gint session, gint argc, gchar **argv)
370 {
371 if (argc < 3)
372 {
373 g_print("%s: invalid parameters for playlist-addurl.\n", argv[0]);
374 g_print("%s: syntax: %s playlist-addurl <url>\n", argv[0], argv[0]);
375 return;
376 }
377
378 xmms_remote_playlist_add_url_string(session, argv[2]);
379 }
380
381 void playlist_delete(gint session, gint argc, gchar **argv)
382 {
383 gint playpos;
384
385 if (argc < 3)
386 {
387 g_print("%s: invalid parameters for playlist-delete.\n", argv[0]);
388 g_print("%s: syntax: %s playlist-delete <position>\n", argv[0], argv[0]);
389 return;
390 }
391
392 playpos = atoi(argv[2]);
393
394 if (playpos < 1 || playpos > xmms_remote_get_playlist_length(session))
395 {
396 g_print("%s: invalid playlist position %d\n", argv[0], playpos);
397 return;
398 }
399
400 xmms_remote_playlist_delete(session, playpos - 1);
401 }
402
403 void playlist_length(gint session, gint argc, gchar **argv)
404 {
405 gint i;
406
407 i = xmms_remote_get_playlist_length(session);
408
409 g_print("%d\n", i);
410 }
411
412 void playlist_song(gint session, gint argc, gchar **argv)
413 {
414 gint playpos;
415 gchar *song;
416
417 if (argc < 3)
418 {
419 g_print("%s: invalid parameters for playlist-song-title.\n", argv[0]);
420 g_print("%s: syntax: %s playlist-song-title <position>\n", argv[0], argv[0]);
421 return;
422 }
423
424 playpos = atoi(argv[2]);
425
426 if (playpos < 1 || playpos > xmms_remote_get_playlist_length(session))
427 {
428 g_print("%s: invalid playlist position %d\n", argv[0], playpos);
429 return;
430 }
431
432 song = xmms_remote_get_playlist_title(session, playpos - 1);
433
434 g_print("%s\n", song);
435 }
436
437
438 void playlist_song_length(gint session, gint argc, gchar **argv)
439 {
440 gint playpos, frames, length;
441
442 if (argc < 3)
443 {
444 g_print("%s: invalid parameters for playlist-song-length.\n", argv[0]);
445 g_print("%s: syntax: %s playlist-song-length <position>\n", argv[0], argv[0]);
446 return;
447 }
448
449 playpos = atoi(argv[2]);
450
451 if (playpos < 1 || playpos > xmms_remote_get_playlist_length(session))
452 {
453 g_print("%s: invalid playlist position %d\n", argv[0], playpos);
454 return;
455 }
456
457 frames = xmms_remote_get_playlist_time(session, playpos - 1);
458 length = frames / 1000;
459
460 g_print("%d:%.2d\n", length / 60, length % 60);
461 }
462
463 void playlist_song_length_seconds(gint session, gint argc, gchar **argv)
464 {
465 gint playpos, frames, length;
466
467 if (argc < 3)
468 {
469 g_print("%s: invalid parameters for playlist-song-length-seconds.\n", argv[0]);
470 g_print("%s: syntax: %s playlist-song-length-seconds <position>\n", argv[0], argv[0]);
471 return;
472 }
473
474 playpos = atoi(argv[2]);
475
476 if (playpos < 1 || playpos > xmms_remote_get_playlist_length(session))
477 {
478 g_print("%s: invalid playlist position %d\n", argv[0], playpos);
479 return;
480 }
481
482 frames = xmms_remote_get_playlist_time(session, playpos - 1);
483 length = frames / 1000;
484
485 g_print("%d\n", length);
486 }
487
488 void playlist_song_length_frames(gint session, gint argc, gchar **argv)
489 {
490 gint playpos, frames;
491
492 if (argc < 3)
493 {
494 g_print("%s: invalid parameters for playlist-song-length-frames.\n", argv[0]);
495 g_print("%s: syntax: %s playlist-song-length-frames <position>\n", argv[0], argv[0]);
496 return;
497 }
498
499 playpos = atoi(argv[2]);
500
501 if (playpos < 1 || playpos > xmms_remote_get_playlist_length(session))
502 {
503 g_print("%s: invalid playlist position %d\n", argv[0], playpos);
504 return;
505 }
506
507 frames = xmms_remote_get_playlist_time(session, playpos - 1);
508
509 g_print("%d\n", frames);
510 }
511
512 void playlist_display(gint session, gint argc, gchar **argv)
513 {
514 gint i, ii, frames, length, total;
515 gchar *songname;
516 gchar *fmt = NULL, *p;
517 gint column;
518
519 i = xmms_remote_get_playlist_length(session);
520
521 g_print("%d tracks.\n", i);
522
523 total = 0;
524
525 for (ii = 0; ii < i; ii++)
526 {
527 songname = xmms_remote_get_playlist_title(session, ii);
528 frames = xmms_remote_get_playlist_time(session, ii);
529 length = frames / 1000;
530 total += length;
531
532 /* adjust width for multi byte characters */
533 column = 60;
534 if(songname){
535 p = songname;
536 while(*p){
537 gint stride;
538 stride = g_utf8_next_char(p) - p;
539 if(g_unichar_iswide(g_utf8_get_char(p))
540 #if ( (GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION >= 12) )
541 || g_unichar_iswide_cjk(g_utf8_get_char(p))
542 #endif
543 ){
544 column += (stride - 2);
545 }
546 else {
547 column += (stride - 1);
548 }
549 p = g_utf8_next_char(p);
550 }
551
552 }
553
554 fmt = g_strdup_printf("%%4d | %%-%ds | %%d:%%.2d\n", column);
555 g_print(fmt, ii + 1, songname, length / 60, length % 60);
556 g_free(fmt);
557 }
558
559 g_print("Total length: %d:%.2d\n", total / 60, total % 60);
560 }
561
562 void playlist_position(gint session, gint argc, gchar **argv)
563 {
564 gint i;
565
566 i = xmms_remote_get_playlist_pos(session);
567
568 g_print("%d\n", i + 1);
569 }
570
571 void playlist_song_filename(gint session, gint argc, gchar **argv)
572 {
573 gint i;
574
575 if (argc < 3)
576 {
577 g_print("%s: invalid parameters for playlist-filename.\n", argv[0]);
578 g_print("%s: syntax: %s playlist-filename <position>\n", argv[0], argv[0]);
579 return;
580 }
581
582 i = atoi(argv[2]);
583
584 if (i < 1 || i > xmms_remote_get_playlist_length(session))
585 {
586 g_print("%s: invalid playlist position %d\n", argv[0], i);
587 return;
588 }
589
590 g_print("%s\n", xmms_remote_get_playlist_file(session, i - 1));
591 }
592
593 void playlist_jump(gint session, gint argc, gchar **argv)
594 {
595 gint i;
596
597 if (argc < 3)
598 {
599 g_print("%s: invalid parameters for playlist-jump.\n", argv[0]);
600 g_print("%s: syntax: %s playlist-jump <position>\n", argv[0], argv[0]);
601 return;
602 }
603
604 i = atoi(argv[2]);
605
606 if (i < 1 || i > xmms_remote_get_playlist_length(session))
607 {
608 g_print("%s: invalid playlist position %d\n", argv[0], i);
609 return;
610 }
611
612 xmms_remote_set_playlist_pos(session, i - 1);
613 }
614
615 void playlist_clear(gint session, gint argc, gchar **argv)
616 {
617 xmms_remote_playlist_clear(session);
618 }
619
620 void playlist_repeat_status(gint session, gint argc, gchar **argv)
621 {
622 if (xmms_remote_is_repeat(session))
623 {
624 g_print("on\n");
625 return;
626 }
627 else
628 {
629 g_print("off\n");
630 return;
631 }
632 }
633
634 void playlist_repeat_toggle(gint session, gint argc, gchar **argv)
635 {
636 xmms_remote_toggle_repeat(session);
637 }
638
639 void playlist_shuffle_status(gint session, gint argc, gchar **argv)
640 {
641 if (xmms_remote_is_shuffle(session))
642 {
643 g_print("on\n");
644 return;
645 }
646 else
647 {
648 g_print("off\n");
649 return;
650 }
651 }
652
653 void playlist_shuffle_toggle(gint session, gint argc, gchar **argv)
654 {
655 xmms_remote_toggle_shuffle(session);
656 }
657
658 void playqueue_add(gint session, gint argc, gchar **argv)
659 {
660 gint i;
661
662 if (argc < 3)
663 {
664 g_print("%s: invalid parameters for playqueue-add.\n", argv[0]);
665 g_print("%s: syntax: %s playqueue-add <position>\n", argv[0], argv[0]);
666 return;
667 }
668
669 i = atoi(argv[2]);
670
671 if (i < 1 || i > xmms_remote_get_playlist_length(session))
672 {
673 g_print("%s: invalid playlist position %d\n", argv[0], i);
674 return;
675 }
676
677 if (!(xmms_remote_playqueue_is_queued(session, i - 1)))
678 xmms_remote_playqueue_add(session, i - 1);
679 }
680
681 void playqueue_remove(gint session, gint argc, gchar **argv)
682 {
683 gint i;
684
685 if (argc < 3)
686 {
687 g_print("%s: invalid parameters for playqueue-remove.\n", argv[0]);
688 g_print("%s: syntax: %s playqueue-remove <position>\n", argv[0], argv[0]);
689 return;
690 }
691
692 i = atoi(argv[2]);
693
694 if (i < 1 || i > xmms_remote_get_playlist_length(session))
695 {
696 g_print("%s: invalid playlist position %d\n", argv[0], i);
697 return;
698 }
699
700 if (xmms_remote_playqueue_is_queued(session, i - 1))
701 xmms_remote_playqueue_remove(session, i - 1);
702 }
703
704 void playqueue_is_queued(gint session, gint argc, gchar **argv)
705 {
706 gint i;
707
708 if (argc < 3)
709 {
710 g_print("%s: invalid parameters for playqueue-is-queued.\n", argv[0]);
711 g_print("%s: syntax: %s playqueue-is-queued <position>\n", argv[0], argv[0]);
712 return;
713 }
714
715 i = atoi(argv[2]);
716
717 if (i < 1 || i > xmms_remote_get_playlist_length(session))
718 {
719 g_print("%s: invalid playlist position %d\n", argv[0], i);
720 return;
721 }
722
723 exit(!(xmms_remote_playqueue_is_queued(session, i - 1)));
724 }
725
726 void playqueue_get_position(gint session, gint argc, gchar **argv)
727 {
728 gint i, pos;
729
730 if (argc < 3)
731 {
732 g_print("%s: invalid parameters for playqueue-get-position.\n", argv[0]);
733 g_print("%s: syntax: %s playqueue-get-position <position>\n", argv[0], argv[0]);
734 return;
735 }
736
737 i = atoi(argv[2]);
738
739 if (i < 1 || i > xmms_remote_get_playlist_length(session))
740 {
741 g_print("%s: invalid playlist position %d\n", argv[0], i);
742 return;
743 }
744
745 pos = xmms_remote_get_playqueue_position(session, i - 1) + 1;
746
747 if (pos < 1)
748 return;
749
750 g_print("%d\n", pos);
751 }
752
753 void playqueue_get_qposition(gint session, gint argc, gchar **argv)
754 {
755 gint i, pos;
756
757 if (argc < 3)
758 {
759 g_print("%s: invalid parameters for playqueue-get-qposition.\n", argv[0]);
760 g_print("%s: syntax: %s playqueue-get-qposition <position>\n", argv[0], argv[0]);
761 return;
762 }
763
764 i = atoi(argv[2]);
765
766 if (i < 1 || i > xmms_remote_get_playqueue_length(session))
767 {
768 g_print("%s: invalid playlist position %d\n", argv[0], i);
769 return;
770 }
771
772 pos = xmms_remote_get_playqueue_queue_position(session, i - 1) + 1;
773
774 if (pos < 1)
775 return;
776
777 g_print("%d\n", pos);
778 }
779
780 void playqueue_display(gint session, gint argc, gchar **argv)
781 {
782 gint i, ii, position, frames, length, total;
783 gchar *songname;
784 gchar *fmt = NULL, *p;
785 gint column;
786
787 i = xmms_remote_get_playqueue_length(session);
788
789 g_print("%d queued tracks.\n", i);
790
791 total = 0;
792
793 for (ii = 0; ii < i; ii++)
794 {
795 position = xmms_remote_get_playqueue_queue_position(session, ii);
796 songname = xmms_remote_get_playlist_title(session, position);
797 frames = xmms_remote_get_playlist_time(session, position);
798 length = frames / 1000;
799 total += length;
800
801 /* adjust width for multi byte characters */
802 column = 60;
803 if(songname) {
804 p = songname;
805 while(*p){
806 gint stride;
807 stride = g_utf8_next_char(p) - p;
808 if(g_unichar_iswide(g_utf8_get_char(p))
809 #if ( (GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION >= 12) )
810 || g_unichar_iswide_cjk(g_utf8_get_char(p))
811 #endif
812 ){
813 column += (stride - 2);
814 }
815 else {
816 column += (stride - 1);
817 }
818 p = g_utf8_next_char(p);
819 }
820 }
821
822 fmt = g_strdup_printf("%%4d | %%4d | %%-%ds | %%d:%%.2d\n", column);
823 g_print(fmt, ii + 1, position + 1, songname, length / 60, length % 60);
824 g_free(fmt);
825 }
826
827 g_print("Total length: %d:%.2d\n", total / 60, total % 60);
828 }
829
830 void playqueue_length(gint session, gint argc, gchar **argv)
831 {
832 gint i;
833
834 i = xmms_remote_get_playqueue_length(session);
835
836 g_print("%d\n", i);
837 }
838
839 void playqueue_clear(gint session, gint argc, gchar **argv)
840 {
841 xmms_remote_playqueue_clear(session);
842 }
843
844 void get_volume(gint session, gint argc, gchar **argv)
845 {
846 gint i;
847
848 i = xmms_remote_get_main_volume(session);
849
850 g_print("%d\n", i);
851 }
852
853 void set_volume(gint session, gint argc, gchar **argv)
854 {
855 gint i, current_volume;
856
857 if (argc < 3)
858 {
859 g_print("%s: invalid parameters for set-volume.\n", argv[0]);
860 g_print("%s: syntax: %s set-volume <level>\n", argv[0], argv[0]);
861 return;
862 }
863
864 current_volume = xmms_remote_get_main_volume(session);
865 switch (argv[2][0])
866 {
867 case '+':
868 case '-':
869 i = current_volume + atoi(argv[2]);
870 break;
871 default:
872 i = atoi(argv[2]);
873 break;
874 }
875
876 xmms_remote_set_main_volume(session, i);
877 }
878
879 void mainwin_show(gint session, gint argc, gchar **argv)
880 {
881 if (argc > 2)
882 {
883 if (!strncmp(argv[2],"on",2)) {
884 xmms_remote_main_win_toggle(session, TRUE);
885 return;
886 }
887 else if (!strncmp(argv[2],"off",3)) {
888 xmms_remote_main_win_toggle(session, FALSE);
889 return;
890 }
891 }
892 g_print("%s: invalid parameter for mainwin-show.\n",argv[0]);
893 g_print("%s: syntax: %s mainwin-show <on/off>\n",argv[0],argv[0]);
894 }
895
896 void playlist_show(gint session, gint argc, gchar **argv)
897 {
898 if (argc > 2)
899 {
900 if (!strncmp(argv[2],"on",2)) {
901 xmms_remote_pl_win_toggle(session, TRUE);
902 return;
903 }
904 else if (!strncmp(argv[2],"off",3)) {
905 xmms_remote_pl_win_toggle(session, FALSE);
906 return;
907 }
908 }
909 g_print("%s: invalid parameter for playlist-show.\n",argv[0]);
910 g_print("%s: syntax: %s playlist-show <on/off>\n",argv[0],argv[0]);
911 }
912
913 void equalizer_show(gint session, gint argc, gchar **argv)
914 {
915 if (argc > 2)
916 {
917 if (!strncmp(argv[2],"on",2)) {
918 xmms_remote_eq_win_toggle(session, TRUE);
919 return;
920 }
921 else if (!strncmp(argv[2],"off",3)) {
922 xmms_remote_eq_win_toggle(session, FALSE);
923 return;
924 }
925 }
926 g_print("%s: invalid parameter for equalizer-show.\n",argv[0]);
927 g_print("%s: syntax: %s equalizer-show <on/off>\n",argv[0],argv[0]);
928 }
929
930 void show_preferences_window(gint session, gint argc, gchar **argv)
931 {
932 xmms_remote_show_prefs_box(session);
933 }
934
935 void show_jtf_window(gint session, gint argc, gchar **argv)
936 {
937 xmms_remote_show_jtf_box(session);
938 }
939
940 void shutdown_audacious_server(gint session, gint argc, gchar **argv)
941 {
942 xmms_remote_quit(session);
943 }
944
945 void get_handlers_list(gint session, gint argc, gchar **argv)
946 {
947 gint i;
948
949 for (i = 0; handlers[i].name != NULL; i++)
950 {
951 if (!g_strcasecmp("<sep>", handlers[i].name))
952 g_print("%s%s:\n", i == 0 ? "" : "\n", handlers[i].desc);
953 else
954 g_print(" %-34s - %s\n", handlers[i].name, handlers[i].desc);
955 }
956
957 g_print("\nHandlers may be prefixed with `--' (GNU-style long-options) or not, your choice.\n");
958 g_print("Report bugs to http://bugs-meta.atheme.org/\n");
959 }