summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@mplayer2.org>2012-02-10 19:03:24 +0100
committerwm4 <wm4@mplayer2.org>2012-02-10 19:14:19 +0100
commit489f61aa4c21a94e664632919577c91abdba89be (patch)
treed13294e72b812ea6ae138075b18dbe756aa50d2f
parent70bf6720963b912bceabb9ae691b5f2b79685b19 (diff)
downloadmpv-489f61aa4c21a94e664632919577c91abdba89be.tar.bz2
mpv-489f61aa4c21a94e664632919577c91abdba89be.tar.xz
commands: add pt_clear command to clear playlist
This deletes all playlist elements, except the currently active playlist entry. NOTE: this doesn't remove parent nodes in the case when we really have a play tree (as opposed to a play list). Apparently this doesn't cause any harm.
-rw-r--r--command.c27
-rw-r--r--input/input.c1
-rw-r--r--input/input.h1
3 files changed, 29 insertions, 0 deletions
diff --git a/command.c b/command.c
index 8c5d02e81d..fab9ccabd7 100644
--- a/command.c
+++ b/command.c
@@ -21,6 +21,7 @@
#include <unistd.h>
#include <string.h>
#include <stdbool.h>
+#include <assert.h>
#include "config.h"
#include "talloc.h"
@@ -2787,6 +2788,28 @@ static void remove_subtitle_range(MPContext *mpctx, int start, int count)
}
}
+static void do_clear_pt(struct play_tree *node, struct play_tree *exclude)
+{
+ while (node) {
+ do_clear_pt(node->child, exclude);
+ struct play_tree *next = node->next;
+ // do not delete root node, or nodes that could lead to "exclude" node
+ if (node->parent && !node->child && node != exclude)
+ play_tree_remove(node, 1, 1);
+ node = next;
+ }
+}
+
+static void clear_play_tree(MPContext *mpctx)
+{
+ struct play_tree *exclude = NULL;
+ if (mpctx->playtree_iter) {
+ assert(mpctx->playtree == mpctx->playtree_iter->root);
+ exclude = mpctx->playtree_iter->tree;
+ }
+ do_clear_pt(mpctx->playtree, exclude);
+}
+
void run_command(MPContext *mpctx, mp_cmd_t *cmd)
{
struct MPOpts *opts = &mpctx->opts;
@@ -3116,6 +3139,10 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
break;
}
+ case MP_CMD_PLAY_TREE_CLEAR:
+ clear_play_tree(mpctx);
+ break;
+
case MP_CMD_STOP:
// Go back to the starting point.
while (play_tree_iter_up_step(mpctx->playtree_iter, 0, 1) !=
diff --git a/input/input.c b/input/input.c
index a880a583d8..c6d5470bb5 100644
--- a/input/input.c
+++ b/input/input.c
@@ -184,6 +184,7 @@ static const mp_cmd_t mp_cmds[] = {
{ MP_CMD_SWITCH_VSYNC, "switch_vsync", 0, { {MP_CMD_ARG_INT} } },
{ MP_CMD_LOADFILE, "loadfile", 1, { {MP_CMD_ARG_STRING}, {MP_CMD_ARG_INT} } },
{ MP_CMD_LOADLIST, "loadlist", 1, { {MP_CMD_ARG_STRING}, {MP_CMD_ARG_INT} } },
+ { MP_CMD_PLAY_TREE_CLEAR, "pt_clear", 0 },
{ MP_CMD_RUN, "run", 1, { {MP_CMD_ARG_STRING} } },
{ MP_CMD_CAPTURING, "capturing", 0 },
{ MP_CMD_VF_CHANGE_RECTANGLE, "change_rectangle", 2, { {MP_CMD_ARG_INT}, {MP_CMD_ARG_INT} } },
diff --git a/input/input.h b/input/input.h
index 99a69c7355..084e2dd3e7 100644
--- a/input/input.h
+++ b/input/input.h
@@ -50,6 +50,7 @@ enum mp_command_type {
MP_CMD_MUTE,
MP_CMD_LOADFILE,
MP_CMD_LOADLIST,
+ MP_CMD_PLAY_TREE_CLEAR,
MP_CMD_VF_CHANGE_RECTANGLE,
MP_CMD_GAMMA,
MP_CMD_SUB_VISIBILITY,