From cbf36c5b93843d434aabfb97bd3127023374e2e9 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Fri, 13 Feb 2009 10:56:35 +0100 Subject: [PATCH] use the new mpd shufflerange command. --- src/libmpdclient.c | 7 +++++++ src/libmpdclient.h | 2 ++ src/mpdclient.c | 10 +++++++++- src/mpdclient.h | 1 + src/screen_play.c | 8 ++------ 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/libmpdclient.c b/src/libmpdclient.c index c037cae..ae362a1 100644 --- a/src/libmpdclient.c +++ b/src/libmpdclient.c @@ -1277,6 +1277,13 @@ void mpd_sendShuffleCommand(mpd_Connection * connection) { mpd_executeCommand(connection,"shuffle\n"); } +void mpd_sendShuffleRangeCommand(mpd_Connection * connection, int start, int end) { + char * string = malloc(strlen("shufflerange")+25); + sprintf(string,"shuffle \"%i:%i\"\n", start, end); + mpd_executeCommand(connection,string); + free(string); +} + void mpd_sendClearCommand(mpd_Connection * connection) { mpd_executeCommand(connection,"clear\n"); } diff --git a/src/libmpdclient.h b/src/libmpdclient.h index cfa87a7..409a178 100644 --- a/src/libmpdclient.h +++ b/src/libmpdclient.h @@ -423,6 +423,8 @@ void mpd_sendRmCommand(mpd_Connection * connection, const char * name); void mpd_sendShuffleCommand(mpd_Connection * connection); +void mpd_sendShuffleRangeCommand(mpd_Connection * connection, int start, int end); + void mpd_sendClearCommand(mpd_Connection * connection); /* use this to start playing at the beginning, useful when in random mode */ diff --git a/src/mpdclient.c b/src/mpdclient.c index f5939e4..8095530 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -1,7 +1,7 @@ /* ncmpc (Ncurses MPD Client) * (c) 2004-2009 The Music Player Daemon Project * Project homepage: http://musicpd.org - + * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -343,6 +343,14 @@ mpdclient_cmd_shuffle(mpdclient_t *c) } gint +mpdclient_cmd_shuffle_range(mpdclient_t *c, gint start, gint end) +{ + mpd_sendShuffleRangeCommand(c->connection, start, end); + c->need_update = TRUE; + return mpdclient_finish_command(c); +} + +gint mpdclient_cmd_clear(mpdclient_t *c) { gint retval = 0; diff --git a/src/mpdclient.h b/src/mpdclient.h index 1b52d06..d4cabf3 100644 --- a/src/mpdclient.h +++ b/src/mpdclient.h @@ -53,6 +53,7 @@ gint mpdclient_cmd_next(mpdclient_t *c); gint mpdclient_cmd_prev(mpdclient_t *c); gint mpdclient_cmd_seek(mpdclient_t *c, gint id, gint pos); gint mpdclient_cmd_shuffle(mpdclient_t *c); +gint mpdclient_cmd_shuffle_range(mpdclient_t *c, gint start, gint end); gint mpdclient_cmd_clear(mpdclient_t *c); gint mpdclient_cmd_repeat(mpdclient_t *c, gint value); gint mpdclient_cmd_random(mpdclient_t *c, gint value); diff --git a/src/screen_play.c b/src/screen_play.c index 6984dfc..75b0f2e 100644 --- a/src/screen_play.c +++ b/src/screen_play.c @@ -600,16 +600,12 @@ play_cmd(mpdclient_t *c, command_t cmd) return false; case CMD_SHUFFLE: { - unsigned i = lw->selected_start + 1; - unsigned last_selected = lw->selected; if(!lw->visual_selection) /* No visual selection, shuffle all list. */ break; - for(; i <= lw->selected_end; ++i) - mpdclient_cmd_move(c, i, lw->selected_start + (rand() % ((i - lw->selected_start) + 1))); - lw->selected = last_selected; - screen_status_printf(_("Shuffled selection!")); + if (mpdclient_cmd_shuffle_range(c, lw->selected_start, lw->selected_end+1) == 0) + screen_status_message(_("Shuffled playlist")); return true; } -- 2.11.4.GIT