File Sample-Accurate-MIDI-control-VST3.patch of Package juce6

From 98b20b0eb376ed7a79bf8e34ad093403e043ce88 Mon Sep 17 00:00:00 2001
From: Paul Walker <paul@pwjw.com>
Date: Tue, 9 Aug 2022 11:14:41 -0400
Subject: [PATCH] Sample Accurate MIDI control VST3

VST3 makes all midi other than notes into parameter changes
and those become sample accurate, so everyone (u-he, old surge,
juce, etc...) who actualy want MIDI instead make 131 * 16 fake params
and read off them. BUT Juce was only reading the very last point in
a midi param since it isn't sample accurate on params. But JUCE
*is* sample accurate on MIDI. So very long block renders with pitch
bends would render improperly in some DAWs, like MultitrackStudio.

Fix that by, if you do unpack param to midi after your daw packs
midi to param, keeping the sample and putting in multiple events,
resulting in VST3 having sample accurate CC, PitchBend and Aftertouch
---
 .../VST3/juce_VST3_Wrapper.cpp                | 23 +++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp
index 623ca9aef2a8..26b264aa65ff 100644
--- a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp
+++ b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp
@@ -3088,8 +3088,27 @@ class JuceVST3Component : public Vst::IComponent,
                     auto vstParamID = paramQueue->getParameterId();
 
                    #if JUCE_VST3_EMULATE_MIDI_CC_WITH_PARAMETERS
-                    if (juceVST3EditController != nullptr && juceVST3EditController->isMidiControllerParamID (vstParamID))
-                        addParameterChangeToMidiBuffer (offsetSamples, vstParamID, value);
+                    if (juceVST3EditController != nullptr &&
+                        juceVST3EditController->isMidiControllerParamID(vstParamID))
+                    {
+                        // SURGE CHANGE - rather than just adding the last sample, add all the midi
+                        // events (this used to just be the numPoints==1 case)
+                        if (numPoints == 1)
+                        {
+                            // No need to re-query
+                            addParameterChangeToMidiBuffer(offsetSamples, vstParamID, value);
+                        }
+                        else
+                        {
+                            for (auto mp = 0; mp < numPoints; ++mp)
+                            {
+                                Steinberg::int32 losampl;
+                                paramQueue->getPoint(mp, losampl, value);
+                                addParameterChangeToMidiBuffer(losampl, vstParamID, value);
+                            }
+                        }
+                        // END SURGE CHANGE
+                    }
                     else
                    #endif
                     {
openSUSE Build Service is sponsored by