mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Dry up error messages.
This commit is contained in:
parent
8c480b7e39
commit
d29337c62d
1 changed files with 199 additions and 207 deletions
406
src/main.rs
406
src/main.rs
|
@ -590,30 +590,23 @@ fn get_setup() -> Setup {
|
||||||
.to_lowercase()
|
.to_lowercase()
|
||||||
};
|
};
|
||||||
|
|
||||||
let env_vars: Vec<_> = env::vars_os().filter_map(|(k, v)| {
|
let env_vars: Vec<_> = env::vars_os().filter_map(|(k, v)| match k.into_string() {
|
||||||
let mut env_var = None;
|
Ok(key) if key.starts_with("LIBRESPOT_") => {
|
||||||
if let Ok(key) = k.into_string() {
|
let stripped_key = stripped_env_key(&key);
|
||||||
if key.starts_with("LIBRESPOT_") {
|
// We only care about long option/flag names.
|
||||||
let stripped_key = stripped_env_key(&key);
|
if stripped_key.chars().count() > 1 && matches.opt_defined(&stripped_key) {
|
||||||
// Only match against long option/flag names.
|
match v.into_string() {
|
||||||
// Something like LIBRESPOT_V for example is
|
Ok(value) => Some((key, value)),
|
||||||
// not valid because there are both -v and -V flags
|
Err(s) => {
|
||||||
// but env vars are assumed to be all uppercase.
|
eprintln!("Environment variable was not valid Unicode and will not be evaluated: {}={:?}", key, s);
|
||||||
let len = stripped_key.chars().count();
|
None
|
||||||
if len > 1 && matches.opt_defined(&stripped_key) {
|
|
||||||
match v.into_string() {
|
|
||||||
Ok(value) => {
|
|
||||||
env_var = Some((key, value));
|
|
||||||
},
|
|
||||||
Err(s) => {
|
|
||||||
eprintln!("Environment variable was not valid Unicode and will not be evaluated: {}={:?}", key, s);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
_ => None
|
||||||
env_var
|
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
@ -706,13 +699,33 @@ fn get_setup() -> Setup {
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let invalid_error_msg =
|
||||||
|
|long: &str, short: &str, invalid: &str, valid_values: &str, default_value: &str| {
|
||||||
|
error!("Invalid `--{}` / `-{}`: \"{}\"", long, short, invalid);
|
||||||
|
|
||||||
|
if !valid_values.is_empty() {
|
||||||
|
println!("Valid `--{}` / `-{}` values: {}", long, short, valid_values);
|
||||||
|
}
|
||||||
|
|
||||||
|
if !default_value.is_empty() {
|
||||||
|
println!("Default: {}", default_value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let empty_string_error_msg = |long: &str, short: &str| {
|
||||||
|
error!("`--{}` / `-{}` can not be an empty string", long, short);
|
||||||
|
exit(1);
|
||||||
|
};
|
||||||
|
|
||||||
let backend = audio_backend::find(backend_name).unwrap_or_else(|| {
|
let backend = audio_backend::find(backend_name).unwrap_or_else(|| {
|
||||||
error!(
|
invalid_error_msg(
|
||||||
"Invalid `--{}` / `-{}`: \"{}\"",
|
|
||||||
BACKEND,
|
BACKEND,
|
||||||
BACKEND_SHORT,
|
BACKEND_SHORT,
|
||||||
opt_str(BACKEND).unwrap_or_default()
|
&opt_str(BACKEND).unwrap_or_default(),
|
||||||
|
"",
|
||||||
|
"",
|
||||||
);
|
);
|
||||||
|
|
||||||
list_backends();
|
list_backends();
|
||||||
exit(1);
|
exit(1);
|
||||||
});
|
});
|
||||||
|
@ -721,15 +734,15 @@ fn get_setup() -> Setup {
|
||||||
.as_deref()
|
.as_deref()
|
||||||
.map(|format| {
|
.map(|format| {
|
||||||
AudioFormat::from_str(format).unwrap_or_else(|_| {
|
AudioFormat::from_str(format).unwrap_or_else(|_| {
|
||||||
error!(
|
let default_value = &format!("{:?}", AudioFormat::default());
|
||||||
"Invalid `--{}` / `-{}`: \"{}\"",
|
invalid_error_msg(
|
||||||
FORMAT, FORMAT_SHORT, format
|
FORMAT,
|
||||||
|
FORMAT_SHORT,
|
||||||
|
format,
|
||||||
|
"F64, F32, S32, S24, S24_3, S16",
|
||||||
|
default_value,
|
||||||
);
|
);
|
||||||
println!(
|
|
||||||
"Valid `--{}` / `-{}` values: F64, F32, S32, S24, S24_3, S16",
|
|
||||||
FORMAT, FORMAT_SHORT
|
|
||||||
);
|
|
||||||
println!("Default: {:?}", AudioFormat::default());
|
|
||||||
exit(1);
|
exit(1);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -752,11 +765,7 @@ fn get_setup() -> Setup {
|
||||||
backend(device, format);
|
backend(device, format);
|
||||||
exit(0);
|
exit(0);
|
||||||
} else if value.is_empty() {
|
} else if value.is_empty() {
|
||||||
error!(
|
empty_string_error_msg(DEVICE, DEVICE_SHORT);
|
||||||
"`--{}` / `-{}` can not be an empty string",
|
|
||||||
DEVICE, DEVICE_SHORT
|
|
||||||
);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -785,17 +794,14 @@ fn get_setup() -> Setup {
|
||||||
let mixer_type: Option<String> = None;
|
let mixer_type: Option<String> = None;
|
||||||
|
|
||||||
let mixer = mixer::find(mixer_type.as_deref()).unwrap_or_else(|| {
|
let mixer = mixer::find(mixer_type.as_deref()).unwrap_or_else(|| {
|
||||||
error!(
|
invalid_error_msg(
|
||||||
"Invalid `--{}` / `-{}`: \"{}\"",
|
|
||||||
MIXER_TYPE,
|
MIXER_TYPE,
|
||||||
MIXER_TYPE_SHORT,
|
MIXER_TYPE_SHORT,
|
||||||
opt_str(MIXER_TYPE).unwrap_or_default()
|
&opt_str(MIXER_TYPE).unwrap_or_default(),
|
||||||
|
"alsa, softvol",
|
||||||
|
"softvol",
|
||||||
);
|
);
|
||||||
println!(
|
|
||||||
"Valid `--{}` / `-{}` values: alsa, softvol",
|
|
||||||
MIXER_TYPE, MIXER_TYPE_SHORT
|
|
||||||
);
|
|
||||||
println!("Default: softvol");
|
|
||||||
exit(1);
|
exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -818,11 +824,14 @@ fn get_setup() -> Setup {
|
||||||
let index = opt_str(ALSA_MIXER_INDEX)
|
let index = opt_str(ALSA_MIXER_INDEX)
|
||||||
.map(|index| {
|
.map(|index| {
|
||||||
index.parse::<u32>().unwrap_or_else(|_| {
|
index.parse::<u32>().unwrap_or_else(|_| {
|
||||||
error!(
|
invalid_error_msg(
|
||||||
"Invalid `--{}` / `-{}`: \"{}\"",
|
ALSA_MIXER_INDEX,
|
||||||
ALSA_MIXER_INDEX, ALSA_MIXER_INDEX_SHORT, index
|
ALSA_MIXER_INDEX_SHORT,
|
||||||
|
&index,
|
||||||
|
"",
|
||||||
|
&mixer_default_config.index.to_string(),
|
||||||
);
|
);
|
||||||
println!("Default: {}", mixer_default_config.index);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -836,11 +845,7 @@ fn get_setup() -> Setup {
|
||||||
|
|
||||||
#[cfg(feature = "alsa-backend")]
|
#[cfg(feature = "alsa-backend")]
|
||||||
if control.is_empty() {
|
if control.is_empty() {
|
||||||
error!(
|
empty_string_error_msg(ALSA_MIXER_CONTROL, ALSA_MIXER_CONTROL_SHORT);
|
||||||
"`--{}` / `-{}` can not be an empty string",
|
|
||||||
ALSA_MIXER_CONTROL, ALSA_MIXER_CONTROL_SHORT
|
|
||||||
);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "alsa-backend"))]
|
#[cfg(not(feature = "alsa-backend"))]
|
||||||
|
@ -849,24 +854,28 @@ fn get_setup() -> Setup {
|
||||||
let volume_range = opt_str(VOLUME_RANGE)
|
let volume_range = opt_str(VOLUME_RANGE)
|
||||||
.map(|range| {
|
.map(|range| {
|
||||||
let on_error = || {
|
let on_error = || {
|
||||||
error!(
|
let valid_values = &format!(
|
||||||
"Invalid `--{}` / `-{}`: \"{}\"",
|
"{} - {}",
|
||||||
VOLUME_RANGE, VOLUME_RANGE_SHORT, range
|
|
||||||
);
|
|
||||||
println!(
|
|
||||||
"Valid `--{}` / `-{}` values: {} - {}",
|
|
||||||
VOLUME_RANGE,
|
|
||||||
VOLUME_RANGE_SHORT,
|
|
||||||
VALID_VOLUME_RANGE.start(),
|
VALID_VOLUME_RANGE.start(),
|
||||||
VALID_VOLUME_RANGE.end()
|
VALID_VOLUME_RANGE.end()
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "alsa-backend")]
|
#[cfg(feature = "alsa-backend")]
|
||||||
println!(
|
let default_value = &format!(
|
||||||
"Default: softvol - {}, alsa - what the control supports",
|
"softvol - {}, alsa - what the control supports",
|
||||||
VolumeCtrl::DEFAULT_DB_RANGE
|
VolumeCtrl::DEFAULT_DB_RANGE
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(not(feature = "alsa-backend"))]
|
#[cfg(not(feature = "alsa-backend"))]
|
||||||
println!("Default: {}", VolumeCtrl::DEFAULT_DB_RANGE);
|
let default_value = &VolumeCtrl::DEFAULT_DB_RANGE.to_string();
|
||||||
|
|
||||||
|
invalid_error_msg(
|
||||||
|
VOLUME_RANGE,
|
||||||
|
VOLUME_RANGE_SHORT,
|
||||||
|
&range,
|
||||||
|
valid_values,
|
||||||
|
default_value,
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
let range = range.parse::<f64>().unwrap_or_else(|_| {
|
let range = range.parse::<f64>().unwrap_or_else(|_| {
|
||||||
|
@ -891,15 +900,14 @@ fn get_setup() -> Setup {
|
||||||
.as_deref()
|
.as_deref()
|
||||||
.map(|volume_ctrl| {
|
.map(|volume_ctrl| {
|
||||||
VolumeCtrl::from_str_with_range(volume_ctrl, volume_range).unwrap_or_else(|_| {
|
VolumeCtrl::from_str_with_range(volume_ctrl, volume_range).unwrap_or_else(|_| {
|
||||||
error!(
|
invalid_error_msg(
|
||||||
"Invalid `--{}` / `-{}`: \"{}\"",
|
VOLUME_CTRL,
|
||||||
VOLUME_CTRL, VOLUME_CTRL_SHORT, volume_ctrl
|
VOLUME_CTRL_SHORT,
|
||||||
|
volume_ctrl,
|
||||||
|
"cubic, fixed, linear, log",
|
||||||
|
"log",
|
||||||
);
|
);
|
||||||
println!(
|
|
||||||
"Valid `--{}` / `-{}` values: cubic, fixed, linear, log",
|
|
||||||
VOLUME_CTRL, VOLUME_CTRL
|
|
||||||
);
|
|
||||||
println!("Default: log");
|
|
||||||
exit(1);
|
exit(1);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -938,10 +946,14 @@ fn get_setup() -> Setup {
|
||||||
.map(parse_file_size)
|
.map(parse_file_size)
|
||||||
.map(|e| {
|
.map(|e| {
|
||||||
e.unwrap_or_else(|e| {
|
e.unwrap_or_else(|e| {
|
||||||
error!(
|
invalid_error_msg(
|
||||||
"Invalid `--{}` / `-{}`: \"{}\"",
|
CACHE_SIZE_LIMIT,
|
||||||
CACHE_SIZE_LIMIT, CACHE_SIZE_LIMIT_SHORT, e
|
CACHE_SIZE_LIMIT_SHORT,
|
||||||
|
&e.to_string(),
|
||||||
|
"",
|
||||||
|
"",
|
||||||
);
|
);
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -970,19 +982,11 @@ fn get_setup() -> Setup {
|
||||||
|
|
||||||
if let Some(username) = opt_str(USERNAME) {
|
if let Some(username) = opt_str(USERNAME) {
|
||||||
if username.is_empty() {
|
if username.is_empty() {
|
||||||
error!(
|
empty_string_error_msg(USERNAME, USERNAME_SHORT);
|
||||||
"`--{}` / `-{}` can not be an empty string",
|
|
||||||
USERNAME, USERNAME_SHORT
|
|
||||||
);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
if let Some(password) = opt_str(PASSWORD) {
|
if let Some(password) = opt_str(PASSWORD) {
|
||||||
if password.is_empty() {
|
if password.is_empty() {
|
||||||
error!(
|
empty_string_error_msg(PASSWORD, PASSWORD_SHORT);
|
||||||
"`--{}` / `-{}` can not be an empty string",
|
|
||||||
PASSWORD, PASSWORD_SHORT
|
|
||||||
);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
Some(Credentials::with_password(username, password))
|
Some(Credentials::with_password(username, password))
|
||||||
} else {
|
} else {
|
||||||
|
@ -990,7 +994,6 @@ fn get_setup() -> Setup {
|
||||||
Some(creds) if username == creds.username => Some(creds),
|
Some(creds) if username == creds.username => Some(creds),
|
||||||
_ => {
|
_ => {
|
||||||
let prompt = &format!("Password for {}: ", username);
|
let prompt = &format!("Password for {}: ", username);
|
||||||
|
|
||||||
match rpassword::prompt_password_stderr(prompt) {
|
match rpassword::prompt_password_stderr(prompt) {
|
||||||
Ok(password) => {
|
Ok(password) => {
|
||||||
if !password.is_empty() {
|
if !password.is_empty() {
|
||||||
|
@ -1015,6 +1018,9 @@ fn get_setup() -> Setup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if cached_creds.is_some() {
|
||||||
|
trace!("Using cached credentials.");
|
||||||
|
}
|
||||||
cached_creds
|
cached_creds
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1037,16 +1043,8 @@ fn get_setup() -> Setup {
|
||||||
opt_str(ZEROCONF_PORT)
|
opt_str(ZEROCONF_PORT)
|
||||||
.map(|port| {
|
.map(|port| {
|
||||||
let on_error = || {
|
let on_error = || {
|
||||||
error!(
|
let valid_values = &format!("1 - {}", u16::MAX);
|
||||||
"Invalid `--{}` / `-{}`: \"{}\"",
|
invalid_error_msg(ZEROCONF_PORT, ZEROCONF_PORT_SHORT, &port, valid_values, "");
|
||||||
ZEROCONF_PORT, ZEROCONF_PORT_SHORT, port
|
|
||||||
);
|
|
||||||
println!(
|
|
||||||
"Valid `--{}` / `-{}` values: 1 - {}",
|
|
||||||
ZEROCONF_PORT,
|
|
||||||
ZEROCONF_PORT_SHORT,
|
|
||||||
u16::MAX
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let port = port.parse::<u16>().unwrap_or_else(|_| {
|
let port = port.parse::<u16>().unwrap_or_else(|_| {
|
||||||
|
@ -1072,36 +1070,37 @@ fn get_setup() -> Setup {
|
||||||
let name = opt_str(NAME).unwrap_or_else(|| connect_default_config.name.clone());
|
let name = opt_str(NAME).unwrap_or_else(|| connect_default_config.name.clone());
|
||||||
|
|
||||||
if name.is_empty() {
|
if name.is_empty() {
|
||||||
error!(
|
empty_string_error_msg(NAME, NAME_SHORT);
|
||||||
"`--{}` / `-{}` can not be an empty string",
|
|
||||||
NAME, NAME_SHORT
|
|
||||||
);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let initial_volume = opt_str(INITIAL_VOLUME)
|
let initial_volume = opt_str(INITIAL_VOLUME)
|
||||||
.map(|initial_volume| {
|
.map(|initial_volume| {
|
||||||
let on_error = || {
|
let on_error = || {
|
||||||
error!(
|
let valid_values = &format!(
|
||||||
"Invalid `--{}` / `-{}`: \"{}\"",
|
"{} - {}",
|
||||||
INITIAL_VOLUME, INITIAL_VOLUME_SHORT, initial_volume
|
|
||||||
);
|
|
||||||
println!(
|
|
||||||
"Valid `--{}` / `-{}` values: {} - {}",
|
|
||||||
INITIAL_VOLUME,
|
|
||||||
INITIAL_VOLUME_SHORT,
|
|
||||||
VALID_INITIAL_VOLUME_RANGE.start(),
|
VALID_INITIAL_VOLUME_RANGE.start(),
|
||||||
VALID_INITIAL_VOLUME_RANGE.end()
|
VALID_INITIAL_VOLUME_RANGE.end()
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "alsa-backend")]
|
#[cfg(feature = "alsa-backend")]
|
||||||
println!(
|
let default_value = &format!(
|
||||||
"Default: {}, or the current value when the alsa mixer is used.",
|
"{}, or the current value when the alsa mixer is used.",
|
||||||
connect_default_config.initial_volume.unwrap_or_default()
|
connect_default_config.initial_volume.unwrap_or_default()
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(not(feature = "alsa-backend"))]
|
#[cfg(not(feature = "alsa-backend"))]
|
||||||
println!(
|
let default_value = &connect_default_config
|
||||||
"Default: {}",
|
.initial_volume
|
||||||
connect_default_config.initial_volume.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
|
.to_string();
|
||||||
|
|
||||||
|
invalid_error_msg(
|
||||||
|
INITIAL_VOLUME,
|
||||||
|
INITIAL_VOLUME_SHORT,
|
||||||
|
&initial_volume,
|
||||||
|
valid_values,
|
||||||
|
default_value,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1127,12 +1126,18 @@ fn get_setup() -> Setup {
|
||||||
.as_deref()
|
.as_deref()
|
||||||
.map(|device_type| {
|
.map(|device_type| {
|
||||||
DeviceType::from_str(device_type).unwrap_or_else(|_| {
|
DeviceType::from_str(device_type).unwrap_or_else(|_| {
|
||||||
error!("Invalid `--{}` / `-{}`: \"{}\"", DEVICE_TYPE, DEVICE_TYPE_SHORT, device_type);
|
invalid_error_msg(
|
||||||
println!("Valid `--{}` / `-{}` values: computer, tablet, smartphone, speaker, tv, avr, stb, audiodongle, \
|
DEVICE_TYPE,
|
||||||
gameconsole, castaudio, castvideo, automobile, smartwatch, chromebook, carthing, homething",
|
DEVICE_TYPE_SHORT,
|
||||||
DEVICE_TYPE, DEVICE_TYPE_SHORT
|
device_type,
|
||||||
|
"computer, tablet, smartphone, \
|
||||||
|
speaker, tv, avr, stb, audiodongle, \
|
||||||
|
gameconsole, castaudio, castvideo, \
|
||||||
|
automobile, smartwatch, chromebook, \
|
||||||
|
carthing, homething",
|
||||||
|
"speaker",
|
||||||
);
|
);
|
||||||
println!("Default: speaker");
|
|
||||||
exit(1);
|
exit(1);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -1178,8 +1183,8 @@ fn get_setup() -> Setup {
|
||||||
),
|
),
|
||||||
ap_port: opt_str(AP_PORT).map(|port| {
|
ap_port: opt_str(AP_PORT).map(|port| {
|
||||||
let on_error = || {
|
let on_error = || {
|
||||||
error!("Invalid `--{}` / `-{}`: \"{}\"", AP_PORT, AP_PORT_SHORT, port);
|
let valid_values = &format!("1 - {}", u16::MAX);
|
||||||
println!("Valid `--{}` / `-{}` values: 1 - {}", AP_PORT, AP_PORT_SHORT, u16::MAX);
|
invalid_error_msg(AP_PORT, AP_PORT_SHORT, &port, valid_values, "");
|
||||||
};
|
};
|
||||||
|
|
||||||
let port = port.parse::<u16>().unwrap_or_else(|_| {
|
let port = port.parse::<u16>().unwrap_or_else(|_| {
|
||||||
|
@ -1203,15 +1208,7 @@ fn get_setup() -> Setup {
|
||||||
.as_deref()
|
.as_deref()
|
||||||
.map(|bitrate| {
|
.map(|bitrate| {
|
||||||
Bitrate::from_str(bitrate).unwrap_or_else(|_| {
|
Bitrate::from_str(bitrate).unwrap_or_else(|_| {
|
||||||
error!(
|
invalid_error_msg(BITRATE, BITRATE_SHORT, bitrate, "96, 160, 320", "160");
|
||||||
"Invalid `--{}` / `-{}`: \"{}\"",
|
|
||||||
BITRATE, BITRATE_SHORT, bitrate
|
|
||||||
);
|
|
||||||
println!(
|
|
||||||
"Valid `--{}` / `-{}` values: 96, 160, 320",
|
|
||||||
BITRATE, BITRATE_SHORT
|
|
||||||
);
|
|
||||||
println!("Default: 160");
|
|
||||||
exit(1);
|
exit(1);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -1265,15 +1262,14 @@ fn get_setup() -> Setup {
|
||||||
);
|
);
|
||||||
|
|
||||||
let method = NormalisationMethod::from_str(method).unwrap_or_else(|_| {
|
let method = NormalisationMethod::from_str(method).unwrap_or_else(|_| {
|
||||||
error!(
|
invalid_error_msg(
|
||||||
"Invalid `--{}` / `-{}`: \"{}\"",
|
NORMALISATION_METHOD,
|
||||||
NORMALISATION_METHOD, NORMALISATION_METHOD_SHORT, method
|
NORMALISATION_METHOD_SHORT,
|
||||||
|
method,
|
||||||
|
"basic, dynamic",
|
||||||
|
&format!("{:?}", player_default_config.normalisation_method),
|
||||||
);
|
);
|
||||||
println!(
|
|
||||||
"Valid `--{}` / `-{}` values: basic, dynamic",
|
|
||||||
NORMALISATION_METHOD, NORMALISATION_METHOD_SHORT
|
|
||||||
);
|
|
||||||
println!("Default: {:?}", player_default_config.normalisation_method);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1292,15 +1288,14 @@ fn get_setup() -> Setup {
|
||||||
.as_deref()
|
.as_deref()
|
||||||
.map(|gain_type| {
|
.map(|gain_type| {
|
||||||
NormalisationType::from_str(gain_type).unwrap_or_else(|_| {
|
NormalisationType::from_str(gain_type).unwrap_or_else(|_| {
|
||||||
error!(
|
invalid_error_msg(
|
||||||
"Invalid `--{}` / `-{}`: \"{}\"",
|
NORMALISATION_GAIN_TYPE,
|
||||||
NORMALISATION_GAIN_TYPE, NORMALISATION_GAIN_TYPE_SHORT, gain_type
|
NORMALISATION_GAIN_TYPE_SHORT,
|
||||||
|
gain_type,
|
||||||
|
"track, album, auto",
|
||||||
|
&format!("{:?}", player_default_config.normalisation_type),
|
||||||
);
|
);
|
||||||
println!(
|
|
||||||
"Valid `--{}` / `-{}` values: track, album, auto",
|
|
||||||
NORMALISATION_GAIN_TYPE, NORMALISATION_GAIN_TYPE_SHORT,
|
|
||||||
);
|
|
||||||
println!("Default: {:?}", player_default_config.normalisation_type);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -1309,18 +1304,19 @@ fn get_setup() -> Setup {
|
||||||
normalisation_pregain = opt_str(NORMALISATION_PREGAIN)
|
normalisation_pregain = opt_str(NORMALISATION_PREGAIN)
|
||||||
.map(|pregain| {
|
.map(|pregain| {
|
||||||
let on_error = || {
|
let on_error = || {
|
||||||
error!(
|
let valid_values = &format!(
|
||||||
"Invalid `--{}` / `-{}`: \"{}\"",
|
"{} - {}",
|
||||||
NORMALISATION_PREGAIN, NORMALISATION_PREGAIN_SHORT, pregain
|
|
||||||
);
|
|
||||||
println!(
|
|
||||||
"Valid `--{}` / `-{}` values: {} - {}",
|
|
||||||
NORMALISATION_PREGAIN,
|
|
||||||
NORMALISATION_PREGAIN_SHORT,
|
|
||||||
VALID_NORMALISATION_PREGAIN_RANGE.start(),
|
VALID_NORMALISATION_PREGAIN_RANGE.start(),
|
||||||
VALID_NORMALISATION_PREGAIN_RANGE.end()
|
VALID_NORMALISATION_PREGAIN_RANGE.end()
|
||||||
);
|
);
|
||||||
println!("Default: {}", player_default_config.normalisation_pregain);
|
|
||||||
|
invalid_error_msg(
|
||||||
|
NORMALISATION_PREGAIN,
|
||||||
|
NORMALISATION_PREGAIN_SHORT,
|
||||||
|
&pregain,
|
||||||
|
valid_values,
|
||||||
|
&player_default_config.normalisation_pregain.to_string(),
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
let pregain = pregain.parse::<f64>().unwrap_or_else(|_| {
|
let pregain = pregain.parse::<f64>().unwrap_or_else(|_| {
|
||||||
|
@ -1340,20 +1336,18 @@ fn get_setup() -> Setup {
|
||||||
normalisation_threshold = opt_str(NORMALISATION_THRESHOLD)
|
normalisation_threshold = opt_str(NORMALISATION_THRESHOLD)
|
||||||
.map(|threshold| {
|
.map(|threshold| {
|
||||||
let on_error = || {
|
let on_error = || {
|
||||||
error!(
|
let valid_values = &format!(
|
||||||
"Invalid `--{}` / `-{}`: \"{}\"",
|
"{} - {}",
|
||||||
NORMALISATION_THRESHOLD, NORMALISATION_THRESHOLD_SHORT, threshold
|
|
||||||
);
|
|
||||||
println!(
|
|
||||||
"Valid `--{}` / `-{}` values: {} - {}",
|
|
||||||
NORMALISATION_THRESHOLD,
|
|
||||||
NORMALISATION_THRESHOLD_SHORT,
|
|
||||||
VALID_NORMALISATION_THRESHOLD_RANGE.start(),
|
VALID_NORMALISATION_THRESHOLD_RANGE.start(),
|
||||||
VALID_NORMALISATION_THRESHOLD_RANGE.end()
|
VALID_NORMALISATION_THRESHOLD_RANGE.end()
|
||||||
);
|
);
|
||||||
println!(
|
|
||||||
"Default: {}",
|
invalid_error_msg(
|
||||||
ratio_to_db(player_default_config.normalisation_threshold)
|
NORMALISATION_THRESHOLD,
|
||||||
|
NORMALISATION_THRESHOLD_SHORT,
|
||||||
|
&threshold,
|
||||||
|
valid_values,
|
||||||
|
&ratio_to_db(player_default_config.normalisation_threshold).to_string(),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1374,20 +1368,21 @@ fn get_setup() -> Setup {
|
||||||
normalisation_attack = opt_str(NORMALISATION_ATTACK)
|
normalisation_attack = opt_str(NORMALISATION_ATTACK)
|
||||||
.map(|attack| {
|
.map(|attack| {
|
||||||
let on_error = || {
|
let on_error = || {
|
||||||
error!(
|
let valid_values = &format!(
|
||||||
"Invalid `--{}` / `-{}`: \"{}\"",
|
"{} - {}",
|
||||||
NORMALISATION_ATTACK, NORMALISATION_ATTACK_SHORT, attack
|
|
||||||
);
|
|
||||||
println!(
|
|
||||||
"Valid `--{}` / `-{}` values: {} - {}",
|
|
||||||
NORMALISATION_ATTACK,
|
|
||||||
NORMALISATION_ATTACK_SHORT,
|
|
||||||
VALID_NORMALISATION_ATTACK_RANGE.start(),
|
VALID_NORMALISATION_ATTACK_RANGE.start(),
|
||||||
VALID_NORMALISATION_ATTACK_RANGE.end()
|
VALID_NORMALISATION_ATTACK_RANGE.end()
|
||||||
);
|
);
|
||||||
println!(
|
|
||||||
"Default: {}",
|
invalid_error_msg(
|
||||||
player_default_config.normalisation_attack.as_millis()
|
NORMALISATION_ATTACK,
|
||||||
|
NORMALISATION_ATTACK_SHORT,
|
||||||
|
&attack,
|
||||||
|
valid_values,
|
||||||
|
&player_default_config
|
||||||
|
.normalisation_attack
|
||||||
|
.as_millis()
|
||||||
|
.to_string(),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1408,20 +1403,21 @@ fn get_setup() -> Setup {
|
||||||
normalisation_release = opt_str(NORMALISATION_RELEASE)
|
normalisation_release = opt_str(NORMALISATION_RELEASE)
|
||||||
.map(|release| {
|
.map(|release| {
|
||||||
let on_error = || {
|
let on_error = || {
|
||||||
error!(
|
let valid_values = &format!(
|
||||||
"Invalid `--{}` / `-{}`: \"{}\"",
|
"{} - {}",
|
||||||
NORMALISATION_RELEASE, NORMALISATION_RELEASE_SHORT, release
|
|
||||||
);
|
|
||||||
println!(
|
|
||||||
"Valid `--{}` / `-{}` values: {} - {}",
|
|
||||||
NORMALISATION_RELEASE,
|
|
||||||
NORMALISATION_RELEASE_SHORT,
|
|
||||||
VALID_NORMALISATION_RELEASE_RANGE.start(),
|
VALID_NORMALISATION_RELEASE_RANGE.start(),
|
||||||
VALID_NORMALISATION_RELEASE_RANGE.end()
|
VALID_NORMALISATION_RELEASE_RANGE.end()
|
||||||
);
|
);
|
||||||
println!(
|
|
||||||
"Default: {}",
|
invalid_error_msg(
|
||||||
player_default_config.normalisation_release.as_millis()
|
NORMALISATION_RELEASE,
|
||||||
|
NORMALISATION_RELEASE_SHORT,
|
||||||
|
&release,
|
||||||
|
valid_values,
|
||||||
|
&player_default_config
|
||||||
|
.normalisation_release
|
||||||
|
.as_millis()
|
||||||
|
.to_string(),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1442,18 +1438,19 @@ fn get_setup() -> Setup {
|
||||||
normalisation_knee = opt_str(NORMALISATION_KNEE)
|
normalisation_knee = opt_str(NORMALISATION_KNEE)
|
||||||
.map(|knee| {
|
.map(|knee| {
|
||||||
let on_error = || {
|
let on_error = || {
|
||||||
error!(
|
let valid_values = &format!(
|
||||||
"Invalid `--{}` / `-{}`: \"{}\"",
|
"{} - {}",
|
||||||
NORMALISATION_KNEE, NORMALISATION_KNEE_SHORT, knee
|
|
||||||
);
|
|
||||||
println!(
|
|
||||||
"Valid `--{}` / `-{}` values: {} - {}",
|
|
||||||
NORMALISATION_KNEE,
|
|
||||||
NORMALISATION_KNEE_SHORT,
|
|
||||||
VALID_NORMALISATION_KNEE_RANGE.start(),
|
VALID_NORMALISATION_KNEE_RANGE.start(),
|
||||||
VALID_NORMALISATION_KNEE_RANGE.end()
|
VALID_NORMALISATION_KNEE_RANGE.end()
|
||||||
);
|
);
|
||||||
println!("Default: {}", player_default_config.normalisation_knee);
|
|
||||||
|
invalid_error_msg(
|
||||||
|
NORMALISATION_KNEE,
|
||||||
|
NORMALISATION_KNEE_SHORT,
|
||||||
|
&knee,
|
||||||
|
valid_values,
|
||||||
|
&player_default_config.normalisation_knee.to_string(),
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
let knee = knee.parse::<f64>().unwrap_or_else(|_| {
|
let knee = knee.parse::<f64>().unwrap_or_else(|_| {
|
||||||
|
@ -1483,19 +1480,14 @@ fn get_setup() -> Setup {
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(dither::find_ditherer(ditherer_name).unwrap_or_else(|| {
|
Some(dither::find_ditherer(ditherer_name).unwrap_or_else(|| {
|
||||||
error!(
|
invalid_error_msg(
|
||||||
"Invalid `--{}` / `-{}`: \"{}\"",
|
|
||||||
DITHER,
|
DITHER,
|
||||||
DITHER_SHORT,
|
DITHER_SHORT,
|
||||||
opt_str(DITHER).unwrap_or_default()
|
&opt_str(DITHER).unwrap_or_default(),
|
||||||
);
|
"none, gpdf, tpdf, tpdf_hp",
|
||||||
println!(
|
"tpdf for formats S16, S24, S24_3 and none for other formats",
|
||||||
"Valid `--{}` / `-{}` values: none, gpdf, tpdf, tpdf_hp",
|
|
||||||
DITHER, DITHER_SHORT
|
|
||||||
);
|
|
||||||
println!(
|
|
||||||
"Default: tpdf for formats S16, S24, S24_3 and none for other formats"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue