The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

234 lines
8.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 7 technical preview.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For the technical preview this file cannot be licensed commercially.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. #ifdef JUCE_AUDIO_PROCESSORS_H_INCLUDED
  14. /* When you add this cpp file to your project, you mustn't include it in a file where you've
  15. already included any other headers - just put it inside a file on its own, possibly with your config
  16. flags preceding it, but don't include anything else. That also includes avoiding any automatic prefix
  17. header files that the compiler may be using.
  18. */
  19. #error "Incorrect use of JUCE cpp file"
  20. #endif
  21. #define JUCE_CORE_INCLUDE_NATIVE_HEADERS 1
  22. #define JUCE_CORE_INCLUDE_OBJC_HELPERS 1
  23. #define JUCE_GUI_BASICS_INCLUDE_XHEADERS 1
  24. #define JUCE_GUI_BASICS_INCLUDE_SCOPED_THREAD_DPI_AWARENESS_SETTER 1
  25. #define JUCE_GRAPHICS_INCLUDE_COREGRAPHICS_HELPERS 1
  26. #include "juce_audio_processors.h"
  27. #include <juce_gui_extra/juce_gui_extra.h>
  28. #include <juce_core/containers/juce_Optional.h>
  29. //==============================================================================
  30. #if JUCE_MAC
  31. #if JUCE_SUPPORT_CARBON && (JUCE_PLUGINHOST_VST || JUCE_PLUGINHOST_AU)
  32. #include <Carbon/Carbon.h>
  33. #include <juce_gui_extra/native/juce_mac_CarbonViewWrapperComponent.h>
  34. #endif
  35. #endif
  36. #if (JUCE_PLUGINHOST_VST || JUCE_PLUGINHOST_VST3) && (JUCE_LINUX || JUCE_BSD)
  37. #include <X11/Xlib.h>
  38. #include <X11/Xutil.h>
  39. #include <sys/utsname.h>
  40. #undef KeyPress
  41. #endif
  42. #if ! JUCE_WINDOWS && ! JUCE_MAC && ! JUCE_LINUX
  43. #undef JUCE_PLUGINHOST_VST3
  44. #define JUCE_PLUGINHOST_VST3 0
  45. #endif
  46. #if JUCE_PLUGINHOST_AU && (JUCE_MAC || JUCE_IOS)
  47. #include <AudioUnit/AudioUnit.h>
  48. #endif
  49. namespace juce
  50. {
  51. #if JUCE_PLUGINHOST_VST || (JUCE_PLUGINHOST_LADSPA && JUCE_LINUX)
  52. static bool arrayContainsPlugin (const OwnedArray<PluginDescription>& list,
  53. const PluginDescription& desc)
  54. {
  55. for (auto* p : list)
  56. if (p->isDuplicateOf (desc))
  57. return true;
  58. return false;
  59. }
  60. #endif
  61. template <typename Callback>
  62. void callOnMessageThread (Callback&& callback)
  63. {
  64. if (MessageManager::getInstance()->existsAndIsLockedByCurrentThread())
  65. {
  66. callback();
  67. return;
  68. }
  69. WaitableEvent completionEvent;
  70. MessageManager::callAsync ([&callback, &completionEvent]
  71. {
  72. callback();
  73. completionEvent.signal();
  74. });
  75. completionEvent.wait();
  76. }
  77. #if JUCE_MAC
  78. //==============================================================================
  79. /* This is an NSViewComponent which holds a long-lived NSView which acts
  80. as the parent view for plugin editors.
  81. Note that this component does not auto-resize depending on the bounds
  82. of the owned view. VST2 and VST3 plugins have dedicated interfaces to
  83. request that the editor bounds are updated. We can call `setSize` on this
  84. component from inside those dedicated callbacks.
  85. */
  86. struct NSViewComponentWithParent : public NSViewComponent,
  87. private AsyncUpdater
  88. {
  89. enum class WantsNudge { no, yes };
  90. explicit NSViewComponentWithParent (WantsNudge shouldNudge)
  91. : wantsNudge (shouldNudge)
  92. {
  93. auto* view = [[getViewClass().createInstance() init] autorelease];
  94. object_setInstanceVariable (view, "owner", this);
  95. setView (view);
  96. }
  97. explicit NSViewComponentWithParent (AudioPluginInstance& instance)
  98. : NSViewComponentWithParent (getWantsNudge (instance)) {}
  99. ~NSViewComponentWithParent() override
  100. {
  101. if (auto* view = static_cast<NSView*> (getView()))
  102. object_setInstanceVariable (view, "owner", nullptr);
  103. cancelPendingUpdate();
  104. }
  105. JUCE_DECLARE_NON_COPYABLE (NSViewComponentWithParent)
  106. JUCE_DECLARE_NON_MOVEABLE (NSViewComponentWithParent)
  107. private:
  108. WantsNudge wantsNudge = WantsNudge::no;
  109. static WantsNudge getWantsNudge (AudioPluginInstance& instance)
  110. {
  111. PluginDescription pd;
  112. instance.fillInPluginDescription (pd);
  113. return pd.manufacturerName == "FabFilter" ? WantsNudge::yes : WantsNudge::no;
  114. }
  115. void handleAsyncUpdate() override
  116. {
  117. if (auto* peer = getTopLevelComponent()->getPeer())
  118. {
  119. auto* view = static_cast<NSView*> (getView());
  120. const auto newArea = peer->getAreaCoveredBy (*this);
  121. [view setFrame: makeNSRect (newArea.withHeight (newArea.getHeight() + 1))];
  122. [view setFrame: makeNSRect (newArea)];
  123. }
  124. }
  125. struct FlippedNSView : public ObjCClass<NSView>
  126. {
  127. FlippedNSView()
  128. : ObjCClass ("JuceFlippedNSView_")
  129. {
  130. addIvar<NSViewComponentWithParent*> ("owner");
  131. addMethod (@selector (isFlipped), isFlipped);
  132. addMethod (@selector (isOpaque), isOpaque);
  133. addMethod (@selector (didAddSubview:), didAddSubview);
  134. registerClass();
  135. }
  136. static BOOL isFlipped (id, SEL) { return YES; }
  137. static BOOL isOpaque (id, SEL) { return YES; }
  138. static void nudge (id self)
  139. {
  140. if (auto* owner = getIvar<NSViewComponentWithParent*> (self, "owner"))
  141. if (owner->wantsNudge == WantsNudge::yes)
  142. owner->triggerAsyncUpdate();
  143. }
  144. static void viewDidUnhide (id self, SEL) { nudge (self); }
  145. static void didAddSubview (id self, SEL, NSView*) { nudge (self); }
  146. static void viewDidMoveToSuperview (id self, SEL) { nudge (self); }
  147. static void viewDidMoveToWindow (id self, SEL) { nudge (self); }
  148. };
  149. static FlippedNSView& getViewClass()
  150. {
  151. static FlippedNSView result;
  152. return result;
  153. }
  154. };
  155. #endif
  156. } // namespace juce
  157. #include "utilities/juce_FlagCache.h"
  158. #include "format/juce_AudioPluginFormat.cpp"
  159. #include "format/juce_AudioPluginFormatManager.cpp"
  160. #include "format_types/juce_LegacyAudioParameter.cpp"
  161. #include "processors/juce_AudioProcessor.cpp"
  162. #include "processors/juce_AudioPluginInstance.cpp"
  163. #include "processors/juce_AudioProcessorEditor.cpp"
  164. #include "processors/juce_AudioProcessorGraph.cpp"
  165. #include "processors/juce_GenericAudioProcessorEditor.cpp"
  166. #include "processors/juce_PluginDescription.cpp"
  167. #include "format_types/juce_LADSPAPluginFormat.cpp"
  168. #include "format_types/juce_VSTPluginFormat.cpp"
  169. #include "format_types/juce_VST3PluginFormat.cpp"
  170. #include "format_types/juce_AudioUnitPluginFormat.mm"
  171. #include "scanning/juce_KnownPluginList.cpp"
  172. #include "scanning/juce_PluginDirectoryScanner.cpp"
  173. #include "scanning/juce_PluginListComponent.cpp"
  174. #include "processors/juce_AudioProcessorParameterGroup.cpp"
  175. #include "utilities/juce_AudioProcessorParameterWithID.cpp"
  176. #include "utilities/juce_RangedAudioParameter.cpp"
  177. #include "utilities/juce_AudioParameterFloat.cpp"
  178. #include "utilities/juce_AudioParameterInt.cpp"
  179. #include "utilities/juce_AudioParameterBool.cpp"
  180. #include "utilities/juce_AudioParameterChoice.cpp"
  181. #include "utilities/juce_ParameterAttachments.cpp"
  182. #include "utilities/juce_AudioProcessorValueTreeState.cpp"
  183. #include "utilities/juce_PluginHostType.cpp"
  184. #include "utilities/juce_NativeScaleFactorNotifier.cpp"
  185. #include "format_types/juce_LV2PluginFormat.cpp"
  186. #if JUCE_UNIT_TESTS
  187. #include "format_types/juce_VST3PluginFormat_test.cpp"
  188. #include "format_types/juce_LV2PluginFormat_test.cpp"
  189. #endif