On Tue, Apr 26, 2011 at 09:52:16AM +0200, Kurt Van Dijck wrote:
> > Feel free to s/queue/insert/g* on my patch if it gets merged in!
> I believe it's better you recreate the patch (I'm not maintainer neither).

Here we go then. This patch has the nomenclature right, and updates the
manpage.

-- 
Olivier Mehani <sht...@ssji.net>
PGP fingerprint: 4435 CF6A 7C8D DD9B E2DE  F5F9 F012 A6E2 98C6 6655
From a16ee5d297be0227634b4e942ee9192931fb151b Mon Sep 17 00:00:00 2001
From: Olivier Mehani <sht...@ssji.net>
Date: Mon, 25 Apr 2011 04:16:45 +1000
Subject: [PATCH] Add an 'insert' command to mpc

The insert 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. The manpage is updated
accordingly.

Signed-off-by: Olivier Mehani <shtrom-...@ssji.net>
Signed-off-by: Olivier Mehani <sht...@ssji.net>
---
 doc/mpc.1     |    5 +++++
 src/command.c |   19 +++++++++++++++++++
 src/command.h |    1 +
 src/main.c    |    1 +
 4 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/doc/mpc.1 b/doc/mpc.1
index 7a8d5f5..3670028 100644
--- a/doc/mpc.1
+++ b/doc/mpc.1
@@ -86,6 +86,11 @@ The port to connect to; if not given, the value of the 
environment variable MPD_
 .B add <file>
 Adds a song from the music database to the playlist. Can also read input from 
pipes. Use "mpc ls | mpc add" to add all files to the playlist.
 .TP
+.B insert <file>
+The insert command works similarly to
+.B add
+except it adds song(s) after the currently playing one, rather than at the end.
+.TP
 .B clear
 Empties playlist.
 .TP
diff --git a/src/command.c b/src/command.c
index bafddb7..705b1ae 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_insert (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..63bafa5 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_insert(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..8aac65c 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"},
+       {"insert",      0,   -1,  1,    cmd_insert,      "<file>", "Insert a 
song to the current playlist 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

Attachment: pgpQLPVaXCETN.pgp
Description: PGP signature

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Musicpd-dev-team mailing list
Musicpd-dev-team@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/musicpd-dev-team

Reply via email to