Code

mpdclient: added mpdclient_cmd_volume_up(), mpdclient_cmd_volume_down()
authorMax Kellermann <max@duempel.org>
Fri, 12 Jun 2009 17:41:24 +0000 (19:41 +0200)
committerMax Kellermann <max@duempel.org>
Fri, 12 Jun 2009 17:41:24 +0000 (19:41 +0200)
src/mpdclient.c
src/mpdclient.h
src/screen.c

index 496d904129968038ea4e106030483682a56149ed..4a12515752b9037366d99f1662022ea4269289e3 100644 (file)
@@ -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)
 {
index c2ba4767356bb1441c168c7409bb5ef0da620d27..e74722e607e01409273ca410f45c2399b8a9500e 100644 (file)
@@ -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);
index 200f9dbb67d27f188f264f9d3877462d01b6e60b..c4e156acd2cf44deba4b7ec4936c48a8f469500f 100644 (file)
@@ -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: