The queue command works similarly to add (in fact, it's a wrapper around
it), except it places the newly added song(s) just after the currently
playing one, rather than at the end.

Signed-off-by: Olivier Mehani <shtrom-...@ssji.net>

(Please CC me on related discussions, as I'm not subscribed to the
list.)

---
 src/command.c |   19 +++++++++++++++++++
 src/command.h |    1 +
 src/main.c    |    1 +
 3 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/src/command.c b/src/command.c
index bafddb7..7715049 100644
--- a/src/command.c
+++ b/src/command.c
@@ -731,6 +731,25 @@ int cmd_load ( int argc, char ** argv, struct 
mpd_connection *conn )
        return 0;
 }
 
+int cmd_queue (int argc, char ** argv, struct mpd_connection *conn )
+{
+       int ret;
+       struct mpd_status *status = mpd_run_status(conn);
+       if (status == NULL)
+               printErrorAndExit(conn);
+
+       const int from = mpd_status_get_queue_length(status);
+
+       ret = cmd_add(argc, argv, conn);        
+       const int cur_pos = mpd_status_get_song_pos(status);
+       mpd_status_free(status);
+       if (ret != 0) {
+               return ret;
+       }
+       return mpd_run_move_range(conn, from, from+argc, 
+               cur_pos+1);
+}
+
 int cmd_list ( int argc, char ** argv, struct mpd_connection *conn )
 {
        enum mpd_tag_type type;
diff --git a/src/command.h b/src/command.h
index 325f0ff..09cf384 100644
--- a/src/command.h
+++ b/src/command.h
@@ -45,6 +45,7 @@ int cmd_listall(int argc, char **argv, struct mpd_connection 
*conn);
 int cmd_ls(int argc, char **argv, struct mpd_connection *conn);
 int cmd_lsplaylists(int argc, char **argv, struct mpd_connection *conn);
 int cmd_load(int argc, char **argv, struct mpd_connection *conn);
+int cmd_queue(int argc, char **argv, struct mpd_connection *conn);
 int cmd_list(int argc, char **argv, struct mpd_connection *conn);
 int cmd_save(int argc, char **argv, struct mpd_connection *conn);
 int cmd_rm(int argc, char **argv, struct mpd_connection *conn);
diff --git a/src/main.c b/src/main.c
index f0532f4..0c93608 100644
--- a/src/main.c
+++ b/src/main.c
@@ -81,6 +81,7 @@ static struct command {
        {"ls",          0,   -1,  2,    cmd_ls,          "[<directory>]", "List 
the contents of <directory>"},
        {"lsplaylists", 0,   -1,  2,    cmd_lsplaylists, "", "List currently 
available playlists"},
        {"load",        0,   -1,  1,    cmd_load,        "<file>", "Load <file> 
as a playlist"},
+       {"queue",       0,   -1,  1,    cmd_queue,         "<file>", "Add a 
song to the current playlist, just after the current track"},
        {"save",        1,   1,   0,    cmd_save,        "<file>", "Save a 
playlist as <file>"},
        {"rm",          1,   1,   0,    cmd_rm,          "<file>", "Remove a 
playlist"},
        {"volume",      0,   1,   0,    cmd_volume,      "[+-]<num>", "Set 
volume to <num> or adjusts by [+-]<num>"},
-- 
1.7.3.4

------------------------------------------------------------------------------
Fulfilling the Lean Software Promise
Lean software platforms are now widely adopted and the benefits have been 
demonstrated beyond question. Learn why your peers are replacing JEE 
containers with lightweight application servers - and what you can gain 
from the move. http://p.sf.net/sfu/vmware-sfemails
_______________________________________________
Musicpd-dev-team mailing list
Musicpd-dev-team@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/musicpd-dev-team

Reply via email to