mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Merge pull request #5 from fossedihelm/master
Default volume 50% and --initial-volume argument
This commit is contained in:
commit
95ef34654b
5 changed files with 46 additions and 16 deletions
14
Cargo.lock
generated
14
Cargo.lock
generated
|
@ -1,10 +1,3 @@
|
||||||
[root]
|
|
||||||
name = "librespot-protocol"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"protobuf 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aho-corasick"
|
name = "aho-corasick"
|
||||||
version = "0.6.3"
|
version = "0.6.3"
|
||||||
|
@ -353,6 +346,13 @@ dependencies = [
|
||||||
"protobuf 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"protobuf 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "librespot-protocol"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"protobuf 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "linear-map"
|
name = "linear-map"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
|
|
|
@ -49,7 +49,7 @@ cargo build --release
|
||||||
A sample program implementing a headless Spotify Connect receiver is provided.
|
A sample program implementing a headless Spotify Connect receiver is provided.
|
||||||
Once you've built *librespot*, run it using :
|
Once you've built *librespot*, run it using :
|
||||||
```shell
|
```shell
|
||||||
target/release/librespot --username USERNAME --cache CACHEDIR --name DEVICENAME
|
target/release/librespot --username USERNAME --cache CACHEDIR --name DEVICENAME [--initial-volume 20]
|
||||||
```
|
```
|
||||||
|
|
||||||
### All options
|
### All options
|
||||||
|
@ -70,6 +70,7 @@ target/release/librespot --username USERNAME --cache CACHEDIR --name DEVICENAME
|
||||||
| Option | | backend | Audio backend to use. Use '?' to list options | BACKEND |
|
| Option | | backend | Audio backend to use. Use '?' to list options | BACKEND |
|
||||||
| Option | | device | Audio device to use. Use '?' to list options | DEVICE |
|
| Option | | device | Audio device to use. Use '?' to list options | DEVICE |
|
||||||
| Option | | mixer | Mixer to use | MIXER |
|
| Option | | mixer | Mixer to use | MIXER |
|
||||||
|
| Option | | initial-volume | Initial volume in %, once connected [0-100] | VOLUME |
|
||||||
|
|
||||||
Taken from here:
|
Taken from here:
|
||||||
https://github.com/ComlOnline/librespot/blob/master/src/main.rs#L88
|
https://github.com/ComlOnline/librespot/blob/master/src/main.rs#L88
|
||||||
|
|
|
@ -121,4 +121,5 @@ impl Default for PlayerConfig {
|
||||||
pub struct ConnectConfig {
|
pub struct ConnectConfig {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub device_type: DeviceType,
|
pub device_type: DeviceType,
|
||||||
|
pub volume: i32,
|
||||||
}
|
}
|
||||||
|
|
32
src/main.rs
32
src/main.rs
|
@ -100,7 +100,8 @@ fn setup(args: &[String]) -> Setup {
|
||||||
.optflag("", "disable-discovery", "Disable discovery mode")
|
.optflag("", "disable-discovery", "Disable discovery mode")
|
||||||
.optopt("", "backend", "Audio backend to use. Use '?' to list options", "BACKEND")
|
.optopt("", "backend", "Audio backend to use. Use '?' to list options", "BACKEND")
|
||||||
.optopt("", "device", "Audio device to use. Use '?' to list options", "DEVICE")
|
.optopt("", "device", "Audio device to use. Use '?' to list options", "DEVICE")
|
||||||
.optopt("", "mixer", "Mixer to use", "MIXER");
|
.optopt("", "mixer", "Mixer to use", "MIXER")
|
||||||
|
.optopt("", "initial-volume", "Initial volume in %, once connected (must be from 0 to 100)", "VOLUME");
|
||||||
|
|
||||||
let matches = match opts.parse(&args[1..]) {
|
let matches = match opts.parse(&args[1..]) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
|
@ -133,6 +134,33 @@ fn setup(args: &[String]) -> Setup {
|
||||||
let mixer_name = matches.opt_str("mixer");
|
let mixer_name = matches.opt_str("mixer");
|
||||||
let mixer = mixer::find(mixer_name.as_ref())
|
let mixer = mixer::find(mixer_name.as_ref())
|
||||||
.expect("Invalid mixer");
|
.expect("Invalid mixer");
|
||||||
|
let initial_volume;
|
||||||
|
// check if initial-volume argument is present
|
||||||
|
if matches.opt_present("initial-volume"){
|
||||||
|
// check if value is a number
|
||||||
|
if matches.opt_str("initial-volume").unwrap().parse::<i32>().is_ok(){
|
||||||
|
// check if value is in [0-100] range, otherwise put the bound values
|
||||||
|
if matches.opt_str("initial-volume").unwrap().parse::<i32>().unwrap() < 0 {
|
||||||
|
initial_volume = 0 as i32;
|
||||||
|
}
|
||||||
|
else if matches.opt_str("initial-volume").unwrap().parse::<i32>().unwrap() > 100{
|
||||||
|
initial_volume = 0xFFFF as i32;
|
||||||
|
}
|
||||||
|
// checks ok
|
||||||
|
else{
|
||||||
|
initial_volume = matches.opt_str("initial-volume").unwrap().parse::<i32>().unwrap()* 0xFFFF as i32 / 100 ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if value is not a number use default value (50%)
|
||||||
|
else {
|
||||||
|
initial_volume = 0x8000 as i32;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if argument not present use default values (50%)
|
||||||
|
else{
|
||||||
|
initial_volume = 0x8000 as i32;
|
||||||
|
}
|
||||||
|
debug!("Volume \"{}\" !", initial_volume);
|
||||||
|
|
||||||
let name = matches.opt_str("name").unwrap();
|
let name = matches.opt_str("name").unwrap();
|
||||||
let use_audio_cache = !matches.opt_present("disable-audio-cache");
|
let use_audio_cache = !matches.opt_present("disable-audio-cache");
|
||||||
|
@ -180,6 +208,7 @@ fn setup(args: &[String]) -> Setup {
|
||||||
ConnectConfig {
|
ConnectConfig {
|
||||||
name: name,
|
name: name,
|
||||||
device_type: device_type,
|
device_type: device_type,
|
||||||
|
volume: initial_volume,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -342,4 +371,3 @@ fn main() {
|
||||||
|
|
||||||
core.run(Main::new(handle, setup(&args))).unwrap()
|
core.run(Main::new(handle, setup(&args))).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,9 +145,9 @@ impl Spirc {
|
||||||
|
|
||||||
let (cmd_tx, cmd_rx) = mpsc::unbounded();
|
let (cmd_tx, cmd_rx) = mpsc::unbounded();
|
||||||
|
|
||||||
let volume = 0xFFFF;
|
let volume = config.volume as u16;
|
||||||
let device = initial_device_state(config, volume);
|
let device = initial_device_state(config, volume);
|
||||||
mixer.set_volume(volume);
|
mixer.set_volume(volume as u16);
|
||||||
|
|
||||||
let mut task = SpircTask {
|
let mut task = SpircTask {
|
||||||
player: player,
|
player: player,
|
||||||
|
|
Loading…
Reference in a new issue