From b94f090bd551db7d619e632b44c8b7158174e72b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 30 Sep 2009 16:33:55 +0200 Subject: [PATCH] player_command: use libmpdclient2 directly Don't use mpdclient_cmd_X(). --- src/mpdclient.c | 110 ------------------------------------------- src/mpdclient.h | 11 ----- src/player_command.c | 46 +++++++++++------- 3 files changed, 30 insertions(+), 137 deletions(-) diff --git a/src/mpdclient.c b/src/mpdclient.c index 124c018..b8d9c6f 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -276,16 +276,6 @@ mpdclient_cmd_play(struct mpdclient *c, gint idx) return mpdclient_finish_command(c); } -gint -mpdclient_cmd_pause(struct mpdclient *c, gint value) -{ - if (MPD_ERROR(c)) - return -1; - - mpd_send_pause(c->connection, value); - return mpdclient_finish_command(c); -} - gint mpdclient_cmd_crop(struct mpdclient *c) { @@ -321,56 +311,6 @@ mpdclient_cmd_crop(struct mpdclient *c) return mpdclient_finish_command(c); } -gint -mpdclient_cmd_stop(struct mpdclient *c) -{ - if (MPD_ERROR(c)) - return -1; - - mpd_send_stop(c->connection); - return mpdclient_finish_command(c); -} - -gint -mpdclient_cmd_next(struct mpdclient *c) -{ - if (MPD_ERROR(c)) - return -1; - - mpd_send_next(c->connection); - return mpdclient_finish_command(c); -} - -gint -mpdclient_cmd_prev(struct mpdclient *c) -{ - if (MPD_ERROR(c)) - return -1; - - mpd_send_previous(c->connection); - return mpdclient_finish_command(c); -} - -gint -mpdclient_cmd_seek(struct mpdclient *c, gint id, gint pos) -{ - if (MPD_ERROR(c)) - return -1; - - mpd_send_seek_id(c->connection, id, pos); - return mpdclient_finish_command(c); -} - -gint -mpdclient_cmd_shuffle(struct mpdclient *c) -{ - if (MPD_ERROR(c)) - return -1; - - mpd_send_shuffle(c->connection); - return mpdclient_finish_command(c); -} - gint mpdclient_cmd_shuffle_range(struct mpdclient *c, guint start, guint end) { @@ -393,56 +333,6 @@ mpdclient_cmd_clear(struct mpdclient *c) return retval; } -gint -mpdclient_cmd_repeat(struct mpdclient *c, gint value) -{ - if (MPD_ERROR(c)) - return -1; - - mpd_send_repeat(c->connection, value); - return mpdclient_finish_command(c); -} - -gint -mpdclient_cmd_random(struct mpdclient *c, gint value) -{ - if (MPD_ERROR(c)) - return -1; - - mpd_send_random(c->connection, value); - return mpdclient_finish_command(c); -} - -gint -mpdclient_cmd_single(struct mpdclient *c, gint value) -{ - if (MPD_ERROR(c)) - return -1; - - mpd_send_single(c->connection, value); - return mpdclient_finish_command(c); -} - -gint -mpdclient_cmd_consume(struct mpdclient *c, gint value) -{ - if (MPD_ERROR(c)) - return -1; - - mpd_send_consume(c->connection, value); - return mpdclient_finish_command(c); -} - -gint -mpdclient_cmd_crossfade(struct mpdclient *c, gint value) -{ - if (MPD_ERROR(c)) - return -1; - - mpd_send_crossfade(c->connection, value); - return mpdclient_finish_command(c); -} - gint mpdclient_cmd_volume(struct mpdclient *c, gint value) { diff --git a/src/mpdclient.h b/src/mpdclient.h index e9150ba..2679a62 100644 --- a/src/mpdclient.h +++ b/src/mpdclient.h @@ -53,21 +53,10 @@ mpdclient_update(struct mpdclient *c); /*** MPD Commands **********************************************************/ gint mpdclient_cmd_play(struct mpdclient *c, gint index); -gint mpdclient_cmd_pause(struct mpdclient *c, gint value); gint mpdclient_cmd_crop(struct mpdclient *c); -gint mpdclient_cmd_stop(struct mpdclient *c); -gint mpdclient_cmd_next(struct mpdclient *c); -gint mpdclient_cmd_prev(struct mpdclient *c); -gint mpdclient_cmd_seek(struct mpdclient *c, gint id, gint pos); -gint mpdclient_cmd_shuffle(struct mpdclient *c); gint mpdclient_cmd_shuffle_range(struct mpdclient *c, guint start, guint end); gint mpdclient_cmd_clear(struct mpdclient *c); -gint mpdclient_cmd_repeat(struct mpdclient *c, gint value); -gint mpdclient_cmd_random(struct mpdclient *c, gint value); -gint mpdclient_cmd_single(struct mpdclient *c, gint value); -gint mpdclient_cmd_consume(struct mpdclient *c, gint value); -gint mpdclient_cmd_crossfade(struct mpdclient *c, gint value); gint mpdclient_cmd_volume(struct mpdclient *c, gint value); gint mpdclient_cmd_volume_up(struct mpdclient *c); gint mpdclient_cmd_volume_down(struct mpdclient *c); diff --git a/src/player_command.c b/src/player_command.c index 678d13a..04256eb 100644 --- a/src/player_command.c +++ b/src/player_command.c @@ -40,7 +40,8 @@ commit_seek(struct mpdclient *c) return; if (c->song != NULL && (unsigned)seek_id == mpd_song_get_id(c->song)) - mpdclient_cmd_seek(c, seek_id, seek_target_time); + if (!mpd_run_seek_id(c->connection, seek_id, seek_target_time)) + mpdclient_handle_error(c); seek_id = -1; } @@ -91,10 +92,13 @@ handle_player_command(struct mpdclient *c, command_t cmd) break; */ case CMD_PAUSE: - mpdclient_cmd_pause(c, !IS_PAUSED(mpd_status_get_state(c->status))); + if (!mpd_run_pause(c->connection, + !IS_PAUSED(mpd_status_get_state(c->status)))) + mpdclient_handle_error(c); break; case CMD_STOP: - mpdclient_cmd_stop(c); + if (!mpd_run_stop(c->connection)) + mpdclient_handle_error(c); break; case CMD_CROP: mpdclient_cmd_crop(c); @@ -114,8 +118,8 @@ handle_player_command(struct mpdclient *c, command_t cmd) break; /* fall through... */ case CMD_TRACK_NEXT: - if (!IS_STOPPED(mpd_status_get_state(c->status))) - mpdclient_cmd_next(c); + if (!mpd_run_next(c->connection)) + mpdclient_handle_error(c); break; case CMD_SEEK_BACKWARD: if (!IS_STOPPED(mpd_status_get_state(c->status))) { @@ -130,34 +134,44 @@ handle_player_command(struct mpdclient *c, command_t cmd) } break; case CMD_TRACK_PREVIOUS: - if (!IS_STOPPED(mpd_status_get_state(c->status))) - mpdclient_cmd_prev(c); + if (!mpd_run_previous(c->connection)) + mpdclient_handle_error(c); break; case CMD_SHUFFLE: - if (mpdclient_cmd_shuffle(c) == 0) + if (mpd_run_shuffle(c->connection)) screen_status_message(_("Shuffled playlist")); + else + mpdclient_handle_error(c); break; case CMD_CLEAR: if (mpdclient_cmd_clear(c) == 0) screen_status_message(_("Cleared playlist")); break; case CMD_REPEAT: - mpdclient_cmd_repeat(c, !mpd_status_get_repeat(c->status)); + if (!mpd_run_repeat(c->connection, + !mpd_status_get_repeat(c->status))) + mpdclient_handle_error(c); break; case CMD_RANDOM: - mpdclient_cmd_random(c, !mpd_status_get_random(c->status)); + if (!mpd_run_random(c->connection, + !mpd_status_get_random(c->status))) + mpdclient_handle_error(c); break; case CMD_SINGLE: - mpdclient_cmd_single(c, !mpd_status_get_single(c->status)); + if (!mpd_run_single(c->connection, + !mpd_status_get_single(c->status))) + mpdclient_handle_error(c); break; case CMD_CONSUME: - mpdclient_cmd_consume(c, !mpd_status_get_consume(c->status)); + if (!mpd_run_consume(c->connection, + !mpd_status_get_consume(c->status))) + mpdclient_handle_error(c); break; case CMD_CROSSFADE: - if (mpd_status_get_crossfade(c->status)) - mpdclient_cmd_crossfade(c, 0); - else - mpdclient_cmd_crossfade(c, options.crossfade_time); + if (!mpd_run_crossfade(c->connection, + mpd_status_get_crossfade(c->status) > 0 + ? 0 : options.crossfade_time)) + mpdclient_handle_error(c); break; case CMD_DB_UPDATE: screen_database_update(c, NULL); -- 2.30.2