1
0
Fork 0

Store timing along with the note events

This commit is contained in:
Robbert van der Helm 2022-02-04 01:50:48 +01:00
parent 02cf16e9c0
commit 0e67c61be0
2 changed files with 17 additions and 2 deletions

View file

@ -157,9 +157,21 @@ pub enum ProcessStatus {
/// Event for (incoming) notes. Right now this only supports a very small subset of the MIDI /// Event for (incoming) notes. Right now this only supports a very small subset of the MIDI
/// specification. /// specification.
/// ///
/// All of the timings are sample offsets withing the current buffer.
///
/// TODO: Add more events as needed /// TODO: Add more events as needed
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum NoteEvent { pub enum NoteEvent {
NoteOn { channel: u8, note: u8, velocity: u8 }, NoteOn {
NoteOff { channel: u8, note: u8, velocity: u8 }, timing: u32,
channel: u8,
note: u8,
velocity: u8,
},
NoteOff {
timing: u32,
channel: u8,
note: u8,
velocity: u8,
},
} }

View file

@ -1055,9 +1055,11 @@ impl<P: Plugin> IAudioProcessor for Wrapper<'_, P> {
for i in 0..num_events { for i in 0..num_events {
nih_debug_assert_eq!(events.get_event(i, event.as_mut_ptr()), kResultOk); nih_debug_assert_eq!(events.get_event(i, event.as_mut_ptr()), kResultOk);
let event = event.assume_init(); let event = event.assume_init();
let timing = event.sample_offset as u32;
if event.type_ == vst3_sys::vst::EventTypes::kNoteOnEvent as u16 { if event.type_ == vst3_sys::vst::EventTypes::kNoteOnEvent as u16 {
let event = event.event.note_on; let event = event.event.note_on;
input_events.push_back(NoteEvent::NoteOn { input_events.push_back(NoteEvent::NoteOn {
timing,
channel: event.channel as u8, channel: event.channel as u8,
note: event.pitch as u8, note: event.pitch as u8,
velocity: (event.velocity * 127.0).round() as u8, velocity: (event.velocity * 127.0).round() as u8,
@ -1065,6 +1067,7 @@ impl<P: Plugin> IAudioProcessor for Wrapper<'_, P> {
} else if event.type_ == vst3_sys::vst::EventTypes::kNoteOffEvent as u16 { } else if event.type_ == vst3_sys::vst::EventTypes::kNoteOffEvent as u16 {
let event = event.event.note_off; let event = event.event.note_off;
input_events.push_back(NoteEvent::NoteOff { input_events.push_back(NoteEvent::NoteOff {
timing,
channel: event.channel as u8, channel: event.channel as u8,
note: event.pitch as u8, note: event.pitch as u8,
velocity: (event.velocity * 127.0).round() as u8, velocity: (event.velocity * 127.0).round() as u8,