diff --git a/src/engine.rs b/src/engine.rs index 85e224a..2b67633 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -476,11 +476,13 @@ mod tests { fn test_engine_get_clip_reuses_existing() { let mut engine = test_engine(); - let clip1 = engine.get_clip(60); - let clip2 = engine.get_clip(60); + // Get the clip once + engine.get_clip(60); - // Both should point to the same clip - assert_eq!(clip1 as *const _, clip2 as *const _); + // Get it again - should reuse the same clip + let clip = engine.get_clip(60); + + assert_eq!(clip.state, ClipState::Empty); assert_eq!(engine.clips.len(), 1); } diff --git a/src/lib.rs b/src/lib.rs index 7998e32..90a8d27 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,14 +1,14 @@ use nih_plug::prelude::*; mod engine; -use engine::{Engine, ClipState}; +use engine::Engine; /// The main plugin struct pub struct ClipLauncher { /// The engine managing clips engine: Engine, /// Pending MIDI output events - pending_midi: Vec, + pending_midi: Vec>, } impl Default for ClipLauncher { @@ -50,7 +50,7 @@ impl Plugin for ClipLauncher { _context: &mut impl InitContext, ) -> bool { self.engine = Engine::new( - _audio_io_layout.main_input_channels.map(|c| c.get()).unwrap_or(2), + _audio_io_layout.main_input_channels.map(|c| c.get() as usize).unwrap_or(2), buffer_config.sample_rate, ); true @@ -71,23 +71,25 @@ impl Plugin for ClipLauncher { // Process MIDI input events while let Some(event) = context.next_event() { match event { - NoteEvent::NoteOn { timing, note, velocity, channel } => { - let output_velocity = self.engine.process_midi_note(note, velocity, true); + NoteEvent::NoteOn { timing, note, velocity, channel, voice_id } => { + let output_velocity = self.engine.process_midi_note(note, velocity as u8, true); // Queue output MIDI event self.pending_midi.push(NoteEvent::NoteOn { timing, note, - velocity: output_velocity, + velocity: output_velocity as f32, channel, + voice_id, }); } - NoteEvent::NoteOff { timing, note, velocity, channel } => { - let output_velocity = self.engine.process_midi_note(note, velocity, false); + NoteEvent::NoteOff { timing, note, velocity, channel, voice_id } => { + let output_velocity = self.engine.process_midi_note(note, velocity as u8, false); self.pending_midi.push(NoteEvent::NoteOff { timing, note, - velocity: output_velocity, + velocity: output_velocity as f32, channel, + voice_id, }); } _ => {} @@ -96,7 +98,7 @@ impl Plugin for ClipLauncher { // Process audio for channel_samples in buffer.iter_samples() { - let (input, mut output) = channel_samples; + let (input, mut output) = channel_samples.split(); let num_samples = input.len(); // Process this block @@ -118,11 +120,17 @@ impl Plugin for ClipLauncher { /// Empty params struct (no parameters needed for this plugin) #[derive(Params)] -struct ClipLauncherParams; +struct ClipLauncherParams { + /// Placeholder parameter to satisfy the derive macro + #[id = "dummy"] + dummy: BoolParam, +} impl Default for ClipLauncherParams { fn default() -> Self { - Self + Self { + dummy: BoolParam::new("Dummy", false), + } } }