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.

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