From c17ac1e987ca42bee41d40e15f7b7ca51ee70139 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 12 Jun 2009 19:41:24 +0200 Subject: [PATCH] mpdclient: added mpdclient_cmd_volume_up(), mpdclient_cmd_volume_down() --- src/mpdclient.c | 32 ++++++++++++++++++++++++++++++++ src/mpdclient.h | 3 +++ src/screen.c | 6 ++---- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/mpdclient.c b/src/mpdclient.c index 496d904..4a12515 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -150,6 +150,7 @@ mpdclient_new(void) c = g_malloc0(sizeof(mpdclient_t)); playlist_init(&c->playlist); + c->volume = MPD_STATUS_NO_VOLUME; return c; } @@ -220,6 +221,8 @@ mpdclient_update(mpdclient_t *c) { gint retval = 0; + c->volume = MPD_STATUS_NO_VOLUME; + if (MPD_ERROR(c)) return -1; @@ -237,6 +240,7 @@ mpdclient_update(mpdclient_t *c) mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL); c->updatingdb = c->status->updatingDb; + c->volume = c->status->volume; /* check if the playlist needs an update */ if (c->playlist.id != c->status->playlist) { @@ -438,6 +442,34 @@ mpdclient_cmd_volume(mpdclient_t *c, gint value) return mpdclient_finish_command(c); } +gint mpdclient_cmd_volume_up(struct mpdclient *c) +{ + if (c->status == NULL || c->status->volume == MPD_STATUS_NO_VOLUME) + return 0; + + if (c->volume == MPD_STATUS_NO_VOLUME) + c->volume = c->status->volume; + + if (c->volume >= 100) + return 0; + + return mpdclient_cmd_volume(c, ++c->volume); +} + +gint mpdclient_cmd_volume_down(struct mpdclient *c) +{ + if (c->status == NULL || c->status->volume == MPD_STATUS_NO_VOLUME) + return 0; + + if (c->volume == MPD_STATUS_NO_VOLUME) + c->volume = c->status->volume; + + if (c->volume <= 0) + return 0; + + return mpdclient_cmd_volume(c, --c->volume); +} + gint mpdclient_cmd_add_path(mpdclient_t *c, gchar *path_utf8) { diff --git a/src/mpdclient.h b/src/mpdclient.h index c2ba476..e74722e 100644 --- a/src/mpdclient.h +++ b/src/mpdclient.h @@ -29,6 +29,7 @@ typedef struct mpdclient { gboolean need_update; + int volume; int updatingdb; } mpdclient_t; @@ -64,6 +65,8 @@ gint mpdclient_cmd_consume(mpdclient_t *c, gint value); gint mpdclient_cmd_crossfade(mpdclient_t *c, gint value); gint mpdclient_cmd_db_update(mpdclient_t *c, gchar *path); gint mpdclient_cmd_volume(mpdclient_t *c, gint value); +gint mpdclient_cmd_volume_up(struct mpdclient *c); +gint mpdclient_cmd_volume_down(struct mpdclient *c); gint mpdclient_cmd_add_path(mpdclient_t *c, gchar *path); gint mpdclient_cmd_add(mpdclient_t *c, struct mpd_song *song); diff --git a/src/screen.c b/src/screen.c index 200f9db..c4e156a 100644 --- a/src/screen.c +++ b/src/screen.c @@ -839,12 +839,10 @@ screen_client_cmd(mpdclient_t *c, command_t cmd) screen_status_printf(_("Database update running...")); break; case CMD_VOLUME_UP: - if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 ) - mpdclient_cmd_volume(c, ++c->status->volume); + mpdclient_cmd_volume_up(c); break; case CMD_VOLUME_DOWN: - if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 ) - mpdclient_cmd_volume(c, --c->status->volume); + mpdclient_cmd_volume_down(c); break; default: -- 2.30.2