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