Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for consume: oneshot #109

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ ins).
Player Commands
^^^^^^^^^^^^^^^

:command:`consume <on|off>` - Toggle consume mode if state (:samp:`on`
or :samp:`off`) is not specified.
:command:`consume <on|once|off>` - Toggle consume mode if state (:samp:`on`
:samp:`once`, or :samp:`off`) is not specified. :samp:`once` toggles
to :samp:`off`.

:command:`crossfade [<seconds>]` - Gets and sets the current amount of
crossfading between songs (:samp:`0` disables crossfading).
Expand Down Expand Up @@ -462,7 +463,7 @@ Other Commands
%random% Current status of random mode. 'on' or 'off'
%repeat% Current status of repeat mode. 'on' or 'off'
%single% Current status of single mode. 'on', 'once', or 'off'
%consume% Current status of consume mode. 'on' or 'off'
%consume% Current status of consume mode. 'on', 'once', or 'off'
%kbitrate% The bit rate in kbps for the current song.
%audioformat% The audio format which MPD is currently playing as 'samplerate:bits:channels'.
%samplerate% The sample rate in Hz extracted from the current MPD audio format.
Expand Down
36 changes: 36 additions & 0 deletions src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -1093,8 +1093,44 @@ cmd_single(int argc, char **argv, struct mpd_connection *conn)
int
cmd_consume(int argc, char **argv, struct mpd_connection *conn)
{
#if LIBMPDCLIENT_CHECK_VERSION(2,21,0)
enum mpd_consume_state mode = MPD_CONSUME_UNKNOWN;

if (argc == 1) {
if (strcasecmp(argv[0], "once") == 0)
mode = MPD_CONSUME_ONESHOT;
else {
int mode_i = get_boolean(argv[0]);
if (mode_i < 0)
return -1;
else if (mode_i)
mode = MPD_CONSUME_ON;
else
mode = MPD_CONSUME_OFF;
}
} else {
struct mpd_status *status;
status = getStatus(conn);
enum mpd_consume_state cur = mpd_status_get_consume_state(status);

if (cur == MPD_CONSUME_ONESHOT || cur == MPD_CONSUME_ON)
mode = MPD_CONSUME_OFF;
else if (cur == MPD_CONSUME_OFF)
mode = MPD_CONSUME_ON;

mpd_status_free(status);
}

if (mode == MPD_CONSUME_UNKNOWN)
return -1;
else if (!mpd_run_consume_state(conn, mode))
printErrorAndExit(conn);

return 1;
#else
return bool_cmd(argc, argv, conn,
mpd_status_get_consume, mpd_run_consume);
#endif
}

int
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static const struct command {
{"clear", 0, 0, 0, cmd_clear, "", "Clear the queue"},
{"clearerror", 0, 0, 0, cmd_clearerror, "", "Clear the current error"},
{"clearplaylist", 1, 1, 0, cmd_clearplaylist, "<file>", "Clear the playlist"},
{"consume", 0, 1, 0, cmd_consume, "<on|off>", "Toggle consume mode, or specify state"},
{"consume", 0, 1, 0, cmd_consume, "<on|once|off>", "Toggle consume mode, or specify state"},
{"crop", 0, 0, 0, cmd_crop, "", "Remove all but the currently playing song"},
{"crossfade", 0, 1, 0, cmd_crossfade, "[<seconds>]", "Set and display crossfade settings"},
{"current", 0, 0, 0, cmd_current, "", "Show the currently playing song"},
Expand Down
9 changes: 9 additions & 0 deletions src/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,18 @@ print_status(struct mpd_connection *conn)
printf("off ");

printf("consume: ");
#if LIBMPDCLIENT_CHECK_VERSION(2,21,0)
if (mpd_status_get_consume_state(status) == MPD_CONSUME_ON)
printf("on \n");
else if (mpd_status_get_consume_state(status) == MPD_CONSUME_ONESHOT)
printf("once\n");
else if (mpd_status_get_consume_state(status) == MPD_CONSUME_OFF)
printf("off \n");
#else
if (mpd_status_get_consume(status))
printf("on \n");
else printf("off\n");
#endif

if (mpd_status_get_error(status) != NULL)
printf("ERROR: %s\n",
Expand Down
10 changes: 10 additions & 0 deletions src/status_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,21 @@ status_value(const struct mpd_status *status, const char *name)
return "off";
}
} else if (strcmp(name, "consume") == 0) {
#if LIBMPDCLIENT_CHECK_VERSION(2,21,0)
if (mpd_status_get_consume_state(status) == MPD_CONSUME_ON) {
return "on";
} else if (mpd_status_get_consume_state(status) == MPD_CONSUME_ONESHOT) {
return "once";
} else if (mpd_status_get_consume_state(status) == MPD_CONSUME_OFF) {
return "off";
}
#else
if (mpd_status_get_consume(status)) {
return "on";
} else {
return "off";
}
#endif
} else if (strcmp(name, "kbitrate") == 0) {
sprintf(buffer, "%u", mpd_status_get_kbit_rate(status));
} else if (strcmp(name, "audioformat") == 0) {
Expand Down
Loading