Code

mpdclient: added inline function mpdclient_is_playing()
authorMax Kellermann <max@duempel.org>
Mon, 2 Nov 2009 17:14:38 +0000 (18:14 +0100)
committerMax Kellermann <max@duempel.org>
Mon, 2 Nov 2009 17:14:38 +0000 (18:14 +0100)
src/mpdclient.c
src/mpdclient.h
src/screen.c
src/screen_song.c

index 3bc6f0760211e6cfca4014750015200d739090a1..059a6ee38898120dd6bb8416252372542cfd7021 100644 (file)
@@ -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);
index 8309aa3a30519869c3f16af90c7c9bf5879ad219..a93db74baf135392acba5ff418bc3f18d2dffc6d 100644 (file)
@@ -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;
 }
index 4abb35a429e0af46b3a45bfdc67bb96f9917bea1..5d6e4091698cc70b61635b7fbdaab4dfe945f58d 100644 (file)
@@ -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;
 
index 9bb7fbfd3150bf2d19a906ec76f4d49ccdb30158..e4fb21c09d5fb23c0b00c87fc43a1c15dc3749c1 100644 (file)
@@ -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);
                }