From b562364ae831d84ce9a4a1f88f2e3d0cf0057d9e Mon Sep 17 00:00:00 2001 From: Bart Brouns Date: Fri, 22 Nov 2024 08:32:20 +0100 Subject: [PATCH] fix tap-management --- src/delay_tap.rs | 5 ----- src/lib.rs | 40 +++++++++++++++++++--------------------- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/delay_tap.rs b/src/delay_tap.rs index d188698..15b8bbe 100644 --- a/src/delay_tap.rs +++ b/src/delay_tap.rs @@ -35,8 +35,6 @@ pub struct DelayTap { /// Is set to true when the tap is created and false is created /// and false when the amplitude envelope hits 0 while the note is releasing. pub is_alive: bool, - /// Only used for indexing into tap_meters - pub meter_index: usize, } impl DelayTap { @@ -55,7 +53,6 @@ impl DelayTap { releasing: false, is_muted: true, is_alive: false, - meter_index: 0, } } @@ -66,7 +63,6 @@ impl DelayTap { delay_time: u32, note: u8, velocity: f32, - index: usize, new_is_alive: bool, ) { self.amp_envelope = amp_envelope; @@ -76,6 +72,5 @@ impl DelayTap { self.velocity = velocity; self.releasing = false; self.is_alive = new_is_alive; - // self.meter_index = index; } } diff --git a/src/lib.rs b/src/lib.rs index e5fe527..614777f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -624,29 +624,24 @@ impl Plugin for Del2 { fn reset(&mut self) { let tap_counter = self.params.tap_counter.load(Ordering::SeqCst); - self.delay_taps - .iter_mut() - .enumerate() - .for_each(|(tap_index, delay_tap)| { - // delay_tap.meter_index = tap_index; - // first make room in the array - if tap_counter > tap_index { - delay_tap.is_alive = true; - } else { - delay_tap.is_alive = false; - } - delay_tap.releasing = false; - delay_tap.ladders.s = [f32x4::splat(0.); 4]; - }); + self.delay_taps.iter_mut().for_each(|delay_tap| { + // first make room in the array + delay_tap.is_alive = false; + delay_tap.amp_envelope.reset(0.0); + // delay_tap.releasing = true; + delay_tap.ladders.s = [f32x4::splat(0.); 4]; + }); // then fill the array - for i in 0..NUM_TAPS { - if i < tap_counter { - self.start_tap(i, true); - } else { - self.start_tap(i, false); + for tap_index in 0..NUM_TAPS { + if tap_index < tap_counter { + self.start_tap(tap_index, true); } } + self.counting_state = CountingState::TimeOut; + self.timing_last_event = 0; + self.samples_since_last_event = 0; + // Indicate filter update needed self.should_update_filter.store(true, Ordering::Release); // reset learning system @@ -721,6 +716,7 @@ impl Plugin for Del2 { self.store_note_on_in_delay_data(timing, note, velocity); let tap_counter = self.params.tap_counter.load(Ordering::SeqCst); if tap_counter > old_nr_taps { + // nih_log!("process: added a tap: {} > {old_nr_taps}", tap_counter); self.start_tap(tap_counter - 1, true); } } @@ -1414,18 +1410,19 @@ impl Del2 { if let Some(delay_tap) = found_inactive { // Initialize the non-active tap + // nih_log!("start_tap: inactive tap: {}", found_inactive_index.unwrap()); delay_tap.init( amp_envelope, self.next_internal_id, delay_time, note, velocity, - new_index, new_is_alive, ); self.next_internal_id = self.next_internal_id.wrapping_add(1); self.meter_indexes[new_index].store(found_inactive_index.unwrap(), Ordering::Relaxed); } else if let Some(oldest_delay_tap) = found_oldest { + // nih_log!("start_tap: oldest tap: {}", found_oldest_index.unwrap()); // Replace the oldest tap if needed oldest_delay_tap.init( amp_envelope, @@ -1433,7 +1430,6 @@ impl Del2 { delay_time, note, velocity, - new_index, new_is_alive, ); self.next_internal_id = self.next_internal_id.wrapping_add(1); @@ -1472,6 +1468,8 @@ impl Del2 { }; let muted = new_mute || !delay_tap.is_alive; let needs_toggle = delay_tap.is_muted != muted; + + // nih_log!("delay_tap.is_alive: {}, {tap_index}", delay_tap.is_alive); if needs_toggle { if muted { delay_tap.amp_envelope.style =