Skip to content

Commit

Permalink
Add configuration options for volume normalisation.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonTeixidor committed Feb 25, 2018
1 parent 3b998e9 commit 88292b9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ onevent = command_run_on_playback_events
device_name = name_in_spotify_connect
bitrate = 96|160|320
cache = cache_directory
volume-normalisation = true
normalisation-pregain = -10
```
Every field is optional, `Spotifyd` can even run without a configuration file.
Options can also be placed in a `[spotifyd]` section, which takes priority over
Expand Down
11 changes: 11 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ pub fn command_line_argument_options() -> Options {
opts.optopt("", "device_name", "Name of this Spotify device.", "DEVICE");
opts.optopt("", "backend", "Audio backend.", "BACKEND");
opts.optopt("", "cache_path", "Path to cache location.", "PATH");
opts.optflag(
"",
"volume-normalisation",
"Apply volume normalisation per track.",
);
opts.optopt(
"",
"normalisation-pregain",
"dB of pregain for volume normalisation",
"PREGAIN",
);
opts.optopt(
"",
"onevent",
Expand Down
13 changes: 13 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ pub fn get_config<P: AsRef<Path>>(config_path: Option<P>, matches: &Matches) ->
}
});
config.onevent = lookup("onevent");
config.player_config.normalisation = matches.opt_present("volume-normalisation")
|| spotifyd
.and_then(|s| s.get("volume-normalisation").map(String::clone))
.or_else(|| global.and_then(|g| g.get("volume-normalisation").map(String::clone)))
.unwrap_or("false".to_string()) == "true";

config.player_config.normalisation_pregain = lookup("normalisation-pregain")
.map(|db| {
db.parse::<f32>()
.expect("volume-normalisation must be a floating point number.")
})
.unwrap_or(PlayerConfig::default().normalisation_pregain);

update(
&mut config.player_config.bitrate,
lookup("bitrate").and_then(|s| Bitrate::from_str(&*s).ok()),
Expand Down

0 comments on commit 88292b9

Please sign in to comment.