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
/// automation has been enabled, and the parameters are only updated when we process this
/// 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 note event needs to have the block start index subtraced from it.
timing: u32,
/// The actual note event, make sure to subtract the block start index with
/// [`NoteEvent::subtract_timing()`] before putting this into the input event queue.
event: PluginNoteEvent<P>,
},
///
/// The timing stored within the note event needs to have the block start index subtraced from
/// it. make sure to subtract the block start index with [`NoteEvent::subtract_timing()`] before
/// putting this into the input event queue.
NoteEvent(PluginNoteEvent<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_channel =
(midi_param_relative_idx / VST3_MIDI_CCS) as u8;
process_events.push(ProcessEvent::NoteEvent {
timing,
event: match midi_cc {
process_events.push(ProcessEvent::NoteEvent(match midi_cc {
// kAfterTouch
128 => NoteEvent::MidiChannelPressure {
timing,
@ -1135,8 +1133,7 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
cc: n,
value,
},
},
});
}));
} else if P::SAMPLE_ACCURATE_AUTOMATION {
process_events.push(ProcessEvent::ParameterChange {
timing,
@ -1177,9 +1174,7 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
// expression value events
note_expression_controller.register_note(&event);
process_events.push(ProcessEvent::NoteEvent {
timing,
event: NoteEvent::NoteOn {
process_events.push(ProcessEvent::NoteEvent(NoteEvent::NoteOn {
timing,
voice_id: if event.note_id != -1 {
Some(event.note_id)
@ -1189,13 +1184,10 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
channel: event.channel as u8,
note: event.pitch as u8,
velocity: event.velocity,
},
});
}));
} else if event.type_ == EventTypes::kNoteOffEvent as u16 {
let event = event.event.note_off;
process_events.push(ProcessEvent::NoteEvent {
timing,
event: NoteEvent::NoteOff {
process_events.push(ProcessEvent::NoteEvent(NoteEvent::NoteOff {
timing,
voice_id: if event.note_id != -1 {
Some(event.note_id)
@ -1205,13 +1197,10 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
channel: event.channel as u8,
note: event.pitch as u8,
velocity: event.velocity,
},
});
}));
} else if event.type_ == EventTypes::kPolyPressureEvent as u16 {
let event = event.event.poly_pressure;
process_events.push(ProcessEvent::NoteEvent {
timing,
event: NoteEvent::PolyPressure {
process_events.push(ProcessEvent::NoteEvent(NoteEvent::PolyPressure {
timing,
voice_id: if event.note_id != -1 {
Some(event.note_id)
@ -1221,16 +1210,12 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
channel: event.channel as u8,
note: event.pitch as u8,
pressure: event.pressure,
},
});
}));
} else if event.type_ == EventTypes::kNoteExpressionValueEvent as u16 {
let event = event.event.note_expression_value;
match note_expression_controller.translate_event(timing, &event) {
Some(translated_event) => {
process_events.push(ProcessEvent::NoteEvent {
timing,
event: translated_event,
})
process_events.push(ProcessEvent::NoteEvent(translated_event))
}
None => nih_debug_assert_failure!(
"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);
match NoteEvent::from_midi(timing, sysex_buffer) {
Ok(note_event) => {
process_events.push(ProcessEvent::NoteEvent {
timing,
event: note_event,
});
process_events.push(ProcessEvent::NoteEvent(note_event));
}
Err(_) => {
// `NoteEvent::from_midi` contains more detailed tracing
@ -1273,7 +1255,7 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
permit_alloc(|| {
process_events.sort_by_key(|event| match event {
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),
);
}
ProcessEvent::NoteEvent { timing: _, event } => {
ProcessEvent::NoteEvent(event) => {
// We need to make sure to compensate the event for any block splitting,
// since we had to create the event object beforehand
let mut event = event.clone();