gboolean cli_jump (cli_context_t *ctx, command_t *cmd) { xmmsc_connection_t *conn = cli_context_xmms_sync (ctx); xmmsv_t *query; gboolean backward = FALSE; playlist_positions_t *positions; command_flag_boolean_get (cmd, "backward", &backward); /* Select by positions */ if (command_arg_positions_get (cmd, 0, &positions, cli_context_current_position (ctx))) { gint pos; if (playlist_positions_get_single (positions, &pos)) { XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_playlist_set_next, conn, pos), XMMS_CALL_P (xmmsc_playback_tickle, conn)); } else { g_printf (_("Cannot jump to several positions!\n")); } playlist_positions_free (positions); /* Select by pattern */ } else if (command_arg_pattern_get (cmd, 0, &query, TRUE)) { query = xmmsv_coll_intersect_with_playlist (query, XMMS_ACTIVE_PLAYLIST); XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_coll_query_ids, conn, query, NULL, 0, 0), FUNC_CALL_P (cli_jump_relative, ctx, (backward ? -1 : 1), XMMS_PREV_VALUE)); xmmsv_unref (query); } return FALSE; }
static gint readline_previous_song (gint count, gint key) { xmmsc_connection_t *conn = cli_context_xmms_sync (readline_cli_ctx); XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_playlist_set_next_rel, conn, -1), XMMS_CALL_P (xmmsc_playback_tickle, conn)); return 0; }
static void currently_playing_request_status (currently_playing_t *entry) { xmmsc_connection_t *conn = cli_context_xmms_sync (entry->ctx); XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_playback_status, conn), FUNC_CALL_P (currently_playing_update_status, entry, XMMS_PREV_VALUE)); }
gboolean cli_next (cli_context_t *ctx, command_t *cmd) { xmmsc_connection_t *conn = cli_context_xmms_sync (ctx); gint offset = 1; gint n; if (command_arg_int_get (cmd, 0, &n)) { offset = n; } XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_playlist_set_next_rel, conn, offset), XMMS_CALL_P (xmmsc_playback_tickle, conn)); return FALSE; }
void cli_cache_refresh (cli_cache_t *cache) { XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_playlist_current_pos, cache->conn, XMMS_ACTIVE_PLAYLIST), FUNC_CALL_P (refresh_currpos, XMMS_PREV_VALUE, cache)); XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_playback_current_id, cache->conn), FUNC_CALL_P (refresh_currid, XMMS_PREV_VALUE, cache)); XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_playback_status, cache->conn), FUNC_CALL_P (refresh_playback_status, XMMS_PREV_VALUE, cache)); XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_playlist_list_entries, cache->conn, XMMS_ACTIVE_PLAYLIST), FUNC_CALL_P (refresh_active_playlist, XMMS_PREV_VALUE, cache)); XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_playlist_current_active, cache->conn), FUNC_CALL_P (refresh_active_playlist_name, XMMS_PREV_VALUE, cache)); }
static void cli_jump_relative (cli_context_t *ctx, gint inc, xmmsv_t *value) { xmmsc_connection_t *conn = cli_context_xmms_sync (ctx); xmmsv_list_iter_t *it; gint i, plid, id, currpos, plsize; xmmsv_t *playlist; currpos = cli_context_current_position (ctx); playlist = cli_context_active_playlist (ctx); plsize = xmmsv_list_get_size (playlist); /* If no currpos, start jump from beginning */ if (currpos < 0) { currpos = 0; } /* magic trick so we can loop in either direction */ inc += plsize; xmmsv_get_list_iter (value, &it); /* Loop on the playlist */ for (i = (currpos + inc) % plsize; i != currpos; i = (i + inc) % plsize) { xmmsv_list_iter_first (it); xmmsv_list_get_int (playlist, i, &plid); /* Loop on the matched media */ while (xmmsv_list_iter_entry_int (it, &id)) { /* If both match, jump! */ if (plid == id) { XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_playlist_set_next, conn, i), XMMS_CALL_P (xmmsc_playback_tickle, conn)); return; } xmmsv_list_iter_next (it); } } /* No matching media found, don't jump */ g_printf (_("No media matching the pattern in the playlist!\n")); }
static void currently_playing_request_info (currently_playing_t *entry) { xmmsc_connection_t *conn = cli_context_xmms_sync (entry->ctx); gint current_id = cli_context_current_id (entry->ctx); if (current_id > 0) { XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_medialib_get_info, conn, current_id), FUNC_CALL_P (currently_playing_update_info, entry, XMMS_PREV_VALUE)); } }
/* Get current position in @playlist or in active playlist if @playlist == NULL. */ static gboolean playlist_currpos_get (cli_context_t *ctx, const gchar *playlist, gint *pos) { xmmsc_connection_t *conn = cli_context_xmms_sync (ctx); if (playlist) { XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_coll_get, conn, playlist, XMMS_COLLECTION_NS_PLAYLISTS), FUNC_CALL_P (playlist_coll_attribute_get_position, XMMS_PREV_VALUE, pos)); } else { *pos = cli_context_current_position (ctx); } return TRUE; }
static void cli_list_print_positions_row (gint pos, void *udata) { cli_list_positions_t *pack = (cli_list_positions_t *) udata; gint id; if (pos >= xmmsv_list_get_size (pack->entries)) { return; } if (xmmsv_list_get_int (pack->entries, pos, &id)) { column_display_set_position (pack->coldisp, pos); XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_medialib_get_info, pack->sync, id), FUNC_CALL_P (cli_list_print_row, pack->coldisp, XMMS_PREV_VALUE)); } }
/* Get length of @playlist or of active playlist if @playlist == NULL. */ static gboolean playlist_length_get (cli_context_t *ctx, const gchar *playlist, gint *length) { xmmsc_connection_t *conn = cli_context_xmms_sync (ctx); *length = -1; if (playlist) { XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_coll_get, conn, playlist, XMMS_COLLECTION_NS_PLAYLISTS), FUNC_CALL_P (playlist_coll_idlist_get_size, XMMS_PREV_VALUE, length)); } else { xmmsv_t *entries = cli_context_active_playlist (ctx); *length = xmmsv_list_get_size (entries); } return *length >= 0; }
/* TODO: Not really a part of the server sub-command, but in the future it * can be refactored to just call "xmms2 server property" and let that * do the printing */ gboolean cli_info (cli_context_t *ctx, command_t *cmd) { xmmsc_connection_t *conn = cli_context_xmms_sync (ctx); playlist_positions_t *positions; xmmsv_t *query; gint current_position = cli_context_current_position (ctx); gint current_id = cli_context_current_id (ctx); if (command_arg_positions_get (cmd, 0, &positions, current_position)) { cli_info_print_positions (ctx, positions); playlist_positions_free (positions); } else if (command_arg_pattern_get (cmd, 0, &query, FALSE)) { XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_coll_query_ids, conn, query, NULL, 0, 0); FUNC_CALL_P (cli_info_print_list, ctx, XMMS_PREV_VALUE)); xmmsv_unref (query); } else {
static void cli_info_print_list (cli_context_t *ctx, xmmsv_t *val) { xmmsc_connection_t *conn = cli_context_xmms_sync (ctx); xmmsv_list_iter_t *it; gboolean first = TRUE; gint32 id; xmmsv_get_list_iter (val, &it); while (xmmsv_list_iter_entry_int (it, &id)) { if (!first) { g_printf ("\n"); } else { first = FALSE; } XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_medialib_get_info, conn, id), FUNC_CALL_P (cli_info_print, XMMS_PREV_VALUE)); xmmsv_list_iter_next (it); } }
static void cli_info_print_position (gint pos, void *userdata) { cli_info_print_positions_t *pack = (cli_info_print_positions_t *) userdata; xmmsc_connection_t *conn = cli_context_xmms_sync (pack->ctx); xmmsv_t *playlist = cli_context_active_playlist (pack->ctx); gint id; /* Skip if outside of playlist */ if (!xmmsv_list_get_int (playlist, pos, &id)) { return; } /* Do not prepend newline before the first entry */ if (pack->inc > 0) { g_printf ("\n"); } else { pack->inc++; } XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_medialib_get_info, conn, id), FUNC_CALL_P (cli_info_print, XMMS_PREV_VALUE)); }