Ver código fonte

--initial-volume as parameter

fossedihelm 7 anos atrás
pai
commit
8313da522b
4 arquivos alterados com 21 adições e 11 exclusões
  1. 7 7
      Cargo.lock
  2. 1 0
      core/src/config.rs
  3. 11 2
      src/main.rs
  4. 2 2
      src/spirc.rs

+ 7 - 7
Cargo.lock

@@ -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]]
 name = "aho-corasick"
 version = "0.6.3"
@@ -353,6 +346,13 @@ dependencies = [
  "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]]
 name = "linear-map"
 version = "1.2.0"

+ 1 - 0
core/src/config.rs

@@ -121,4 +121,5 @@ impl Default for PlayerConfig {
 pub struct ConnectConfig {
     pub name: String,
     pub device_type: DeviceType,
+    pub volume: i32,
 }

+ 11 - 2
src/main.rs

@@ -100,7 +100,8 @@ fn setup(args: &[String]) -> Setup {
         .optflag("", "disable-discovery", "Disable discovery mode")
         .optopt("", "backend", "Audio backend to use. Use '?' to list options", "BACKEND")
         .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", "VOLUME");
 
     let matches = match opts.parse(&args[1..]) {
         Ok(m) => m,
@@ -133,6 +134,14 @@ fn setup(args: &[String]) -> Setup {
     let mixer_name = matches.opt_str("mixer");
     let mixer = mixer::find(mixer_name.as_ref())
         .expect("Invalid mixer");
+    let initial_volume;
+    if matches.opt_present("initial-volume"){
+        initial_volume = matches.opt_str("initial-volume").unwrap().parse::<i32>().unwrap()* 0xFFFF as i32 / 100 ;
+        }
+    else{
+        initial_volume = 0x8000 as i32;
+        }
+    info!("Volume \"{}\" !", initial_volume);
 
     let name = matches.opt_str("name").unwrap();
     let use_audio_cache = !matches.opt_present("disable-audio-cache");
@@ -180,6 +189,7 @@ fn setup(args: &[String]) -> Setup {
         ConnectConfig {
             name: name,
             device_type: device_type,
+            volume: initial_volume,
         }
     };
 
@@ -342,4 +352,3 @@ fn main() {
 
     core.run(Main::new(handle, setup(&args))).unwrap()
 }
-

+ 2 - 2
src/spirc.rs

@@ -142,9 +142,9 @@ impl Spirc {
 
         let (cmd_tx, cmd_rx) = mpsc::unbounded();
 
-        let volume = 0x8000;
+        let volume = config.volume as u16;
         let device = initial_device_state(config, volume);
-        mixer.set_volume(volume);
+        mixer.set_volume(volume as u16);
 
         let mut task = SpircTask {
             player: player,