From b871878b86a7876cd54e30d6be2bfb57f461dbb1 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 2 Nov 2009 18:14:38 +0100 Subject: [PATCH] mpdclient: added inline function mpdclient_is_playing() --- src/mpdclient.c | 7 ++----- src/mpdclient.h | 13 ++++++++++--- src/screen.c | 4 +--- src/screen_song.c | 14 ++++---------- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/mpdclient.c b/src/mpdclient.c index 3bc6f07..059a6ee 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -286,15 +286,12 @@ mpdclient_cmd_crop(struct mpdclient *c) struct mpd_connection *connection; int length, current; - if (c->status == NULL) + if (!mpdclient_is_playing(c)) return false; length = mpd_status_get_queue_length(c->status); current = mpd_status_get_song_pos(c->status); - if (current < 0 || - (mpd_status_get_state(c->status) != MPD_STATE_PLAY && - mpd_status_get_state(c->status) != MPD_STATE_PAUSE) || - mpd_status_get_queue_length(c->status) < 2) + if (current < 0 || mpd_status_get_queue_length(c->status) < 2) return true; connection = mpdclient_get_connection(c); diff --git a/src/mpdclient.h b/src/mpdclient.h index 8309aa3..a93db74 100644 --- a/src/mpdclient.h +++ b/src/mpdclient.h @@ -57,12 +57,19 @@ mpdclient_is_connected(const struct mpdclient *c) return c->connection != NULL; } +G_GNUC_PURE +static inline bool +mpdclient_is_playing(const struct mpdclient *c) +{ + return c->status != NULL && + (mpd_status_get_state(c->status) == MPD_STATE_PLAY || + mpd_status_get_state(c->status) == MPD_STATE_PAUSE); +} + static inline const struct mpd_song * mpdclient_get_current_song(const struct mpdclient *c) { - return c->song != NULL && c->status != NULL && - (mpd_status_get_state(c->status) == MPD_STATE_PLAY || - mpd_status_get_state(c->status) == MPD_STATE_PAUSE) + return c->song != NULL && mpdclient_is_playing(c) ? c->song : NULL; } diff --git a/src/screen.c b/src/screen.c index 4abb35a..5d6e409 100644 --- a/src/screen.c +++ b/src/screen.c @@ -165,9 +165,7 @@ update_progress_window(struct mpdclient *c, bool repaint) else elapsed = 0; - duration = c->status != NULL && - (mpd_status_get_state(c->status) == MPD_STATE_PLAY || - mpd_status_get_state(c->status) == MPD_STATE_PAUSE) + duration = mpdclient_is_playing(c) ? mpd_status_get_total_time(c->status) : 0; diff --git a/src/screen_song.c b/src/screen_song.c index 9bb7fbf..e4fb21c 100644 --- a/src/screen_song.c +++ b/src/screen_song.c @@ -253,10 +253,8 @@ screen_song_add_song(const struct mpd_song *song, const struct mpdclient *c) screen_song_append_tag(labels[COMMENT], song, MPD_TAG_COMMENT, max_label_width); screen_song_append(_("Path"), mpd_song_get_uri(song), max_label_width); - if (c->status != NULL && c->song != NULL && - strcmp(mpd_song_get_uri(c->song), mpd_song_get_uri(song)) == 0 && - (mpd_status_get_state(c->status) == MPD_STATE_PLAY || - mpd_status_get_state(c->status) == MPD_STATE_PAUSE)) { + if (mpdclient_is_playing(c) && c->song != NULL && + strcmp(mpd_song_get_uri(c->song), mpd_song_get_uri(song)) == 0) { char buf[16]; g_snprintf(buf, sizeof(buf), _("%d kbps"), mpd_status_get_kbit_rate(c->status)); @@ -349,17 +347,13 @@ screen_song_update(struct mpdclient *c) (c->song == NULL || strcmp(mpd_song_get_uri(current.selected_song), mpd_song_get_uri(c->song)) != 0 || - c->status == NULL || - (mpd_status_get_state(c->status) != MPD_STATE_PLAY && - mpd_status_get_state(c->status) != MPD_STATE_PAUSE))) { + !mpdclient_is_playing(c))) { g_ptr_array_add(current.lines, g_strdup(_("Selected song")) ); screen_song_add_song(current.selected_song, c); g_ptr_array_add(current.lines, g_strdup("\0")); } - if (c->song != NULL && c->status != NULL && - (mpd_status_get_state(c->status) == MPD_STATE_PLAY || - mpd_status_get_state(c->status) == MPD_STATE_PAUSE)) { + if (c->song != NULL && mpdclient_is_playing(c)) { if (current.played_song != NULL) { mpd_song_free(current.played_song); } -- 2.30.2