iPlug2 / iPlug2

C++ Audio Plug-in Framework for desktop, mobile and web
https://iplug2.github.io
Other
1.92k stars 284 forks source link

MIDI velocity values get rounded incorrectly #1088

Open olilarkin opened 6 months ago

olilarkin commented 6 months ago

From: Certain MIDI velocity values get decremented by 1 when read into VST3

If you send out a midi note with iPlug2 VST3 and read it back in with iPlug2 VST3 certain velocity values get decremented by 1. These are a set of values to test with… 9, 13, 18, 26, 36, 52 they arrive as… 8, 12, 17, 25, 35, 51

I was discussing this with the guys at Blue Cat Audio and they pointed me to this line (84) of code in IPlugVST3_ProcessorBase.cpp:

msg.MakeNoteOnMsg(event.noteOn.pitch, event.noteOn.velocity * 127, event.sampleOffset, event.noteOn.channel);

Rounding up of the velocity is needed. This works for me:

msg.MakeNoteOnMsg(event.noteOn.pitch, (int)(event.noteOn.velocity * 127.0 + 0.5), event.sampleOffset, event.noteOn.channel);

AlexHarker commented 6 months ago

std::round() might be better than a manual rounding/truncate