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:
committed by
GitHub
parent
da915ab563
commit
c9d02507ac
2
.gitignore
vendored
2
.gitignore
vendored
@@ -9,3 +9,5 @@
|
|||||||
*.log
|
*.log
|
||||||
|
|
||||||
tags
|
tags
|
||||||
|
|
||||||
|
/.vscode/
|
||||||
@@ -95,7 +95,8 @@ depending on your desktop environment settings. Have a look at the
|
|||||||
* `<` and `>` play the previous or next track
|
* `<` and `>` play the previous or next track
|
||||||
* `f` and `b` to seek forward or backward
|
* `f` and `b` to seek forward or backward
|
||||||
* `Shift-f` and `Shift-b` to seek forward or backward in steps of 10s
|
* `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
|
* `r` to toggle repeat mode
|
||||||
* `z` to toggle shuffle playback
|
* `z` to toggle shuffle playback
|
||||||
* `q` quits ncspot
|
* `q` quits ncspot
|
||||||
|
|||||||
@@ -99,8 +99,8 @@ pub enum Command {
|
|||||||
Delete,
|
Delete,
|
||||||
Focus(String),
|
Focus(String),
|
||||||
Seek(SeekDirection),
|
Seek(SeekDirection),
|
||||||
VolumeUp,
|
VolumeUp(u16),
|
||||||
VolumeDown,
|
VolumeDown(u16),
|
||||||
Repeat(Option<RepeatSetting>),
|
Repeat(Option<RepeatSetting>),
|
||||||
Shuffle(Option<bool>),
|
Shuffle(Option<bool>),
|
||||||
Share(TargetMode),
|
Share(TargetMode),
|
||||||
@@ -136,8 +136,8 @@ impl fmt::Display for Command {
|
|||||||
Command::Delete => "delete".to_string(),
|
Command::Delete => "delete".to_string(),
|
||||||
Command::Focus(tab) => format!("focus {}", tab),
|
Command::Focus(tab) => format!("focus {}", tab),
|
||||||
Command::Seek(direction) => format!("seek {}", direction),
|
Command::Seek(direction) => format!("seek {}", direction),
|
||||||
Command::VolumeUp => "volup".to_string(),
|
Command::VolumeUp(amount) => format!("volup {}", amount),
|
||||||
Command::VolumeDown => "voldown".to_string(),
|
Command::VolumeDown(amount) => format!("voldown {}", amount),
|
||||||
Command::Repeat(mode) => {
|
Command::Repeat(mode) => {
|
||||||
let param = match mode {
|
let param = match mode {
|
||||||
Some(mode) => format!("{}", mode),
|
Some(mode) => format!("{}", mode),
|
||||||
@@ -344,8 +344,12 @@ pub fn parse(input: &str) -> Option<Command> {
|
|||||||
_ => Command::Save,
|
_ => Command::Save,
|
||||||
})
|
})
|
||||||
.or(Some(Command::Save)),
|
.or(Some(Command::Save)),
|
||||||
"volup" => Some(Command::VolumeUp),
|
"volup" => Some(Command::VolumeUp(
|
||||||
"voldown" => Some(Command::VolumeDown),
|
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),
|
"help" => Some(Command::Help),
|
||||||
"reload" => Some(Command::ReloadConfig),
|
"reload" => Some(Command::ReloadConfig),
|
||||||
"insert" => {
|
"insert" => {
|
||||||
|
|||||||
@@ -148,13 +148,19 @@ impl CommandManager {
|
|||||||
}
|
}
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
Command::VolumeUp => {
|
Command::VolumeUp(amount) => {
|
||||||
let volume = self.spotify.volume().saturating_add(VOLUME_PERCENT);
|
let volume = self
|
||||||
|
.spotify
|
||||||
|
.volume()
|
||||||
|
.saturating_add(VOLUME_PERCENT * amount);
|
||||||
self.spotify.set_volume(volume);
|
self.spotify.set_volume(volume);
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
Command::VolumeDown => {
|
Command::VolumeDown(amount) => {
|
||||||
let volume = self.spotify.volume().saturating_sub(VOLUME_PERCENT);
|
let volume = self
|
||||||
|
.spotify
|
||||||
|
.volume()
|
||||||
|
.saturating_sub(VOLUME_PERCENT * amount);
|
||||||
debug!("vol {}", volume);
|
debug!("vol {}", volume);
|
||||||
self.spotify.set_volume(volume);
|
self.spotify.set_volume(volume);
|
||||||
Ok(None)
|
Ok(None)
|
||||||
@@ -294,8 +300,11 @@ impl CommandManager {
|
|||||||
"Shift+b".into(),
|
"Shift+b".into(),
|
||||||
Command::Seek(SeekDirection::Relative(-10000)),
|
Command::Seek(SeekDirection::Relative(-10000)),
|
||||||
);
|
);
|
||||||
kb.insert("+".into(), Command::VolumeUp);
|
kb.insert("+".into(), Command::VolumeUp(1));
|
||||||
kb.insert("-".into(), Command::VolumeDown);
|
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("r".into(), Command::Repeat(None));
|
||||||
kb.insert("z".into(), Command::Shuffle(None));
|
kb.insert("z".into(), Command::Shuffle(None));
|
||||||
kb.insert("x".into(), Command::Share(TargetMode::Current));
|
kb.insert("x".into(), Command::Share(TargetMode::Current));
|
||||||
|
|||||||
Reference in New Issue
Block a user