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