Code

use the new mpd shufflerange command.
authorRomain Bignon <romain@peerfuse.org>
Fri, 13 Feb 2009 09:56:35 +0000 (10:56 +0100)
committerMax Kellermann <max@duempel.org>
Fri, 13 Feb 2009 09:59:17 +0000 (10:59 +0100)
src/libmpdclient.c
src/libmpdclient.h
src/mpdclient.c
src/mpdclient.h
src/screen_play.c

index c037caeace2c3c2aec59fe18509f7ae686101939..ae362a1342ec1a2819cd84d14854dff8b64ac2e4 100644 (file)
@@ -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");
 }
index cfa87a7d0803a3d99a41bb542d98a4f753a9f608..409a178ce81784246f8bbb16b6e2f18087282a5f 100644 (file)
@@ -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 */
index f5939e475e03e90cd020684978842b6a1865d1fc..809553030df861e066aaffa7f83e4a2044fb95cb 100644 (file)
@@ -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
@@ -342,6 +342,14 @@ mpdclient_cmd_shuffle(mpdclient_t *c)
        return mpdclient_finish_command(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)
 {
index 1b52d06e9c739583f1ef11004bfeb935e8bc1e59..d4cabf3585993815446f368a6a135b88299651bd 100644 (file)
@@ -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);
index 6984dfcac97678d44578637007910b6110653ea8..75b0f2edad5f03ce31912b66b40d2374b495ad43 100644 (file)
@@ -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;
        }