diff --git a/src/plugin.rs b/src/plugin.rs index 4d69edba..d9e0ce86 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -157,9 +157,21 @@ pub enum ProcessStatus { /// Event for (incoming) notes. Right now this only supports a very small subset of the MIDI /// specification. /// +/// All of the timings are sample offsets withing the current buffer. +/// /// TODO: Add more events as needed #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum NoteEvent { - NoteOn { channel: u8, note: u8, velocity: u8 }, - NoteOff { channel: u8, note: u8, velocity: u8 }, + NoteOn { + timing: u32, + channel: u8, + note: u8, + velocity: u8, + }, + NoteOff { + timing: u32, + channel: u8, + note: u8, + velocity: u8, + }, } diff --git a/src/wrapper/vst3.rs b/src/wrapper/vst3.rs index 4660be6d..b387d3ab 100644 --- a/src/wrapper/vst3.rs +++ b/src/wrapper/vst3.rs @@ -1055,9 +1055,11 @@ impl IAudioProcessor for Wrapper<'_, P> { for i in 0..num_events { nih_debug_assert_eq!(events.get_event(i, event.as_mut_ptr()), kResultOk); let event = event.assume_init(); + let timing = event.sample_offset as u32; if event.type_ == vst3_sys::vst::EventTypes::kNoteOnEvent as u16 { let event = event.event.note_on; input_events.push_back(NoteEvent::NoteOn { + timing, channel: event.channel as u8, note: event.pitch as u8, velocity: (event.velocity * 127.0).round() as u8, @@ -1065,6 +1067,7 @@ impl IAudioProcessor for Wrapper<'_, P> { } else if event.type_ == vst3_sys::vst::EventTypes::kNoteOffEvent as u16 { let event = event.event.note_off; input_events.push_back(NoteEvent::NoteOff { + timing, channel: event.channel as u8, note: event.pitch as u8, velocity: (event.velocity * 127.0).round() as u8,