aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/command.c2
-rw-r--r--src/command.h1
-rw-r--r--src/mpdclient.c35
-rw-r--r--src/mpdclient.h2
-rw-r--r--src/screen.c3
-rw-r--r--src/screen_help.c1
6 files changed, 44 insertions, 0 deletions
diff --git a/src/command.c b/src/command.c
index afb7e42e4..0ae903381 100644
--- a/src/command.c
+++ b/src/command.c
@@ -102,6 +102,8 @@ static command_definition_t cmds[] =
N_("Pause") },
{ { 's', BS, 0 }, 0, CMD_STOP, "stop",
N_("Stop") },
+ { { 'o', 0, 0 }, 0, CMD_CROP, "crop",
+ N_("Crop") },
{ { '>', 0, 0 }, 0, CMD_TRACK_NEXT, "next",
N_("Next track") },
{ { '<', 0, 0 }, 0, CMD_TRACK_PREVIOUS, "prev",
diff --git a/src/command.h b/src/command.h
index dab6c99ce..f4b6859e8 100644
--- a/src/command.h
+++ b/src/command.h
@@ -16,6 +16,7 @@ typedef enum
CMD_SELECT_ALL,
CMD_PAUSE,
CMD_STOP,
+ CMD_CROP,
CMD_TRACK_NEXT,
CMD_TRACK_PREVIOUS,
CMD_SEEK_FORWARD,
diff --git a/src/mpdclient.c b/src/mpdclient.c
index 2c46d8e90..6d9d72b9c 100644
--- a/src/mpdclient.c
+++ b/src/mpdclient.c
@@ -300,6 +300,41 @@ mpdclient_cmd_pause(mpdclient_t *c, gint value)
}
gint
+mpdclient_cmd_crop(mpdclient_t *c)
+{
+ mpd_Status *status;
+ int length;
+
+ mpd_sendStatusCommand(c->connection);
+ status = mpd_getStatus(c->connection);
+ length = status->playlistLength - 1;
+
+ if (length <= 0) {
+ mpd_freeStatus(status);
+ screen_status_message("You have to have a playlist longer than 1 song in length to crop");
+ } else if (status->state == 3 || status->state == 2) {
+ /* If playing or paused */
+
+ mpd_sendCommandListBegin( c->connection );
+
+ while (length >= 0) {
+ if (length != status->song)
+ mpd_sendDeleteCommand(c->connection, length);
+
+ length--;
+ }
+
+ mpd_sendCommandListEnd(c->connection);
+ mpd_freeStatus(status);
+ } else {
+ mpd_freeStatus(status);
+ screen_status_message("You need to be playing to crop the playlist\n");
+ }
+
+ return mpdclient_finish_command(c);
+}
+
+gint
mpdclient_cmd_stop(mpdclient_t *c)
{
mpd_sendStopCommand(c->connection);
diff --git a/src/mpdclient.h b/src/mpdclient.h
index c55e15453..2735f04ff 100644
--- a/src/mpdclient.h
+++ b/src/mpdclient.h
@@ -46,6 +46,8 @@ gint mpdclient_update(mpdclient_t *c);
/*** MPD Commands **********************************************************/
gint mpdclient_cmd_play(mpdclient_t *c, gint index);
gint mpdclient_cmd_pause(mpdclient_t *c, gint value);
+gint
+mpdclient_cmd_crop(mpdclient_t *c);
gint mpdclient_cmd_stop(mpdclient_t *c);
gint mpdclient_cmd_next(mpdclient_t *c);
gint mpdclient_cmd_prev(mpdclient_t *c);
diff --git a/src/screen.c b/src/screen.c
index e510b1682..2a5d6416f 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -814,6 +814,9 @@ screen_client_cmd(mpdclient_t *c, command_t cmd)
case CMD_STOP:
mpdclient_cmd_stop(c);
break;
+ case CMD_CROP:
+ mpdclient_cmd_crop(c);
+ break;
case CMD_SEEK_FORWARD:
if (!IS_STOPPED(c->status->state)) {
if (c->song && seek_id != c->song->id) {
diff --git a/src/screen_help.c b/src/screen_help.c
index 7416e6e40..79b8fa722 100644
--- a/src/screen_help.c
+++ b/src/screen_help.c
@@ -67,6 +67,7 @@ static help_text_row_t help_text[] =
{ 2, CMD_NONE, NULL },
{ 0, CMD_STOP, NULL },
{ 0, CMD_PAUSE, NULL },
+ { 0, CMD_CROP, NULL },
{ 0, CMD_TRACK_NEXT, NULL },
{ 0, CMD_TRACK_PREVIOUS, NULL },
{ 0, CMD_SEEK_FORWARD, NULL },