mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Refactor main.rs
* Don't panic when parsing options. Instead list valid values and exit. * Get rid of needless .expect in playback/src/audio_backend/mod.rs. * Enforce reasonable ranges for option values (breaking). * Don't evaluate options that would otherwise have no effect. * Add pub const MIXERS to mixer/mod.rs very similar to the audio_backend's implementation. (non-breaking though) * Use different option descriptions and error messages based on what backends are enabled at build time. * Add a -q, --quiet option that changed the logging level to warn. * Add a short name for every flag and option. * Note removed options. * Other misc cleanups.
This commit is contained in:
parent
45b19efd03
commit
0e9fdbe6b4
6 changed files with 969 additions and 332 deletions
13
CHANGELOG.md
13
CHANGELOG.md
|
@ -7,11 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- [main] Enforce reasonable ranges for option values (breaking).
|
||||||
|
- [main] Don't evaluate options that would otherwise have no effect.
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- [cache] Add `disable-credential-cache` flag (breaking).
|
- [cache] Add `disable-credential-cache` flag (breaking).
|
||||||
|
- [main] Use different option descriptions and error messages based on what backends are enabled at build time.
|
||||||
|
- [main] Add a `-q`, `--quiet` option that changes the logging level to warn.
|
||||||
|
- [main] Add a short name for every flag and option.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- [main] Prevent hang when discovery is disabled and there are no credentials or when bad credentials are given.
|
- [main] Prevent hang when discovery is disabled and there are no credentials or when bad credentials are given.
|
||||||
|
- [main] Don't panic when parsing options. Instead list valid values and exit.
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
- [playback] `alsamixer`: previously deprecated option `mixer-card` has been removed.
|
||||||
|
- [playback] `alsamixer`: previously deprecated option `mixer-name` has been removed.
|
||||||
|
- [playback] `alsamixer`: previously deprecated option `mixer-index` has been removed.
|
||||||
|
|
||||||
## [0.3.1] - 2021-10-24
|
## [0.3.1] - 2021-10-24
|
||||||
|
|
||||||
|
|
|
@ -125,3 +125,15 @@ pub struct ConnectConfig {
|
||||||
pub has_volume_ctrl: bool,
|
pub has_volume_ctrl: bool,
|
||||||
pub autoplay: bool,
|
pub autoplay: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for ConnectConfig {
|
||||||
|
fn default() -> ConnectConfig {
|
||||||
|
ConnectConfig {
|
||||||
|
name: "Librespot".to_string(),
|
||||||
|
device_type: DeviceType::default(),
|
||||||
|
initial_volume: Some(50),
|
||||||
|
has_volume_ctrl: true,
|
||||||
|
autoplay: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -146,11 +146,6 @@ pub fn find(name: Option<String>) -> Option<SinkBuilder> {
|
||||||
.find(|backend| name == backend.0)
|
.find(|backend| name == backend.0)
|
||||||
.map(|backend| backend.1)
|
.map(|backend| backend.1)
|
||||||
} else {
|
} else {
|
||||||
Some(
|
BACKENDS.first().map(|backend| backend.1)
|
||||||
BACKENDS
|
|
||||||
.first()
|
|
||||||
.expect("No backends were enabled at build time")
|
|
||||||
.1,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ impl AudioFormat {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
pub enum NormalisationType {
|
pub enum NormalisationType {
|
||||||
Album,
|
Album,
|
||||||
Track,
|
Track,
|
||||||
|
@ -101,7 +101,7 @@ impl Default for NormalisationType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
pub enum NormalisationMethod {
|
pub enum NormalisationMethod {
|
||||||
Basic,
|
Basic,
|
||||||
Dynamic,
|
Dynamic,
|
||||||
|
|
|
@ -53,11 +53,19 @@ fn mk_sink<M: Mixer + 'static>(config: MixerConfig) -> Box<dyn Mixer> {
|
||||||
Box::new(M::open(config))
|
Box::new(M::open(config))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const MIXERS: &[(&str, MixerFn)] = &[
|
||||||
|
(SoftMixer::NAME, mk_sink::<SoftMixer>), // default goes first
|
||||||
|
#[cfg(feature = "alsa-backend")]
|
||||||
|
(AlsaMixer::NAME, mk_sink::<AlsaMixer>),
|
||||||
|
];
|
||||||
|
|
||||||
pub fn find(name: Option<&str>) -> Option<MixerFn> {
|
pub fn find(name: Option<&str>) -> Option<MixerFn> {
|
||||||
match name {
|
if let Some(name) = name {
|
||||||
None | Some(SoftMixer::NAME) => Some(mk_sink::<SoftMixer>),
|
MIXERS
|
||||||
#[cfg(feature = "alsa-backend")]
|
.iter()
|
||||||
Some(AlsaMixer::NAME) => Some(mk_sink::<AlsaMixer>),
|
.find(|mixer| name == mixer.0)
|
||||||
_ => None,
|
.map(|mixer| mixer.1)
|
||||||
|
} else {
|
||||||
|
MIXERS.first().map(|mixer| mixer.1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
1247
src/main.rs
1247
src/main.rs
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue