From 1bbb56151d31e722d573151e3d9e4de20a1cc2f5 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Mon, 4 Jul 2022 22:43:48 +0200 Subject: [PATCH] Remove duplication in CLAP note timing handling --- src/wrapper/clap/wrapper.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/wrapper/clap/wrapper.rs b/src/wrapper/clap/wrapper.rs index 55cdac84..bb208b7b 100644 --- a/src/wrapper/clap/wrapper.rs +++ b/src/wrapper/clap/wrapper.rs @@ -1261,6 +1261,8 @@ impl Wrapper

{ current_sample_idx: usize, ) -> bool { let raw_event = &*event; + let timing = raw_event.time - current_sample_idx as u32; + match (raw_event.space_id, raw_event.type_) { (CLAP_CORE_EVENT_SPACE_ID, CLAP_EVENT_PARAM_VALUE) => { let event = &*(event as *const clap_event_param_value); @@ -1296,7 +1298,7 @@ impl Wrapper

{ input_events.push_back(NoteEvent::NoteOn { // When splitting up the buffer for sample accurate automation all events // should be relative to the block - timing: raw_event.time - current_sample_idx as u32, + timing, voice_id: if event.note_id != -1 { Some(event.note_id) } else { @@ -1314,7 +1316,7 @@ impl Wrapper

{ if P::MIDI_INPUT >= MidiConfig::Basic { let event = &*(event as *const clap_event_note); input_events.push_back(NoteEvent::NoteOff { - timing: raw_event.time - current_sample_idx as u32, + timing, voice_id: if event.note_id != -1 { Some(event.note_id) } else { @@ -1332,7 +1334,7 @@ impl Wrapper

{ if P::MIDI_INPUT >= MidiConfig::Basic { let event = &*(event as *const clap_event_note); input_events.push_back(NoteEvent::Choke { - timing: raw_event.time - current_sample_idx as u32, + timing, voice_id: if event.note_id != -1 { Some(event.note_id) } else { @@ -1352,7 +1354,7 @@ impl Wrapper

{ match event.expression_id { CLAP_NOTE_EXPRESSION_PRESSURE => { input_events.push_back(NoteEvent::PolyPressure { - timing: raw_event.time - current_sample_idx as u32, + timing, voice_id: if event.note_id != -1 { Some(event.note_id) } else { @@ -1365,7 +1367,7 @@ impl Wrapper

{ } CLAP_NOTE_EXPRESSION_VOLUME => { input_events.push_back(NoteEvent::PolyVolume { - timing: raw_event.time - current_sample_idx as u32, + timing, voice_id: if event.note_id != -1 { Some(event.note_id) } else { @@ -1378,7 +1380,7 @@ impl Wrapper

{ } CLAP_NOTE_EXPRESSION_PAN => { input_events.push_back(NoteEvent::PolyPan { - timing: raw_event.time - current_sample_idx as u32, + timing, voice_id: if event.note_id != -1 { Some(event.note_id) } else { @@ -1392,7 +1394,7 @@ impl Wrapper

{ } CLAP_NOTE_EXPRESSION_TUNING => { input_events.push_back(NoteEvent::PolyTuning { - timing: raw_event.time - current_sample_idx as u32, + timing, voice_id: if event.note_id != -1 { Some(event.note_id) } else { @@ -1405,7 +1407,7 @@ impl Wrapper

{ } CLAP_NOTE_EXPRESSION_VIBRATO => { input_events.push_back(NoteEvent::PolyVibrato { - timing: raw_event.time - current_sample_idx as u32, + timing, voice_id: if event.note_id != -1 { Some(event.note_id) } else { @@ -1418,7 +1420,7 @@ impl Wrapper

{ } CLAP_NOTE_EXPRESSION_EXPRESSION => { input_events.push_back(NoteEvent::PolyExpression { - timing: raw_event.time - current_sample_idx as u32, + timing, voice_id: if event.note_id != -1 { Some(event.note_id) } else { @@ -1431,7 +1433,7 @@ impl Wrapper

{ } CLAP_NOTE_EXPRESSION_BRIGHTNESS => { input_events.push_back(NoteEvent::PolyBrightness { - timing: raw_event.time - current_sample_idx as u32, + timing, voice_id: if event.note_id != -1 { Some(event.note_id) } else {