From 00c77194f6b6f69e821ab3971b4db9532caa945d Mon Sep 17 00:00:00 2001 From: jules Date: Sat, 15 Nov 2014 10:03:49 +0000 Subject: [PATCH 1/4] Fix for an Android message-passing bug --- modules/juce_events/native/juce_android_Messaging.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/juce_events/native/juce_android_Messaging.cpp b/modules/juce_events/native/juce_android_Messaging.cpp index 733994ad6c..144a32646a 100644 --- a/modules/juce_events/native/juce_android_Messaging.cpp +++ b/modules/juce_events/native/juce_android_Messaging.cpp @@ -42,7 +42,7 @@ bool MessageManager::postMessageToSystemQueue (MessageManager::MessageBase* cons return true; } -JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, deliverMessage, void, (jobject activity, jlong value)) +JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, deliverMessage, void, (JNIEnv* env, jobject activity, jlong value)) { JUCE_TRY { From 7743dabe76209f0265ba450addc7e05ba70dbab7 Mon Sep 17 00:00:00 2001 From: jules Date: Sat, 15 Nov 2014 11:01:13 +0000 Subject: [PATCH 2/4] Added parameter smoothing to Reverb class. --- .../juce_audio_basics/effects/juce_Reverb.h | 135 ++++++++++++------ 1 file changed, 92 insertions(+), 43 deletions(-) diff --git a/modules/juce_audio_basics/effects/juce_Reverb.h b/modules/juce_audio_basics/effects/juce_Reverb.h index 53457a60b5..c0b7596ec8 100644 --- a/modules/juce_audio_basics/effects/juce_Reverb.h +++ b/modules/juce_audio_basics/effects/juce_Reverb.h @@ -82,12 +82,13 @@ public: const float dryScaleFactor = 2.0f; const float wet = newParams.wetLevel * wetScaleFactor; - wet1 = wet * (newParams.width * 0.5f + 0.5f); - wet2 = wet * (1.0f - newParams.width) * 0.5f; - dry = newParams.dryLevel * dryScaleFactor; + dryGain.setValue (newParams.dryLevel * dryScaleFactor); + wetGain1.setValue (0.5f * wet * (1.0f + newParams.width)); + wetGain2.setValue (0.5f * wet * (1.0f - newParams.width)); + gain = isFrozen (newParams.freezeMode) ? 0.0f : 0.015f; parameters = newParams; - shouldUpdateDamping = true; + updateDamping(); } //============================================================================== @@ -115,7 +116,12 @@ public: allPass[1][i].setSize ((intSampleRate * (allPassTunings[i] + stereoSpread)) / 44100); } - shouldUpdateDamping = true; + const double smoothTime = 0.01; + damping .reset (sampleRate, smoothTime); + feedback.reset (sampleRate, smoothTime); + dryGain .reset (sampleRate, smoothTime); + wetGain1.reset (sampleRate, smoothTime); + wetGain2.reset (sampleRate, smoothTime); } /** Clears the reverb's buffers. */ @@ -137,18 +143,18 @@ public: { jassert (left != nullptr && right != nullptr); - if (shouldUpdateDamping) - updateDamping(); - for (int i = 0; i < numSamples; ++i) { const float input = (left[i] + right[i]) * gain; float outL = 0, outR = 0; + const float damp = damping.getNextValue(); + const float feedbck = feedback.getNextValue(); + for (int j = 0; j < numCombs; ++j) // accumulate the comb filters in parallel { - outL += comb[0][j].process (input); - outR += comb[1][j].process (input); + outL += comb[0][j].process (input, damp, feedbck); + outR += comb[1][j].process (input, damp, feedbck); } for (int j = 0; j < numAllPasses; ++j) // run the allpass filters in series @@ -157,6 +163,10 @@ public: outR = allPass[1][j].process (outR); } + const float dry = dryGain.getNextValue(); + const float wet1 = wetGain1.getNextValue(); + const float wet2 = wetGain2.getNextValue(); + left[i] = outL * wet1 + outR * wet2 + left[i] * dry; right[i] = outR * wet1 + outL * wet2 + right[i] * dry; } @@ -167,32 +177,30 @@ public: { jassert (samples != nullptr); - if (shouldUpdateDamping) - updateDamping(); - for (int i = 0; i < numSamples; ++i) { const float input = samples[i] * gain; float output = 0; + const float damp = damping.getNextValue(); + const float feedbck = feedback.getNextValue(); + for (int j = 0; j < numCombs; ++j) // accumulate the comb filters in parallel - output += comb[0][j].process (input); + output += comb[0][j].process (input, damp, feedbck); for (int j = 0; j < numAllPasses; ++j) // run the allpass filters in series output = allPass[0][j].process (output); + const float dry = dryGain.getNextValue(); + const float wet1 = wetGain1.getNextValue(); + samples[i] = output * wet1 + samples[i] * dry; } } private: //============================================================================== - Parameters parameters; - - volatile bool shouldUpdateDamping; - float gain, wet1, wet2, dry; - - inline static bool isFrozen (const float freezeMode) noexcept { return freezeMode >= 0.5f; } + static bool isFrozen (const float freezeMode) noexcept { return freezeMode >= 0.5f; } void updateDamping() noexcept { @@ -200,8 +208,6 @@ private: const float roomOffset = 0.7f; const float dampScaleFactor = 0.4f; - shouldUpdateDamping = false; - if (isFrozen (parameters.freezeMode)) setDamping (0.0f, 1.0f); else @@ -211,19 +217,15 @@ private: void setDamping (const float dampingToUse, const float roomSizeToUse) noexcept { - for (int j = 0; j < numChannels; ++j) - for (int i = numCombs; --i >= 0;) - comb[j][i].setFeedbackAndDamp (roomSizeToUse, dampingToUse); + damping.setValue (dampingToUse); + feedback.setValue (roomSizeToUse); } //============================================================================== class CombFilter { public: - CombFilter() noexcept - : bufferSize (0), bufferIndex (0), - feedback (0), last (0), damp1 (0), damp2 (0) - {} + CombFilter() noexcept : bufferSize (0), bufferIndex (0), last (0) {} void setSize (const int size) { @@ -243,22 +245,15 @@ private: buffer.clear ((size_t) bufferSize); } - void setFeedbackAndDamp (const float f, const float d) noexcept + float process (const float input, const float damp, const float feedbackLevel) noexcept { - damp1 = d; - damp2 = 1.0f - d; - feedback = f; - } - - inline float process (const float input) noexcept - { - const float output = buffer [bufferIndex]; - last = (output * damp2) + (last * damp1); + const float output = buffer[bufferIndex]; + last = (output * (1.0f - damp)) + (last * damp); JUCE_UNDENORMALISE (last); - float temp = input + (last * feedback); + float temp = input + (last * feedbackLevel); JUCE_UNDENORMALISE (temp); - buffer [bufferIndex] = temp; + buffer[bufferIndex] = temp; bufferIndex = (bufferIndex + 1) % bufferSize; return output; } @@ -266,7 +261,7 @@ private: private: HeapBlock buffer; int bufferSize, bufferIndex; - float feedback, last, damp1, damp2; + float last; JUCE_DECLARE_NON_COPYABLE (CombFilter) }; @@ -294,7 +289,7 @@ private: buffer.clear ((size_t) bufferSize); } - inline float process (const float input) noexcept + float process (const float input) noexcept { const float bufferedValue = buffer [bufferIndex]; float temp = input + (bufferedValue * 0.5f); @@ -311,11 +306,65 @@ private: JUCE_DECLARE_NON_COPYABLE (AllPassFilter) }; + //============================================================================== + class LinearSmoothedValue + { + public: + LinearSmoothedValue() noexcept + : currentValue (0), target (0), step (0), countdown (0), stepsToTarget (0) + { + } + + void reset (double sampleRate, double fadeLengthSeconds) noexcept + { + jassert (sampleRate > 0 && fadeLengthSeconds >= 0); + stepsToTarget = (int) std::floor (fadeLengthSeconds * sampleRate); + currentValue = target; + countdown = 0; + } + + void setValue (float newValue) noexcept + { + if (target != newValue) + { + target = newValue; + countdown = stepsToTarget; + + if (countdown <= 0) + currentValue = target; + else + step = (target - currentValue) / countdown; + } + } + + float getNextValue() noexcept + { + if (countdown <= 0) + return target; + + --countdown; + currentValue += step; + return currentValue; + } + + private: + float currentValue, target, step; + int countdown, stepsToTarget; + + JUCE_DECLARE_NON_COPYABLE (LinearSmoothedValue) + }; + + //============================================================================== enum { numCombs = 8, numAllPasses = 4, numChannels = 2 }; + Parameters parameters; + float gain; + CombFilter comb [numChannels][numCombs]; AllPassFilter allPass [numChannels][numAllPasses]; + LinearSmoothedValue damping, feedback, dryGain, wetGain1, wetGain2; + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Reverb) }; From 1c37a7781b21bf54d3992058726ad4ab4e8cd602 Mon Sep 17 00:00:00 2001 From: jules Date: Sat, 15 Nov 2014 14:06:26 +0000 Subject: [PATCH 3/4] Introjucer shutdown sequence fix. --- .../Source/Application/jucer_Application.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/extras/Introjucer/Source/Application/jucer_Application.h b/extras/Introjucer/Source/Application/jucer_Application.h index d06c218984..28513a6489 100644 --- a/extras/Introjucer/Source/Application/jucer_Application.h +++ b/extras/Introjucer/Source/Application/jucer_Application.h @@ -99,16 +99,16 @@ public: utf8Window = nullptr; svgPathWindow = nullptr; - #if JUCE_MAC - MenuBarModel::setMacMainMenu (nullptr); - #endif - menuModel = nullptr; - mainWindowList.forceCloseAllWindows(); openDocumentManager.clear(); commandManager = nullptr; settings = nullptr; + #if JUCE_MAC + MenuBarModel::setMacMainMenu (nullptr); + #endif + menuModel = nullptr; + LookAndFeel::setDefaultLookAndFeel (nullptr); if (! isRunningCommandLine) @@ -168,19 +168,19 @@ public: setApplicationCommandManagerToWatch (&getCommandManager()); } - StringArray getMenuBarNames() + StringArray getMenuBarNames() override { return getApp().getMenuNames(); } - PopupMenu getMenuForIndex (int /*topLevelMenuIndex*/, const String& menuName) + PopupMenu getMenuForIndex (int /*topLevelMenuIndex*/, const String& menuName) override { PopupMenu menu; getApp().createMenu (menu, menuName); return menu; } - void menuItemSelected (int menuItemID, int /*topLevelMenuIndex*/) + void menuItemSelected (int menuItemID, int /*topLevelMenuIndex*/) override { getApp().handleMainMenuCommand (menuItemID); } From e98db059f94860613b9731096b57752539635559 Mon Sep 17 00:00:00 2001 From: jules Date: Sat, 15 Nov 2014 16:08:07 +0000 Subject: [PATCH 4/4] VST3 hosting parameter fix. --- .../format_types/juce_VST3PluginFormat.cpp | 107 ++++++++++++------ 1 file changed, 72 insertions(+), 35 deletions(-) diff --git a/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp b/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp index a7416264c8..3bbc61dbb4 100644 --- a/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp +++ b/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp @@ -364,7 +364,6 @@ class VST3HostContext : public Vst::IComponentHandler, // From VST V3.0.0 public Vst::IComponentHandler3, // From VST V3.5.0 (also very well named!) public Vst::IContextMenuTarget, public Vst::IHostApplication, - public Vst::IParamValueQueue, public Vst::IUnitHandler { public: @@ -684,31 +683,6 @@ public: return kNotImplemented; } - //============================================================================== - Vst::ParamID PLUGIN_API getParameterId() override - { - jassertfalse; - return 0; - } - - Steinberg::int32 PLUGIN_API getPointCount() override - { - jassertfalse; - return 0; - } - - tresult PLUGIN_API getPoint (Steinberg::int32, Steinberg::int32&, Vst::ParamValue&) override - { - jassertfalse; - return kResultFalse; - } - - tresult PLUGIN_API addPoint (Steinberg::int32, Vst::ParamValue, Steinberg::int32&) override - { - jassertfalse; - return kResultFalse; - } - //============================================================================== tresult PLUGIN_API notifyUnitSelection (Vst::UnitID) override { @@ -736,7 +710,6 @@ public: TEST_FOR_AND_RETURN_IF_VALID (iid, Vst::IComponentHandler3) TEST_FOR_AND_RETURN_IF_VALID (iid, Vst::IContextMenuTarget) TEST_FOR_AND_RETURN_IF_VALID (iid, Vst::IHostApplication) - TEST_FOR_AND_RETURN_IF_VALID (iid, Vst::IParamValueQueue) TEST_FOR_AND_RETURN_IF_VALID (iid, Vst::IUnitHandler) TEST_FOR_COMMON_BASE_AND_RETURN_IF_VALID (iid, FUnknown, Vst::IComponentHandler) @@ -2132,21 +2105,85 @@ private: JUCE_DECLARE_VST3_COM_REF_METHODS JUCE_DECLARE_VST3_COM_QUERY_METHODS - Steinberg::int32 PLUGIN_API getParameterCount() override { return 0; } + Steinberg::int32 PLUGIN_API getParameterCount() override { return (Steinberg::int32) queues.size(); } + Vst::IParamValueQueue* PLUGIN_API getParameterData (Steinberg::int32 index) override { return queues[(int) index]; } - Vst::IParamValueQueue* PLUGIN_API getParameterData (Steinberg::int32) override + Vst::IParamValueQueue* PLUGIN_API addParameterData (const Vst::ParamID& id, Steinberg::int32& index) override { - return nullptr; - } + for (int i = queues.size(); --i >= 0;) + { + if (queues.getUnchecked (i)->getParameterId() == id) + { + index = (Steinberg::int32) i; + return queues.getUnchecked (i); + } + } - Vst::IParamValueQueue* PLUGIN_API addParameterData (const Vst::ParamID&, Steinberg::int32& index) override - { - index = 0; - return nullptr; + ParamValueQueue* q = queues.add (new ParamValueQueue (id)); + index = getParameterCount() - 1; + return q; } private: + struct ParamValueQueue : public Vst::IParamValueQueue + { + ParamValueQueue (Vst::ParamID parameterID) : paramID (parameterID) + { + points.ensureStorageAllocated (1024); + } + + virtual ~ParamValueQueue() {} + + JUCE_DECLARE_VST3_COM_REF_METHODS + JUCE_DECLARE_VST3_COM_QUERY_METHODS + + Steinberg::Vst::ParamID PLUGIN_API getParameterId() override { return paramID; } + Steinberg::int32 PLUGIN_API getPointCount() override { return (Steinberg::int32) points.size(); } + + Steinberg::tresult PLUGIN_API getPoint (Steinberg::int32 index, + Steinberg::int32& sampleOffset, + Steinberg::Vst::ParamValue& value) override + { + if (isPositiveAndBelow ((int) index, points.size())) + { + ParamPoint e (points.getUnchecked ((int) index)); + sampleOffset = e.sampleOffset; + value = e.value; + return kResultTrue; + } + + sampleOffset = -1; + value = 0.0; + return kResultFalse; + } + + Steinberg::tresult PLUGIN_API addPoint (Steinberg::int32 sampleOffset, + Steinberg::Vst::ParamValue value, + Steinberg::int32& index) override + { + // XXX this may need to be made thread-safe.. + ParamPoint p = { sampleOffset, value }; + points.add (p); + index = (Steinberg::int32) points.size(); + return kResultTrue; + } + + private: + struct ParamPoint + { + Steinberg::int32 sampleOffset; + Steinberg::Vst::ParamValue value; + }; + + Atomic refCount; + const Vst::ParamID paramID; + Array points; + + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ParamValueQueue) + }; + Atomic refCount; + OwnedArray queues; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ParameterChangeList) };