aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2006-07-30 23:32:54 +0000
committerEric Wong <normalperson@yhbt.net>2006-07-30 23:32:54 +0000
commit44f9e16922a08db82b267ce8f567453a19c7c100 (patch)
tree65a09540a211f8b95cafc1a56d8a3f5222e5b0a7
parent12aec5738b8333a0dd676871bbfb6d6762ea87a5 (diff)
downloadmpd-44f9e16922a08db82b267ce8f567453a19c7c100.tar.gz
mpd-44f9e16922a08db82b267ce8f567453a19c7c100.tar.xz
mpd-44f9e16922a08db82b267ce8f567453a19c7c100.zip
software volume can now be saved and read from the state file
git-svn-id: https://svn.musicpd.org/mpd/trunk@4495 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r--src/state_file.c2
-rw-r--r--src/volume.c35
-rw-r--r--src/volume.h4
3 files changed, 41 insertions, 0 deletions
diff --git a/src/state_file.c b/src/state_file.c
index 1307faa54..452031ed6 100644
--- a/src/state_file.c
+++ b/src/state_file.c
@@ -24,6 +24,7 @@
#include "audio.h"
#include "playlist.h"
#include "utils.h"
+#include "volume.h"
#include <errno.h>
#include <stdlib.h>
@@ -35,6 +36,7 @@ static struct _sf_cb {
void (*reader)(FILE *);
void (*writer)(FILE *);
} sf_callbacks [] = {
+ { read_sw_volume_state, save_sw_volume_state },
{ readAudioDevicesState, saveAudioDevicesState },
{ readPlaylistState, savePlaylistState },
};
diff --git a/src/volume.c b/src/volume.c
index 7d4fce584..de631ab8c 100644
--- a/src/volume.c
+++ b/src/volume.c
@@ -21,6 +21,9 @@
#include "conf.h"
#include "log.h"
#include "player.h"
+#include "state_file.h"
+#include "gcc.h"
+#include "utils.h"
#include <math.h>
#include <stdlib.h>
@@ -44,6 +47,7 @@
#define VOLUME_MIXER_OSS_DEFAULT "/dev/mixer"
#define VOLUME_MIXER_ALSA_DEFAULT "default"
#define VOLUME_MIXER_ALSA_CONTROL_DEFAULT "PCM"
+#define SW_VOLUME_STATE "sw_volume: "
#ifdef HAVE_OSS
#define VOLUME_MIXER_TYPE_DEFAULT VOLUME_MIXER_TYPE_OSS
@@ -515,3 +519,34 @@ int changeVolumeLevel(int fd, int change, int rel)
break;
}
}
+
+void read_sw_volume_state(FILE *fp)
+{
+ /* strlen(SW_VOLUME_STATE) + strlen('100') + '\0' */
+ #define bufsize 16
+ char buf[bufsize];
+ const size_t len = strlen(SW_VOLUME_STATE);
+ char *end = NULL;
+ long int sv;
+
+ if (volume_mixerType != VOLUME_MIXER_TYPE_SOFTWARE)
+ return;
+ while (myFgets(buf, bufsize, fp)) {
+ if (strncmp(buf, SW_VOLUME_STATE, len))
+ continue;
+ sv = strtol(buf + len, &end, 10);
+ if (mpd_likely(!*end))
+ changeSoftwareVolume(STDERR_FILENO, sv, 0);
+ else
+ ERROR("Can't parse software volume: %s\n", buf);
+ return;
+ }
+ #undef bufsize
+}
+
+void save_sw_volume_state(FILE *fp)
+{
+ if (volume_mixerType == VOLUME_MIXER_TYPE_SOFTWARE)
+ fprintf(fp, SW_VOLUME_STATE "%d\n", volume_softwareSet);
+}
+
diff --git a/src/volume.h b/src/volume.h
index 92fd868be..8c4d3803e 100644
--- a/src/volume.h
+++ b/src/volume.h
@@ -37,4 +37,8 @@ int getVolumeLevel();
int changeVolumeLevel(int fd, int change, int rel);
+void read_sw_volume_state(FILE *fp);
+
+void save_sw_volume_state(FILE *fp);
+
#endif