Skip to content

Commit

Permalink
fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelLieb committed Mar 3, 2024
1 parent 309d3dd commit fbbabd5
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 51 deletions.
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async fn main() {
if let Some(e) = e.source() {
debug!("{}", e);
}
panic!("Couldn't initialize Lightservices");
return;
}
};

Expand All @@ -61,7 +61,7 @@ async fn main() {
}
}
};
panic!("Audio stream couldn't be build");
return;
}
};

Expand Down
9 changes: 4 additions & 5 deletions src/utils/audiodevices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ pub fn create_monitor_stream(
onset_detector: impl OnsetDetector + Send + 'static,
lightservices: Vec<Box<dyn LightService + Send>>,
) -> Result<cpal::Stream, BuildStreamError> {
let device_name = if device_name == "" {
let device_name = if device_name.is_empty() {
cpal::default_host()
.default_output_device()
.ok_or_else(|| BuildStreamError::DeviceNotAvailable)?
.ok_or(BuildStreamError::DeviceNotAvailable)?
.name()
.map_err(|_| BuildStreamError::DeviceNotAvailable)?
} else {
Expand All @@ -32,9 +32,8 @@ pub fn create_monitor_stream(
let out = cpal::default_host()
.devices()
.map_err(|_| BuildStreamError::DeviceNotAvailable)?
.filter(|d| d.name().unwrap_or_default() == device_name)
.next()
.ok_or_else(|| BuildStreamError::DeviceNotAvailable)?;
.find(|d| d.name().unwrap_or_default() == device_name)
.ok_or(BuildStreamError::DeviceNotAvailable)?;

let audio_cfg = out
.default_output_config()
Expand Down
4 changes: 1 addition & 3 deletions src/utils/audioprocessing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,8 @@ impl MelFilterBank {
.enumerate()
.for_each(|(m, (band, x))| {
let start = (self.points[m] / bin_res) as usize;
let sum = freq_bins
let sum = freq_bins[start..(start + band.len())]
.iter()
.skip(start)
.take(band.len())
.zip(band)
.map(|(&f, &w)| f * w)
.sum::<f32>();
Expand Down
48 changes: 25 additions & 23 deletions src/utils/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl Default for Config {

impl Config {
pub fn load(file: &str) -> Result<Self, ConfigError> {
if file.split_terminator(".").last() != Some("toml") {
if file.split_terminator('.').last() != Some("toml") {
return Err(ConfigError::FileFormat);
}

Expand All @@ -141,7 +141,7 @@ impl Config {
let mut lightservices: Vec<Box<dyn LightService + Send>> = Vec::new();

if let Some(path) = &self.serialize_onsets {
let path = if path == "" { "onsets.cbor" } else { path };
let path = if path.is_empty() { "onsets.cbor" } else { path };
let serializer = serialize::OnsetContainer::init(
path,
self.audio_processing.sample_rate as usize,
Expand Down Expand Up @@ -184,32 +184,34 @@ impl Config {
pub fn initialize_onset_detector(
&self,
) -> Box<dyn audioprocessing::OnsetDetector + Send + 'static> {
let detector: Box<dyn audioprocessing::OnsetDetector + Send + 'static>;
match self.onset_detector {
OnsetDetector::SpecFlux(settings) => {
let alg = SpecFlux::with_settings(
self.audio_processing.sample_rate,
self.audio_processing.fft_size as u32,
settings,
);
detector = Box::new(alg);
}
OnsetDetector::HFC(settings) => {
let alg = Hfc::with_settings(
self.audio_processing.sample_rate as usize,
self.audio_processing.fft_size,
settings,
);
detector = Box::new(alg);
}
};
let detector: Box<dyn audioprocessing::OnsetDetector + Send + 'static> =
match self.onset_detector {
OnsetDetector::SpecFlux(settings) => {
let alg = SpecFlux::with_settings(
self.audio_processing.sample_rate,
self.audio_processing.fft_size as u32,
settings,
);
Box::new(alg)
}
OnsetDetector::HFC(settings) => {
let alg = Hfc::with_settings(
self.audio_processing.sample_rate as usize,
self.audio_processing.fft_size,
settings,
);
Box::new(alg)
}
};
detector
}

#[allow(dead_code)]
pub fn generate_template(file_path: &str) {
let mut template = Config::default();
template.onset_detector = OnsetDetector::SpecFlux(Default::default());
let mut template = Config{
onset_detector: OnsetDetector::SpecFlux(Default::default()),
..Default::default()
};
template.wled.push(WLEDConfig::Spectrum {
ip: "Ip of Strip".to_owned(),
settings: Default::default(),
Expand Down
19 changes: 5 additions & 14 deletions src/utils/lights/hue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,7 @@ impl BridgeManager {
let mut found_bridges = self.filter_reachable(&saved_bridges).await;

if let Some(ip) = ip {
found_bridges = found_bridges
.into_iter()
.filter(|bridge| bridge.ip == ip)
.collect();
found_bridges.retain(|bridge| bridge.ip == ip);
} else if found_bridges.len() > 1 {
warn!("Multiple bridges found");
for bridge in found_bridges.iter().rev() {
Expand All @@ -323,10 +320,7 @@ impl BridgeManager {

let mut new_bridges = self.search_bridges().await?;
if let Some(ip) = ip {
new_bridges = new_bridges
.into_iter()
.filter(|bridge| bridge.ip == ip)
.collect();
new_bridges.retain(|bridge| bridge.ip == ip);
} else if new_bridges.len() > 1 {
warn!("Multiple bridges found");
for bridge in new_bridges.iter().rev() {
Expand Down Expand Up @@ -380,7 +374,7 @@ impl BridgeManager {

let mut saved_bridge = BridgeData {
id: config.id,
ip: ip,
ip,
app_key: String::new(),
app_id: String::new(),
psk: String::new(),
Expand Down Expand Up @@ -491,10 +485,7 @@ impl BridgeManager {
let mut areas = self.get_entertainment_areas(&bridge).await?;

if let Some(area) = area {
areas = areas
.into_iter()
.filter(|ent_area| ent_area.id == area)
.collect();
areas.retain(|ent_area| ent_area.id == area);
} else if areas.len() > 1 {
warn!("Multiple areas found");
for area in areas.iter().rev() {
Expand Down Expand Up @@ -723,7 +714,7 @@ impl State {
prefix.put(area.id.as_bytes());

let channels: Vec<_> = area.channels.iter().map(|chan| chan.channel_id).collect();
let buffer_size = &prefix.len() + 7 * channels.clone().len();
let buffer_size = prefix.len() + 7 * channels.clone().len();
State {
drum: envelope::DynamicDecay::init(settings.drum_decay_rate),
hihat: envelope::FixedDecay::init(settings.hihat_decay),
Expand Down
2 changes: 1 addition & 1 deletion src/utils/lights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl Drop for PollingHelper {
}
}
Err(_) => {
if let Ok(_) = self.tx.blocking_send(()) {
if self.tx.blocking_send(()).is_ok() {
while !self.handle.is_finished() {
sleep(std::time::Duration::from_millis(10));
}
Expand Down
6 changes: 3 additions & 3 deletions src/utils/lights/wled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ impl Pollable for OnsetState {

bytes.put_slice(&self.prefix);

let red = self.drum_envelope.get_value() as f32 * self.led_count as f32 * 0.5;
let blue = self.note_envelope.get_value() as f32 * self.led_count as f32 * 0.5;
let white = self.hihat_envelope.get_value() as f32 * self.led_count as f32 * 0.2;
let red = self.drum_envelope.get_value() * self.led_count as f32 * 0.5;
let blue = self.note_envelope.get_value() * self.led_count as f32 * 0.5;
let white = self.hihat_envelope.get_value() * self.led_count as f32 * 0.2;

let mut colors: Vec<Vec<u8>> = if self.rgbw {
vec![vec![0, 0, 0, 0]; self.led_count as usize / 2]
Expand Down

0 comments on commit fbbabd5

Please sign in to comment.