diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 0798944..035244c 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -34,6 +34,10 @@ jobs: run: cargo +nightly-2022-02-16 bench --verbose --features=bench --no-run - name: Build examples run: cargo build --examples --verbose --features=serde + - name: Lint + run: cargo clippy --examples --features=serde -- -D warnings + - name: Check format + run: cargo fmt -- --check build-test-lint-windows: name: Windows - build, test and lint @@ -65,14 +69,10 @@ jobs: override: true components: rustfmt, clippy - name: Build - run: | - cargo build --examples + run: cargo build --examples - name: Test - run: | - cargo test --examples + run: cargo test --examples --features=serde - name: Lint - run: | - cargo clippy --examples -- -D warnings + run: cargo clippy --examples --features=serde -- -D warnings - name: Check format - run: | - cargo fmt -- --check + run: cargo fmt -- --check diff --git a/examples/playlist.rs b/examples/playlist.rs index 99e009f..7b81d59 100644 --- a/examples/playlist.rs +++ b/examples/playlist.rs @@ -1,13 +1,20 @@ +#[cfg(feature = "serde")] use anyhow::Result; +#[cfg(feature = "serde")] use bliss_audio::distance::{closest_to_first_song, dedup_playlist, euclidean_distance}; +#[cfg(feature = "serde")] use bliss_audio::{library::analyze_paths_streaming, Song}; +#[cfg(feature = "serde")] use clap::{App, Arg}; +#[cfg(feature = "serde")] use glob::glob; -use mime_guess; -use serde_json; +#[cfg(feature = "serde")] use std::env; +#[cfg(feature = "serde")] use std::fs; +#[cfg(feature = "serde")] use std::io::BufReader; +#[cfg(feature = "serde")] use std::path::{Path, PathBuf}; /* Analyzes a folder recursively, and make a playlist out of the file diff --git a/src/chroma.rs b/src/chroma.rs index 75bf619..7ca6ce3 100644 --- a/src/chroma.rs +++ b/src/chroma.rs @@ -207,13 +207,13 @@ fn chroma_filter( wts *= &freq_bins; // np.roll(), np bro - let mut uninit: Vec = Vec::with_capacity((&wts).len()); + let mut uninit: Vec = vec![0.; (&wts).len()]; unsafe { uninit.set_len(wts.len()); } let mut b = Array::from(uninit) .into_shape(wts.dim()) - .map_err(|e| BlissError::AnalysisError(format!("in chroma: {}", e.to_string())))?; + .map_err(|e| BlissError::AnalysisError(format!("in chroma: {}", e)))?; b.slice_mut(s![-3.., ..]).assign(&wts.slice(s![..3, ..])); b.slice_mut(s![..-3, ..]).assign(&wts.slice(s![3.., ..])); @@ -308,7 +308,7 @@ fn pitch_tuning( } let max_index = counts .argmax() - .map_err(|e| BlissError::AnalysisError(format!("in chroma: {}", e.to_string())))?; + .map_err(|e| BlissError::AnalysisError(format!("in chroma: {}", e)))?; // Return the bin with the most reoccuring frequency. Ok((-50. + (100. * resolution * max_index as f64)) / 100.) @@ -332,7 +332,7 @@ fn estimate_tuning( let threshold: N64 = Array::from(filtered_mag.to_vec()) .quantile_axis_mut(Axis(0), n64(0.5), &Midpoint) - .map_err(|e| BlissError::AnalysisError(format!("in chroma: {}", e.to_string())))? + .map_err(|e| BlissError::AnalysisError(format!("in chroma: {}", e)))? .into_scalar(); let mut pitch = filtered_pitch diff --git a/src/temporal.rs b/src/temporal.rs index d054508..3c10866 100644 --- a/src/temporal.rs +++ b/src/temporal.rs @@ -48,10 +48,7 @@ impl BPMDesc { sample_rate, ) .map_err(|e| { - BlissError::AnalysisError(format!( - "error while loading aubio tempo object: {}", - e.to_string() - )) + BlissError::AnalysisError(format!("error while loading aubio tempo object: {}", e)) })?, bpms: Vec::new(), }) @@ -59,10 +56,7 @@ impl BPMDesc { pub fn do_(&mut self, chunk: &[f32]) -> BlissResult<()> { let result = self.aubio_obj.do_result(chunk).map_err(|e| { - BlissError::AnalysisError(format!( - "aubio error while computing tempo {}", - e.to_string() - )) + BlissError::AnalysisError(format!("aubio error while computing tempo {}", e)) })?; if result > 0. { diff --git a/src/timbral.rs b/src/timbral.rs index 2624207..a8ed6e2 100644 --- a/src/timbral.rs +++ b/src/timbral.rs @@ -126,21 +126,21 @@ impl SpectralDesc { .map_err(|e| { BlissError::AnalysisError(format!( "error while loading aubio centroid object: {}", - e.to_string() + e )) })?, rolloff_aubio_desc: SpecDesc::new(SpecShape::Rolloff, SpectralDesc::WINDOW_SIZE) .map_err(|e| { BlissError::AnalysisError(format!( "error while loading aubio rolloff object: {}", - e.to_string() + e )) })?, phase_vocoder: PVoc::new(SpectralDesc::WINDOW_SIZE, SpectralDesc::HOP_SIZE).map_err( |e| { BlissError::AnalysisError(format!( "error while loading aubio pvoc object: {}", - e.to_string() + e )) }, )?, @@ -163,10 +163,7 @@ impl SpectralDesc { self.phase_vocoder .do_(chunk, fftgrain.as_mut_slice()) .map_err(|e| { - BlissError::AnalysisError(format!( - "error while processing aubio pv object: {}", - e.to_string() - )) + BlissError::AnalysisError(format!("error while processing aubio pv object: {}", e)) })?; let bin = self @@ -175,7 +172,7 @@ impl SpectralDesc { .map_err(|e| { BlissError::AnalysisError(format!( "error while processing aubio centroid object: {}", - e.to_string() + e )) })?;