diff --git a/src/lib.rs b/src/lib.rs index 452e1e3..8715c4d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -601,14 +601,8 @@ impl Plugin for Del2 { &mut self, _audio_io_layout: &AudioIOLayout, buffer_config: &BufferConfig, - context: &mut impl InitContext, + _context: &mut impl InitContext, ) -> bool { - println!( - "initialize taps: {}", - self.params - .current_tap - .load(std::sync::atomic::Ordering::SeqCst) - ); // Set the sample rate from the buffer configuration self.sample_rate = buffer_config.sample_rate; @@ -620,13 +614,6 @@ impl Plugin for Del2 { // Calculate and set the delay buffer size self.set_delay_buffer_size(buffer_config); - for tap_index in 0..self - .params - .current_tap - .load(std::sync::atomic::Ordering::SeqCst) - { - self.load_and_configure_tap(self.sample_rate, 0, 0, None, tap_index); - } // Initialize filter parameters for each tap self.initialize_filter_parameters(); @@ -634,18 +621,22 @@ impl Plugin for Del2 { } fn reset(&mut self) { - println!( - "reset taps: {}", - self.params - .current_tap - .load(std::sync::atomic::Ordering::SeqCst) - ); for tap in 0..NUM_TAPS { self.ladders[tap].s = [f32x4::splat(0.); 4]; self.amp_envelopes[tap].reset(0.0); } self.delay_taps.fill(None); + for tap_index in 0..self + .params + .current_tap + .load(std::sync::atomic::Ordering::SeqCst) + { + self.load_and_configure_tap(self.sample_rate, 0, None, tap_index); + } + + // Indicate filter update needed + self.should_update_filter.store(true, Ordering::Release); // Reset buffers and envelopes here. This can be called from the audio thread and may not // allocate. You can remove this function if you do not need it. } @@ -667,11 +658,6 @@ impl Plugin for Del2 { let mut block_start: usize = 0; let mut block_end: usize = MAX_BLOCK_SIZE.min(num_samples); - // for now, we assume one note or less per block - let mut live_timing = 0; - let mut live_channel = 0; - let mut live_voice_id = None; - // write the audio buffer into the delay self.write_into_delay(buffer); @@ -703,9 +689,25 @@ impl Plugin for Del2 { velocity, } => { self.store_note_on_in_delay_data(timing, note, velocity); - let live_timing = timing; - let live_channel = channel; - let live_voice_id = voice_id; + if self + .params + .current_tap + .load(std::sync::atomic::Ordering::SeqCst) + > old_nr_taps + { + let tap_index = self + .params + .current_tap + .load(std::sync::atomic::Ordering::SeqCst) + - 1; + self.load_and_configure_tap( + sample_rate, + // timing, + channel, + voice_id, + tap_index, + ); + } } NoteEvent::NoteOff { timing: _, @@ -715,15 +717,6 @@ impl Plugin for Del2 { velocity: _, } => { self.store_note_off_in_delay_data(note); - // if we are in instrument mode - // if !self.params.global.mute_is_toggle.value() { - // self.start_mute_for_delay_tap( - // sample_rate, - // voice_id, - // channel, - // note, - // ) - // } } NoteEvent::Choke { timing, @@ -843,26 +836,6 @@ impl Plugin for Del2 { } } } - - if self - .params - .current_tap - .load(std::sync::atomic::Ordering::SeqCst) - > old_nr_taps - { - let tap_index = self - .params - .current_tap - .load(std::sync::atomic::Ordering::SeqCst) - - 1; - self.load_and_configure_tap( - sample_rate, - live_timing, - live_channel, - live_voice_id, - tap_index, - ); - } self.prepare_for_delay(block_end - block_start); if self @@ -1260,25 +1233,18 @@ impl Del2 { &mut self, sample_rate: f32, // context: &mut (impl ProcessContext + nih_plug::prelude::ProcessContext), - timing: u32, + // timing: u32, channel: u8, voice_id: Option, tap_index: usize, ) { - // Determine tap index - println!("loading {tap_index} + 1 taps"); - println!( - "voice id: {:#?}, channel: {channel}, timing: {timing}", - voice_id - ); - // Load atomic values corresponding to the tap index let delay_time = self.params.delay_times[tap_index].load(Ordering::SeqCst); let note = self.params.notes[tap_index].load(Ordering::SeqCst); let velocity = self.params.velocities[tap_index].load(Ordering::SeqCst); // Create amplitude envelope - let mut amp_envelope = + let amp_envelope = Smoother::new(SmoothingStyle::Linear(self.params.global.attack_ms.value())); // Conditionally reset and configure the amplitude envelope @@ -1288,7 +1254,7 @@ impl Del2 { } // Start delay tap and configure its properties - let mut delay_tap = self.start_delay_tap(timing, channel, note); + let delay_tap = self.start_delay_tap(channel, note); delay_tap.velocity = velocity; delay_tap.amp_envelope = amp_envelope; delay_tap.tap_index = tap_index; @@ -1590,7 +1556,7 @@ impl Del2 { fn start_delay_tap( &mut self, // context: &mut impl ProcessContext, - sample_offset: u32, + // sample_offset: u32, channel: u8, note: u8, ) -> &mut DelayTap { @@ -1636,15 +1602,15 @@ impl Del2 { // The stolen delay tap needs to be terminated so the host can reuse its modulation // resources - { - let oldest_delay_tap = oldest_delay_tap.as_ref().unwrap(); - // context.send_event(NoteEvent::VoiceTerminated { - // timing: sample_offset, - // voice_id: Some(oldest_delay_tap.id), - // channel: oldest_delay_tap.channel, - // note: oldest_delay_tap.note, - // }); - } + // { + // let oldest_delay_tap = oldest_delay_tap.as_ref().unwrap(); + // context.send_event(NoteEvent::VoiceTerminated { + // timing: sample_offset, + // voice_id: Some(oldest_delay_tap.id), + // channel: oldest_delay_tap.channel, + // note: oldest_delay_tap.note, + // }); + // } *oldest_delay_tap = Some(new_delay_tap); oldest_delay_tap.as_mut().unwrap() @@ -1987,7 +1953,6 @@ impl PersistentField<'_, u8> for ArcAtomicBoolArray { f(&value) } } - struct AtomicU8Array([Arc; NUM_TAPS]); struct AtomicU32Array([Arc; NUM_TAPS]); struct AtomicF32Array([Arc; NUM_TAPS]); @@ -2059,6 +2024,14 @@ impl PersistentField<'_, [f32; 8]> for AtomicF32Array { } } +// TODO: use this: +// impl Index for AtomicArray { +// type Output = Arc; +// fn index(&self, index: usize) -> &Self::Output { +// &self.0[index] +// } +// } + // Implement the Index trait to allow for array-style access impl Index for AtomicU8Array { type Output = Arc;