summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: eae0b74)
raw | patch | inline | side by side (parent: eae0b74)
author | Max Kellermann <max@duempel.org> | |
Mon, 2 Nov 2009 17:14:38 +0000 (18:14 +0100) | ||
committer | Max Kellermann <max@duempel.org> | |
Mon, 2 Nov 2009 17:14:38 +0000 (18:14 +0100) |
src/mpdclient.c | patch | blob | history | |
src/mpdclient.h | patch | blob | history | |
src/screen.c | patch | blob | history | |
src/screen_song.c | patch | blob | history |
diff --git a/src/mpdclient.c b/src/mpdclient.c
index 3bc6f0760211e6cfca4014750015200d739090a1..059a6ee38898120dd6bb8416252372542cfd7021 100644 (file)
--- a/src/mpdclient.c
+++ b/src/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 8309aa3a30519869c3f16af90c7c9bf5879ad219..a93db74baf135392acba5ff418bc3f18d2dffc6d 100644 (file)
--- a/src/mpdclient.h
+++ b/src/mpdclient.h
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 4abb35a429e0af46b3a45bfdc67bb96f9917bea1..5d6e4091698cc70b61635b7fbdaab4dfe945f58d 100644 (file)
--- a/src/screen.c
+++ b/src/screen.c
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 9bb7fbfd3150bf2d19a906ec76f4d49ccdb30158..e4fb21c09d5fb23c0b00c87fc43a1c15dc3749c1 100644 (file)
--- a/src/screen_song.c
+++ b/src/screen_song.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));
(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);
}