summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8055246)
raw | patch | inline | side by side (parent: 8055246)
author | Max Kellermann <max@duempel.org> | |
Wed, 30 Sep 2009 19:05:48 +0000 (21:05 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Wed, 30 Sep 2009 19:05:48 +0000 (21:05 +0200) |
src/mpdclient.h | patch | blob | history | |
src/player_command.c | patch | blob | history | |
src/screen_play.c | patch | blob | history |
diff --git a/src/mpdclient.h b/src/mpdclient.h
index 1b83feb01d2c8e573110bf973ce916a378331d90..f363aa9d2a05c297dfcfe5b262453b27eed7dd6d 100644 (file)
--- a/src/mpdclient.h
+++ b/src/mpdclient.h
return c->connection != NULL;
}
+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)
+ ? c->song
+ : NULL;
+}
+
bool
mpdclient_connect(struct mpdclient *c, const gchar *host, gint port,
gfloat timeout_, const gchar *password);
diff --git a/src/player_command.c b/src/player_command.c
index 04256eb1438714ef2dcb6e1d6c8a12377c51005c..085ffa14a478f0eba1f211954b7fd3653369c59d 100644 (file)
--- a/src/player_command.c
+++ b/src/player_command.c
#include "i18n.h"
#include "screen_client.h"
-#define IS_PLAYING(s) (s==MPD_STATE_PLAY)
#define IS_PAUSED(s) (s==MPD_STATE_PAUSE)
-#define IS_STOPPED(s) (!(IS_PLAYING(s) | IS_PAUSED(s)))
int seek_id = -1;
int seek_target_time;
bool
handle_player_command(struct mpdclient *c, command_t cmd)
{
+ const struct mpd_song *song;
+
if (c->connection == NULL || c->status == NULL)
return false;
mpdclient_cmd_crop(c);
break;
case CMD_SEEK_FORWARD:
- if (!IS_STOPPED(mpd_status_get_state(c->status))) {
- if (c->song != NULL &&
- seek_id != (int)mpd_song_get_id(c->song)) {
- seek_id = mpd_song_get_id(c->song);
+ song = mpdclient_get_current_song(c);
+ if (song != NULL) {
+ if (seek_id != (int)mpd_song_get_id(song)) {
+ seek_id = mpd_song_get_id(song);
seek_target_time = mpd_status_get_elapsed_time(c->status);
}
seek_target_time+=options.seek_time;
mpdclient_handle_error(c);
break;
case CMD_SEEK_BACKWARD:
- if (!IS_STOPPED(mpd_status_get_state(c->status))) {
- if (seek_id != (int)mpd_song_get_id(c->song)) {
+ song = mpdclient_get_current_song(c);
+ if (song != NULL) {
+ if (seek_id != (int)mpd_song_get_id(song)) {
seek_id = mpd_song_get_id(c->song);
seek_target_time = mpd_status_get_elapsed_time(c->status);
}
diff --git a/src/screen_play.c b/src/screen_play.c
index 0f31032d1175ac78fd6ec0f567cfcf72c657fbaa..5cc3457592878492362a7ff04df9390b759922a9 100644 (file)
--- a/src/screen_play.c
+++ b/src/screen_play.c
@@ -182,11 +182,12 @@ list_callback(unsigned idx, bool *highlight, char **second_column, G_GNUC_UNUSED
static void
center_playing_item(struct mpdclient *c, bool center_cursor)
{
+ const struct mpd_song *song;
unsigned length = c->playlist.list->len;
int idx;
- if (!c->song || c->status == NULL ||
- IS_STOPPED(mpd_status_get_state(c->status)))
+ song = mpdclient_get_current_song(c);
+ if (song == NULL)
return;
/* try to center the song that are playing */