Increase/Decrease volume by 5 (#298)

* Increase/Decrease volume by 5

* Fixed static value

* use fallback value in case parsing fails

fixes #282

Co-authored-by: Henrik Friedrichsen <henrik@affekt.org>
This commit is contained in:
Saul Chavez Sanchez
2020-10-22 13:21:49 -05:00
committed by GitHub
parent da915ab563
commit c9d02507ac
4 changed files with 29 additions and 13 deletions

2
.gitignore vendored
View File

@@ -9,3 +9,5 @@
*.log
tags
/.vscode/

View File

@@ -95,7 +95,8 @@ depending on your desktop environment settings. Have a look at the
* `<` and `>` play the previous or next track
* `f` and `b` to seek forward or backward
* `Shift-f` and `Shift-b` to seek forward or backward in steps of 10s
* `-` and `+` decrease or increase the volume
* `-` and `+` decrease or increase the volume by 1
* `[` and `]` decrease of increase the volume by 5
* `r` to toggle repeat mode
* `z` to toggle shuffle playback
* `q` quits ncspot

View File

@@ -99,8 +99,8 @@ pub enum Command {
Delete,
Focus(String),
Seek(SeekDirection),
VolumeUp,
VolumeDown,
VolumeUp(u16),
VolumeDown(u16),
Repeat(Option<RepeatSetting>),
Shuffle(Option<bool>),
Share(TargetMode),
@@ -136,8 +136,8 @@ impl fmt::Display for Command {
Command::Delete => "delete".to_string(),
Command::Focus(tab) => format!("focus {}", tab),
Command::Seek(direction) => format!("seek {}", direction),
Command::VolumeUp => "volup".to_string(),
Command::VolumeDown => "voldown".to_string(),
Command::VolumeUp(amount) => format!("volup {}", amount),
Command::VolumeDown(amount) => format!("voldown {}", amount),
Command::Repeat(mode) => {
let param = match mode {
Some(mode) => format!("{}", mode),
@@ -344,8 +344,12 @@ pub fn parse(input: &str) -> Option<Command> {
_ => Command::Save,
})
.or(Some(Command::Save)),
"volup" => Some(Command::VolumeUp),
"voldown" => Some(Command::VolumeDown),
"volup" => Some(Command::VolumeUp(
args.get(0).and_then(|v| v.parse::<u16>().ok()).unwrap_or(1),
)),
"voldown" => Some(Command::VolumeDown(
args.get(0).and_then(|v| v.parse::<u16>().ok()).unwrap_or(1),
)),
"help" => Some(Command::Help),
"reload" => Some(Command::ReloadConfig),
"insert" => {

View File

@@ -148,13 +148,19 @@ impl CommandManager {
}
Ok(None)
}
Command::VolumeUp => {
let volume = self.spotify.volume().saturating_add(VOLUME_PERCENT);
Command::VolumeUp(amount) => {
let volume = self
.spotify
.volume()
.saturating_add(VOLUME_PERCENT * amount);
self.spotify.set_volume(volume);
Ok(None)
}
Command::VolumeDown => {
let volume = self.spotify.volume().saturating_sub(VOLUME_PERCENT);
Command::VolumeDown(amount) => {
let volume = self
.spotify
.volume()
.saturating_sub(VOLUME_PERCENT * amount);
debug!("vol {}", volume);
self.spotify.set_volume(volume);
Ok(None)
@@ -294,8 +300,11 @@ impl CommandManager {
"Shift+b".into(),
Command::Seek(SeekDirection::Relative(-10000)),
);
kb.insert("+".into(), Command::VolumeUp);
kb.insert("-".into(), Command::VolumeDown);
kb.insert("+".into(), Command::VolumeUp(1));
kb.insert("]".into(), Command::VolumeUp(5));
kb.insert("-".into(), Command::VolumeDown(1));
kb.insert("[".into(), Command::VolumeDown(5));
kb.insert("r".into(), Command::Repeat(None));
kb.insert("z".into(), Command::Shuffle(None));
kb.insert("x".into(), Command::Share(TargetMode::Current));