Mercurial > audlegacy
annotate audtool/audtool.c @ 2065:598564ddc4e9 trunk
[svn] - no, this is not going to work
| author | nenolod |
|---|---|
| date | Thu, 07 Dec 2006 00:22:55 -0800 |
| parents | 8feb3d69b5be |
| children | 6bfa0777a57a |
| 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 { | |
| 2055 | 380 gint playpos; |
| 381 | |
| 1365 | 382 if (argc < 3) |
| 383 { | |
| 384 g_print("%s: invalid parameters for playlist-delete.\n", argv[0]); | |
| 385 g_print("%s: syntax: %s playlist-delete <position>\n", argv[0], argv[0]); | |
| 386 return; | |
| 387 } | |
| 388 | |
| 2055 | 389 playpos = atoi(argv[2]); |
| 1365 | 390 |
| 391 if (playpos < 1 || playpos > xmms_remote_get_playlist_length(session)) | |
| 392 { | |
| 393 g_print("%s: invalid playlist position %d\n", argv[0], playpos); | |
| 394 return; | |
| 395 } | |
| 396 | |
| 397 xmms_remote_playlist_delete(session, playpos - 1); | |
| 398 } | |
| 399 | |
| 1200 | 400 void playlist_length(gint session, gint argc, gchar **argv) |
| 401 { | |
| 402 gint i; | |
| 403 | |
| 404 i = xmms_remote_get_playlist_length(session); | |
| 405 | |
| 406 g_print("%d\n", i); | |
| 407 } | |
| 408 | |
| 409 void playlist_song(gint session, gint argc, gchar **argv) | |
| 410 { | |
| 2055 | 411 gint playpos; |
| 412 gchar *song; | |
| 413 | |
| 1200 | 414 if (argc < 3) |
| 415 { | |
| 416 g_print("%s: invalid parameters for playlist-song-title.\n", argv[0]); | |
| 417 g_print("%s: syntax: %s playlist-song-title <position>\n", argv[0], argv[0]); | |
| 418 return; | |
| 419 } | |
| 420 | |
| 2055 | 421 playpos = atoi(argv[2]); |
| 1200 | 422 |
| 423 if (playpos < 1 || playpos > xmms_remote_get_playlist_length(session)) | |
| 424 { | |
| 425 g_print("%s: invalid playlist position %d\n", argv[0], playpos); | |
| 426 return; | |
| 427 } | |
| 428 | |
| 2055 | 429 song = xmms_remote_get_playlist_title(session, playpos - 1); |
| 1200 | 430 |
| 431 g_print("%s\n", song); | |
| 432 } | |
| 433 | |
| 434 | |
| 435 void playlist_song_length(gint session, gint argc, gchar **argv) | |
| 436 { | |
| 2055 | 437 gint playpos, frames, length; |
| 438 | |
| 1200 | 439 if (argc < 3) |
| 440 { | |
| 441 g_print("%s: invalid parameters for playlist-song-length.\n", argv[0]); | |
| 442 g_print("%s: syntax: %s playlist-song-length <position>\n", argv[0], argv[0]); | |
| 443 return; | |
| 444 } | |
| 445 | |
| 2055 | 446 playpos = atoi(argv[2]); |
| 1200 | 447 |
| 448 if (playpos < 1 || playpos > xmms_remote_get_playlist_length(session)) | |
| 449 { | |
| 450 g_print("%s: invalid playlist position %d\n", argv[0], playpos); | |
| 451 return; | |
| 452 } | |
| 453 | |
| 2055 | 454 frames = xmms_remote_get_playlist_time(session, playpos - 1); |
| 455 length = frames / 1000; | |
| 1200 | 456 |
| 457 g_print("%d:%.2d\n", length / 60, length % 60); | |
| 458 } | |
| 459 | |
| 460 void playlist_song_length_seconds(gint session, gint argc, gchar **argv) | |
| 461 { | |
| 2055 | 462 gint playpos, frames, length; |
| 463 | |
| 1200 | 464 if (argc < 3) |
| 465 { | |
| 466 g_print("%s: invalid parameters for playlist-song-length-seconds.\n", argv[0]); | |
| 467 g_print("%s: syntax: %s playlist-song-length-seconds <position>\n", argv[0], argv[0]); | |
| 468 return; | |
| 469 } | |
| 470 | |
| 2055 | 471 playpos = atoi(argv[2]); |
| 1200 | 472 |
| 473 if (playpos < 1 || playpos > xmms_remote_get_playlist_length(session)) | |
| 474 { | |
| 475 g_print("%s: invalid playlist position %d\n", argv[0], playpos); | |
| 476 return; | |
| 477 } | |
| 478 | |
| 2055 | 479 frames = xmms_remote_get_playlist_time(session, playpos - 1); |
| 480 length = frames / 1000; | |
| 1200 | 481 |
| 482 g_print("%d\n", length); | |
| 483 } | |
| 484 | |
| 485 void playlist_song_length_frames(gint session, gint argc, gchar **argv) | |
| 486 { | |
| 2055 | 487 gint playpos, frames; |
| 488 | |
| 1200 | 489 if (argc < 3) |
| 490 { | |
| 491 g_print("%s: invalid parameters for playlist-song-length-frames.\n", argv[0]); | |
| 492 g_print("%s: syntax: %s playlist-song-length-frames <position>\n", argv[0], argv[0]); | |
| 493 return; | |
| 494 } | |
| 495 | |
| 2055 | 496 playpos = atoi(argv[2]); |
| 1200 | 497 |
| 498 if (playpos < 1 || playpos > xmms_remote_get_playlist_length(session)) | |
| 499 { | |
| 500 g_print("%s: invalid playlist position %d\n", argv[0], playpos); | |
| 501 return; | |
| 502 } | |
| 503 | |
| 2055 | 504 frames = xmms_remote_get_playlist_time(session, playpos - 1); |
| 1200 | 505 |
| 506 g_print("%d\n", frames); | |
| 507 } | |
| 508 | |
| 509 void playlist_display(gint session, gint argc, gchar **argv) | |
| 510 { | |
| 511 gint i, ii, frames, length, total; | |
| 512 gchar *songname; | |
| 1931 | 513 gchar *fmt = NULL, *p; |
| 514 gint column; | |
| 515 | |
| 1200 | 516 i = xmms_remote_get_playlist_length(session); |
| 517 | |
| 518 g_print("%d tracks.\n", i); | |
| 519 | |
| 520 total = 0; | |
| 521 | |
| 522 for (ii = 0; ii < i; ii++) | |
| 523 { | |
| 524 songname = xmms_remote_get_playlist_title(session, ii); | |
| 525 frames = xmms_remote_get_playlist_time(session, ii); | |
| 526 length = frames / 1000; | |
| 527 total += length; | |
| 528 | |
| 1931 | 529 /* adjust width for multi byte characters */ |
| 530 column = 60; | |
| 531 if(songname){ | |
| 532 p = songname; | |
| 533 while(*p){ | |
| 534 gint stride; | |
| 535 stride = g_utf8_next_char(p) - p; | |
| 1953 | 536 if(g_unichar_iswide(g_utf8_get_char(p)) |
| 537 #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
|
538 || 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
|
539 #endif |
|
78e8d9dd5036
[svn] - only use g_unichar_iswide_cjk if GLib 2.12 is available.
nenolod
parents:
1932
diff
changeset
|
540 ){ |
| 1931 | 541 column += (stride - 2); |
| 542 } | |
| 543 else { | |
| 544 column += (stride - 1); | |
| 545 } | |
| 546 p = g_utf8_next_char(p); | |
| 547 } | |
| 548 | |
| 549 } | |
| 550 | |
| 551 fmt = g_strdup_printf("%%4d | %%-%ds | %%d:%%.2d\n", column); | |
| 552 g_print(fmt, ii + 1, songname, length / 60, length % 60); | |
| 553 g_free(fmt); | |
| 1200 | 554 } |
| 555 | |
| 556 g_print("Total length: %d:%.2d\n", total / 60, total % 60); | |
| 557 } | |
| 558 | |
| 559 void playlist_position(gint session, gint argc, gchar **argv) | |
| 560 { | |
| 561 gint i; | |
| 562 | |
| 563 i = xmms_remote_get_playlist_pos(session); | |
| 564 | |
| 565 g_print("%d\n", i + 1); | |
| 566 } | |
| 567 | |
| 568 void playlist_song_filename(gint session, gint argc, gchar **argv) | |
| 569 { | |
| 570 gint i; | |
| 571 | |
| 572 if (argc < 3) | |
| 573 { | |
| 574 g_print("%s: invalid parameters for playlist-filename.\n", argv[0]); | |
| 575 g_print("%s: syntax: %s playlist-filename <position>\n", argv[0], argv[0]); | |
| 576 return; | |
| 577 } | |
| 578 | |
| 579 i = atoi(argv[2]); | |
| 580 | |
| 581 if (i < 1 || i > xmms_remote_get_playlist_length(session)) | |
| 582 { | |
| 583 g_print("%s: invalid playlist position %d\n", argv[0], i); | |
| 584 return; | |
| 585 } | |
| 586 | |
| 587 g_print("%s\n", xmms_remote_get_playlist_file(session, i - 1)); | |
| 588 } | |
| 589 | |
| 590 void playlist_jump(gint session, gint argc, gchar **argv) | |
| 591 { | |
| 592 gint i; | |
| 593 | |
| 594 if (argc < 3) | |
| 595 { | |
| 596 g_print("%s: invalid parameters for playlist-jump.\n", argv[0]); | |
| 597 g_print("%s: syntax: %s playlist-jump <position>\n", argv[0], argv[0]); | |
| 598 return; | |
| 599 } | |
| 600 | |
| 601 i = atoi(argv[2]); | |
| 602 | |
| 603 if (i < 1 || i > xmms_remote_get_playlist_length(session)) | |
| 604 { | |
| 605 g_print("%s: invalid playlist position %d\n", argv[0], i); | |
| 606 return; | |
| 607 } | |
| 608 | |
| 609 xmms_remote_set_playlist_pos(session, i - 1); | |
| 610 } | |
| 611 | |
| 612 void playlist_clear(gint session, gint argc, gchar **argv) | |
| 613 { | |
| 614 xmms_remote_playlist_clear(session); | |
| 615 } | |
| 616 | |
| 617 void playlist_repeat_status(gint session, gint argc, gchar **argv) | |
| 618 { | |
| 619 if (xmms_remote_is_repeat(session)) | |
| 620 { | |
| 621 g_print("on\n"); | |
| 622 return; | |
| 623 } | |
| 624 else | |
| 625 { | |
| 626 g_print("off\n"); | |
| 627 return; | |
| 628 } | |
| 629 } | |
| 630 | |
| 631 void playlist_repeat_toggle(gint session, gint argc, gchar **argv) | |
| 632 { | |
| 633 xmms_remote_toggle_repeat(session); | |
| 634 } | |
| 635 | |
| 636 void playlist_shuffle_status(gint session, gint argc, gchar **argv) | |
| 637 { | |
| 638 if (xmms_remote_is_shuffle(session)) | |
| 639 { | |
| 640 g_print("on\n"); | |
| 641 return; | |
| 642 } | |
| 643 else | |
| 644 { | |
| 645 g_print("off\n"); | |
| 646 return; | |
| 647 } | |
| 648 } | |
| 649 | |
| 650 void playlist_shuffle_toggle(gint session, gint argc, gchar **argv) | |
| 651 { | |
| 652 xmms_remote_toggle_shuffle(session); | |
| 653 } | |
| 654 | |
| 655 void playqueue_add(gint session, gint argc, gchar **argv) | |
| 656 { | |
|
1204
76e6b66fb859
[svn] - compiles warningless inside the audacious buildsystem now
nenolod
parents:
1203
diff
changeset
|
657 gint i; |
| 1200 | 658 |
| 659 if (argc < 3) | |
| 660 { | |
| 661 g_print("%s: invalid parameters for playqueue-add.\n", argv[0]); | |
| 662 g_print("%s: syntax: %s playqueue-add <position>\n", argv[0], argv[0]); | |
| 663 return; | |
| 664 } | |
| 665 | |
| 666 i = atoi(argv[2]); | |
| 667 | |
| 668 if (i < 1 || i > xmms_remote_get_playlist_length(session)) | |
| 669 { | |
| 670 g_print("%s: invalid playlist position %d\n", argv[0], i); | |
| 671 return; | |
| 672 } | |
| 673 | |
| 674 if (!(xmms_remote_playqueue_is_queued(session, i - 1))) | |
| 675 xmms_remote_playqueue_add(session, i - 1); | |
| 676 } | |
| 677 | |
| 678 void playqueue_remove(gint session, gint argc, gchar **argv) | |
| 679 { | |
|
1204
76e6b66fb859
[svn] - compiles warningless inside the audacious buildsystem now
nenolod
parents:
1203
diff
changeset
|
680 gint i; |
| 1200 | 681 |
| 682 if (argc < 3) | |
| 683 { | |
| 684 g_print("%s: invalid parameters for playqueue-remove.\n", argv[0]); | |
| 685 g_print("%s: syntax: %s playqueue-remove <position>\n", argv[0], argv[0]); | |
| 686 return; | |
| 687 } | |
| 688 | |
| 689 i = atoi(argv[2]); | |
| 690 | |
| 691 if (i < 1 || i > xmms_remote_get_playlist_length(session)) | |
| 692 { | |
| 693 g_print("%s: invalid playlist position %d\n", argv[0], i); | |
| 694 return; | |
| 695 } | |
| 696 | |
| 697 if (xmms_remote_playqueue_is_queued(session, i - 1)) | |
| 698 xmms_remote_playqueue_remove(session, i - 1); | |
| 699 } | |
| 700 | |
| 701 void playqueue_is_queued(gint session, gint argc, gchar **argv) | |
| 702 { | |
| 703 gint i; | |
| 704 | |
| 705 if (argc < 3) | |
| 706 { | |
| 707 g_print("%s: invalid parameters for playqueue-is-queued.\n", argv[0]); | |
| 708 g_print("%s: syntax: %s playqueue-is-queued <position>\n", argv[0], argv[0]); | |
| 709 return; | |
| 710 } | |
| 711 | |
| 712 i = atoi(argv[2]); | |
| 713 | |
| 714 if (i < 1 || i > xmms_remote_get_playlist_length(session)) | |
| 715 { | |
| 716 g_print("%s: invalid playlist position %d\n", argv[0], i); | |
| 717 return; | |
| 718 } | |
| 719 | |
| 720 exit(!(xmms_remote_playqueue_is_queued(session, i - 1))); | |
| 721 } | |
| 722 | |
| 723 void playqueue_get_position(gint session, gint argc, gchar **argv) | |
| 724 { | |
| 725 gint i, pos; | |
| 726 | |
| 727 if (argc < 3) | |
| 728 { | |
| 729 g_print("%s: invalid parameters for playqueue-get-position.\n", argv[0]); | |
| 730 g_print("%s: syntax: %s playqueue-get-position <position>\n", argv[0], argv[0]); | |
| 731 return; | |
| 732 } | |
| 733 | |
| 734 i = atoi(argv[2]); | |
| 735 | |
| 736 if (i < 1 || i > xmms_remote_get_playlist_length(session)) | |
| 737 { | |
| 738 g_print("%s: invalid playlist position %d\n", argv[0], i); | |
| 739 return; | |
| 740 } | |
| 741 | |
| 742 pos = xmms_remote_get_playqueue_position(session, i - 1) + 1; | |
| 743 | |
| 744 if (pos < 1) | |
| 745 return; | |
| 746 | |
| 747 g_print("%d\n", pos); | |
| 748 } | |
| 749 | |
| 750 void playqueue_get_qposition(gint session, gint argc, gchar **argv) | |
| 751 { | |
| 752 gint i, pos; | |
| 753 | |
| 754 if (argc < 3) | |
| 755 { | |
| 756 g_print("%s: invalid parameters for playqueue-get-qposition.\n", argv[0]); | |
| 757 g_print("%s: syntax: %s playqueue-get-qposition <position>\n", argv[0], argv[0]); | |
| 758 return; | |
| 759 } | |
| 760 | |
| 761 i = atoi(argv[2]); | |
| 762 | |
| 763 if (i < 1 || i > xmms_remote_get_playqueue_length(session)) | |
| 764 { | |
| 765 g_print("%s: invalid playlist position %d\n", argv[0], i); | |
| 766 return; | |
| 767 } | |
| 768 | |
| 769 pos = xmms_remote_get_playqueue_queue_position(session, i - 1) + 1; | |
| 770 | |
| 771 if (pos < 1) | |
| 772 return; | |
| 773 | |
| 774 g_print("%d\n", pos); | |
| 775 } | |
| 776 | |
| 777 void playqueue_display(gint session, gint argc, gchar **argv) | |
| 778 { | |
| 779 gint i, ii, position, frames, length, total; | |
| 780 gchar *songname; | |
| 1931 | 781 gchar *fmt = NULL, *p; |
| 782 gint column; | |
| 1200 | 783 |
| 784 i = xmms_remote_get_playqueue_length(session); | |
| 785 | |
| 786 g_print("%d queued tracks.\n", i); | |
| 787 | |
| 788 total = 0; | |
| 789 | |
| 790 for (ii = 0; ii < i; ii++) | |
| 791 { | |
| 792 position = xmms_remote_get_playqueue_queue_position(session, ii); | |
| 793 songname = xmms_remote_get_playlist_title(session, position); | |
| 794 frames = xmms_remote_get_playlist_time(session, position); | |
| 795 length = frames / 1000; | |
| 796 total += length; | |
| 797 | |
| 1931 | 798 /* adjust width for multi byte characters */ |
| 799 column = 60; | |
| 800 if(songname) { | |
| 801 p = songname; | |
| 802 while(*p){ | |
| 803 gint stride; | |
| 804 stride = g_utf8_next_char(p) - p; | |
| 1953 | 805 if(g_unichar_iswide(g_utf8_get_char(p)) |
| 806 #if ( (GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION >= 12) ) | |
| 807 || g_unichar_iswide_cjk(g_utf8_get_char(p)) | |
| 808 #endif | |
| 809 ){ | |
| 1931 | 810 column += (stride - 2); |
| 811 } | |
| 812 else { | |
| 813 column += (stride - 1); | |
| 814 } | |
| 815 p = g_utf8_next_char(p); | |
| 816 } | |
| 817 } | |
| 818 | |
| 819 fmt = g_strdup_printf("%%4d | %%4d | %%-%ds | %%d:%%.2d\n", column); | |
| 820 g_print(fmt, ii + 1, position + 1, songname, length / 60, length % 60); | |
| 821 g_free(fmt); | |
| 1200 | 822 } |
| 823 | |
| 824 g_print("Total length: %d:%.2d\n", total / 60, total % 60); | |
| 825 } | |
| 826 | |
| 827 void playqueue_length(gint session, gint argc, gchar **argv) | |
| 828 { | |
| 829 gint i; | |
| 830 | |
| 831 i = xmms_remote_get_playqueue_length(session); | |
| 832 | |
| 833 g_print("%d\n", i); | |
| 834 } | |
| 835 | |
| 836 void playqueue_clear(gint session, gint argc, gchar **argv) | |
| 837 { | |
| 838 xmms_remote_playqueue_clear(session); | |
| 839 } | |
| 840 | |
| 841 void get_volume(gint session, gint argc, gchar **argv) | |
| 842 { | |
| 843 gint i; | |
| 844 | |
| 845 i = xmms_remote_get_main_volume(session); | |
| 846 | |
| 847 g_print("%d\n", i); | |
| 848 } | |
| 849 | |
| 850 void set_volume(gint session, gint argc, gchar **argv) | |
| 851 { | |
| 852 gint i, current_volume; | |
| 853 | |
| 854 if (argc < 3) | |
| 855 { | |
| 856 g_print("%s: invalid parameters for set-volume.\n", argv[0]); | |
| 857 g_print("%s: syntax: %s set-volume <level>\n", argv[0], argv[0]); | |
| 858 return; | |
| 859 } | |
| 860 | |
| 861 current_volume = xmms_remote_get_main_volume(session); | |
| 862 switch (argv[2][0]) | |
| 863 { | |
| 864 case '+': | |
| 865 case '-': | |
| 866 i = current_volume + atoi(argv[2]); | |
| 867 break; | |
| 868 default: | |
| 869 i = atoi(argv[2]); | |
| 870 break; | |
| 871 } | |
| 872 | |
| 873 xmms_remote_set_main_volume(session, i); | |
| 874 } | |
| 875 | |
| 876 void show_preferences_window(gint session, gint argc, gchar **argv) | |
| 877 { | |
| 878 xmms_remote_show_prefs_box(session); | |
| 879 } | |
| 880 | |
| 881 void show_jtf_window(gint session, gint argc, gchar **argv) | |
| 882 { | |
| 883 xmms_remote_show_jtf_box(session); | |
| 884 } | |
| 885 | |
| 886 void shutdown_audacious_server(gint session, gint argc, gchar **argv) | |
| 887 { | |
| 888 xmms_remote_quit(session); | |
| 889 } | |
| 890 | |
| 891 void get_handlers_list(gint session, gint argc, gchar **argv) | |
| 892 { | |
| 893 gint i; | |
| 894 | |
| 895 for (i = 0; handlers[i].name != NULL; i++) | |
| 896 { | |
|
1203
a09393433f83
[svn] - OMKize Makefile (examples not installed yet)
nenolod
parents:
1200
diff
changeset
|
897 if (!g_strcasecmp("<sep>", handlers[i].name)) |
| 1316 | 898 g_print("%s%s:\n", i == 0 ? "" : "\n", handlers[i].desc); |
| 1200 | 899 else |
| 900 g_print(" %-34s - %s\n", handlers[i].name, handlers[i].desc); | |
| 901 } | |
| 902 | |
| 903 g_print("\nHandlers may be prefixed with `--' (GNU-style long-options) or not, your choice.\n"); | |
| 904 g_print("Report bugs to http://bugs.audacious-media-player.org.\n"); | |
| 905 } |
