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