DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

commit f5815166356e85a5fe244f6024c2e401f04b10fa
parent 077fcf5758ed6038bfe6e7aee1e407aa02e807b2
Author: FergusL <Simon-L@users.noreply.github.com>
Date:   Fri, 21 Jun 2024 07:53:25 +0200

[WIP] VST3: Fix incorrect MIDI input values for CC and Note On/Off (#453)

* Add debug prints to MidiThrough example

* Fix CC and Note On/Off calculation

Given the current normalized input, mutliply by 127 would give wrong result for some input values, dividing by 0.0078125, which is 1.0/128, fixes this

* Use std::round

* Use DPF functions for rounding

* Remove  debug prints in MidiThrough example

This reverts commit 82767715a16b715d44ceed3ccd97402696a0e8de.
Diffstat:
Mdistrho/src/DistrhoPluginVST3.cpp | 10+++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/distrho/src/DistrhoPluginVST3.cpp b/distrho/src/DistrhoPluginVST3.cpp @@ -359,14 +359,14 @@ class PluginVst3 midiEvent.size = 3; midiEvent.data[0] = 0x90 | (eventStorage.noteOn.channel & 0xf); midiEvent.data[1] = eventStorage.noteOn.pitch; - midiEvent.data[2] = std::max(0, std::min(127, (int)(eventStorage.noteOn.velocity * 127))); + midiEvent.data[2] = std::max(0, std::min(127, d_roundToIntPositive(eventStorage.noteOn.velocity * 127))); midiEvent.data[3] = 0; break; case NoteOff: midiEvent.size = 3; midiEvent.data[0] = 0x80 | (eventStorage.noteOff.channel & 0xf); midiEvent.data[1] = eventStorage.noteOff.pitch; - midiEvent.data[2] = std::max(0, std::min(127, (int)(eventStorage.noteOff.velocity * 127))); + midiEvent.data[2] = std::max(0, std::min(127, d_roundToIntPositive(eventStorage.noteOff.velocity * 127))); midiEvent.data[3] = 0; break; /* TODO @@ -377,7 +377,7 @@ class PluginVst3 midiEvent.size = 3; midiEvent.data[0] = 0xA0 | (eventStorage.polyPressure.channel & 0xf); midiEvent.data[1] = eventStorage.polyPressure.pitch; - midiEvent.data[2] = std::max(0, std::min(127, (int)(eventStorage.polyPressure.pressure * 127))); + midiEvent.data[2] = std::max(0, std::min(127, d_roundToIntPositive(eventStorage.polyPressure.pressure * 127))); midiEvent.data[3] = 0; break; case CC_Normal: @@ -469,7 +469,7 @@ class PluginVst3 { case 128: eventStorage.type = CC_ChannelPressure; - eventStorage.midi[1] = std::max(0, std::min(127, (int)(normalized * 127))); + eventStorage.midi[1] = std::max(0, std::min(127, d_roundToIntPositive(normalized * 127))); eventStorage.midi[2] = 0; break; case 129: @@ -480,7 +480,7 @@ class PluginVst3 default: eventStorage.type = CC_Normal; eventStorage.midi[1] = cc; - eventStorage.midi[2] = std::max(0, std::min(127, (int)(normalized * 127))); + eventStorage.midi[2] = std::max(0, std::min(127, d_roundToIntPositive(normalized * 127))); break; }