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.

2472 lines
92KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #include "../../juce_core/system/juce_TargetPlatform.h"
  20. #include "../utility/juce_CheckSettingMacros.h"
  21. #if JucePlugin_Build_VST
  22. #ifdef _MSC_VER
  23. #pragma warning (disable : 4996 4100)
  24. #endif
  25. #include "../utility/juce_IncludeSystemHeaders.h"
  26. #include <juce_core/juce_core.h>
  27. #if JucePlugin_VersionCode < 0x010000 // Major < 0
  28. #if (JucePlugin_VersionCode & 0x00FF00) > (9 * 0x100) // check if Minor number exceeds 9
  29. JUCE_COMPILER_WARNING ("When version has 'major' = 0, VST2 has trouble displaying 'minor' exceeding 9")
  30. #endif
  31. #if (JucePlugin_VersionCode & 0xFF) > 9 // check if Bugfix number exceeds 9
  32. JUCE_COMPILER_WARNING ("When version has 'major' = 0, VST2 has trouble displaying 'bugfix' exceeding 9")
  33. #endif
  34. #elif JucePlugin_VersionCode >= 0x650000 // Major >= 101
  35. #if (JucePlugin_VersionCode & 0x00FF00) > (99 * 0x100) // check if Minor number exceeds 99
  36. JUCE_COMPILER_WARNING ("When version has 'major' > 100, VST2 has trouble displaying 'minor' exceeding 99")
  37. #endif
  38. #if (JucePlugin_VersionCode & 0xFF) > 99 // check if Bugfix number exceeds 99
  39. JUCE_COMPILER_WARNING ("When version has 'major' > 100, VST2 has trouble displaying 'bugfix' exceeding 99")
  40. #endif
  41. #endif
  42. #ifdef PRAGMA_ALIGN_SUPPORTED
  43. #undef PRAGMA_ALIGN_SUPPORTED
  44. #define PRAGMA_ALIGN_SUPPORTED 1
  45. #endif
  46. #ifndef _MSC_VER
  47. #define __cdecl
  48. #endif
  49. #if JUCE_CLANG
  50. #pragma clang diagnostic push
  51. #pragma clang diagnostic ignored "-Wconversion"
  52. #pragma clang diagnostic ignored "-Wshadow"
  53. #pragma clang diagnostic ignored "-Wdeprecated-register"
  54. #pragma clang diagnostic ignored "-Wunused-parameter"
  55. #pragma clang diagnostic ignored "-Wdeprecated-writable-strings"
  56. #pragma clang diagnostic ignored "-Wnon-virtual-dtor"
  57. #if __has_warning("-Wzero-as-null-pointer-constant")
  58. #pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
  59. #endif
  60. #endif
  61. #if JUCE_GCC
  62. #pragma GCC diagnostic push
  63. #pragma GCC diagnostic ignored "-Wshadow"
  64. #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
  65. #endif
  66. #ifdef _MSC_VER
  67. #pragma warning (push)
  68. #pragma warning (disable : 4458)
  69. #endif
  70. #define VST_FORCE_DEPRECATED 0
  71. namespace Vst2
  72. {
  73. // If the following files cannot be found then you are probably trying to build
  74. // a VST2 plug-in or a VST2-compatible VST3 plug-in. To do this you must have a
  75. // VST2 SDK in your header search paths or use the "VST (Legacy) SDK Folder"
  76. // field in the Projucer. The VST2 SDK can be obtained from the
  77. // vstsdk3610_11_06_2018_build_37 (or older) VST3 SDK or JUCE version 5.3.2. You
  78. // also need a VST2 license from Steinberg to distribute VST2 plug-ins.
  79. #include "pluginterfaces/vst2.x/aeffect.h"
  80. #include "pluginterfaces/vst2.x/aeffectx.h"
  81. }
  82. using namespace juce;
  83. #ifdef _MSC_VER
  84. #pragma warning (pop)
  85. #endif
  86. #if JUCE_CLANG
  87. #pragma clang diagnostic pop
  88. #endif
  89. #if JUCE_GCC
  90. #pragma GCC diagnostic pop
  91. #endif
  92. //==============================================================================
  93. #ifdef _MSC_VER
  94. #pragma pack (push, 8)
  95. #endif
  96. #define JUCE_VSTINTERFACE_H_INCLUDED 1
  97. #include "../utility/juce_IncludeModuleHeaders.h"
  98. #include "../utility/juce_FakeMouseMoveGenerator.h"
  99. #include "../utility/juce_WindowsHooks.h"
  100. #include "../../juce_audio_processors/format_types/juce_LegacyAudioParameter.cpp"
  101. #include "../../juce_audio_processors/format_types/juce_VSTCommon.h"
  102. #if JUCE_BIG_ENDIAN
  103. #define JUCE_MULTICHAR_CONSTANT(a, b, c, d) (a | (((uint32) b) << 8) | (((uint32) c) << 16) | (((uint32) d) << 24))
  104. #else
  105. #define JUCE_MULTICHAR_CONSTANT(a, b, c, d) (d | (((uint32) c) << 8) | (((uint32) b) << 16) | (((uint32) a) << 24))
  106. #endif
  107. #ifdef _MSC_VER
  108. #pragma pack (pop)
  109. #endif
  110. #undef MemoryBlock
  111. class JuceVSTWrapper;
  112. static bool recursionCheck = false;
  113. namespace juce
  114. {
  115. #if JUCE_MAC
  116. extern JUCE_API void initialiseMacVST();
  117. extern JUCE_API void* attachComponentToWindowRefVST (Component*, void* parent, bool isNSView);
  118. extern JUCE_API void detachComponentFromWindowRefVST (Component*, void* window, bool isNSView);
  119. extern JUCE_API void setNativeHostWindowSizeVST (void* window, Component*, int newWidth, int newHeight, bool isNSView);
  120. extern JUCE_API void checkWindowVisibilityVST (void* window, Component*, bool isNSView);
  121. extern JUCE_API bool forwardCurrentKeyEventToHostVST (Component*, bool isNSView);
  122. #if ! JUCE_64BIT
  123. extern JUCE_API void updateEditorCompBoundsVST (Component*);
  124. #endif
  125. #endif
  126. #if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE
  127. extern JUCE_API double getScaleFactorForWindow (HWND);
  128. #endif
  129. extern JUCE_API bool handleManufacturerSpecificVST2Opcode (int32, pointer_sized_int, void*, float);
  130. }
  131. //==============================================================================
  132. #if JUCE_WINDOWS
  133. namespace
  134. {
  135. // Returns the actual container window, unlike GetParent, which can also return a separate owner window.
  136. static HWND getWindowParent (HWND w) noexcept { return GetAncestor (w, GA_PARENT); }
  137. static HWND findMDIParentOf (HWND w)
  138. {
  139. const int frameThickness = GetSystemMetrics (SM_CYFIXEDFRAME);
  140. while (w != 0)
  141. {
  142. auto parent = getWindowParent (w);
  143. if (parent == 0)
  144. break;
  145. TCHAR windowType[32] = { 0 };
  146. GetClassName (parent, windowType, 31);
  147. if (String (windowType).equalsIgnoreCase ("MDIClient"))
  148. return parent;
  149. RECT windowPos, parentPos;
  150. GetWindowRect (w, &windowPos);
  151. GetWindowRect (parent, &parentPos);
  152. auto dw = (parentPos.right - parentPos.left) - (windowPos.right - windowPos.left);
  153. auto dh = (parentPos.bottom - parentPos.top) - (windowPos.bottom - windowPos.top);
  154. if (dw > 100 || dh > 100)
  155. break;
  156. w = parent;
  157. if (dw == 2 * frameThickness)
  158. break;
  159. }
  160. return w;
  161. }
  162. static bool messageThreadIsDefinitelyCorrect = false;
  163. }
  164. //==============================================================================
  165. #elif JUCE_LINUX
  166. struct SharedMessageThread : public Thread
  167. {
  168. SharedMessageThread() : Thread ("VstMessageThread")
  169. {
  170. startThread (7);
  171. while (! initialised)
  172. sleep (1);
  173. }
  174. ~SharedMessageThread() override
  175. {
  176. signalThreadShouldExit();
  177. JUCEApplicationBase::quit();
  178. waitForThreadToExit (5000);
  179. clearSingletonInstance();
  180. }
  181. void run() override
  182. {
  183. initialiseJuce_GUI();
  184. initialised = true;
  185. MessageManager::getInstance()->setCurrentThreadAsMessageThread();
  186. ScopedXDisplay xDisplay;
  187. while ((! threadShouldExit()) && MessageManager::getInstance()->runDispatchLoopUntil (250))
  188. {}
  189. }
  190. JUCE_DECLARE_SINGLETON (SharedMessageThread, false)
  191. bool initialised = false;
  192. };
  193. JUCE_IMPLEMENT_SINGLETON (SharedMessageThread)
  194. #endif
  195. static Array<void*> activePlugins;
  196. //==============================================================================
  197. // Ableton Live host specific commands
  198. struct AbletonLiveHostSpecific
  199. {
  200. enum
  201. {
  202. KCantBeSuspended = (1 << 2)
  203. };
  204. uint32 magic; // 'AbLi'
  205. int cmd; // 5 = realtime properties
  206. size_t commandSize; // sizeof (int)
  207. int flags; // KCantBeSuspended = (1 << 2)
  208. };
  209. //==============================================================================
  210. /**
  211. This is an AudioEffectX object that holds and wraps our AudioProcessor...
  212. */
  213. class JuceVSTWrapper : public AudioProcessorListener,
  214. public AudioPlayHead,
  215. private Timer,
  216. private AsyncUpdater,
  217. private AudioProcessorParameter::Listener
  218. {
  219. private:
  220. //==============================================================================
  221. template <typename FloatType>
  222. struct VstTempBuffers
  223. {
  224. VstTempBuffers() {}
  225. ~VstTempBuffers() { release(); }
  226. void release() noexcept
  227. {
  228. for (auto* c : tempChannels)
  229. delete[] c;
  230. tempChannels.clear();
  231. }
  232. HeapBlock<FloatType*> channels;
  233. Array<FloatType*> tempChannels; // see note in processReplacing()
  234. juce::AudioBuffer<FloatType> processTempBuffer;
  235. };
  236. /** Use the same names as the VST SDK. */
  237. struct VstOpCodeArguments
  238. {
  239. int32 index;
  240. pointer_sized_int value;
  241. void* ptr;
  242. float opt;
  243. };
  244. public:
  245. //==============================================================================
  246. JuceVSTWrapper (Vst2::audioMasterCallback cb, AudioProcessor* af)
  247. : hostCallback (cb),
  248. processor (af)
  249. {
  250. inParameterChangedCallback = false;
  251. // VST-2 does not support disabling buses: so always enable all of them
  252. processor->enableAllBuses();
  253. findMaxTotalChannels (maxNumInChannels, maxNumOutChannels);
  254. // You must at least have some channels
  255. jassert (processor->isMidiEffect() || (maxNumInChannels > 0 || maxNumOutChannels > 0));
  256. if (processor->isMidiEffect())
  257. maxNumInChannels = maxNumOutChannels = 2;
  258. #ifdef JucePlugin_PreferredChannelConfigurations
  259. processor->setPlayConfigDetails (maxNumInChannels, maxNumOutChannels, 44100.0, 1024);
  260. #endif
  261. processor->setRateAndBufferSizeDetails (0, 0);
  262. processor->setPlayHead (this);
  263. processor->addListener (this);
  264. if (auto* juceParam = processor->getBypassParameter())
  265. juceParam->addListener (this);
  266. juceParameters.update (*processor, false);
  267. memset (&vstEffect, 0, sizeof (vstEffect));
  268. vstEffect.magic = 0x56737450 /* 'VstP' */;
  269. vstEffect.dispatcher = (Vst2::AEffectDispatcherProc) dispatcherCB;
  270. vstEffect.process = nullptr;
  271. vstEffect.setParameter = (Vst2::AEffectSetParameterProc) setParameterCB;
  272. vstEffect.getParameter = (Vst2::AEffectGetParameterProc) getParameterCB;
  273. vstEffect.numPrograms = jmax (1, af->getNumPrograms());
  274. vstEffect.numParams = juceParameters.getNumParameters();
  275. vstEffect.numInputs = maxNumInChannels;
  276. vstEffect.numOutputs = maxNumOutChannels;
  277. vstEffect.initialDelay = processor->getLatencySamples();
  278. vstEffect.object = this;
  279. vstEffect.uniqueID = JucePlugin_VSTUniqueID;
  280. #ifdef JucePlugin_VSTChunkStructureVersion
  281. vstEffect.version = JucePlugin_VSTChunkStructureVersion;
  282. #else
  283. vstEffect.version = JucePlugin_VersionCode;
  284. #endif
  285. vstEffect.processReplacing = (Vst2::AEffectProcessProc) processReplacingCB;
  286. vstEffect.processDoubleReplacing = (Vst2::AEffectProcessDoubleProc) processDoubleReplacingCB;
  287. vstEffect.flags |= Vst2::effFlagsHasEditor;
  288. vstEffect.flags |= Vst2::effFlagsCanReplacing;
  289. if (processor->supportsDoublePrecisionProcessing())
  290. vstEffect.flags |= Vst2::effFlagsCanDoubleReplacing;
  291. vstEffect.flags |= Vst2::effFlagsProgramChunks;
  292. #if JucePlugin_IsSynth
  293. vstEffect.flags |= Vst2::effFlagsIsSynth;
  294. #else
  295. if (processor->getTailLengthSeconds() == 0.0)
  296. vstEffect.flags |= Vst2::effFlagsNoSoundInStop;
  297. #endif
  298. activePlugins.add (this);
  299. }
  300. ~JuceVSTWrapper() override
  301. {
  302. JUCE_AUTORELEASEPOOL
  303. {
  304. {
  305. #if JUCE_LINUX
  306. MessageManagerLock mmLock;
  307. #endif
  308. stopTimer();
  309. deleteEditor (false);
  310. hasShutdown = true;
  311. delete processor;
  312. processor = nullptr;
  313. jassert (editorComp == nullptr);
  314. deleteTempChannels();
  315. jassert (activePlugins.contains (this));
  316. activePlugins.removeFirstMatchingValue (this);
  317. }
  318. if (activePlugins.size() == 0)
  319. {
  320. #if JUCE_LINUX
  321. SharedMessageThread::deleteInstance();
  322. #endif
  323. shutdownJuce_GUI();
  324. #if JUCE_WINDOWS
  325. messageThreadIsDefinitelyCorrect = false;
  326. #endif
  327. }
  328. }
  329. }
  330. Vst2::AEffect* getAEffect() noexcept { return &vstEffect; }
  331. template <typename FloatType>
  332. void internalProcessReplacing (FloatType** inputs, FloatType** outputs,
  333. int32 numSamples, VstTempBuffers<FloatType>& tmpBuffers)
  334. {
  335. const bool isMidiEffect = processor->isMidiEffect();
  336. if (firstProcessCallback)
  337. {
  338. firstProcessCallback = false;
  339. // if this fails, the host hasn't called resume() before processing
  340. jassert (isProcessing);
  341. // (tragically, some hosts actually need this, although it's stupid to have
  342. // to do it here..)
  343. if (! isProcessing)
  344. resume();
  345. processor->setNonRealtime (isProcessLevelOffline());
  346. #if JUCE_WINDOWS
  347. if (getHostType().isWavelab())
  348. {
  349. int priority = GetThreadPriority (GetCurrentThread());
  350. if (priority <= THREAD_PRIORITY_NORMAL && priority >= THREAD_PRIORITY_LOWEST)
  351. processor->setNonRealtime (true);
  352. }
  353. #endif
  354. }
  355. #if JUCE_DEBUG && ! (JucePlugin_ProducesMidiOutput || JucePlugin_IsMidiEffect)
  356. const int numMidiEventsComingIn = midiEvents.getNumEvents();
  357. #endif
  358. jassert (activePlugins.contains (this));
  359. {
  360. const int numIn = processor->getTotalNumInputChannels();
  361. const int numOut = processor->getTotalNumOutputChannels();
  362. const ScopedLock sl (processor->getCallbackLock());
  363. if (processor->isSuspended())
  364. {
  365. for (int i = 0; i < numOut; ++i)
  366. if (outputs[i] != nullptr)
  367. FloatVectorOperations::clear (outputs[i], numSamples);
  368. }
  369. else
  370. {
  371. int i;
  372. for (i = 0; i < numOut; ++i)
  373. {
  374. auto* chan = tmpBuffers.tempChannels.getUnchecked(i);
  375. if (chan == nullptr)
  376. {
  377. chan = outputs[i];
  378. bool bufferPointerReusedForOtherChannels = false;
  379. for (int j = i; --j >= 0;)
  380. {
  381. if (outputs[j] == chan)
  382. {
  383. bufferPointerReusedForOtherChannels = true;
  384. break;
  385. }
  386. }
  387. // if some output channels are disabled, some hosts supply the same buffer
  388. // for multiple channels or supply a nullptr - this buggers up our method
  389. // of copying the inputs over the outputs, so we need to create unique temp
  390. // buffers in this case..
  391. if (bufferPointerReusedForOtherChannels || chan == nullptr)
  392. {
  393. chan = new FloatType [(size_t) blockSize * 2];
  394. tmpBuffers.tempChannels.set (i, chan);
  395. }
  396. }
  397. if (i < numIn)
  398. {
  399. if (chan != inputs[i])
  400. memcpy (chan, inputs[i], (size_t) numSamples * sizeof (FloatType));
  401. }
  402. else
  403. {
  404. FloatVectorOperations::clear (chan, numSamples);
  405. }
  406. tmpBuffers.channels[i] = chan;
  407. }
  408. for (; i < numIn; ++i)
  409. tmpBuffers.channels[i] = inputs[i];
  410. {
  411. const int numChannels = jmax (numIn, numOut);
  412. AudioBuffer<FloatType> chans (tmpBuffers.channels, isMidiEffect ? 0 : numChannels, numSamples);
  413. if (isBypassed)
  414. processor->processBlockBypassed (chans, midiEvents);
  415. else
  416. processor->processBlock (chans, midiEvents);
  417. }
  418. // copy back any temp channels that may have been used..
  419. for (i = 0; i < numOut; ++i)
  420. if (auto* chan = tmpBuffers.tempChannels.getUnchecked(i))
  421. if (auto* dest = outputs[i])
  422. memcpy (dest, chan, (size_t) numSamples * sizeof (FloatType));
  423. }
  424. }
  425. if (! midiEvents.isEmpty())
  426. {
  427. #if JucePlugin_ProducesMidiOutput || JucePlugin_IsMidiEffect
  428. auto numEvents = midiEvents.getNumEvents();
  429. outgoingEvents.ensureSize (numEvents);
  430. outgoingEvents.clear();
  431. const uint8* midiEventData;
  432. int midiEventSize, midiEventPosition;
  433. MidiBuffer::Iterator i (midiEvents);
  434. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  435. {
  436. jassert (midiEventPosition >= 0 && midiEventPosition < numSamples);
  437. outgoingEvents.addEvent (midiEventData, midiEventSize, midiEventPosition);
  438. }
  439. // Send VST events to the host.
  440. if (hostCallback != nullptr)
  441. hostCallback (&vstEffect, Vst2::audioMasterProcessEvents, 0, 0, outgoingEvents.events, 0);
  442. #elif JUCE_DEBUG
  443. /* This assertion is caused when you've added some events to the
  444. midiMessages array in your processBlock() method, which usually means
  445. that you're trying to send them somewhere. But in this case they're
  446. getting thrown away.
  447. If your plugin does want to send midi messages, you'll need to set
  448. the JucePlugin_ProducesMidiOutput macro to 1 in your
  449. JucePluginCharacteristics.h file.
  450. If you don't want to produce any midi output, then you should clear the
  451. midiMessages array at the end of your processBlock() method, to
  452. indicate that you don't want any of the events to be passed through
  453. to the output.
  454. */
  455. jassert (midiEvents.getNumEvents() <= numMidiEventsComingIn);
  456. #endif
  457. midiEvents.clear();
  458. }
  459. }
  460. void processReplacing (float** inputs, float** outputs, int32 sampleFrames)
  461. {
  462. jassert (! processor->isUsingDoublePrecision());
  463. internalProcessReplacing (inputs, outputs, sampleFrames, floatTempBuffers);
  464. }
  465. static void processReplacingCB (Vst2::AEffect* vstInterface, float** inputs, float** outputs, int32 sampleFrames)
  466. {
  467. getWrapper (vstInterface)->processReplacing (inputs, outputs, sampleFrames);
  468. }
  469. void processDoubleReplacing (double** inputs, double** outputs, int32 sampleFrames)
  470. {
  471. jassert (processor->isUsingDoublePrecision());
  472. internalProcessReplacing (inputs, outputs, sampleFrames, doubleTempBuffers);
  473. }
  474. static void processDoubleReplacingCB (Vst2::AEffect* vstInterface, double** inputs, double** outputs, int32 sampleFrames)
  475. {
  476. getWrapper (vstInterface)->processDoubleReplacing (inputs, outputs, sampleFrames);
  477. }
  478. //==============================================================================
  479. void resume()
  480. {
  481. if (processor != nullptr)
  482. {
  483. isProcessing = true;
  484. auto numInAndOutChannels = static_cast<size_t> (vstEffect.numInputs + vstEffect.numOutputs);
  485. floatTempBuffers .channels.calloc (numInAndOutChannels);
  486. doubleTempBuffers.channels.calloc (numInAndOutChannels);
  487. auto currentRate = sampleRate;
  488. auto currentBlockSize = blockSize;
  489. firstProcessCallback = true;
  490. processor->setNonRealtime (isProcessLevelOffline());
  491. processor->setRateAndBufferSizeDetails (currentRate, currentBlockSize);
  492. deleteTempChannels();
  493. processor->prepareToPlay (currentRate, currentBlockSize);
  494. midiEvents.ensureSize (2048);
  495. midiEvents.clear();
  496. vstEffect.initialDelay = processor->getLatencySamples();
  497. /** If this plug-in is a synth or it can receive midi events we need to tell the
  498. host that we want midi. In the SDK this method is marked as deprecated, but
  499. some hosts rely on this behaviour.
  500. */
  501. if (vstEffect.flags & Vst2::effFlagsIsSynth || JucePlugin_WantsMidiInput || JucePlugin_IsMidiEffect)
  502. {
  503. if (hostCallback != nullptr)
  504. hostCallback (&vstEffect, Vst2::audioMasterWantMidi, 0, 1, nullptr, 0);
  505. }
  506. if (getHostType().isAbletonLive()
  507. && hostCallback != nullptr
  508. && processor->getTailLengthSeconds() == std::numeric_limits<double>::infinity())
  509. {
  510. AbletonLiveHostSpecific hostCmd;
  511. hostCmd.magic = 0x41624c69; // 'AbLi'
  512. hostCmd.cmd = 5;
  513. hostCmd.commandSize = sizeof (int);
  514. hostCmd.flags = AbletonLiveHostSpecific::KCantBeSuspended;
  515. hostCallback (&vstEffect, Vst2::audioMasterVendorSpecific, 0, 0, &hostCmd, 0.0f);
  516. }
  517. #if JucePlugin_ProducesMidiOutput || JucePlugin_IsMidiEffect
  518. outgoingEvents.ensureSize (512);
  519. #endif
  520. }
  521. }
  522. void suspend()
  523. {
  524. if (processor != nullptr)
  525. {
  526. processor->releaseResources();
  527. outgoingEvents.freeEvents();
  528. isProcessing = false;
  529. floatTempBuffers.channels.free();
  530. doubleTempBuffers.channels.free();
  531. deleteTempChannels();
  532. }
  533. }
  534. //==============================================================================
  535. bool getCurrentPosition (AudioPlayHead::CurrentPositionInfo& info) override
  536. {
  537. const Vst2::VstTimeInfo* ti = nullptr;
  538. if (hostCallback != nullptr)
  539. {
  540. int32 flags = Vst2::kVstPpqPosValid | Vst2::kVstTempoValid
  541. | Vst2::kVstBarsValid | Vst2::kVstCyclePosValid
  542. | Vst2::kVstTimeSigValid | Vst2::kVstSmpteValid
  543. | Vst2::kVstClockValid;
  544. auto result = hostCallback (&vstEffect, Vst2::audioMasterGetTime, 0, flags, nullptr, 0);
  545. ti = reinterpret_cast<Vst2::VstTimeInfo*> (result);
  546. }
  547. if (ti == nullptr || ti->sampleRate <= 0)
  548. return false;
  549. info.bpm = (ti->flags & Vst2::kVstTempoValid) != 0 ? ti->tempo : 0.0;
  550. if ((ti->flags & Vst2::kVstTimeSigValid) != 0)
  551. {
  552. info.timeSigNumerator = ti->timeSigNumerator;
  553. info.timeSigDenominator = ti->timeSigDenominator;
  554. }
  555. else
  556. {
  557. info.timeSigNumerator = 4;
  558. info.timeSigDenominator = 4;
  559. }
  560. info.timeInSamples = (int64) (ti->samplePos + 0.5);
  561. info.timeInSeconds = ti->samplePos / ti->sampleRate;
  562. info.ppqPosition = (ti->flags & Vst2::kVstPpqPosValid) != 0 ? ti->ppqPos : 0.0;
  563. info.ppqPositionOfLastBarStart = (ti->flags & Vst2::kVstBarsValid) != 0 ? ti->barStartPos : 0.0;
  564. if ((ti->flags & Vst2::kVstSmpteValid) != 0)
  565. {
  566. AudioPlayHead::FrameRateType rate = AudioPlayHead::fpsUnknown;
  567. double fps = 1.0;
  568. switch (ti->smpteFrameRate)
  569. {
  570. case Vst2::kVstSmpte239fps: rate = AudioPlayHead::fps23976; fps = 24.0 * 1000.0 / 1001.0; break;
  571. case Vst2::kVstSmpte24fps: rate = AudioPlayHead::fps24; fps = 24.0; break;
  572. case Vst2::kVstSmpte25fps: rate = AudioPlayHead::fps25; fps = 25.0; break;
  573. case Vst2::kVstSmpte2997fps: rate = AudioPlayHead::fps2997; fps = 30.0 * 1000.0 / 1001.0; break;
  574. case Vst2::kVstSmpte30fps: rate = AudioPlayHead::fps30; fps = 30.0; break;
  575. case Vst2::kVstSmpte2997dfps: rate = AudioPlayHead::fps2997drop; fps = 30.0 * 1000.0 / 1001.0; break;
  576. case Vst2::kVstSmpte30dfps: rate = AudioPlayHead::fps30drop; fps = 30.0; break;
  577. case Vst2::kVstSmpteFilm16mm:
  578. case Vst2::kVstSmpteFilm35mm: fps = 24.0; break;
  579. case Vst2::kVstSmpte249fps: fps = 25.0 * 1000.0 / 1001.0; break;
  580. case Vst2::kVstSmpte599fps: fps = 60.0 * 1000.0 / 1001.0; break;
  581. case Vst2::kVstSmpte60fps: fps = 60; break;
  582. default: jassertfalse; // unknown frame-rate..
  583. }
  584. info.frameRate = rate;
  585. info.editOriginTime = ti->smpteOffset / (80.0 * fps);
  586. }
  587. else
  588. {
  589. info.frameRate = AudioPlayHead::fpsUnknown;
  590. info.editOriginTime = 0;
  591. }
  592. info.isRecording = (ti->flags & Vst2::kVstTransportRecording) != 0;
  593. info.isPlaying = (ti->flags & (Vst2::kVstTransportRecording | Vst2::kVstTransportPlaying)) != 0;
  594. info.isLooping = (ti->flags & Vst2::kVstTransportCycleActive) != 0;
  595. if ((ti->flags & Vst2::kVstCyclePosValid) != 0)
  596. {
  597. info.ppqLoopStart = ti->cycleStartPos;
  598. info.ppqLoopEnd = ti->cycleEndPos;
  599. }
  600. else
  601. {
  602. info.ppqLoopStart = 0;
  603. info.ppqLoopEnd = 0;
  604. }
  605. return true;
  606. }
  607. //==============================================================================
  608. float getParameter (int32 index) const
  609. {
  610. if (auto* param = juceParameters.getParamForIndex (index))
  611. return param->getValue();
  612. return 0.0f;
  613. }
  614. static float getParameterCB (Vst2::AEffect* vstInterface, int32 index)
  615. {
  616. return getWrapper (vstInterface)->getParameter (index);
  617. }
  618. void setParameter (int32 index, float value)
  619. {
  620. if (auto* param = juceParameters.getParamForIndex (index))
  621. {
  622. param->setValue (value);
  623. inParameterChangedCallback = true;
  624. param->sendValueChangedMessageToListeners (value);
  625. }
  626. }
  627. static void setParameterCB (Vst2::AEffect* vstInterface, int32 index, float value)
  628. {
  629. getWrapper (vstInterface)->setParameter (index, value);
  630. }
  631. void audioProcessorParameterChanged (AudioProcessor*, int index, float newValue) override
  632. {
  633. if (inParameterChangedCallback.get())
  634. {
  635. inParameterChangedCallback = false;
  636. return;
  637. }
  638. if (hostCallback != nullptr)
  639. hostCallback (&vstEffect, Vst2::audioMasterAutomate, index, 0, nullptr, newValue);
  640. }
  641. void audioProcessorParameterChangeGestureBegin (AudioProcessor*, int index) override
  642. {
  643. if (hostCallback != nullptr)
  644. hostCallback (&vstEffect, Vst2::audioMasterBeginEdit, index, 0, nullptr, 0);
  645. }
  646. void audioProcessorParameterChangeGestureEnd (AudioProcessor*, int index) override
  647. {
  648. if (hostCallback != nullptr)
  649. hostCallback (&vstEffect, Vst2::audioMasterEndEdit, index, 0, nullptr, 0);
  650. }
  651. void parameterValueChanged (int, float newValue) override
  652. {
  653. // this can only come from the bypass parameter
  654. isBypassed = (newValue != 0.0f);
  655. }
  656. void parameterGestureChanged (int, bool) override {}
  657. void audioProcessorChanged (AudioProcessor*) override
  658. {
  659. vstEffect.initialDelay = processor->getLatencySamples();
  660. triggerAsyncUpdate();
  661. }
  662. void handleAsyncUpdate() override
  663. {
  664. if (hostCallback != nullptr)
  665. {
  666. hostCallback (&vstEffect, Vst2::audioMasterUpdateDisplay, 0, 0, nullptr, 0);
  667. hostCallback (&vstEffect, Vst2::audioMasterIOChanged, 0, 0, nullptr, 0);
  668. }
  669. }
  670. bool getPinProperties (Vst2::VstPinProperties& properties, bool direction, int index) const
  671. {
  672. if (processor->isMidiEffect())
  673. return false;
  674. int channelIdx, busIdx;
  675. // fill with default
  676. properties.flags = 0;
  677. properties.label[0] = 0;
  678. properties.shortLabel[0] = 0;
  679. properties.arrangementType = Vst2::kSpeakerArrEmpty;
  680. if ((channelIdx = processor->getOffsetInBusBufferForAbsoluteChannelIndex (direction, index, busIdx)) >= 0)
  681. {
  682. auto& bus = *processor->getBus (direction, busIdx);
  683. auto& channelSet = bus.getCurrentLayout();
  684. auto channelType = channelSet.getTypeOfChannel (channelIdx);
  685. properties.flags = Vst2::kVstPinIsActive | Vst2::kVstPinUseSpeaker;
  686. properties.arrangementType = SpeakerMappings::channelSetToVstArrangementType (channelSet);
  687. String label = bus.getName();
  688. #ifdef JucePlugin_PreferredChannelConfigurations
  689. label += " " + String (channelIdx);
  690. #else
  691. if (channelSet.size() > 1)
  692. label += " " + AudioChannelSet::getAbbreviatedChannelTypeName (channelType);
  693. #endif
  694. label.copyToUTF8 (properties.label, (size_t) (Vst2::kVstMaxLabelLen + 1));
  695. label.copyToUTF8 (properties.shortLabel, (size_t) (Vst2::kVstMaxShortLabelLen + 1));
  696. if (channelType == AudioChannelSet::left
  697. || channelType == AudioChannelSet::leftSurround
  698. || channelType == AudioChannelSet::leftCentre
  699. || channelType == AudioChannelSet::leftSurroundSide
  700. || channelType == AudioChannelSet::topFrontLeft
  701. || channelType == AudioChannelSet::topRearLeft
  702. || channelType == AudioChannelSet::leftSurroundRear
  703. || channelType == AudioChannelSet::wideLeft)
  704. properties.flags |= Vst2::kVstPinIsStereo;
  705. return true;
  706. }
  707. return false;
  708. }
  709. //==============================================================================
  710. struct SpeakerMappings : private AudioChannelSet // (inheritance only to give easier access to items in the namespace)
  711. {
  712. struct Mapping
  713. {
  714. int32 vst2;
  715. ChannelType channels[13];
  716. bool matches (const Array<ChannelType>& chans) const noexcept
  717. {
  718. const int n = sizeof (channels) / sizeof (ChannelType);
  719. for (int i = 0; i < n; ++i)
  720. {
  721. if (channels[i] == unknown) return (i == chans.size());
  722. if (i == chans.size()) return (channels[i] == unknown);
  723. if (channels[i] != chans.getUnchecked(i))
  724. return false;
  725. }
  726. return true;
  727. }
  728. };
  729. static AudioChannelSet vstArrangementTypeToChannelSet (const Vst2::VstSpeakerArrangement& arr)
  730. {
  731. if (arr.type == Vst2::kSpeakerArrEmpty) return AudioChannelSet::disabled();
  732. if (arr.type == Vst2::kSpeakerArrMono) return AudioChannelSet::mono();
  733. if (arr.type == Vst2::kSpeakerArrStereo) return AudioChannelSet::stereo();
  734. if (arr.type == Vst2::kSpeakerArr30Cine) return AudioChannelSet::createLCR();
  735. if (arr.type == Vst2::kSpeakerArr30Music) return AudioChannelSet::createLRS();
  736. if (arr.type == Vst2::kSpeakerArr40Cine) return AudioChannelSet::createLCRS();
  737. if (arr.type == Vst2::kSpeakerArr50) return AudioChannelSet::create5point0();
  738. if (arr.type == Vst2::kSpeakerArr51) return AudioChannelSet::create5point1();
  739. if (arr.type == Vst2::kSpeakerArr60Cine) return AudioChannelSet::create6point0();
  740. if (arr.type == Vst2::kSpeakerArr61Cine) return AudioChannelSet::create6point1();
  741. if (arr.type == Vst2::kSpeakerArr60Music) return AudioChannelSet::create6point0Music();
  742. if (arr.type == Vst2::kSpeakerArr61Music) return AudioChannelSet::create6point1Music();
  743. if (arr.type == Vst2::kSpeakerArr70Music) return AudioChannelSet::create7point0();
  744. if (arr.type == Vst2::kSpeakerArr70Cine) return AudioChannelSet::create7point0SDDS();
  745. if (arr.type == Vst2::kSpeakerArr71Music) return AudioChannelSet::create7point1();
  746. if (arr.type == Vst2::kSpeakerArr71Cine) return AudioChannelSet::create7point1SDDS();
  747. if (arr.type == Vst2::kSpeakerArr40Music) return AudioChannelSet::quadraphonic();
  748. for (auto* m = getMappings(); m->vst2 != Vst2::kSpeakerArrEmpty; ++m)
  749. {
  750. if (m->vst2 == arr.type)
  751. {
  752. AudioChannelSet s;
  753. for (int i = 0; m->channels[i] != 0; ++i)
  754. s.addChannel (m->channels[i]);
  755. return s;
  756. }
  757. }
  758. return AudioChannelSet::discreteChannels (arr.numChannels);
  759. }
  760. static int32 channelSetToVstArrangementType (AudioChannelSet channels)
  761. {
  762. if (channels == AudioChannelSet::disabled()) return Vst2::kSpeakerArrEmpty;
  763. if (channels == AudioChannelSet::mono()) return Vst2::kSpeakerArrMono;
  764. if (channels == AudioChannelSet::stereo()) return Vst2::kSpeakerArrStereo;
  765. if (channels == AudioChannelSet::createLCR()) return Vst2::kSpeakerArr30Cine;
  766. if (channels == AudioChannelSet::createLRS()) return Vst2::kSpeakerArr30Music;
  767. if (channels == AudioChannelSet::createLCRS()) return Vst2::kSpeakerArr40Cine;
  768. if (channels == AudioChannelSet::create5point0()) return Vst2::kSpeakerArr50;
  769. if (channels == AudioChannelSet::create5point1()) return Vst2::kSpeakerArr51;
  770. if (channels == AudioChannelSet::create6point0()) return Vst2::kSpeakerArr60Cine;
  771. if (channels == AudioChannelSet::create6point1()) return Vst2::kSpeakerArr61Cine;
  772. if (channels == AudioChannelSet::create6point0Music()) return Vst2::kSpeakerArr60Music;
  773. if (channels == AudioChannelSet::create6point1Music()) return Vst2::kSpeakerArr61Music;
  774. if (channels == AudioChannelSet::create7point0()) return Vst2::kSpeakerArr70Music;
  775. if (channels == AudioChannelSet::create7point0SDDS()) return Vst2::kSpeakerArr70Cine;
  776. if (channels == AudioChannelSet::create7point1()) return Vst2::kSpeakerArr71Music;
  777. if (channels == AudioChannelSet::create7point1SDDS()) return Vst2::kSpeakerArr71Cine;
  778. if (channels == AudioChannelSet::quadraphonic()) return Vst2::kSpeakerArr40Music;
  779. if (channels == AudioChannelSet::disabled())
  780. return Vst2::kSpeakerArrEmpty;
  781. auto chans = channels.getChannelTypes();
  782. for (auto* m = getMappings(); m->vst2 != Vst2::kSpeakerArrEmpty; ++m)
  783. if (m->matches (chans))
  784. return m->vst2;
  785. return Vst2::kSpeakerArrUserDefined;
  786. }
  787. static void channelSetToVstArrangement (const AudioChannelSet& channels, Vst2::VstSpeakerArrangement& result)
  788. {
  789. result.type = channelSetToVstArrangementType (channels);
  790. result.numChannels = channels.size();
  791. for (int i = 0; i < result.numChannels; ++i)
  792. {
  793. auto& speaker = result.speakers[i];
  794. zeromem (&speaker, sizeof (Vst2::VstSpeakerProperties));
  795. speaker.type = getSpeakerType (channels.getTypeOfChannel (i));
  796. }
  797. }
  798. static const Mapping* getMappings() noexcept
  799. {
  800. static const Mapping mappings[] =
  801. {
  802. { Vst2::kSpeakerArrMono, { centre, unknown } },
  803. { Vst2::kSpeakerArrStereo, { left, right, unknown } },
  804. { Vst2::kSpeakerArrStereoSurround, { leftSurround, rightSurround, unknown } },
  805. { Vst2::kSpeakerArrStereoCenter, { leftCentre, rightCentre, unknown } },
  806. { Vst2::kSpeakerArrStereoSide, { leftSurroundRear, rightSurroundRear, unknown } },
  807. { Vst2::kSpeakerArrStereoCLfe, { centre, LFE, unknown } },
  808. { Vst2::kSpeakerArr30Cine, { left, right, centre, unknown } },
  809. { Vst2::kSpeakerArr30Music, { left, right, surround, unknown } },
  810. { Vst2::kSpeakerArr31Cine, { left, right, centre, LFE, unknown } },
  811. { Vst2::kSpeakerArr31Music, { left, right, LFE, surround, unknown } },
  812. { Vst2::kSpeakerArr40Cine, { left, right, centre, surround, unknown } },
  813. { Vst2::kSpeakerArr40Music, { left, right, leftSurround, rightSurround, unknown } },
  814. { Vst2::kSpeakerArr41Cine, { left, right, centre, LFE, surround, unknown } },
  815. { Vst2::kSpeakerArr41Music, { left, right, LFE, leftSurround, rightSurround, unknown } },
  816. { Vst2::kSpeakerArr50, { left, right, centre, leftSurround, rightSurround, unknown } },
  817. { Vst2::kSpeakerArr51, { left, right, centre, LFE, leftSurround, rightSurround, unknown } },
  818. { Vst2::kSpeakerArr60Cine, { left, right, centre, leftSurround, rightSurround, surround, unknown } },
  819. { Vst2::kSpeakerArr60Music, { left, right, leftSurround, rightSurround, leftSurroundRear, rightSurroundRear, unknown } },
  820. { Vst2::kSpeakerArr61Cine, { left, right, centre, LFE, leftSurround, rightSurround, surround, unknown } },
  821. { Vst2::kSpeakerArr61Music, { left, right, LFE, leftSurround, rightSurround, leftSurroundRear, rightSurroundRear, unknown } },
  822. { Vst2::kSpeakerArr70Cine, { left, right, centre, leftSurround, rightSurround, topFrontLeft, topFrontRight, unknown } },
  823. { Vst2::kSpeakerArr70Music, { left, right, centre, leftSurround, rightSurround, leftSurroundRear, rightSurroundRear, unknown } },
  824. { Vst2::kSpeakerArr71Cine, { left, right, centre, LFE, leftSurround, rightSurround, topFrontLeft, topFrontRight, unknown } },
  825. { Vst2::kSpeakerArr71Music, { left, right, centre, LFE, leftSurround, rightSurround, leftSurroundRear, rightSurroundRear, unknown } },
  826. { Vst2::kSpeakerArr80Cine, { left, right, centre, leftSurround, rightSurround, topFrontLeft, topFrontRight, surround, unknown } },
  827. { Vst2::kSpeakerArr80Music, { left, right, centre, leftSurround, rightSurround, surround, leftSurroundRear, rightSurroundRear, unknown } },
  828. { Vst2::kSpeakerArr81Cine, { left, right, centre, LFE, leftSurround, rightSurround, topFrontLeft, topFrontRight, surround, unknown } },
  829. { Vst2::kSpeakerArr81Music, { left, right, centre, LFE, leftSurround, rightSurround, surround, leftSurroundRear, rightSurroundRear, unknown } },
  830. { Vst2::kSpeakerArr102, { left, right, centre, LFE, leftSurround, rightSurround, topFrontLeft, topFrontCentre, topFrontRight, topRearLeft, topRearRight, LFE2, unknown } },
  831. { Vst2::kSpeakerArrEmpty, { unknown } }
  832. };
  833. return mappings;
  834. }
  835. static inline int32 getSpeakerType (AudioChannelSet::ChannelType type) noexcept
  836. {
  837. switch (type)
  838. {
  839. case AudioChannelSet::left: return Vst2::kSpeakerL;
  840. case AudioChannelSet::right: return Vst2::kSpeakerR;
  841. case AudioChannelSet::centre: return Vst2::kSpeakerC;
  842. case AudioChannelSet::LFE: return Vst2::kSpeakerLfe;
  843. case AudioChannelSet::leftSurround: return Vst2::kSpeakerLs;
  844. case AudioChannelSet::rightSurround: return Vst2::kSpeakerRs;
  845. case AudioChannelSet::leftCentre: return Vst2::kSpeakerLc;
  846. case AudioChannelSet::rightCentre: return Vst2::kSpeakerRc;
  847. case AudioChannelSet::surround: return Vst2::kSpeakerS;
  848. case AudioChannelSet::leftSurroundRear: return Vst2::kSpeakerSl;
  849. case AudioChannelSet::rightSurroundRear: return Vst2::kSpeakerSr;
  850. case AudioChannelSet::topMiddle: return Vst2::kSpeakerTm;
  851. case AudioChannelSet::topFrontLeft: return Vst2::kSpeakerTfl;
  852. case AudioChannelSet::topFrontCentre: return Vst2::kSpeakerTfc;
  853. case AudioChannelSet::topFrontRight: return Vst2::kSpeakerTfr;
  854. case AudioChannelSet::topRearLeft: return Vst2::kSpeakerTrl;
  855. case AudioChannelSet::topRearCentre: return Vst2::kSpeakerTrc;
  856. case AudioChannelSet::topRearRight: return Vst2::kSpeakerTrr;
  857. case AudioChannelSet::LFE2: return Vst2::kSpeakerLfe2;
  858. default: break;
  859. }
  860. return 0;
  861. }
  862. static inline AudioChannelSet::ChannelType getChannelType (int32 type) noexcept
  863. {
  864. switch (type)
  865. {
  866. case Vst2::kSpeakerL: return AudioChannelSet::left;
  867. case Vst2::kSpeakerR: return AudioChannelSet::right;
  868. case Vst2::kSpeakerC: return AudioChannelSet::centre;
  869. case Vst2::kSpeakerLfe: return AudioChannelSet::LFE;
  870. case Vst2::kSpeakerLs: return AudioChannelSet::leftSurround;
  871. case Vst2::kSpeakerRs: return AudioChannelSet::rightSurround;
  872. case Vst2::kSpeakerLc: return AudioChannelSet::leftCentre;
  873. case Vst2::kSpeakerRc: return AudioChannelSet::rightCentre;
  874. case Vst2::kSpeakerS: return AudioChannelSet::surround;
  875. case Vst2::kSpeakerSl: return AudioChannelSet::leftSurroundRear;
  876. case Vst2::kSpeakerSr: return AudioChannelSet::rightSurroundRear;
  877. case Vst2::kSpeakerTm: return AudioChannelSet::topMiddle;
  878. case Vst2::kSpeakerTfl: return AudioChannelSet::topFrontLeft;
  879. case Vst2::kSpeakerTfc: return AudioChannelSet::topFrontCentre;
  880. case Vst2::kSpeakerTfr: return AudioChannelSet::topFrontRight;
  881. case Vst2::kSpeakerTrl: return AudioChannelSet::topRearLeft;
  882. case Vst2::kSpeakerTrc: return AudioChannelSet::topRearCentre;
  883. case Vst2::kSpeakerTrr: return AudioChannelSet::topRearRight;
  884. case Vst2::kSpeakerLfe2: return AudioChannelSet::LFE2;
  885. default: break;
  886. }
  887. return AudioChannelSet::unknown;
  888. }
  889. };
  890. void timerCallback() override
  891. {
  892. if (shouldDeleteEditor)
  893. {
  894. shouldDeleteEditor = false;
  895. deleteEditor (true);
  896. }
  897. {
  898. ScopedLock lock (stateInformationLock);
  899. if (chunkMemoryTime > 0
  900. && chunkMemoryTime < juce::Time::getApproximateMillisecondCounter() - 2000
  901. && ! recursionCheck)
  902. {
  903. chunkMemory.reset();
  904. chunkMemoryTime = 0;
  905. }
  906. }
  907. if (editorComp != nullptr)
  908. editorComp->checkVisibility();
  909. }
  910. void setHasEditorFlag (bool shouldSetHasEditor)
  911. {
  912. auto hasEditor = (vstEffect.flags & Vst2::effFlagsHasEditor) != 0;
  913. if (shouldSetHasEditor == hasEditor)
  914. return;
  915. if (shouldSetHasEditor)
  916. vstEffect.flags |= Vst2::effFlagsHasEditor;
  917. else
  918. vstEffect.flags &= ~Vst2::effFlagsHasEditor;
  919. }
  920. void createEditorComp()
  921. {
  922. if (hasShutdown || processor == nullptr)
  923. return;
  924. if (editorComp == nullptr)
  925. {
  926. if (auto* ed = processor->createEditorIfNeeded())
  927. {
  928. setHasEditorFlag (true);
  929. editorComp.reset (new EditorCompWrapper (*this, *ed));
  930. }
  931. else
  932. {
  933. setHasEditorFlag (false);
  934. }
  935. }
  936. shouldDeleteEditor = false;
  937. }
  938. void deleteEditor (bool canDeleteLaterIfModal)
  939. {
  940. JUCE_AUTORELEASEPOOL
  941. {
  942. PopupMenu::dismissAllActiveMenus();
  943. jassert (! recursionCheck);
  944. ScopedValueSetter<bool> svs (recursionCheck, true, false);
  945. if (editorComp != nullptr)
  946. {
  947. if (auto* modalComponent = Component::getCurrentlyModalComponent())
  948. {
  949. modalComponent->exitModalState (0);
  950. if (canDeleteLaterIfModal)
  951. {
  952. shouldDeleteEditor = true;
  953. return;
  954. }
  955. }
  956. editorComp->detachHostWindow();
  957. if (auto* ed = editorComp->getEditorComp())
  958. processor->editorBeingDeleted (ed);
  959. editorComp = nullptr;
  960. // there's some kind of component currently modal, but the host
  961. // is trying to delete our plugin. You should try to avoid this happening..
  962. jassert (Component::getCurrentlyModalComponent() == nullptr);
  963. }
  964. }
  965. }
  966. pointer_sized_int dispatcher (int32 opCode, VstOpCodeArguments args)
  967. {
  968. if (hasShutdown)
  969. return 0;
  970. switch (opCode)
  971. {
  972. case Vst2::effOpen: return handleOpen (args);
  973. case Vst2::effClose: return handleClose (args);
  974. case Vst2::effSetProgram: return handleSetCurrentProgram (args);
  975. case Vst2::effGetProgram: return handleGetCurrentProgram (args);
  976. case Vst2::effSetProgramName: return handleSetCurrentProgramName (args);
  977. case Vst2::effGetProgramName: return handleGetCurrentProgramName (args);
  978. case Vst2::effGetParamLabel: return handleGetParameterLabel (args);
  979. case Vst2::effGetParamDisplay: return handleGetParameterText (args);
  980. case Vst2::effGetParamName: return handleGetParameterName (args);
  981. case Vst2::effSetSampleRate: return handleSetSampleRate (args);
  982. case Vst2::effSetBlockSize: return handleSetBlockSize (args);
  983. case Vst2::effMainsChanged: return handleResumeSuspend (args);
  984. case Vst2::effEditGetRect: return handleGetEditorBounds (args);
  985. case Vst2::effEditOpen: return handleOpenEditor (args);
  986. case Vst2::effEditClose: return handleCloseEditor (args);
  987. case Vst2::effIdentify: return (pointer_sized_int) ByteOrder::bigEndianInt ("NvEf");
  988. case Vst2::effGetChunk: return handleGetData (args);
  989. case Vst2::effSetChunk: return handleSetData (args);
  990. case Vst2::effProcessEvents: return handlePreAudioProcessingEvents (args);
  991. case Vst2::effCanBeAutomated: return handleIsParameterAutomatable (args);
  992. case Vst2::effString2Parameter: return handleParameterValueForText (args);
  993. case Vst2::effGetProgramNameIndexed: return handleGetProgramName (args);
  994. case Vst2::effGetInputProperties: return handleGetInputPinProperties (args);
  995. case Vst2::effGetOutputProperties: return handleGetOutputPinProperties (args);
  996. case Vst2::effGetPlugCategory: return handleGetPlugInCategory (args);
  997. case Vst2::effSetSpeakerArrangement: return handleSetSpeakerConfiguration (args);
  998. case Vst2::effSetBypass: return handleSetBypass (args);
  999. case Vst2::effGetEffectName: return handleGetPlugInName (args);
  1000. case Vst2::effGetProductString: return handleGetPlugInName (args);
  1001. case Vst2::effGetVendorString: return handleGetManufacturerName (args);
  1002. case Vst2::effGetVendorVersion: return handleGetManufacturerVersion (args);
  1003. case Vst2::effVendorSpecific: return handleManufacturerSpecific (args);
  1004. case Vst2::effCanDo: return handleCanPlugInDo (args);
  1005. case Vst2::effGetTailSize: return handleGetTailSize (args);
  1006. case Vst2::effKeysRequired: return handleKeyboardFocusRequired (args);
  1007. case Vst2::effGetVstVersion: return handleGetVstInterfaceVersion (args);
  1008. case Vst2::effGetCurrentMidiProgram: return handleGetCurrentMidiProgram (args);
  1009. case Vst2::effGetSpeakerArrangement: return handleGetSpeakerConfiguration (args);
  1010. case Vst2::effSetTotalSampleToProcess: return handleSetNumberOfSamplesToProcess (args);
  1011. case Vst2::effSetProcessPrecision: return handleSetSampleFloatType (args);
  1012. case Vst2::effGetNumMidiInputChannels: return handleGetNumMidiInputChannels();
  1013. case Vst2::effGetNumMidiOutputChannels: return handleGetNumMidiOutputChannels();
  1014. default: return 0;
  1015. }
  1016. }
  1017. static pointer_sized_int dispatcherCB (Vst2::AEffect* vstInterface, int32 opCode, int32 index,
  1018. pointer_sized_int value, void* ptr, float opt)
  1019. {
  1020. auto* wrapper = getWrapper (vstInterface);
  1021. VstOpCodeArguments args = { index, value, ptr, opt };
  1022. if (opCode == Vst2::effClose)
  1023. {
  1024. wrapper->dispatcher (opCode, args);
  1025. delete wrapper;
  1026. return 1;
  1027. }
  1028. return wrapper->dispatcher (opCode, args);
  1029. }
  1030. //==============================================================================
  1031. // A component to hold the AudioProcessorEditor, and cope with some housekeeping
  1032. // chores when it changes or repaints.
  1033. struct EditorCompWrapper : public Component
  1034. #if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE
  1035. , public Timer
  1036. #endif
  1037. {
  1038. EditorCompWrapper (JuceVSTWrapper& w, AudioProcessorEditor& editor)
  1039. : wrapper (w)
  1040. {
  1041. editor.setOpaque (true);
  1042. editor.setVisible (true);
  1043. setOpaque (true);
  1044. setTopLeftPosition (editor.getPosition());
  1045. editor.setTopLeftPosition (0, 0);
  1046. auto b = getLocalArea (&editor, editor.getLocalBounds());
  1047. setSize (b.getWidth(), b.getHeight());
  1048. addAndMakeVisible (editor);
  1049. #if JUCE_WINDOWS
  1050. if (! getHostType().isReceptor())
  1051. addMouseListener (this, true);
  1052. #endif
  1053. ignoreUnused (fakeMouseGenerator);
  1054. #if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE
  1055. startTimer (500);
  1056. #endif
  1057. }
  1058. ~EditorCompWrapper() override
  1059. {
  1060. deleteAllChildren(); // note that we can't use a std::unique_ptr because the editor may
  1061. // have been transferred to another parent which takes over ownership.
  1062. }
  1063. void paint (Graphics&) override {}
  1064. void getEditorBounds (Vst2::ERect& bounds)
  1065. {
  1066. auto b = getSizeToContainChild();
  1067. bounds = convertToHostBounds ({ 0, 0, (int16) b.getHeight(), (int16) b.getWidth() });
  1068. }
  1069. void attachToHost (VstOpCodeArguments args)
  1070. {
  1071. setOpaque (true);
  1072. setVisible (false);
  1073. #if JUCE_WINDOWS
  1074. addToDesktop (0, args.ptr);
  1075. hostWindow = (HWND) args.ptr;
  1076. #elif JUCE_LINUX
  1077. addToDesktop (0, args.ptr);
  1078. hostWindow = (Window) args.ptr;
  1079. XReparentWindow (display.display, (Window) getWindowHandle(), hostWindow, 0, 0);
  1080. #else
  1081. hostWindow = attachComponentToWindowRefVST (this, args.ptr, wrapper.useNSView);
  1082. #endif
  1083. setVisible (true);
  1084. }
  1085. void detachHostWindow()
  1086. {
  1087. #if JUCE_MAC
  1088. if (hostWindow != nullptr)
  1089. {
  1090. detachComponentFromWindowRefVST (this, hostWindow, wrapper.useNSView);
  1091. hostWindow = nullptr;
  1092. }
  1093. #endif
  1094. #if JUCE_LINUX
  1095. hostWindow = {};
  1096. #endif
  1097. }
  1098. void checkVisibility()
  1099. {
  1100. #if JUCE_MAC
  1101. if (hostWindow != nullptr)
  1102. checkWindowVisibilityVST (hostWindow, this, wrapper.useNSView);
  1103. #endif
  1104. }
  1105. AudioProcessorEditor* getEditorComp() const noexcept
  1106. {
  1107. return dynamic_cast<AudioProcessorEditor*> (getChildComponent (0));
  1108. }
  1109. void resized() override
  1110. {
  1111. if (auto* ed = getEditorComp())
  1112. {
  1113. ed->setTopLeftPosition (0, 0);
  1114. if (shouldResizeEditor)
  1115. {
  1116. auto newBounds = getLocalBounds();
  1117. #if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE
  1118. if (! lastBounds.isEmpty() && isWithin (newBounds.toDouble().getAspectRatio(), lastBounds.toDouble().getAspectRatio(), 0.1))
  1119. return;
  1120. lastBounds = newBounds;
  1121. #endif
  1122. ed->setBounds (ed->getLocalArea (this, newBounds));
  1123. }
  1124. updateWindowSize (false);
  1125. }
  1126. #if JUCE_MAC && ! JUCE_64BIT
  1127. if (! wrapper.useNSView)
  1128. updateEditorCompBoundsVST (this);
  1129. #endif
  1130. }
  1131. void childBoundsChanged (Component*) override
  1132. {
  1133. updateWindowSize (false);
  1134. }
  1135. juce::Rectangle<int> getSizeToContainChild()
  1136. {
  1137. if (auto* ed = getEditorComp())
  1138. return getLocalArea (ed, ed->getLocalBounds());
  1139. return {};
  1140. }
  1141. void updateWindowSize (bool resizeEditor)
  1142. {
  1143. if (! isInSizeWindow)
  1144. {
  1145. if (auto* ed = getEditorComp())
  1146. {
  1147. ed->setTopLeftPosition (0, 0);
  1148. auto pos = getSizeToContainChild();
  1149. #if JUCE_MAC
  1150. if (wrapper.useNSView)
  1151. setTopLeftPosition (0, getHeight() - pos.getHeight());
  1152. #endif
  1153. resizeHostWindow (pos.getWidth(), pos.getHeight());
  1154. #if ! JUCE_LINUX // setSize() on linux causes renoise and energyxt to fail.
  1155. if (! resizeEditor) // this is needed to prevent an infinite resizing loop due to coordinate rounding
  1156. shouldResizeEditor = false;
  1157. setSize (pos.getWidth(), pos.getHeight());
  1158. shouldResizeEditor = true;
  1159. #else
  1160. ignoreUnused (resizeEditor);
  1161. auto scale = Desktop::getInstance().getGlobalScaleFactor();
  1162. if (auto* peer = ed->getPeer())
  1163. scale *= (float) peer->getPlatformScaleFactor();
  1164. XResizeWindow (display.display, (Window) getWindowHandle(),
  1165. static_cast<unsigned int> (roundToInt (pos.getWidth() * scale)),
  1166. static_cast<unsigned int> (roundToInt (pos.getHeight() * scale)));
  1167. #endif
  1168. #if JUCE_MAC
  1169. resizeHostWindow (pos.getWidth(), pos.getHeight()); // (doing this a second time seems to be necessary in tracktion)
  1170. #endif
  1171. }
  1172. }
  1173. }
  1174. void resizeHostWindow (int newWidth, int newHeight)
  1175. {
  1176. auto rect = convertToHostBounds ({ 0, 0, (int16) newHeight, (int16) newWidth });
  1177. newWidth = rect.right - rect.left;
  1178. newHeight = rect.bottom - rect.top;
  1179. bool sizeWasSuccessful = false;
  1180. if (auto host = wrapper.hostCallback)
  1181. {
  1182. auto status = host (wrapper.getAEffect(), Vst2::audioMasterCanDo, 0, 0, const_cast<char*> ("sizeWindow"), 0);
  1183. if (status == (pointer_sized_int) 1 || getHostType().isAbletonLive())
  1184. {
  1185. const ScopedValueSetter<bool> inSizeWindowSetter (isInSizeWindow, true);
  1186. sizeWasSuccessful = (host (wrapper.getAEffect(), Vst2::audioMasterSizeWindow,
  1187. newWidth, newHeight, nullptr, 0) != 0);
  1188. }
  1189. }
  1190. if (! sizeWasSuccessful)
  1191. {
  1192. // some hosts don't support the sizeWindow call, so do it manually..
  1193. #if JUCE_MAC
  1194. setNativeHostWindowSizeVST (hostWindow, this, newWidth, newHeight, wrapper.useNSView);
  1195. #elif JUCE_LINUX
  1196. // (Currently, all linux hosts support sizeWindow, so this should never need to happen)
  1197. setSize (newWidth, newHeight);
  1198. #else
  1199. int dw = 0;
  1200. int dh = 0;
  1201. const int frameThickness = GetSystemMetrics (SM_CYFIXEDFRAME);
  1202. HWND w = (HWND) getWindowHandle();
  1203. while (w != 0)
  1204. {
  1205. HWND parent = getWindowParent (w);
  1206. if (parent == 0)
  1207. break;
  1208. TCHAR windowType [32] = { 0 };
  1209. GetClassName (parent, windowType, 31);
  1210. if (String (windowType).equalsIgnoreCase ("MDIClient"))
  1211. break;
  1212. RECT windowPos, parentPos;
  1213. GetWindowRect (w, &windowPos);
  1214. GetWindowRect (parent, &parentPos);
  1215. if (w != (HWND) getWindowHandle())
  1216. SetWindowPos (w, 0, 0, 0, newWidth + dw, newHeight + dh,
  1217. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  1218. dw = (parentPos.right - parentPos.left) - (windowPos.right - windowPos.left);
  1219. dh = (parentPos.bottom - parentPos.top) - (windowPos.bottom - windowPos.top);
  1220. w = parent;
  1221. if (dw == 2 * frameThickness)
  1222. break;
  1223. if (dw > 100 || dh > 100)
  1224. w = 0;
  1225. }
  1226. if (w != 0)
  1227. SetWindowPos (w, 0, 0, 0, newWidth + dw, newHeight + dh,
  1228. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  1229. #endif
  1230. }
  1231. if (auto* peer = getPeer())
  1232. {
  1233. peer->handleMovedOrResized();
  1234. repaint();
  1235. }
  1236. }
  1237. void setContentScaleFactor (float scale)
  1238. {
  1239. if (! approximatelyEqual (scale, editorScaleFactor))
  1240. {
  1241. editorScaleFactor = scale;
  1242. if (auto* ed = getEditorComp())
  1243. ed->setScaleFactor (editorScaleFactor);
  1244. updateWindowSize (true);
  1245. }
  1246. }
  1247. #if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE
  1248. void timerCallback() override
  1249. {
  1250. auto hostWindowScale = (float) getScaleFactorForWindow (hostWindow);
  1251. if (hostWindowScale > 0.0f && ! approximatelyEqual (hostWindowScale, editorScaleFactor))
  1252. wrapper.handleSetContentScaleFactor (hostWindowScale);
  1253. }
  1254. #endif
  1255. #if JUCE_WINDOWS
  1256. void mouseDown (const MouseEvent&) override
  1257. {
  1258. broughtToFront();
  1259. }
  1260. void broughtToFront() override
  1261. {
  1262. // for hosts like nuendo, need to also pop the MDI container to the
  1263. // front when our comp is clicked on.
  1264. if (! isCurrentlyBlockedByAnotherModalComponent())
  1265. if (HWND parent = findMDIParentOf ((HWND) getWindowHandle()))
  1266. SetWindowPos (parent, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  1267. }
  1268. #endif
  1269. #if JUCE_MAC
  1270. bool keyPressed (const KeyPress&) override
  1271. {
  1272. // If we have an unused keypress, move the key-focus to a host window
  1273. // and re-inject the event..
  1274. return forwardCurrentKeyEventToHostVST (this, wrapper.useNSView);
  1275. }
  1276. #endif
  1277. //==============================================================================
  1278. static Vst2::ERect convertToHostBounds (const Vst2::ERect& rect)
  1279. {
  1280. auto desktopScale = Desktop::getInstance().getGlobalScaleFactor();
  1281. if (approximatelyEqual (desktopScale, 1.0f))
  1282. return rect;
  1283. return { (int16) roundToInt (rect.top * desktopScale),
  1284. (int16) roundToInt (rect.left * desktopScale),
  1285. (int16) roundToInt (rect.bottom * desktopScale),
  1286. (int16) roundToInt (rect.right * desktopScale)};
  1287. }
  1288. //==============================================================================
  1289. JuceVSTWrapper& wrapper;
  1290. FakeMouseMoveGenerator fakeMouseGenerator;
  1291. bool isInSizeWindow = false;
  1292. bool shouldResizeEditor = true;
  1293. float editorScaleFactor = 1.0f;
  1294. #if JUCE_MAC
  1295. void* hostWindow = nullptr;
  1296. #elif JUCE_LINUX
  1297. ScopedXDisplay display;
  1298. Window hostWindow = {};
  1299. #elif JUCE_WINDOWS
  1300. HWND hostWindow = {};
  1301. WindowsHooks hooks;
  1302. #if JUCE_WIN_PER_MONITOR_DPI_AWARE
  1303. juce::Rectangle<int> lastBounds;
  1304. #endif
  1305. #endif
  1306. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (EditorCompWrapper)
  1307. };
  1308. //==============================================================================
  1309. private:
  1310. static JuceVSTWrapper* getWrapper (Vst2::AEffect* v) noexcept { return static_cast<JuceVSTWrapper*> (v->object); }
  1311. bool isProcessLevelOffline()
  1312. {
  1313. return hostCallback != nullptr
  1314. && (int32) hostCallback (&vstEffect, Vst2::audioMasterGetCurrentProcessLevel, 0, 0, nullptr, 0) == 4;
  1315. }
  1316. static inline int32 convertHexVersionToDecimal (const unsigned int hexVersion)
  1317. {
  1318. #if JUCE_VST_RETURN_HEX_VERSION_NUMBER_DIRECTLY
  1319. return (int32) hexVersion;
  1320. #else
  1321. // Currently, only Cubase displays the version number to the user
  1322. // We are hoping here that when other DAWs start to display the version
  1323. // number, that they do so according to yfede's encoding table in the link
  1324. // below. If not, then this code will need an if (isSteinberg()) in the
  1325. // future.
  1326. int major = (hexVersion >> 16) & 0xff;
  1327. int minor = (hexVersion >> 8) & 0xff;
  1328. int bugfix = hexVersion & 0xff;
  1329. // for details, see: https://forum.juce.com/t/issues-with-version-integer-reported-by-vst2/23867
  1330. // Encoding B
  1331. if (major < 1)
  1332. return major * 1000 + minor * 100 + bugfix * 10;
  1333. // Encoding E
  1334. if (major > 100)
  1335. return major * 10000000 + minor * 100000 + bugfix * 1000;
  1336. // Encoding D
  1337. return static_cast<int32> (hexVersion);
  1338. #endif
  1339. }
  1340. //==============================================================================
  1341. #if JUCE_WINDOWS
  1342. // Workarounds for hosts which attempt to open editor windows on a non-GUI thread.. (Grrrr...)
  1343. static void checkWhetherMessageThreadIsCorrect()
  1344. {
  1345. auto host = getHostType();
  1346. if (host.isWavelab() || host.isCubaseBridged() || host.isPremiere())
  1347. {
  1348. if (! messageThreadIsDefinitelyCorrect)
  1349. {
  1350. MessageManager::getInstance()->setCurrentThreadAsMessageThread();
  1351. struct MessageThreadCallback : public CallbackMessage
  1352. {
  1353. MessageThreadCallback (bool& tr) : triggered (tr) {}
  1354. void messageCallback() override { triggered = true; }
  1355. bool& triggered;
  1356. };
  1357. (new MessageThreadCallback (messageThreadIsDefinitelyCorrect))->post();
  1358. }
  1359. }
  1360. }
  1361. #else
  1362. static void checkWhetherMessageThreadIsCorrect() {}
  1363. #endif
  1364. //==============================================================================
  1365. template <typename FloatType>
  1366. void deleteTempChannels (VstTempBuffers<FloatType>& tmpBuffers)
  1367. {
  1368. tmpBuffers.release();
  1369. if (processor != nullptr)
  1370. tmpBuffers.tempChannels.insertMultiple (0, nullptr, vstEffect.numInputs
  1371. + vstEffect.numOutputs);
  1372. }
  1373. void deleteTempChannels()
  1374. {
  1375. deleteTempChannels (floatTempBuffers);
  1376. deleteTempChannels (doubleTempBuffers);
  1377. }
  1378. //==============================================================================
  1379. void findMaxTotalChannels (int& maxTotalIns, int& maxTotalOuts)
  1380. {
  1381. #ifdef JucePlugin_PreferredChannelConfigurations
  1382. int configs[][2] = { JucePlugin_PreferredChannelConfigurations };
  1383. maxTotalIns = maxTotalOuts = 0;
  1384. for (auto& config : configs)
  1385. {
  1386. maxTotalIns = jmax (maxTotalIns, config[0]);
  1387. maxTotalOuts = jmax (maxTotalOuts, config[1]);
  1388. }
  1389. #else
  1390. auto numInputBuses = processor->getBusCount (true);
  1391. auto numOutputBuses = processor->getBusCount (false);
  1392. if (numInputBuses > 1 || numOutputBuses > 1)
  1393. {
  1394. maxTotalIns = maxTotalOuts = 0;
  1395. for (int i = 0; i < numInputBuses; ++i)
  1396. maxTotalIns += processor->getChannelCountOfBus (true, i);
  1397. for (int i = 0; i < numOutputBuses; ++i)
  1398. maxTotalOuts += processor->getChannelCountOfBus (false, i);
  1399. }
  1400. else
  1401. {
  1402. maxTotalIns = numInputBuses > 0 ? processor->getBus (true, 0)->getMaxSupportedChannels (64) : 0;
  1403. maxTotalOuts = numOutputBuses > 0 ? processor->getBus (false, 0)->getMaxSupportedChannels (64) : 0;
  1404. }
  1405. #endif
  1406. }
  1407. bool pluginHasSidechainsOrAuxs() const { return (processor->getBusCount (true) > 1 || processor->getBusCount (false) > 1); }
  1408. //==============================================================================
  1409. /** Host to plug-in calls. */
  1410. pointer_sized_int handleOpen (VstOpCodeArguments)
  1411. {
  1412. // Note: most hosts call this on the UI thread, but wavelab doesn't, so be careful in here.
  1413. setHasEditorFlag (processor->hasEditor());
  1414. return 0;
  1415. }
  1416. pointer_sized_int handleClose (VstOpCodeArguments)
  1417. {
  1418. // Note: most hosts call this on the UI thread, but wavelab doesn't, so be careful in here.
  1419. stopTimer();
  1420. if (MessageManager::getInstance()->isThisTheMessageThread())
  1421. deleteEditor (false);
  1422. return 0;
  1423. }
  1424. pointer_sized_int handleSetCurrentProgram (VstOpCodeArguments args)
  1425. {
  1426. if (processor != nullptr && isPositiveAndBelow ((int) args.value, processor->getNumPrograms()))
  1427. processor->setCurrentProgram ((int) args.value);
  1428. return 0;
  1429. }
  1430. pointer_sized_int handleGetCurrentProgram (VstOpCodeArguments)
  1431. {
  1432. return (processor != nullptr && processor->getNumPrograms() > 0 ? processor->getCurrentProgram() : 0);
  1433. }
  1434. pointer_sized_int handleSetCurrentProgramName (VstOpCodeArguments args)
  1435. {
  1436. if (processor != nullptr && processor->getNumPrograms() > 0)
  1437. processor->changeProgramName (processor->getCurrentProgram(), (char*) args.ptr);
  1438. return 0;
  1439. }
  1440. pointer_sized_int handleGetCurrentProgramName (VstOpCodeArguments args)
  1441. {
  1442. if (processor != nullptr && processor->getNumPrograms() > 0)
  1443. processor->getProgramName (processor->getCurrentProgram()).copyToUTF8 ((char*) args.ptr, 24 + 1);
  1444. return 0;
  1445. }
  1446. pointer_sized_int handleGetParameterLabel (VstOpCodeArguments args)
  1447. {
  1448. if (auto* param = juceParameters.getParamForIndex (args.index))
  1449. {
  1450. // length should technically be kVstMaxParamStrLen, which is 8, but hosts will normally allow a bit more.
  1451. param->getLabel().copyToUTF8 ((char*) args.ptr, 24 + 1);
  1452. }
  1453. return 0;
  1454. }
  1455. pointer_sized_int handleGetParameterText (VstOpCodeArguments args)
  1456. {
  1457. if (auto* param = juceParameters.getParamForIndex (args.index))
  1458. {
  1459. // length should technically be kVstMaxParamStrLen, which is 8, but hosts will normally allow a bit more.
  1460. param->getCurrentValueAsText().copyToUTF8 ((char*) args.ptr, 24 + 1);
  1461. }
  1462. return 0;
  1463. }
  1464. pointer_sized_int handleGetParameterName (VstOpCodeArguments args)
  1465. {
  1466. if (auto* param = juceParameters.getParamForIndex (args.index))
  1467. {
  1468. // length should technically be kVstMaxParamStrLen, which is 8, but hosts will normally allow a bit more.
  1469. param->getName (32).copyToUTF8 ((char*) args.ptr, 32 + 1);
  1470. }
  1471. return 0;
  1472. }
  1473. pointer_sized_int handleSetSampleRate (VstOpCodeArguments args)
  1474. {
  1475. sampleRate = args.opt;
  1476. return 0;
  1477. }
  1478. pointer_sized_int handleSetBlockSize (VstOpCodeArguments args)
  1479. {
  1480. blockSize = (int32) args.value;
  1481. return 0;
  1482. }
  1483. pointer_sized_int handleResumeSuspend (VstOpCodeArguments args)
  1484. {
  1485. if (args.value)
  1486. resume();
  1487. else
  1488. suspend();
  1489. return 0;
  1490. }
  1491. pointer_sized_int handleGetEditorBounds (VstOpCodeArguments args)
  1492. {
  1493. checkWhetherMessageThreadIsCorrect();
  1494. const MessageManagerLock mmLock;
  1495. createEditorComp();
  1496. if (editorComp != nullptr)
  1497. {
  1498. editorComp->getEditorBounds (editorBounds);
  1499. *((Vst2::ERect**) args.ptr) = &editorBounds;
  1500. return (pointer_sized_int) &editorBounds;
  1501. }
  1502. return 0;
  1503. }
  1504. pointer_sized_int handleOpenEditor (VstOpCodeArguments args)
  1505. {
  1506. checkWhetherMessageThreadIsCorrect();
  1507. const MessageManagerLock mmLock;
  1508. jassert (! recursionCheck);
  1509. startTimerHz (4); // performs misc housekeeping chores
  1510. deleteEditor (true);
  1511. createEditorComp();
  1512. if (editorComp != nullptr)
  1513. {
  1514. editorComp->attachToHost (args);
  1515. return 1;
  1516. }
  1517. return 0;
  1518. }
  1519. pointer_sized_int handleCloseEditor (VstOpCodeArguments)
  1520. {
  1521. checkWhetherMessageThreadIsCorrect();
  1522. const MessageManagerLock mmLock;
  1523. deleteEditor (true);
  1524. return 0;
  1525. }
  1526. pointer_sized_int handleGetData (VstOpCodeArguments args)
  1527. {
  1528. if (processor == nullptr)
  1529. return 0;
  1530. auto data = (void**) args.ptr;
  1531. bool onlyStoreCurrentProgramData = (args.index != 0);
  1532. ScopedLock lock (stateInformationLock);
  1533. chunkMemory.reset();
  1534. if (onlyStoreCurrentProgramData)
  1535. processor->getCurrentProgramStateInformation (chunkMemory);
  1536. else
  1537. processor->getStateInformation (chunkMemory);
  1538. *data = (void*) chunkMemory.getData();
  1539. // because the chunk is only needed temporarily by the host (or at least you'd
  1540. // hope so) we'll give it a while and then free it in the timer callback.
  1541. chunkMemoryTime = juce::Time::getApproximateMillisecondCounter();
  1542. return (int32) chunkMemory.getSize();
  1543. }
  1544. pointer_sized_int handleSetData (VstOpCodeArguments args)
  1545. {
  1546. if (processor != nullptr)
  1547. {
  1548. void* data = args.ptr;
  1549. int32 byteSize = (int32) args.value;
  1550. bool onlyRestoreCurrentProgramData = (args.index != 0);
  1551. {
  1552. ScopedLock lock (stateInformationLock);
  1553. chunkMemory.reset();
  1554. chunkMemoryTime = 0;
  1555. if (byteSize > 0 && data != nullptr)
  1556. {
  1557. if (onlyRestoreCurrentProgramData)
  1558. processor->setCurrentProgramStateInformation (data, byteSize);
  1559. else
  1560. processor->setStateInformation (data, byteSize);
  1561. }
  1562. }
  1563. }
  1564. return 0;
  1565. }
  1566. pointer_sized_int handlePreAudioProcessingEvents (VstOpCodeArguments args)
  1567. {
  1568. #if JucePlugin_WantsMidiInput || JucePlugin_IsMidiEffect
  1569. VSTMidiEventList::addEventsToMidiBuffer ((Vst2::VstEvents*) args.ptr, midiEvents);
  1570. return 1;
  1571. #else
  1572. ignoreUnused (args);
  1573. return 0;
  1574. #endif
  1575. }
  1576. pointer_sized_int handleIsParameterAutomatable (VstOpCodeArguments args)
  1577. {
  1578. if (auto* param = juceParameters.getParamForIndex (args.index))
  1579. {
  1580. const bool isMeter = ((((unsigned int) param->getCategory() & 0xffff0000) >> 16) == 2);
  1581. return (param->isAutomatable() && (! isMeter) ? 1 : 0);
  1582. }
  1583. return 0;
  1584. }
  1585. pointer_sized_int handleParameterValueForText (VstOpCodeArguments args)
  1586. {
  1587. if (auto* param = juceParameters.getParamForIndex (args.index))
  1588. {
  1589. if (! LegacyAudioParameter::isLegacy (param))
  1590. {
  1591. auto value = param->getValueForText (String::fromUTF8 ((char*) args.ptr));
  1592. param->setValue (value);
  1593. inParameterChangedCallback = true;
  1594. param->sendValueChangedMessageToListeners (value);
  1595. return 1;
  1596. }
  1597. }
  1598. return 0;
  1599. }
  1600. pointer_sized_int handleGetProgramName (VstOpCodeArguments args)
  1601. {
  1602. if (processor != nullptr && isPositiveAndBelow (args.index, processor->getNumPrograms()))
  1603. {
  1604. processor->getProgramName (args.index).copyToUTF8 ((char*) args.ptr, 24 + 1);
  1605. return 1;
  1606. }
  1607. return 0;
  1608. }
  1609. pointer_sized_int handleGetInputPinProperties (VstOpCodeArguments args)
  1610. {
  1611. return (processor != nullptr && getPinProperties (*(Vst2::VstPinProperties*) args.ptr, true, args.index)) ? 1 : 0;
  1612. }
  1613. pointer_sized_int handleGetOutputPinProperties (VstOpCodeArguments args)
  1614. {
  1615. return (processor != nullptr && getPinProperties (*(Vst2::VstPinProperties*) args.ptr, false, args.index)) ? 1 : 0;
  1616. }
  1617. pointer_sized_int handleGetPlugInCategory (VstOpCodeArguments)
  1618. {
  1619. return Vst2::JucePlugin_VSTCategory;
  1620. }
  1621. pointer_sized_int handleSetSpeakerConfiguration (VstOpCodeArguments args)
  1622. {
  1623. auto* pluginInput = reinterpret_cast<Vst2::VstSpeakerArrangement*> (args.value);
  1624. auto* pluginOutput = reinterpret_cast<Vst2::VstSpeakerArrangement*> (args.ptr);
  1625. if (processor->isMidiEffect())
  1626. return 0;
  1627. auto numIns = processor->getBusCount (true);
  1628. auto numOuts = processor->getBusCount (false);
  1629. if (pluginInput != nullptr && pluginInput->type >= 0)
  1630. {
  1631. // inconsistent request?
  1632. if (SpeakerMappings::vstArrangementTypeToChannelSet (*pluginInput).size() != pluginInput->numChannels)
  1633. return 0;
  1634. }
  1635. if (pluginOutput != nullptr && pluginOutput->type >= 0)
  1636. {
  1637. // inconsistent request?
  1638. if (SpeakerMappings::vstArrangementTypeToChannelSet (*pluginOutput).size() != pluginOutput->numChannels)
  1639. return 0;
  1640. }
  1641. if (pluginInput != nullptr && pluginInput->numChannels > 0 && numIns == 0)
  1642. return 0;
  1643. if (pluginOutput != nullptr && pluginOutput->numChannels > 0 && numOuts == 0)
  1644. return 0;
  1645. auto layouts = processor->getBusesLayout();
  1646. if (pluginInput != nullptr && pluginInput-> numChannels >= 0 && numIns > 0)
  1647. layouts.getChannelSet (true, 0) = SpeakerMappings::vstArrangementTypeToChannelSet (*pluginInput);
  1648. if (pluginOutput != nullptr && pluginOutput->numChannels >= 0 && numOuts > 0)
  1649. layouts.getChannelSet (false, 0) = SpeakerMappings::vstArrangementTypeToChannelSet (*pluginOutput);
  1650. #ifdef JucePlugin_PreferredChannelConfigurations
  1651. short configs[][2] = { JucePlugin_PreferredChannelConfigurations };
  1652. if (! AudioProcessor::containsLayout (layouts, configs))
  1653. return 0;
  1654. #endif
  1655. return processor->setBusesLayout (layouts) ? 1 : 0;
  1656. }
  1657. pointer_sized_int handleSetBypass (VstOpCodeArguments args)
  1658. {
  1659. isBypassed = (args.value != 0);
  1660. if (auto* bypass = processor->getBypassParameter())
  1661. bypass->setValueNotifyingHost (isBypassed ? 1.0f : 0.0f);
  1662. return 1;
  1663. }
  1664. pointer_sized_int handleGetPlugInName (VstOpCodeArguments args)
  1665. {
  1666. String (JucePlugin_Name).copyToUTF8 ((char*) args.ptr, 64 + 1);
  1667. return 1;
  1668. }
  1669. pointer_sized_int handleGetManufacturerName (VstOpCodeArguments args)
  1670. {
  1671. String (JucePlugin_Manufacturer).copyToUTF8 ((char*) args.ptr, 64 + 1);
  1672. return 1;
  1673. }
  1674. pointer_sized_int handleGetManufacturerVersion (VstOpCodeArguments)
  1675. {
  1676. return convertHexVersionToDecimal (JucePlugin_VersionCode);
  1677. }
  1678. pointer_sized_int handleManufacturerSpecific (VstOpCodeArguments args)
  1679. {
  1680. if (handleManufacturerSpecificVST2Opcode (args.index, args.value, args.ptr, args.opt))
  1681. return 1;
  1682. if (args.index == JUCE_MULTICHAR_CONSTANT ('P', 'r', 'e', 'S')
  1683. && args.value == JUCE_MULTICHAR_CONSTANT ('A', 'e', 'C', 's'))
  1684. return handleSetContentScaleFactor (args.opt);
  1685. if (args.index == Vst2::effGetParamDisplay)
  1686. return handleCockosGetParameterText (args.value, args.ptr, args.opt);
  1687. if (auto callbackHandler = dynamic_cast<VSTCallbackHandler*> (processor))
  1688. return callbackHandler->handleVstManufacturerSpecific (args.index, args.value, args.ptr, args.opt);
  1689. return 0;
  1690. }
  1691. pointer_sized_int handleCanPlugInDo (VstOpCodeArguments args)
  1692. {
  1693. auto text = (const char*) args.ptr;
  1694. auto matches = [=](const char* s) { return strcmp (text, s) == 0; };
  1695. if (matches ("receiveVstEvents")
  1696. || matches ("receiveVstMidiEvent")
  1697. || matches ("receiveVstMidiEvents"))
  1698. {
  1699. #if JucePlugin_WantsMidiInput || JucePlugin_IsMidiEffect
  1700. return 1;
  1701. #else
  1702. return -1;
  1703. #endif
  1704. }
  1705. if (matches ("sendVstEvents")
  1706. || matches ("sendVstMidiEvent")
  1707. || matches ("sendVstMidiEvents"))
  1708. {
  1709. #if JucePlugin_ProducesMidiOutput || JucePlugin_IsMidiEffect
  1710. return 1;
  1711. #else
  1712. return -1;
  1713. #endif
  1714. }
  1715. if (matches ("receiveVstTimeInfo")
  1716. || matches ("conformsToWindowRules")
  1717. || matches ("supportsViewDpiScaling")
  1718. || matches ("bypass"))
  1719. {
  1720. return 1;
  1721. }
  1722. // This tells Wavelab to use the UI thread to invoke open/close,
  1723. // like all other hosts do.
  1724. if (matches ("openCloseAnyThread"))
  1725. return -1;
  1726. if (matches ("MPE"))
  1727. return processor->supportsMPE() ? 1 : 0;
  1728. #if JUCE_MAC
  1729. if (matches ("hasCockosViewAsConfig"))
  1730. {
  1731. useNSView = true;
  1732. return (int32) 0xbeef0000;
  1733. }
  1734. #endif
  1735. if (matches ("hasCockosExtensions"))
  1736. return (int32) 0xbeef0000;
  1737. if (auto callbackHandler = dynamic_cast<VSTCallbackHandler*> (processor))
  1738. return callbackHandler->handleVstPluginCanDo (args.index, args.value, args.ptr, args.opt);
  1739. return 0;
  1740. }
  1741. pointer_sized_int handleGetTailSize (VstOpCodeArguments)
  1742. {
  1743. if (processor != nullptr)
  1744. {
  1745. int32 result;
  1746. auto tailSeconds = processor->getTailLengthSeconds();
  1747. if (tailSeconds == std::numeric_limits<double>::infinity())
  1748. result = std::numeric_limits<int32>::max();
  1749. else
  1750. result = static_cast<int32> (tailSeconds * sampleRate);
  1751. return result; // Vst2 expects an int32 upcasted to a intptr_t here
  1752. }
  1753. return 0;
  1754. }
  1755. pointer_sized_int handleKeyboardFocusRequired (VstOpCodeArguments)
  1756. {
  1757. return (JucePlugin_EditorRequiresKeyboardFocus != 0) ? 1 : 0;
  1758. }
  1759. pointer_sized_int handleGetVstInterfaceVersion (VstOpCodeArguments)
  1760. {
  1761. return kVstVersion;
  1762. }
  1763. pointer_sized_int handleGetCurrentMidiProgram (VstOpCodeArguments)
  1764. {
  1765. return -1;
  1766. }
  1767. pointer_sized_int handleGetSpeakerConfiguration (VstOpCodeArguments args)
  1768. {
  1769. auto** pluginInput = reinterpret_cast<Vst2::VstSpeakerArrangement**> (args.value);
  1770. auto** pluginOutput = reinterpret_cast<Vst2::VstSpeakerArrangement**> (args.ptr);
  1771. if (pluginHasSidechainsOrAuxs() || processor->isMidiEffect())
  1772. return false;
  1773. auto inputLayout = processor->getChannelLayoutOfBus (true, 0);
  1774. auto outputLayout = processor->getChannelLayoutOfBus (false, 0);
  1775. auto speakerBaseSize = sizeof (Vst2::VstSpeakerArrangement) - (sizeof (Vst2::VstSpeakerProperties) * 8);
  1776. cachedInArrangement .malloc (speakerBaseSize + (static_cast<std::size_t> (inputLayout. size()) * sizeof (Vst2::VstSpeakerArrangement)), 1);
  1777. cachedOutArrangement.malloc (speakerBaseSize + (static_cast<std::size_t> (outputLayout.size()) * sizeof (Vst2::VstSpeakerArrangement)), 1);
  1778. *pluginInput = cachedInArrangement. getData();
  1779. *pluginOutput = cachedOutArrangement.getData();
  1780. SpeakerMappings::channelSetToVstArrangement (processor->getChannelLayoutOfBus (true, 0), **pluginInput);
  1781. SpeakerMappings::channelSetToVstArrangement (processor->getChannelLayoutOfBus (false, 0), **pluginOutput);
  1782. return 1;
  1783. }
  1784. pointer_sized_int handleSetNumberOfSamplesToProcess (VstOpCodeArguments args)
  1785. {
  1786. return args.value;
  1787. }
  1788. pointer_sized_int handleSetSampleFloatType (VstOpCodeArguments args)
  1789. {
  1790. if (! isProcessing)
  1791. {
  1792. if (processor != nullptr)
  1793. {
  1794. processor->setProcessingPrecision ((args.value == Vst2::kVstProcessPrecision64
  1795. && processor->supportsDoublePrecisionProcessing())
  1796. ? AudioProcessor::doublePrecision
  1797. : AudioProcessor::singlePrecision);
  1798. return 1;
  1799. }
  1800. }
  1801. return 0;
  1802. }
  1803. pointer_sized_int handleSetContentScaleFactor (float scale)
  1804. {
  1805. #if ! JUCE_MAC
  1806. if (editorComp != nullptr)
  1807. editorComp->setContentScaleFactor (scale);
  1808. lastScaleFactorReceived = scale;
  1809. #else
  1810. ignoreUnused (scale);
  1811. #endif
  1812. return 1;
  1813. }
  1814. pointer_sized_int handleCockosGetParameterText (pointer_sized_int paramIndex,
  1815. void* dest,
  1816. float value)
  1817. {
  1818. if (processor != nullptr && dest != nullptr)
  1819. {
  1820. if (auto* param = juceParameters.getParamForIndex ((int) paramIndex))
  1821. {
  1822. if (! LegacyAudioParameter::isLegacy (param))
  1823. {
  1824. String text (param->getText (value, 1024));
  1825. memcpy (dest, text.toRawUTF8(), ((size_t) text.length()) + 1);
  1826. return 0xbeef;
  1827. }
  1828. }
  1829. }
  1830. return 0;
  1831. }
  1832. //==============================================================================
  1833. pointer_sized_int handleGetNumMidiInputChannels()
  1834. {
  1835. #if JucePlugin_WantsMidiInput || JucePlugin_IsMidiEffect
  1836. #ifdef JucePlugin_VSTNumMidiInputs
  1837. return JucePlugin_VSTNumMidiInputs;
  1838. #else
  1839. return 16;
  1840. #endif
  1841. #else
  1842. return 0;
  1843. #endif
  1844. }
  1845. pointer_sized_int handleGetNumMidiOutputChannels()
  1846. {
  1847. #if JucePlugin_ProducesMidiOutput || JucePlugin_IsMidiEffect
  1848. #ifdef JucePlugin_VSTNumMidiOutputs
  1849. return JucePlugin_VSTNumMidiOutputs;
  1850. #else
  1851. return 16;
  1852. #endif
  1853. #else
  1854. return 0;
  1855. #endif
  1856. }
  1857. //==============================================================================
  1858. Vst2::audioMasterCallback hostCallback;
  1859. AudioProcessor* processor = {};
  1860. double sampleRate = 44100.0;
  1861. int32 blockSize = 1024;
  1862. Vst2::AEffect vstEffect;
  1863. CriticalSection stateInformationLock;
  1864. juce::MemoryBlock chunkMemory;
  1865. uint32 chunkMemoryTime = 0;
  1866. std::unique_ptr<EditorCompWrapper> editorComp;
  1867. Vst2::ERect editorBounds;
  1868. MidiBuffer midiEvents;
  1869. VSTMidiEventList outgoingEvents;
  1870. #if ! JUCE_MAC
  1871. float lastScaleFactorReceived = 1.0f;
  1872. #endif
  1873. LegacyAudioParametersWrapper juceParameters;
  1874. bool isProcessing = false, isBypassed = false, hasShutdown = false;
  1875. bool firstProcessCallback = true, shouldDeleteEditor = false;
  1876. #if JUCE_MAC
  1877. #if JUCE_64BIT
  1878. bool useNSView = true;
  1879. #else
  1880. bool useNSView = false;
  1881. #endif
  1882. #endif
  1883. VstTempBuffers<float> floatTempBuffers;
  1884. VstTempBuffers<double> doubleTempBuffers;
  1885. int maxNumInChannels = 0, maxNumOutChannels = 0;
  1886. HeapBlock<Vst2::VstSpeakerArrangement> cachedInArrangement, cachedOutArrangement;
  1887. ThreadLocalValue<bool> inParameterChangedCallback;
  1888. //==============================================================================
  1889. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (JuceVSTWrapper)
  1890. };
  1891. //==============================================================================
  1892. namespace
  1893. {
  1894. Vst2::AEffect* pluginEntryPoint (Vst2::audioMasterCallback audioMaster)
  1895. {
  1896. JUCE_AUTORELEASEPOOL
  1897. {
  1898. initialiseJuce_GUI();
  1899. try
  1900. {
  1901. if (audioMaster (nullptr, Vst2::audioMasterVersion, 0, 0, nullptr, 0) != 0)
  1902. {
  1903. #if JUCE_LINUX
  1904. MessageManagerLock mmLock;
  1905. #endif
  1906. auto* processor = createPluginFilterOfType (AudioProcessor::wrapperType_VST);
  1907. auto* wrapper = new JuceVSTWrapper (audioMaster, processor);
  1908. auto* aEffect = wrapper->getAEffect();
  1909. if (auto* callbackHandler = dynamic_cast<VSTCallbackHandler*> (processor))
  1910. {
  1911. callbackHandler->handleVstHostCallbackAvailable ([audioMaster, aEffect](int32 opcode, int32 index, pointer_sized_int value, void* ptr, float opt)
  1912. {
  1913. return audioMaster (aEffect, opcode, index, value, ptr, opt);
  1914. });
  1915. }
  1916. return aEffect;
  1917. }
  1918. }
  1919. catch (...)
  1920. {}
  1921. }
  1922. return nullptr;
  1923. }
  1924. }
  1925. #if ! JUCE_WINDOWS
  1926. #define JUCE_EXPORTED_FUNCTION extern "C" __attribute__ ((visibility("default")))
  1927. #endif
  1928. //==============================================================================
  1929. // Mac startup code..
  1930. #if JUCE_MAC
  1931. JUCE_EXPORTED_FUNCTION Vst2::AEffect* VSTPluginMain (Vst2::audioMasterCallback audioMaster);
  1932. JUCE_EXPORTED_FUNCTION Vst2::AEffect* VSTPluginMain (Vst2::audioMasterCallback audioMaster)
  1933. {
  1934. PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_VST;
  1935. initialiseMacVST();
  1936. return pluginEntryPoint (audioMaster);
  1937. }
  1938. JUCE_EXPORTED_FUNCTION Vst2::AEffect* main_macho (Vst2::audioMasterCallback audioMaster);
  1939. JUCE_EXPORTED_FUNCTION Vst2::AEffect* main_macho (Vst2::audioMasterCallback audioMaster)
  1940. {
  1941. PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_VST;
  1942. initialiseMacVST();
  1943. return pluginEntryPoint (audioMaster);
  1944. }
  1945. //==============================================================================
  1946. // Linux startup code..
  1947. #elif JUCE_LINUX
  1948. JUCE_EXPORTED_FUNCTION Vst2::AEffect* VSTPluginMain (Vst2::audioMasterCallback audioMaster);
  1949. JUCE_EXPORTED_FUNCTION Vst2::AEffect* VSTPluginMain (Vst2::audioMasterCallback audioMaster)
  1950. {
  1951. PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_VST;
  1952. SharedMessageThread::getInstance();
  1953. return pluginEntryPoint (audioMaster);
  1954. }
  1955. JUCE_EXPORTED_FUNCTION Vst2::AEffect* main_plugin (Vst2::audioMasterCallback audioMaster) asm ("main");
  1956. JUCE_EXPORTED_FUNCTION Vst2::AEffect* main_plugin (Vst2::audioMasterCallback audioMaster)
  1957. {
  1958. PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_VST;
  1959. return VSTPluginMain (audioMaster);
  1960. }
  1961. // don't put initialiseJuce_GUI or shutdownJuce_GUI in these... it will crash!
  1962. __attribute__((constructor)) void myPluginInit() {}
  1963. __attribute__((destructor)) void myPluginFini() {}
  1964. //==============================================================================
  1965. // Win32 startup code..
  1966. #else
  1967. extern "C" __declspec (dllexport) Vst2::AEffect* VSTPluginMain (Vst2::audioMasterCallback audioMaster)
  1968. {
  1969. PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_VST;
  1970. return pluginEntryPoint (audioMaster);
  1971. }
  1972. #ifndef JUCE_64BIT // (can't compile this on win64, but it's not needed anyway with VST2.4)
  1973. extern "C" __declspec (dllexport) int main (Vst2::audioMasterCallback audioMaster)
  1974. {
  1975. PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_VST;
  1976. return (int) pluginEntryPoint (audioMaster);
  1977. }
  1978. #endif
  1979. extern "C" BOOL WINAPI DllMain (HINSTANCE instance, DWORD reason, LPVOID)
  1980. {
  1981. if (reason == DLL_PROCESS_ATTACH)
  1982. Process::setCurrentModuleInstanceHandle (instance);
  1983. return true;
  1984. }
  1985. #endif
  1986. #endif