From 8f359feadbec21ed627d8def01e8ae27bebc5472 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Thu, 7 Apr 2022 20:12:30 +0200 Subject: [PATCH] Store velocity as a float Instead of converting this to a 0-127 value. We may be throwing away precision otherwise. --- src/plugin.rs | 14 ++++++++++++-- src/wrapper/clap/wrapper.rs | 4 ++-- src/wrapper/vst3/wrapper.rs | 4 ++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/plugin.rs b/src/plugin.rs index 2f4b0028..4f4b5278 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -311,17 +311,27 @@ pub enum ProcessStatus { /// TODO: Add more events as needed #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum NoteEvent { + /// A note on event. NoteOn { timing: u32, + /// The note's channel, from 0 to 16. channel: u8, + /// The note's MIDI key number, from 0 to 127. note: u8, - velocity: u8, + /// The note's velocity, from 0 to 1. Some plugin APIs may allow higher precision than the + /// 127 levels available in MIDI. + velocity: f32, }, + /// A note off event. NoteOff { timing: u32, + /// The note's channel, from 0 to 16. channel: u8, + /// The note's MIDI key number, from 0 to 127. note: u8, - velocity: u8, + /// The note's velocity, from 0 to 1. Some plugin APIs may allow higher precision than the + /// 127 levels available in MIDI. + velocity: f32, }, } diff --git a/src/wrapper/clap/wrapper.rs b/src/wrapper/clap/wrapper.rs index 200b720c..2457cb54 100644 --- a/src/wrapper/clap/wrapper.rs +++ b/src/wrapper/clap/wrapper.rs @@ -875,7 +875,7 @@ impl Wrapper

{ timing: raw_event.time - current_sample_idx as u32, channel: event.channel as u8, note: event.key as u8, - velocity: (event.velocity * 127.0).round() as u8, + velocity: event.velocity as f32, }); } @@ -888,7 +888,7 @@ impl Wrapper

{ timing: raw_event.time - current_sample_idx as u32, channel: event.channel as u8, note: event.key as u8, - velocity: (event.velocity * 127.0).round() as u8, + velocity: event.velocity as f32, }); } diff --git a/src/wrapper/vst3/wrapper.rs b/src/wrapper/vst3/wrapper.rs index 8f2a9b28..adbe6cd9 100644 --- a/src/wrapper/vst3/wrapper.rs +++ b/src/wrapper/vst3/wrapper.rs @@ -770,7 +770,7 @@ impl IAudioProcessor for Wrapper

{ timing, channel: event.channel as u8, note: event.pitch as u8, - velocity: (event.velocity * 127.0).round() as u8, + velocity: event.velocity, }); } else if event.type_ == vst3_sys::vst::EventTypes::kNoteOffEvent as u16 { @@ -779,7 +779,7 @@ impl IAudioProcessor for Wrapper

{ timing, channel: event.channel as u8, note: event.pitch as u8, - velocity: (event.velocity * 127.0).round() as u8, + velocity: event.velocity, }); } }