From c0a72661e1dc1efb4d6281a619fe264e37314efc Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sun, 3 Sep 2023 16:35:57 +0200 Subject: [PATCH] Fix new Clippy lints --- nih_plug_egui/src/widgets/param_slider.rs | 2 +- nih_plug_iced/src/lib.rs | 4 +++- nih_plug_vizia/src/widgets/param_base.rs | 2 +- .../src/compressor_bank.rs | 6 ++--- plugins/spectral_compressor/src/lib.rs | 4 ++-- src/wrapper/clap/wrapper.rs | 24 ++++++++++++++++++- 6 files changed, 33 insertions(+), 9 deletions(-) diff --git a/nih_plug_egui/src/widgets/param_slider.rs b/nih_plug_egui/src/widgets/param_slider.rs index 7d003e5c..cbae9310 100644 --- a/nih_plug_egui/src/widgets/param_slider.rs +++ b/nih_plug_egui/src/widgets/param_slider.rs @@ -173,7 +173,7 @@ impl<'a, P: Param> ParamSlider<'a, P> { ui.memory_mut(|mem| mem.data.insert_temp(*DRAG_AMOUNT_MEMORY_ID, amount)); } - fn slider_ui(&self, ui: &mut Ui, response: &mut Response) { + fn slider_ui(&self, ui: &Ui, response: &mut Response) { // Handle user input // TODO: Optionally (since it can be annoying) add scrolling behind a builder option if response.drag_started() { diff --git a/nih_plug_iced/src/lib.rs b/nih_plug_iced/src/lib.rs index e629d4f2..a8ae536b 100644 --- a/nih_plug_iced/src/lib.rs +++ b/nih_plug_iced/src/lib.rs @@ -95,7 +95,9 @@ use crossbeam::channel; use nih_plug::params::persist::PersistentField; use nih_plug::prelude::{Editor, GuiContext}; use serde::{Deserialize, Serialize}; -use std::fmt::Debug; +// This doesn't need to be re-export but otherwise the compiler complains about +// `hidden_glob_reexports` +pub use std::fmt::Debug; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; diff --git a/nih_plug_vizia/src/widgets/param_base.rs b/nih_plug_vizia/src/widgets/param_base.rs index 0b73ad11..7eef61d0 100644 --- a/nih_plug_vizia/src/widgets/param_base.rs +++ b/nih_plug_vizia/src/widgets/param_base.rs @@ -98,7 +98,7 @@ impl ParamWidgetBase { /// `Params` object to the parameter you want to display a widget for. Parameter changes are /// handled by emitting [`ParamEvent`][super::ParamEvent]s which are automatically handled by /// the VIZIA wrapper. - pub fn new(cx: &mut Context, params: L, params_to_param: FMap) -> Self + pub fn new(cx: &Context, params: L, params_to_param: FMap) -> Self where L: Lens + Clone, Params: 'static, diff --git a/plugins/spectral_compressor/src/compressor_bank.rs b/plugins/spectral_compressor/src/compressor_bank.rs index 3aeea248..9e097434 100644 --- a/plugins/spectral_compressor/src/compressor_bank.rs +++ b/plugins/spectral_compressor/src/compressor_bank.rs @@ -675,7 +675,7 @@ impl CompressorBank { /// Set the sidechain frequency spectrum magnitudes just before a [`process()`][Self::process()] /// call. These will be multiplied with the existing compressor thresholds and knee values to /// get the effective values for use with sidechaining. - pub fn process_sidechain(&mut self, sc_buffer: &mut [Complex32], channel_idx: usize) { + pub fn process_sidechain(&mut self, sc_buffer: &[Complex32], channel_idx: usize) { nih_debug_assert_eq!(sc_buffer.len(), self.ln_freqs.len()); self.update_sidechain_spectra(sc_buffer, channel_idx); @@ -684,7 +684,7 @@ impl CompressorBank { /// Update the envelope followers based on the bin magnitudes. fn update_envelopes( &mut self, - buffer: &mut [Complex32], + buffer: &[Complex32], channel_idx: usize, params: &SpectralCompressorParams, overlap_times: usize, @@ -815,7 +815,7 @@ impl CompressorBank { } /// Update the spectral data using the sidechain input - fn update_sidechain_spectra(&mut self, sc_buffer: &mut [Complex32], channel_idx: usize) { + fn update_sidechain_spectra(&mut self, sc_buffer: &[Complex32], channel_idx: usize) { nih_debug_assert!(channel_idx < self.sidechain_spectrum_magnitudes.len()); for (bin, magnitude) in sc_buffer diff --git a/plugins/spectral_compressor/src/lib.rs b/plugins/spectral_compressor/src/lib.rs index b5e81b50..4a8ea593 100644 --- a/plugins/spectral_compressor/src/lib.rs +++ b/plugins/spectral_compressor/src/lib.rs @@ -547,7 +547,7 @@ fn process_stft_main( channel_idx: usize, real_fft_buffer: &mut [f32], complex_fft_buffer: &mut [Complex32], - fft_plan: &mut Plan, + fft_plan: &Plan, window_function: &[f32], params: &SpectralCompressorParams, compressor_bank: &mut compressor_bank::CompressorBank, @@ -601,7 +601,7 @@ fn process_stft_sidechain( channel_idx: usize, real_fft_buffer: &mut [f32], complex_fft_buffer: &mut [Complex32], - fft_plan: &mut Plan, + fft_plan: &Plan, window_function: &[f32], compressor_bank: &mut compressor_bank::CompressorBank, input_gain: f32, diff --git a/src/wrapper/clap/wrapper.rs b/src/wrapper/clap/wrapper.rs index 77b33c23..81b56a64 100644 --- a/src/wrapper/clap/wrapper.rs +++ b/src/wrapper/clap/wrapper.rs @@ -425,7 +425,10 @@ impl MainThreadExecutor> for Wrapper

{ } impl Wrapper

{ - pub fn new(host_callback: *const clap_host) -> Arc { + /// # Safety + /// + /// `host_callback` needs to outlive the returned object. + pub unsafe fn new(host_callback: *const clap_host) -> Arc { let mut plugin = P::default(); let task_executor = Mutex::new(plugin.task_executor()); @@ -878,6 +881,11 @@ impl Wrapper

{ } /// Handle all incoming events from an event queue. This will clear `self.input_events` first. + /// + /// # Safety + /// + /// `in_` must contain only pointers to valid data (Clippy insists on there being a safety + /// section here). pub unsafe fn handle_in_events( &self, in_: &clap_input_events, @@ -909,6 +917,11 @@ impl Wrapper

{ /// `(sample_idx, event_idx)` tuple. This allows for splitting the audio buffer into segments /// with distinct sample values to enable sample accurate automation without modifications to the /// wrapped plugin. + /// + /// # Safety + /// + /// `in_` must contain only pointers to valid data (Clippy insists on there being a safety + /// section here). pub unsafe fn handle_in_events_until( &self, in_: &clap_input_events, @@ -966,6 +979,10 @@ impl Wrapper

{ /// plugin is not actually processing audio. /// /// The `total_buffer_len` argument is used to clamp out of bounds events to the buffer's length. + /// + /// # Safety + /// + /// `out` must be a valid object (Clippy insists on there being a safety section here). pub unsafe fn handle_out_events( &self, out: &clap_output_events, @@ -1374,6 +1391,11 @@ impl Wrapper

{ /// /// If the event was a transport event and the `transport_info` argument is not `None`, then the /// pointer will be changed to point to the transport information from this event. + /// + /// # Safety + /// + /// `in_` must contain only pointers to valid data (Clippy insists on there being a safety + /// section here). pub unsafe fn handle_in_event( &self, event: *const clap_event_header,