diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2010-12-26 18:56:40 +0100 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2010-12-27 13:43:06 +0100 |
commit | b452bc6cd392fcb7631a5d5c4d794aafd5e380e9 (patch) | |
tree | 252ca5a8b261f7ffc33b058c13cba49eb6385398 /src | |
parent | 46b837ce695ca844db9f408512b43b592eab5126 (diff) | |
download | pianobar-b452bc6cd392fcb7631a5d5c4d794aafd5e380e9.tar.gz pianobar-b452bc6cd392fcb7631a5d5c4d794aafd5e380e9.tar.bz2 pianobar-b452bc6cd392fcb7631a5d5c4d794aafd5e380e9.zip |
Software volume control
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 4 | ||||
-rw-r--r-- | src/player.c | 3 | ||||
-rw-r--r-- | src/player.h | 1 | ||||
-rw-r--r-- | src/settings.c | 7 | ||||
-rw-r--r-- | src/settings.h | 5 | ||||
-rw-r--r-- | src/ui_act.c | 18 | ||||
-rw-r--r-- | src/ui_act.h | 2 |
7 files changed, 34 insertions, 6 deletions
@@ -180,7 +180,8 @@ static void BarMainHandleUserInput (BarApp_t *app) { BarUiActQuit, BarUiActRenameStation, BarUiActSelectStation, BarUiActTempBanSong, BarUiActPrintUpcoming, BarUiActSelectQuickMix, - BarUiActDebug, BarUiActBookmark}; + BarUiActDebug, BarUiActBookmark, BarUiActVolDown, + BarUiActVolUp}; idToF[i] (app, curFd); break; } @@ -275,6 +276,7 @@ static void BarMainStartPlayback (BarApp_t *app, pthread_t *playerThread) { } app->player.gain = app->playlist->fileGain; + app->player.scale = BarPlayerCalcScale (app->player.gain + app->settings.volume); app->player.audioFormat = app->playlist->audioFormat; /* throw event */ diff --git a/src/player.c b/src/player.c index 83c5713..a819103 100644 --- a/src/player.c +++ b/src/player.c @@ -56,7 +56,7 @@ THE SOFTWARE. * @param apply this gain * @return this * yourvalue = newgain value */ -static inline unsigned int computeReplayGainScale (float applyGain) { +unsigned int BarPlayerCalcScale (float applyGain) { return pow (10.0, applyGain / 20.0) * RG_SCALE_FACTOR; } @@ -414,7 +414,6 @@ void *BarPlayerThread (void *data) { /* init handles */ pthread_mutex_init (&player->pauseMutex, NULL); - player->scale = computeReplayGainScale (player->gain); player->waith.data = (void *) player; /* extraHeaders will be initialized later */ player->waith.extraHeaders = extraHeaders; diff --git a/src/player.h b/src/player.h index 4ce0fbb..0062589 100644 --- a/src/player.h +++ b/src/player.h @@ -102,5 +102,6 @@ struct audioPlayer { enum {PLAYER_RET_OK = 0, PLAYER_RET_ERR = 1}; void *BarPlayerThread (void *data); +unsigned int BarPlayerCalcScale (float); #endif /* _PLAYER_H */ diff --git a/src/settings.c b/src/settings.c index 259c9f0..d181b7a 100644 --- a/src/settings.c +++ b/src/settings.c @@ -95,7 +95,7 @@ void BarSettingsRead (BarSettings_t *settings) { /* _must_ have same order as in BarKeyShortcutId_t */ static const char defaultKeys[] = {'?', '+', '-', 'a', 'c', 'd', 'e', 'g', 'h', 'i', 'j', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'x', '$', - 'b', + 'b', '(', ')', }; static const char *shortcutFileKeys[] = { "act_help", "act_songlove", "act_songban", "act_stationaddmusic", @@ -104,7 +104,7 @@ void BarSettingsRead (BarSettings_t *settings) { "act_addshared", "act_songmove", "act_songnext", "act_songpause", "act_quit", "act_stationrename", "act_stationchange", "act_songtired", "act_upcoming", "act_stationselectquickmix", - "act_debug", "act_bookmark", + "act_debug", "act_bookmark", "act_voldown", "act_volup", }; /* apply defaults */ @@ -116,6 +116,7 @@ void BarSettingsRead (BarSettings_t *settings) { #endif #endif settings->history = 5; + settings->volume = 0; settings->sortOrder = BAR_SORT_NAME_AZ; memcpy (settings->keys, defaultKeys, sizeof (defaultKeys)); settings->loveIcon = strdup ("<3"); @@ -187,6 +188,8 @@ void BarSettingsRead (BarSettings_t *settings) { } else if (streq ("ban_icon", key)) { free (settings->banIcon); settings->banIcon = strdup (val); + } else if (streq ("volume", key)) { + settings->volume = atoi (val); } } diff --git a/src/settings.h b/src/settings.h index 078c337..0d97c80 100644 --- a/src/settings.h +++ b/src/settings.h @@ -52,8 +52,10 @@ typedef enum { BAR_KS_SELECTQUICKMIX = 19, BAR_KS_DEBUG = 20, BAR_KS_BOOKMARK = 21, + BAR_KS_VOLDOWN = 22, + BAR_KS_VOLUP = 23, /* insert new shortcuts _before_ this element and increase its value */ - BAR_KS_COUNT = 22, + BAR_KS_COUNT = 24, } BarKeyShortcutId_t; typedef enum { @@ -68,6 +70,7 @@ typedef enum { typedef struct { unsigned int history; + int volume; BarStationSorting_t sortOrder; PianoAudioFormat_t audioFormat; char *username; diff --git a/src/ui_act.c b/src/ui_act.c index 679f098..0ed55ec 100644 --- a/src/ui_act.c +++ b/src/ui_act.c @@ -103,6 +103,8 @@ BarUiActCallback(BarUiActHelp) { "select quickmix stations", NULL, "bookmark song/artist", + "decrease volume", + "increase volume", }; size_t i; @@ -564,3 +566,19 @@ BarUiActCallback(BarUiActBookmark) { } } +/* decrease volume + */ +BarUiActCallback(BarUiActVolDown) { + --app->settings.volume; + /* FIXME: assuming unsigned integer store is atomic operation */ + app->player.scale = BarPlayerCalcScale (app->player.gain + app->settings.volume); +} + +/* increase volume + */ +BarUiActCallback(BarUiActVolUp) { + ++app->settings.volume; + /* FIXME: assuming unsigned integer store is atomic operation */ + app->player.scale = BarPlayerCalcScale (app->player.gain + app->settings.volume); +} + diff --git a/src/ui_act.h b/src/ui_act.h index f731f72..66ad731 100644 --- a/src/ui_act.h +++ b/src/ui_act.h @@ -50,5 +50,7 @@ BarUiActCallback(BarUiActQuit); BarUiActCallback(BarUiActDebug); BarUiActCallback(BarUiActHistory); BarUiActCallback(BarUiActBookmark); +BarUiActCallback(BarUiActVolDown); +BarUiActCallback(BarUiActVolUp); #endif /* _UI_ACT_H */ |