1
0
Fork 0

Simplify VST3 ProcessEvent::NoteEvent

This commit is contained in:
Robbert van der Helm 2023-01-31 21:55:26 +01:00
parent b35914bbbd
commit 0deb8ab1cd
2 changed files with 55 additions and 76 deletions

View file

@ -192,14 +192,11 @@ pub enum ProcessEvent<P: Plugin> {
/// An incoming parameter change sent by the host. This will only be used when sample accurate /// An incoming parameter change sent by the host. This will only be used when sample accurate
/// automation has been enabled, and the parameters are only updated when we process this /// automation has been enabled, and the parameters are only updated when we process this
/// spooled event at the start of a block. /// spooled event at the start of a block.
NoteEvent { ///
/// The event's sample offset within the buffer. Used for sorting. The timing stored within /// The timing stored within the note event needs to have the block start index subtraced from
/// the note event needs to have the block start index subtraced from it. /// it. make sure to subtract the block start index with [`NoteEvent::subtract_timing()`] before
timing: u32, /// putting this into the input event queue.
/// The actual note event, make sure to subtract the block start index with NoteEvent(PluginNoteEvent<P>),
/// [`NoteEvent::subtract_timing()`] before putting this into the input event queue.
event: PluginNoteEvent<P>,
},
} }
impl<P: Vst3Plugin> WrapperInner<P> { impl<P: Vst3Plugin> WrapperInner<P> {

View file

@ -1114,9 +1114,7 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
let midi_cc = (midi_param_relative_idx % VST3_MIDI_CCS) as u8; let midi_cc = (midi_param_relative_idx % VST3_MIDI_CCS) as u8;
let midi_channel = let midi_channel =
(midi_param_relative_idx / VST3_MIDI_CCS) as u8; (midi_param_relative_idx / VST3_MIDI_CCS) as u8;
process_events.push(ProcessEvent::NoteEvent { process_events.push(ProcessEvent::NoteEvent(match midi_cc {
timing,
event: match midi_cc {
// kAfterTouch // kAfterTouch
128 => NoteEvent::MidiChannelPressure { 128 => NoteEvent::MidiChannelPressure {
timing, timing,
@ -1135,8 +1133,7 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
cc: n, cc: n,
value, value,
}, },
}, }));
});
} else if P::SAMPLE_ACCURATE_AUTOMATION { } else if P::SAMPLE_ACCURATE_AUTOMATION {
process_events.push(ProcessEvent::ParameterChange { process_events.push(ProcessEvent::ParameterChange {
timing, timing,
@ -1177,9 +1174,7 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
// expression value events // expression value events
note_expression_controller.register_note(&event); note_expression_controller.register_note(&event);
process_events.push(ProcessEvent::NoteEvent { process_events.push(ProcessEvent::NoteEvent(NoteEvent::NoteOn {
timing,
event: NoteEvent::NoteOn {
timing, timing,
voice_id: if event.note_id != -1 { voice_id: if event.note_id != -1 {
Some(event.note_id) Some(event.note_id)
@ -1189,13 +1184,10 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
channel: event.channel as u8, channel: event.channel as u8,
note: event.pitch as u8, note: event.pitch as u8,
velocity: event.velocity, velocity: event.velocity,
}, }));
});
} else if event.type_ == EventTypes::kNoteOffEvent as u16 { } else if event.type_ == EventTypes::kNoteOffEvent as u16 {
let event = event.event.note_off; let event = event.event.note_off;
process_events.push(ProcessEvent::NoteEvent { process_events.push(ProcessEvent::NoteEvent(NoteEvent::NoteOff {
timing,
event: NoteEvent::NoteOff {
timing, timing,
voice_id: if event.note_id != -1 { voice_id: if event.note_id != -1 {
Some(event.note_id) Some(event.note_id)
@ -1205,13 +1197,10 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
channel: event.channel as u8, channel: event.channel as u8,
note: event.pitch as u8, note: event.pitch as u8,
velocity: event.velocity, velocity: event.velocity,
}, }));
});
} else if event.type_ == EventTypes::kPolyPressureEvent as u16 { } else if event.type_ == EventTypes::kPolyPressureEvent as u16 {
let event = event.event.poly_pressure; let event = event.event.poly_pressure;
process_events.push(ProcessEvent::NoteEvent { process_events.push(ProcessEvent::NoteEvent(NoteEvent::PolyPressure {
timing,
event: NoteEvent::PolyPressure {
timing, timing,
voice_id: if event.note_id != -1 { voice_id: if event.note_id != -1 {
Some(event.note_id) Some(event.note_id)
@ -1221,16 +1210,12 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
channel: event.channel as u8, channel: event.channel as u8,
note: event.pitch as u8, note: event.pitch as u8,
pressure: event.pressure, pressure: event.pressure,
}, }));
});
} else if event.type_ == EventTypes::kNoteExpressionValueEvent as u16 { } else if event.type_ == EventTypes::kNoteExpressionValueEvent as u16 {
let event = event.event.note_expression_value; let event = event.event.note_expression_value;
match note_expression_controller.translate_event(timing, &event) { match note_expression_controller.translate_event(timing, &event) {
Some(translated_event) => { Some(translated_event) => {
process_events.push(ProcessEvent::NoteEvent { process_events.push(ProcessEvent::NoteEvent(translated_event))
timing,
event: translated_event,
})
} }
None => nih_debug_assert_failure!( None => nih_debug_assert_failure!(
"Unhandled note expression type: {}", "Unhandled note expression type: {}",
@ -1248,10 +1233,7 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
std::slice::from_raw_parts(event.bytes, event.size as usize); std::slice::from_raw_parts(event.bytes, event.size as usize);
match NoteEvent::from_midi(timing, sysex_buffer) { match NoteEvent::from_midi(timing, sysex_buffer) {
Ok(note_event) => { Ok(note_event) => {
process_events.push(ProcessEvent::NoteEvent { process_events.push(ProcessEvent::NoteEvent(note_event));
timing,
event: note_event,
});
} }
Err(_) => { Err(_) => {
// `NoteEvent::from_midi` contains more detailed tracing // `NoteEvent::from_midi` contains more detailed tracing
@ -1273,7 +1255,7 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
permit_alloc(|| { permit_alloc(|| {
process_events.sort_by_key(|event| match event { process_events.sort_by_key(|event| match event {
ProcessEvent::ParameterChange { timing, .. } => *timing, ProcessEvent::ParameterChange { timing, .. } => *timing,
ProcessEvent::NoteEvent { timing, .. } => *timing, ProcessEvent::NoteEvent(event) => event.timing(),
}) })
}); });
@ -1315,7 +1297,7 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
Some(sample_rate), Some(sample_rate),
); );
} }
ProcessEvent::NoteEvent { timing: _, event } => { ProcessEvent::NoteEvent(event) => {
// We need to make sure to compensate the event for any block splitting, // We need to make sure to compensate the event for any block splitting,
// since we had to create the event object beforehand // since we had to create the event object beforehand
let mut event = event.clone(); let mut event = event.clone();