Skip to content

Commit

Permalink
[WIP] VST3: Fix incorrect MIDI input values for CC and Note On/Off (#453
Browse files Browse the repository at this point in the history
)

* 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 8276771.
  • Loading branch information
Simon-L authored and falkTX committed Oct 5, 2024
1 parent 2e2cbb7 commit c7fb0ca
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions distrho/src/DistrhoPluginVST3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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;
}

Expand Down

0 comments on commit c7fb0ca

Please sign in to comment.