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.

2052 lines
73KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #include "../../juce_core/system/juce_TargetPlatform.h"
  18. #include "../utility/juce_CheckSettingMacros.h"
  19. #if JucePlugin_Build_VST
  20. #ifdef _MSC_VER
  21. #pragma warning (disable : 4996 4100)
  22. #endif
  23. #include "../utility/juce_IncludeSystemHeaders.h"
  24. #ifdef PRAGMA_ALIGN_SUPPORTED
  25. #undef PRAGMA_ALIGN_SUPPORTED
  26. #define PRAGMA_ALIGN_SUPPORTED 1
  27. #endif
  28. #ifndef _MSC_VER
  29. #define __cdecl
  30. #endif
  31. #ifdef __clang__
  32. #pragma clang diagnostic push
  33. #pragma clang diagnostic ignored "-Wconversion"
  34. #pragma clang diagnostic ignored "-Wshadow"
  35. #pragma clang diagnostic ignored "-Wdeprecated-register"
  36. #pragma clang diagnostic ignored "-Wunused-parameter"
  37. #pragma clang diagnostic ignored "-Wdeprecated-writable-strings"
  38. #pragma clang diagnostic ignored "-Wnon-virtual-dtor"
  39. #endif
  40. #ifdef _MSC_VER
  41. #pragma warning (push)
  42. #pragma warning (disable : 4458)
  43. #endif
  44. /* These files come with the Steinberg VST SDK - to get them, you'll need to
  45. visit the Steinberg website and agree to whatever is currently required to
  46. get them. The best version to get is the VST3 SDK, which also contains
  47. the older VST2.4 files.
  48. Then, you'll need to make sure your include path contains your "VST SDK3"
  49. directory (or whatever you've named it on your machine). The Projucer has
  50. a special box for setting this path.
  51. */
  52. #include <public.sdk/source/vst2.x/audioeffectx.h>
  53. #include <public.sdk/source/vst2.x/aeffeditor.h>
  54. #include <public.sdk/source/vst2.x/audioeffectx.cpp>
  55. #include <public.sdk/source/vst2.x/audioeffect.cpp>
  56. #if ! VST_2_4_EXTENSIONS
  57. #error "It looks like you're trying to include an out-of-date VSTSDK version - make sure you have at least version 2.4"
  58. #endif
  59. #ifndef JUCE_VST3_CAN_REPLACE_VST2
  60. #define JUCE_VST3_CAN_REPLACE_VST2 1
  61. #endif
  62. #if JucePlugin_Build_VST3 && JUCE_VST3_CAN_REPLACE_VST2
  63. #include <pluginterfaces/base/funknown.h>
  64. namespace juce { extern Steinberg::FUID getJuceVST3ComponentIID(); }
  65. #endif
  66. #ifdef _MSC_VER
  67. #pragma warning (pop)
  68. #endif
  69. #ifdef __clang__
  70. #pragma clang diagnostic pop
  71. #endif
  72. //==============================================================================
  73. #ifdef _MSC_VER
  74. #pragma pack (push, 8)
  75. #endif
  76. #include "../utility/juce_IncludeModuleHeaders.h"
  77. #include "../utility/juce_FakeMouseMoveGenerator.h"
  78. #include "../utility/juce_WindowsHooks.h"
  79. #include "../utility/juce_PluginBusUtilities.h"
  80. #ifdef _MSC_VER
  81. #pragma pack (pop)
  82. #endif
  83. #undef MemoryBlock
  84. class JuceVSTWrapper;
  85. static bool recursionCheck = false;
  86. namespace juce
  87. {
  88. #if JUCE_MAC
  89. extern JUCE_API void initialiseMacVST();
  90. extern JUCE_API void* attachComponentToWindowRefVST (Component*, void* parent, bool isNSView);
  91. extern JUCE_API void detachComponentFromWindowRefVST (Component*, void* window, bool isNSView);
  92. extern JUCE_API void setNativeHostWindowSizeVST (void* window, Component*, int newWidth, int newHeight, bool isNSView);
  93. extern JUCE_API void checkWindowVisibilityVST (void* window, Component*, bool isNSView);
  94. extern JUCE_API bool forwardCurrentKeyEventToHostVST (Component*, bool isNSView);
  95. #if ! JUCE_64BIT
  96. extern JUCE_API void updateEditorCompBoundsVST (Component*);
  97. #endif
  98. #endif
  99. #if JUCE_LINUX
  100. extern Display* display;
  101. #endif
  102. }
  103. //==============================================================================
  104. #if JUCE_WINDOWS
  105. namespace
  106. {
  107. // Returns the actual container window, unlike GetParent, which can also return a separate owner window.
  108. static HWND getWindowParent (HWND w) noexcept { return GetAncestor (w, GA_PARENT); }
  109. static HWND findMDIParentOf (HWND w)
  110. {
  111. const int frameThickness = GetSystemMetrics (SM_CYFIXEDFRAME);
  112. while (w != 0)
  113. {
  114. HWND parent = getWindowParent (w);
  115. if (parent == 0)
  116. break;
  117. TCHAR windowType[32] = { 0 };
  118. GetClassName (parent, windowType, 31);
  119. if (String (windowType).equalsIgnoreCase ("MDIClient"))
  120. return parent;
  121. RECT windowPos, parentPos;
  122. GetWindowRect (w, &windowPos);
  123. GetWindowRect (parent, &parentPos);
  124. const int dw = (parentPos.right - parentPos.left) - (windowPos.right - windowPos.left);
  125. const int dh = (parentPos.bottom - parentPos.top) - (windowPos.bottom - windowPos.top);
  126. if (dw > 100 || dh > 100)
  127. break;
  128. w = parent;
  129. if (dw == 2 * frameThickness)
  130. break;
  131. }
  132. return w;
  133. }
  134. static bool messageThreadIsDefinitelyCorrect = false;
  135. }
  136. //==============================================================================
  137. #elif JUCE_LINUX
  138. class SharedMessageThread : public Thread
  139. {
  140. public:
  141. SharedMessageThread()
  142. : Thread ("VstMessageThread"),
  143. initialised (false)
  144. {
  145. startThread (7);
  146. while (! initialised)
  147. sleep (1);
  148. }
  149. ~SharedMessageThread()
  150. {
  151. signalThreadShouldExit();
  152. JUCEApplicationBase::quit();
  153. waitForThreadToExit (5000);
  154. clearSingletonInstance();
  155. }
  156. void run() override
  157. {
  158. initialiseJuce_GUI();
  159. initialised = true;
  160. MessageManager::getInstance()->setCurrentThreadAsMessageThread();
  161. while ((! threadShouldExit()) && MessageManager::getInstance()->runDispatchLoopUntil (250))
  162. {}
  163. }
  164. juce_DeclareSingleton (SharedMessageThread, false)
  165. private:
  166. bool initialised;
  167. };
  168. juce_ImplementSingleton (SharedMessageThread)
  169. #endif
  170. static Array<void*> activePlugins;
  171. //==============================================================================
  172. /**
  173. This is an AudioEffectX object that holds and wraps our AudioProcessor...
  174. */
  175. class JuceVSTWrapper : public AudioEffectX,
  176. public AudioProcessorListener,
  177. public AudioPlayHead,
  178. private Timer,
  179. private AsyncUpdater
  180. {
  181. private:
  182. //==============================================================================
  183. template <typename FloatType>
  184. struct VstTempBuffers
  185. {
  186. VstTempBuffers() {}
  187. ~VstTempBuffers() { release(); }
  188. void release() noexcept
  189. {
  190. for (int i = tempChannels.size(); --i >= 0;)
  191. delete[] (tempChannels.getUnchecked(i));
  192. tempChannels.clear();
  193. }
  194. HeapBlock<FloatType*> channels;
  195. Array<FloatType*> tempChannels; // see note in processReplacing()
  196. juce::AudioBuffer<FloatType> processTempBuffer;
  197. };
  198. public:
  199. //==============================================================================
  200. JuceVSTWrapper (audioMasterCallback audioMasterCB, AudioProcessor* const af)
  201. : AudioEffectX (audioMasterCB, jmax (1, af->getNumPrograms()), af->getNumParameters()),
  202. filter (af),
  203. busUtils (*filter, true, 64),
  204. chunkMemoryTime (0),
  205. isProcessing (false),
  206. isBypassed (false),
  207. hasShutdown (false),
  208. isInSizeWindow (false),
  209. firstProcessCallback (true),
  210. shouldDeleteEditor (false),
  211. #if JUCE_64BIT
  212. useNSView (true),
  213. #else
  214. useNSView (false),
  215. #endif
  216. hostWindow (0)
  217. {
  218. busUtils.init();
  219. // VST-2 does not support disabling buses: so always enable all of them
  220. if (busUtils.hasDynamicInBuses() || busUtils.hasDynamicOutBuses())
  221. busUtils.enableAllBuses();
  222. {
  223. // Using the legacy Projucer field? Then keep the maximum number of channels
  224. // as the default plug-in layout. Otherwise, leave it up to the user
  225. // which default layout the prefer.
  226. #ifndef JucePlugin_PreferredChannelConfigurations
  227. PluginBusUtilities::ScopedBusRestorer busRestorer (busUtils);
  228. #endif
  229. findMaxTotalChannels (maxNumInChannels, maxNumOutChannels);
  230. bool success = setBusArrangementFromTotalChannelNum (maxNumInChannels, maxNumOutChannels);
  231. ignoreUnused (success);
  232. // please file a bug if you hit this assertsion!
  233. jassert (maxNumInChannels == busUtils.findTotalNumChannels (true) && success
  234. && maxNumOutChannels == busUtils.findTotalNumChannels (false));
  235. }
  236. filter->setRateAndBufferSizeDetails (0, 0);
  237. filter->setPlayHead (this);
  238. filter->addListener (this);
  239. cEffect.flags |= effFlagsHasEditor;
  240. cEffect.version = convertHexVersionToDecimal (JucePlugin_VersionCode);
  241. setUniqueID ((int) (JucePlugin_VSTUniqueID));
  242. setNumInputs (maxNumInChannels);
  243. setNumOutputs (maxNumOutChannels);
  244. canProcessReplacing (true);
  245. canDoubleReplacing (filter->supportsDoublePrecisionProcessing());
  246. isSynth ((JucePlugin_IsSynth) != 0);
  247. setInitialDelay (filter->getLatencySamples());
  248. programsAreChunks (true);
  249. activePlugins.add (this);
  250. }
  251. ~JuceVSTWrapper()
  252. {
  253. JUCE_AUTORELEASEPOOL
  254. {
  255. {
  256. #if JUCE_LINUX
  257. MessageManagerLock mmLock;
  258. #endif
  259. stopTimer();
  260. deleteEditor (false);
  261. hasShutdown = true;
  262. delete filter;
  263. filter = nullptr;
  264. jassert (editorComp == 0);
  265. deleteTempChannels();
  266. jassert (activePlugins.contains (this));
  267. activePlugins.removeFirstMatchingValue (this);
  268. }
  269. if (activePlugins.size() == 0)
  270. {
  271. #if JUCE_LINUX
  272. SharedMessageThread::deleteInstance();
  273. #endif
  274. shutdownJuce_GUI();
  275. #if JUCE_WINDOWS
  276. messageThreadIsDefinitelyCorrect = false;
  277. #endif
  278. }
  279. }
  280. }
  281. void open() override
  282. {
  283. // Note: most hosts call this on the UI thread, but wavelab doesn't, so be careful in here.
  284. if (filter->hasEditor())
  285. cEffect.flags |= effFlagsHasEditor;
  286. else
  287. cEffect.flags &= ~effFlagsHasEditor;
  288. }
  289. void close() override
  290. {
  291. // Note: most hosts call this on the UI thread, but wavelab doesn't, so be careful in here.
  292. stopTimer();
  293. if (MessageManager::getInstance()->isThisTheMessageThread())
  294. deleteEditor (false);
  295. }
  296. //==============================================================================
  297. bool getEffectName (char* name) override
  298. {
  299. String (JucePlugin_Name).copyToUTF8 (name, 64 + 1);
  300. return true;
  301. }
  302. bool getVendorString (char* text) override
  303. {
  304. String (JucePlugin_Manufacturer).copyToUTF8 (text, 64 + 1);
  305. return true;
  306. }
  307. bool getProductString (char* text) override { return getEffectName (text); }
  308. VstInt32 getVendorVersion() override { return convertHexVersionToDecimal (JucePlugin_VersionCode); }
  309. VstPlugCategory getPlugCategory() override { return JucePlugin_VSTCategory; }
  310. bool keysRequired() { return (JucePlugin_EditorRequiresKeyboardFocus) != 0; }
  311. VstInt32 canDo (char* text) override
  312. {
  313. if (strcmp (text, "receiveVstEvents") == 0
  314. || strcmp (text, "receiveVstMidiEvent") == 0
  315. || strcmp (text, "receiveVstMidiEvents") == 0)
  316. {
  317. #if JucePlugin_WantsMidiInput
  318. return 1;
  319. #else
  320. return -1;
  321. #endif
  322. }
  323. if (strcmp (text, "sendVstEvents") == 0
  324. || strcmp (text, "sendVstMidiEvent") == 0
  325. || strcmp (text, "sendVstMidiEvents") == 0)
  326. {
  327. #if JucePlugin_ProducesMidiOutput
  328. return 1;
  329. #else
  330. return -1;
  331. #endif
  332. }
  333. if (strcmp (text, "receiveVstTimeInfo") == 0
  334. || strcmp (text, "conformsToWindowRules") == 0
  335. || strcmp (text, "bypass") == 0)
  336. {
  337. return 1;
  338. }
  339. // This tells Wavelab to use the UI thread to invoke open/close,
  340. // like all other hosts do.
  341. if (strcmp (text, "openCloseAnyThread") == 0)
  342. return -1;
  343. if (strcmp (text, "MPE") == 0)
  344. return filter->supportsMPE() ? 1 : 0;
  345. #if JUCE_MAC
  346. if (strcmp (text, "hasCockosViewAsConfig") == 0)
  347. {
  348. useNSView = true;
  349. return (VstInt32) 0xbeef0000;
  350. }
  351. #endif
  352. return 0;
  353. }
  354. VstIntPtr vendorSpecific (VstInt32 lArg, VstIntPtr lArg2, void* ptrArg, float floatArg) override
  355. {
  356. ignoreUnused (lArg, lArg2, ptrArg, floatArg);
  357. #if JucePlugin_Build_VST3 && JUCE_VST3_CAN_REPLACE_VST2
  358. if ((lArg == 'stCA' || lArg == 'stCa') && lArg2 == 'FUID' && ptrArg != nullptr)
  359. {
  360. memcpy (ptrArg, getJuceVST3ComponentIID(), 16);
  361. return 1;
  362. }
  363. #endif
  364. return 0;
  365. }
  366. bool setBypass (bool b) override
  367. {
  368. isBypassed = b;
  369. return true;
  370. }
  371. VstInt32 getGetTailSize() override
  372. {
  373. if (filter != nullptr)
  374. return (VstInt32) (filter->getTailLengthSeconds() * getSampleRate());
  375. return 0;
  376. }
  377. //==============================================================================
  378. VstInt32 processEvents (VstEvents* events) override
  379. {
  380. #if JucePlugin_WantsMidiInput
  381. VSTMidiEventList::addEventsToMidiBuffer (events, midiEvents);
  382. return 1;
  383. #else
  384. ignoreUnused (events);
  385. return 0;
  386. #endif
  387. }
  388. template <typename FloatType>
  389. void internalProcessReplacing (FloatType** inputs, FloatType** outputs,
  390. VstInt32 numSamples, VstTempBuffers<FloatType>& tmpBuffers)
  391. {
  392. if (firstProcessCallback)
  393. {
  394. firstProcessCallback = false;
  395. // if this fails, the host hasn't called resume() before processing
  396. jassert (isProcessing);
  397. // (tragically, some hosts actually need this, although it's stupid to have
  398. // to do it here..)
  399. if (! isProcessing)
  400. resume();
  401. filter->setNonRealtime (getCurrentProcessLevel() == 4 /* kVstProcessLevelOffline */);
  402. #if JUCE_WINDOWS
  403. if (getHostType().isWavelab())
  404. {
  405. int priority = GetThreadPriority (GetCurrentThread());
  406. if (priority <= THREAD_PRIORITY_NORMAL && priority >= THREAD_PRIORITY_LOWEST)
  407. filter->setNonRealtime (true);
  408. }
  409. #endif
  410. }
  411. #if JUCE_DEBUG && ! JucePlugin_ProducesMidiOutput
  412. const int numMidiEventsComingIn = midiEvents.getNumEvents();
  413. #endif
  414. jassert (activePlugins.contains (this));
  415. {
  416. const int numIn = filter->getTotalNumInputChannels();
  417. const int numOut = filter->getTotalNumOutputChannels();
  418. const ScopedLock sl (filter->getCallbackLock());
  419. if (filter->isSuspended())
  420. {
  421. for (int i = 0; i < numOut; ++i)
  422. FloatVectorOperations::clear (outputs[i], numSamples);
  423. }
  424. else
  425. {
  426. int i;
  427. for (i = 0; i < numOut; ++i)
  428. {
  429. FloatType* chan = tmpBuffers.tempChannels.getUnchecked(i);
  430. if (chan == nullptr)
  431. {
  432. chan = outputs[i];
  433. // if some output channels are disabled, some hosts supply the same buffer
  434. // for multiple channels - this buggers up our method of copying the
  435. // inputs over the outputs, so we need to create unique temp buffers in this case..
  436. for (int j = i; --j >= 0;)
  437. {
  438. if (outputs[j] == chan)
  439. {
  440. chan = new FloatType [blockSize * 2];
  441. tmpBuffers.tempChannels.set (i, chan);
  442. break;
  443. }
  444. }
  445. }
  446. if (i < numIn)
  447. {
  448. if (chan != inputs[i])
  449. memcpy (chan, inputs[i], sizeof (FloatType) * (size_t) numSamples);
  450. }
  451. else
  452. {
  453. FloatVectorOperations::clear (chan, numSamples);
  454. }
  455. tmpBuffers.channels[i] = chan;
  456. }
  457. for (; i < numIn; ++i)
  458. tmpBuffers.channels[i] = inputs[i];
  459. {
  460. const int numChannels = jmax (numIn, numOut);
  461. AudioBuffer<FloatType> chans (tmpBuffers.channels, numChannels, numSamples);
  462. if (isBypassed)
  463. filter->processBlockBypassed (chans, midiEvents);
  464. else
  465. filter->processBlock (chans, midiEvents);
  466. }
  467. // copy back any temp channels that may have been used..
  468. for (i = 0; i < numOut; ++i)
  469. if (const FloatType* const chan = tmpBuffers.tempChannels.getUnchecked(i))
  470. memcpy (outputs[i], chan, sizeof (FloatType) * (size_t) numSamples);
  471. }
  472. }
  473. if (! midiEvents.isEmpty())
  474. {
  475. #if JucePlugin_ProducesMidiOutput
  476. const int numEvents = midiEvents.getNumEvents();
  477. outgoingEvents.ensureSize (numEvents);
  478. outgoingEvents.clear();
  479. const juce::uint8* midiEventData;
  480. int midiEventSize, midiEventPosition;
  481. MidiBuffer::Iterator i (midiEvents);
  482. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  483. {
  484. jassert (midiEventPosition >= 0 && midiEventPosition < numSamples);
  485. outgoingEvents.addEvent (midiEventData, midiEventSize, midiEventPosition);
  486. }
  487. sendVstEventsToHost (outgoingEvents.events);
  488. #elif JUCE_DEBUG
  489. /* This assertion is caused when you've added some events to the
  490. midiMessages array in your processBlock() method, which usually means
  491. that you're trying to send them somewhere. But in this case they're
  492. getting thrown away.
  493. If your plugin does want to send midi messages, you'll need to set
  494. the JucePlugin_ProducesMidiOutput macro to 1 in your
  495. JucePluginCharacteristics.h file.
  496. If you don't want to produce any midi output, then you should clear the
  497. midiMessages array at the end of your processBlock() method, to
  498. indicate that you don't want any of the events to be passed through
  499. to the output.
  500. */
  501. jassert (midiEvents.getNumEvents() <= numMidiEventsComingIn);
  502. #endif
  503. midiEvents.clear();
  504. }
  505. }
  506. void processReplacing (float** inputs, float** outputs, VstInt32 sampleFrames) override
  507. {
  508. jassert (! filter->isUsingDoublePrecision());
  509. internalProcessReplacing (inputs, outputs, sampleFrames, floatTempBuffers);
  510. }
  511. void processDoubleReplacing (double** inputs, double** outputs, VstInt32 sampleFrames) override
  512. {
  513. jassert (filter->isUsingDoublePrecision());
  514. internalProcessReplacing (inputs, outputs, sampleFrames, doubleTempBuffers);
  515. }
  516. //==============================================================================
  517. VstInt32 startProcess() override { return 0; }
  518. VstInt32 stopProcess() override { return 0; }
  519. //==============================================================================
  520. bool setProcessPrecision (VstInt32 vstPrecision) override
  521. {
  522. if (! isProcessing)
  523. {
  524. if (filter != nullptr)
  525. {
  526. filter->setProcessingPrecision (vstPrecision == kVstProcessPrecision64 && filter->supportsDoublePrecisionProcessing()
  527. ? AudioProcessor::doublePrecision
  528. : AudioProcessor::singlePrecision);
  529. return true;
  530. }
  531. }
  532. return false;
  533. }
  534. void resume() override
  535. {
  536. if (filter != nullptr)
  537. {
  538. isProcessing = true;
  539. floatTempBuffers .channels.calloc ((size_t) (cEffect.numInputs + cEffect.numOutputs));
  540. doubleTempBuffers.channels.calloc ((size_t) (cEffect.numInputs + cEffect.numOutputs));
  541. const double currentRate = getSampleRate();
  542. const int currentBlockSize = getBlockSize();
  543. firstProcessCallback = true;
  544. filter->setNonRealtime (getCurrentProcessLevel() == 4 /* kVstProcessLevelOffline */);
  545. filter->setRateAndBufferSizeDetails (currentRate, currentBlockSize);
  546. deleteTempChannels();
  547. filter->prepareToPlay (currentRate, currentBlockSize);
  548. midiEvents.ensureSize (2048);
  549. midiEvents.clear();
  550. setInitialDelay (filter->getLatencySamples());
  551. AudioEffectX::resume();
  552. #if JucePlugin_ProducesMidiOutput
  553. outgoingEvents.ensureSize (512);
  554. #endif
  555. }
  556. }
  557. void suspend() override
  558. {
  559. if (filter != nullptr)
  560. {
  561. AudioEffectX::suspend();
  562. filter->releaseResources();
  563. outgoingEvents.freeEvents();
  564. isProcessing = false;
  565. floatTempBuffers.channels.free();
  566. doubleTempBuffers.channels.free();
  567. deleteTempChannels();
  568. }
  569. }
  570. bool getCurrentPosition (AudioPlayHead::CurrentPositionInfo& info) override
  571. {
  572. const VstTimeInfo* const ti = getTimeInfo (kVstPpqPosValid | kVstTempoValid | kVstBarsValid | kVstCyclePosValid
  573. | kVstTimeSigValid | kVstSmpteValid | kVstClockValid);
  574. if (ti == nullptr || ti->sampleRate <= 0)
  575. return false;
  576. info.bpm = (ti->flags & kVstTempoValid) != 0 ? ti->tempo : 0.0;
  577. if ((ti->flags & kVstTimeSigValid) != 0)
  578. {
  579. info.timeSigNumerator = ti->timeSigNumerator;
  580. info.timeSigDenominator = ti->timeSigDenominator;
  581. }
  582. else
  583. {
  584. info.timeSigNumerator = 4;
  585. info.timeSigDenominator = 4;
  586. }
  587. info.timeInSamples = (int64) (ti->samplePos + 0.5);
  588. info.timeInSeconds = ti->samplePos / ti->sampleRate;
  589. info.ppqPosition = (ti->flags & kVstPpqPosValid) != 0 ? ti->ppqPos : 0.0;
  590. info.ppqPositionOfLastBarStart = (ti->flags & kVstBarsValid) != 0 ? ti->barStartPos : 0.0;
  591. if ((ti->flags & kVstSmpteValid) != 0)
  592. {
  593. AudioPlayHead::FrameRateType rate = AudioPlayHead::fpsUnknown;
  594. double fps = 1.0;
  595. switch (ti->smpteFrameRate)
  596. {
  597. case kVstSmpte24fps: rate = AudioPlayHead::fps24; fps = 24.0; break;
  598. case kVstSmpte25fps: rate = AudioPlayHead::fps25; fps = 25.0; break;
  599. case kVstSmpte2997fps: rate = AudioPlayHead::fps2997; fps = 29.97; break;
  600. case kVstSmpte30fps: rate = AudioPlayHead::fps30; fps = 30.0; break;
  601. case kVstSmpte2997dfps: rate = AudioPlayHead::fps2997drop; fps = 29.97; break;
  602. case kVstSmpte30dfps: rate = AudioPlayHead::fps30drop; fps = 30.0; break;
  603. case kVstSmpteFilm16mm:
  604. case kVstSmpteFilm35mm: fps = 24.0; break;
  605. case kVstSmpte239fps: fps = 23.976; break;
  606. case kVstSmpte249fps: fps = 24.976; break;
  607. case kVstSmpte599fps: fps = 59.94; break;
  608. case kVstSmpte60fps: fps = 60; break;
  609. default: jassertfalse; // unknown frame-rate..
  610. }
  611. info.frameRate = rate;
  612. info.editOriginTime = ti->smpteOffset / (80.0 * fps);
  613. }
  614. else
  615. {
  616. info.frameRate = AudioPlayHead::fpsUnknown;
  617. info.editOriginTime = 0;
  618. }
  619. info.isRecording = (ti->flags & kVstTransportRecording) != 0;
  620. info.isPlaying = (ti->flags & (kVstTransportRecording | kVstTransportPlaying)) != 0;
  621. info.isLooping = (ti->flags & kVstTransportCycleActive) != 0;
  622. if ((ti->flags & kVstCyclePosValid) != 0)
  623. {
  624. info.ppqLoopStart = ti->cycleStartPos;
  625. info.ppqLoopEnd = ti->cycleEndPos;
  626. }
  627. else
  628. {
  629. info.ppqLoopStart = 0;
  630. info.ppqLoopEnd = 0;
  631. }
  632. return true;
  633. }
  634. //==============================================================================
  635. VstInt32 getProgram() override
  636. {
  637. return (filter != nullptr && filter->getNumPrograms() > 0 ? filter->getCurrentProgram() : 0);
  638. }
  639. void setProgram (VstInt32 program) override
  640. {
  641. if (filter != nullptr && filter->getNumPrograms() > 0)
  642. filter->setCurrentProgram (program);
  643. }
  644. void setProgramName (char* name) override
  645. {
  646. if (filter != nullptr && filter->getNumPrograms() > 0)
  647. filter->changeProgramName (filter->getCurrentProgram(), name);
  648. }
  649. void getProgramName (char* name) override
  650. {
  651. if (filter != nullptr && filter->getNumPrograms() > 0)
  652. filter->getProgramName (filter->getCurrentProgram()).copyToUTF8 (name, 24 + 1);
  653. }
  654. bool getProgramNameIndexed (VstInt32 /*category*/, VstInt32 index, char* text) override
  655. {
  656. if (filter != nullptr && isPositiveAndBelow (index, filter->getNumPrograms()))
  657. {
  658. filter->getProgramName (index).copyToUTF8 (text, 24 + 1);
  659. return true;
  660. }
  661. return false;
  662. }
  663. //==============================================================================
  664. float getParameter (VstInt32 index) override
  665. {
  666. if (filter == nullptr)
  667. return 0.0f;
  668. jassert (isPositiveAndBelow (index, filter->getNumParameters()));
  669. return filter->getParameter (index);
  670. }
  671. void setParameter (VstInt32 index, float value) override
  672. {
  673. if (filter != nullptr)
  674. {
  675. jassert (isPositiveAndBelow (index, filter->getNumParameters()));
  676. filter->setParameter (index, value);
  677. }
  678. }
  679. void getParameterDisplay (VstInt32 index, char* text) override
  680. {
  681. if (filter != nullptr)
  682. {
  683. jassert (isPositiveAndBelow (index, filter->getNumParameters()));
  684. filter->getParameterText (index, 24).copyToUTF8 (text, 24 + 1); // length should technically be kVstMaxParamStrLen, which is 8, but hosts will normally allow a bit more.
  685. }
  686. }
  687. bool string2parameter (VstInt32 index, char* text) override
  688. {
  689. if (filter != nullptr)
  690. {
  691. jassert (isPositiveAndBelow (index, filter->getNumParameters()));
  692. if (AudioProcessorParameter* p = filter->getParameters()[index])
  693. {
  694. filter->setParameter (index, p->getValueForText (String::fromUTF8 (text)));
  695. return true;
  696. }
  697. }
  698. return false;
  699. }
  700. void getParameterName (VstInt32 index, char* text) override
  701. {
  702. if (filter != nullptr)
  703. {
  704. jassert (isPositiveAndBelow (index, filter->getNumParameters()));
  705. filter->getParameterName (index, 16).copyToUTF8 (text, 16 + 1); // length should technically be kVstMaxParamStrLen, which is 8, but hosts will normally allow a bit more.
  706. }
  707. }
  708. void getParameterLabel (VstInt32 index, char* text) override
  709. {
  710. if (filter != nullptr)
  711. {
  712. jassert (isPositiveAndBelow (index, filter->getNumParameters()));
  713. filter->getParameterLabel (index).copyToUTF8 (text, 24 + 1); // length should technically be kVstMaxParamStrLen, which is 8, but hosts will normally allow a bit more.
  714. }
  715. }
  716. void audioProcessorParameterChanged (AudioProcessor*, int index, float newValue) override
  717. {
  718. if (audioMaster != nullptr)
  719. audioMaster (&cEffect, audioMasterAutomate, index, 0, 0, newValue);
  720. }
  721. void audioProcessorParameterChangeGestureBegin (AudioProcessor*, int index) override { beginEdit (index); }
  722. void audioProcessorParameterChangeGestureEnd (AudioProcessor*, int index) override { endEdit (index); }
  723. void audioProcessorChanged (AudioProcessor*) override
  724. {
  725. setInitialDelay (filter->getLatencySamples());
  726. updateDisplay();
  727. triggerAsyncUpdate();
  728. }
  729. void handleAsyncUpdate() override
  730. {
  731. ioChanged();
  732. }
  733. bool canParameterBeAutomated (VstInt32 index) override
  734. {
  735. return filter != nullptr && filter->isParameterAutomatable ((int) index);
  736. }
  737. bool setSpeakerArrangement (VstSpeakerArrangement* pluginInput,
  738. VstSpeakerArrangement* pluginOutput) override
  739. {
  740. const int numIns = busUtils.getBusCount (true);
  741. const int numOuts = busUtils.getBusCount (false);;
  742. if (pluginInput != nullptr && numIns == 0)
  743. return false;
  744. if (pluginOutput != nullptr && numOuts == 0)
  745. return false;
  746. if (pluginInput != nullptr && pluginInput->type >= 0)
  747. {
  748. // inconsistent request?
  749. if (SpeakerMappings::vstArrangementTypeToChannelSet (*pluginInput).size() != pluginInput->numChannels)
  750. return false;
  751. }
  752. if (pluginOutput != nullptr && pluginOutput->type >= 0)
  753. {
  754. // inconsistent request?
  755. if (SpeakerMappings::vstArrangementTypeToChannelSet (*pluginOutput).size() != pluginOutput->numChannels)
  756. return false;
  757. }
  758. if (numIns > 1 || numOuts > 1)
  759. {
  760. int newNumInChannels = (pluginInput != nullptr && pluginInput-> numChannels >= 0) ? pluginInput-> numChannels
  761. : busUtils.findTotalNumChannels (true);
  762. int newNumOutChannels = (pluginOutput != nullptr && pluginOutput->numChannels >= 0) ? pluginOutput->numChannels
  763. : busUtils.findTotalNumChannels (false);
  764. newNumInChannels = jmin (newNumInChannels, maxNumInChannels);
  765. newNumOutChannels = jmin (newNumOutChannels, maxNumOutChannels);
  766. if (! setBusArrangementFromTotalChannelNum (newNumInChannels, newNumOutChannels))
  767. return false;
  768. }
  769. else
  770. {
  771. PluginBusUtilities::ScopedBusRestorer busRestorer (busUtils);
  772. AudioChannelSet inLayoutType;
  773. if (pluginInput != nullptr && pluginInput-> numChannels >= 0)
  774. {
  775. inLayoutType = SpeakerMappings::vstArrangementTypeToChannelSet (*pluginInput);
  776. if (busUtils.getChannelSet (true, 0) != inLayoutType)
  777. if (! filter->setPreferredBusArrangement (true, 0, inLayoutType))
  778. return false;
  779. }
  780. if (pluginOutput != nullptr && pluginOutput->numChannels >= 0)
  781. {
  782. AudioChannelSet newType = SpeakerMappings::vstArrangementTypeToChannelSet (*pluginOutput);
  783. if (busUtils.getChannelSet (false, 0) != newType)
  784. if (! filter->setPreferredBusArrangement (false, 0, newType))
  785. return false;
  786. // re-check the input
  787. if ((! inLayoutType.isDisabled()) && busUtils.getChannelSet (true, 0) != inLayoutType)
  788. return false;
  789. busRestorer.release();
  790. }
  791. }
  792. filter->setRateAndBufferSizeDetails(0, 0);
  793. return true;
  794. }
  795. bool getSpeakerArrangement (VstSpeakerArrangement** pluginInput, VstSpeakerArrangement** pluginOutput) override
  796. {
  797. *pluginInput = 0;
  798. *pluginOutput = 0;
  799. if (! AudioEffectX::allocateArrangement (pluginInput, busUtils.findTotalNumChannels (true)))
  800. return false;
  801. if (! AudioEffectX::allocateArrangement (pluginOutput, busUtils.findTotalNumChannels (false)))
  802. {
  803. AudioEffectX::deallocateArrangement (pluginInput);
  804. *pluginInput = 0;
  805. return false;
  806. }
  807. if (pluginHasSidechainsOrAuxs())
  808. {
  809. int numIns = busUtils.findTotalNumChannels (true);
  810. int numOuts = busUtils.findTotalNumChannels (false);
  811. AudioChannelSet layout = AudioChannelSet::canonicalChannelSet (numIns);
  812. SpeakerMappings::channelSetToVstArrangement (layout, **pluginInput);
  813. layout = AudioChannelSet::canonicalChannelSet (numOuts);
  814. SpeakerMappings::channelSetToVstArrangement (layout, **pluginOutput);
  815. }
  816. else
  817. {
  818. SpeakerMappings::channelSetToVstArrangement (busUtils.getChannelSet (true, 0), **pluginInput);
  819. SpeakerMappings::channelSetToVstArrangement (busUtils.getChannelSet (false, 0), **pluginOutput);
  820. }
  821. return true;
  822. }
  823. bool getInputProperties (VstInt32 index, VstPinProperties* properties) override
  824. {
  825. return filter != nullptr
  826. && getPinProperties (*properties, true, (int) index);
  827. }
  828. bool getOutputProperties (VstInt32 index, VstPinProperties* properties) override
  829. {
  830. return filter != nullptr
  831. && getPinProperties (*properties, false, (int) index);
  832. }
  833. bool getPinProperties (VstPinProperties& properties, bool direction, int index) const
  834. {
  835. // fill with default
  836. properties.flags = kVstPinUseSpeaker;
  837. properties.label[0] = 0;
  838. properties.shortLabel[0] = 0;
  839. properties.arrangementType = kSpeakerArrEmpty;
  840. // index refers to the absolute index when combining all channels of every bus
  841. if (index >= (direction ? cEffect.numInputs : cEffect.numOutputs))
  842. return false;
  843. const int n = busUtils.getBusCount(direction);
  844. int busIdx;
  845. for (busIdx = 0; busIdx < n; ++busIdx)
  846. {
  847. const int numChans = busUtils.getNumChannels (direction, busIdx);
  848. if (index < numChans)
  849. break;
  850. index -= numChans;
  851. }
  852. if (busIdx >= n)
  853. return true;
  854. const AudioProcessor::AudioProcessorBus& busInfo = busUtils.getFilterBus (direction).getReference (busIdx);
  855. #ifdef JucePlugin_PreferredChannelConfigurations
  856. String abbvChannelName = String (index);
  857. #else
  858. String abbvChannelName = AudioChannelSet::getAbbreviatedChannelTypeName (busInfo.channels.getTypeOfChannel(index));
  859. #endif
  860. String channelName = busInfo.name + String (" ") + abbvChannelName;
  861. channelName.copyToUTF8 (properties.label, (size_t) (kVstMaxLabelLen + 1));
  862. channelName.copyToUTF8 (properties.shortLabel, (size_t) (kVstMaxShortLabelLen + 1));
  863. properties.flags = kVstPinUseSpeaker | kVstPinIsActive;
  864. properties.arrangementType = SpeakerMappings::channelSetToVstArrangementType (busInfo.channels);
  865. if (properties.arrangementType == kSpeakerArrEmpty)
  866. properties.flags &= ~kVstPinIsActive;
  867. if (busInfo.channels.size() == 2)
  868. properties.flags |= kVstPinIsStereo;
  869. return true;
  870. }
  871. //==============================================================================
  872. struct SpeakerMappings : private AudioChannelSet // (inheritance only to give easier access to items in the namespace)
  873. {
  874. struct Mapping
  875. {
  876. VstInt32 vst2;
  877. ChannelType channels[13];
  878. bool matches (const Array<ChannelType>& chans) const noexcept
  879. {
  880. const int n = sizeof (channels) / sizeof (ChannelType);
  881. for (int i = 0; i < n; ++i)
  882. {
  883. if (channels[i] == unknown) return (i == chans.size());
  884. if (i == chans.size()) return (channels[i] == unknown);
  885. if (channels[i] != chans.getUnchecked(i))
  886. return false;
  887. }
  888. return true;
  889. }
  890. };
  891. static AudioChannelSet vstArrangementTypeToChannelSet (const VstSpeakerArrangement& arr)
  892. {
  893. for (const Mapping* m = getMappings(); m->vst2 != kSpeakerArrEmpty; ++m)
  894. {
  895. if (m->vst2 == arr.type)
  896. {
  897. AudioChannelSet s;
  898. for (int i = 0; m->channels[i] != 0; ++i)
  899. s.addChannel (m->channels[i]);
  900. return s;
  901. }
  902. }
  903. return AudioChannelSet::discreteChannels (arr.numChannels);
  904. }
  905. static VstInt32 channelSetToVstArrangementType (AudioChannelSet channels)
  906. {
  907. Array<AudioChannelSet::ChannelType> chans (channels.getChannelTypes());
  908. if (channels == AudioChannelSet::disabled())
  909. return kSpeakerArrEmpty;
  910. for (const Mapping* m = getMappings(); m->vst2 != kSpeakerArrEmpty; ++m)
  911. if (m->matches (chans))
  912. return m->vst2;
  913. return kSpeakerArrUserDefined;
  914. }
  915. static void channelSetToVstArrangement (const AudioChannelSet& channels, VstSpeakerArrangement& result)
  916. {
  917. result.type = channelSetToVstArrangementType (channels);
  918. result.numChannels = channels.size();
  919. for (int i = 0; i < result.numChannels; ++i)
  920. {
  921. VstSpeakerProperties& speaker = result.speakers[i];
  922. zeromem (&speaker, sizeof (VstSpeakerProperties));
  923. speaker.type = getSpeakerType (channels.getTypeOfChannel (i));
  924. }
  925. }
  926. static const Mapping* getMappings() noexcept
  927. {
  928. static const Mapping mappings[] =
  929. {
  930. { kSpeakerArrMono, { centre, unknown } },
  931. { kSpeakerArrStereo, { left, right, unknown } },
  932. { kSpeakerArrStereoSurround, { leftSurround, rightSurround, unknown } },
  933. { kSpeakerArrStereoCenter, { leftCentre, rightCentre, unknown } },
  934. { kSpeakerArrStereoSide, { leftRearSurround, rightRearSurround, unknown } },
  935. { kSpeakerArrStereoCLfe, { centre, subbass, unknown } },
  936. { kSpeakerArr30Cine, { left, right, centre, unknown } },
  937. { kSpeakerArr30Music, { left, right, surround, unknown } },
  938. { kSpeakerArr31Cine, { left, right, centre, subbass, unknown } },
  939. { kSpeakerArr31Music, { left, right, subbass, surround, unknown } },
  940. { kSpeakerArr40Cine, { left, right, centre, surround, unknown } },
  941. { kSpeakerArr40Music, { left, right, leftSurround, rightSurround, unknown } },
  942. { kSpeakerArr41Cine, { left, right, centre, subbass, surround, unknown } },
  943. { kSpeakerArr41Music, { left, right, subbass, leftSurround, rightSurround, unknown } },
  944. { kSpeakerArr50, { left, right, centre, leftSurround, rightSurround, unknown } },
  945. { kSpeakerArr51, { left, right, centre, subbass, leftSurround, rightSurround, unknown } },
  946. { kSpeakerArr60Cine, { left, right, centre, leftSurround, rightSurround, surround, unknown } },
  947. { kSpeakerArr60Music, { left, right, leftSurround, rightSurround, leftRearSurround, rightRearSurround, unknown } },
  948. { kSpeakerArr61Cine, { left, right, centre, subbass, leftSurround, rightSurround, surround, unknown } },
  949. { kSpeakerArr61Music, { left, right, subbass, leftSurround, rightSurround, leftRearSurround, rightRearSurround, unknown } },
  950. { kSpeakerArr70Cine, { left, right, centre, leftSurround, rightSurround, topFrontLeft, topFrontRight, unknown } },
  951. { kSpeakerArr70Music, { left, right, centre, leftSurround, rightSurround, leftRearSurround, rightRearSurround, unknown } },
  952. { kSpeakerArr71Cine, { left, right, centre, subbass, leftSurround, rightSurround, topFrontLeft, topFrontRight, unknown } },
  953. { kSpeakerArr71Music, { left, right, centre, subbass, leftSurround, rightSurround, leftRearSurround, rightRearSurround, unknown } },
  954. { kSpeakerArr80Cine, { left, right, centre, leftSurround, rightSurround, topFrontLeft, topFrontRight, surround, unknown } },
  955. { kSpeakerArr80Music, { left, right, centre, leftSurround, rightSurround, surround, leftRearSurround, rightRearSurround, unknown } },
  956. { kSpeakerArr81Cine, { left, right, centre, subbass, leftSurround, rightSurround, topFrontLeft, topFrontRight, surround, unknown } },
  957. { kSpeakerArr81Music, { left, right, centre, subbass, leftSurround, rightSurround, surround, leftRearSurround, rightRearSurround, unknown } },
  958. { kSpeakerArr102, { left, right, centre, subbass, leftSurround, rightSurround, topFrontLeft, topFrontCentre, topFrontRight, topRearLeft, topRearRight, subbass2, unknown } },
  959. { kSpeakerArrEmpty, { unknown } }
  960. };
  961. return mappings;
  962. }
  963. static inline VstInt32 getSpeakerType (AudioChannelSet::ChannelType type) noexcept
  964. {
  965. switch (type)
  966. {
  967. case AudioChannelSet::left: return kSpeakerL;
  968. case AudioChannelSet::right: return kSpeakerR;
  969. case AudioChannelSet::centre: return kSpeakerC;
  970. case AudioChannelSet::subbass: return kSpeakerLfe;
  971. case AudioChannelSet::leftSurround: return kSpeakerLs;
  972. case AudioChannelSet::rightSurround: return kSpeakerRs;
  973. case AudioChannelSet::leftCentre: return kSpeakerLc;
  974. case AudioChannelSet::rightCentre: return kSpeakerRc;
  975. case AudioChannelSet::surround: return kSpeakerS;
  976. case AudioChannelSet::leftRearSurround: return kSpeakerSl;
  977. case AudioChannelSet::rightRearSurround: return kSpeakerSr;
  978. case AudioChannelSet::topMiddle: return kSpeakerTm;
  979. case AudioChannelSet::topFrontLeft: return kSpeakerTfl;
  980. case AudioChannelSet::topFrontCentre: return kSpeakerTfc;
  981. case AudioChannelSet::topFrontRight: return kSpeakerTfr;
  982. case AudioChannelSet::topRearLeft: return kSpeakerTrl;
  983. case AudioChannelSet::topRearCentre: return kSpeakerTrc;
  984. case AudioChannelSet::topRearRight: return kSpeakerTrr;
  985. case AudioChannelSet::subbass2: return kSpeakerLfe2;
  986. default: break;
  987. }
  988. return 0;
  989. }
  990. static inline AudioChannelSet::ChannelType getChannelType (VstInt32 type) noexcept
  991. {
  992. switch (type)
  993. {
  994. case kSpeakerL: return AudioChannelSet::left;
  995. case kSpeakerR: return AudioChannelSet::right;
  996. case kSpeakerC: return AudioChannelSet::centre;
  997. case kSpeakerLfe: return AudioChannelSet::subbass;
  998. case kSpeakerLs: return AudioChannelSet::leftSurround;
  999. case kSpeakerRs: return AudioChannelSet::rightSurround;
  1000. case kSpeakerLc: return AudioChannelSet::leftCentre;
  1001. case kSpeakerRc: return AudioChannelSet::rightCentre;
  1002. case kSpeakerS: return AudioChannelSet::surround;
  1003. case kSpeakerSl: return AudioChannelSet::leftRearSurround;
  1004. case kSpeakerSr: return AudioChannelSet::rightRearSurround;
  1005. case kSpeakerTm: return AudioChannelSet::topMiddle;
  1006. case kSpeakerTfl: return AudioChannelSet::topFrontLeft;
  1007. case kSpeakerTfc: return AudioChannelSet::topFrontCentre;
  1008. case kSpeakerTfr: return AudioChannelSet::topFrontRight;
  1009. case kSpeakerTrl: return AudioChannelSet::topRearLeft;
  1010. case kSpeakerTrc: return AudioChannelSet::topRearCentre;
  1011. case kSpeakerTrr: return AudioChannelSet::topRearRight;
  1012. case kSpeakerLfe2: return AudioChannelSet::subbass2;
  1013. default: break;
  1014. }
  1015. return AudioChannelSet::unknown;
  1016. }
  1017. };
  1018. //==============================================================================
  1019. VstInt32 getChunk (void** data, bool onlyStoreCurrentProgramData) override
  1020. {
  1021. if (filter == nullptr)
  1022. return 0;
  1023. chunkMemory.reset();
  1024. if (onlyStoreCurrentProgramData)
  1025. filter->getCurrentProgramStateInformation (chunkMemory);
  1026. else
  1027. filter->getStateInformation (chunkMemory);
  1028. *data = (void*) chunkMemory.getData();
  1029. // because the chunk is only needed temporarily by the host (or at least you'd
  1030. // hope so) we'll give it a while and then free it in the timer callback.
  1031. chunkMemoryTime = juce::Time::getApproximateMillisecondCounter();
  1032. return (VstInt32) chunkMemory.getSize();
  1033. }
  1034. VstInt32 setChunk (void* data, VstInt32 byteSize, bool onlyRestoreCurrentProgramData) override
  1035. {
  1036. if (filter != nullptr)
  1037. {
  1038. chunkMemory.reset();
  1039. chunkMemoryTime = 0;
  1040. if (byteSize > 0 && data != nullptr)
  1041. {
  1042. if (onlyRestoreCurrentProgramData)
  1043. filter->setCurrentProgramStateInformation (data, byteSize);
  1044. else
  1045. filter->setStateInformation (data, byteSize);
  1046. }
  1047. }
  1048. return 0;
  1049. }
  1050. void timerCallback() override
  1051. {
  1052. if (shouldDeleteEditor)
  1053. {
  1054. shouldDeleteEditor = false;
  1055. deleteEditor (true);
  1056. }
  1057. if (chunkMemoryTime > 0
  1058. && chunkMemoryTime < juce::Time::getApproximateMillisecondCounter() - 2000
  1059. && ! recursionCheck)
  1060. {
  1061. chunkMemory.reset();
  1062. chunkMemoryTime = 0;
  1063. }
  1064. #if JUCE_MAC
  1065. if (hostWindow != 0)
  1066. checkWindowVisibilityVST (hostWindow, editorComp, useNSView);
  1067. #endif
  1068. }
  1069. void doIdleCallback()
  1070. {
  1071. // (wavelab calls this on a separate thread and causes a deadlock)..
  1072. if (MessageManager::getInstance()->isThisTheMessageThread()
  1073. && ! recursionCheck)
  1074. {
  1075. ScopedValueSetter<bool> svs (recursionCheck, true, false);
  1076. JUCE_AUTORELEASEPOOL
  1077. {
  1078. Timer::callPendingTimersSynchronously();
  1079. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  1080. if (ComponentPeer* p = ComponentPeer::getPeer(i))
  1081. p->performAnyPendingRepaintsNow();
  1082. }
  1083. }
  1084. }
  1085. void createEditorComp()
  1086. {
  1087. if (hasShutdown || filter == nullptr)
  1088. return;
  1089. if (editorComp == nullptr)
  1090. {
  1091. if (AudioProcessorEditor* const ed = filter->createEditorIfNeeded())
  1092. {
  1093. cEffect.flags |= effFlagsHasEditor;
  1094. ed->setOpaque (true);
  1095. ed->setVisible (true);
  1096. editorComp = new EditorCompWrapper (*this, ed);
  1097. }
  1098. else
  1099. {
  1100. cEffect.flags &= ~effFlagsHasEditor;
  1101. }
  1102. }
  1103. shouldDeleteEditor = false;
  1104. }
  1105. void deleteEditor (bool canDeleteLaterIfModal)
  1106. {
  1107. JUCE_AUTORELEASEPOOL
  1108. {
  1109. PopupMenu::dismissAllActiveMenus();
  1110. jassert (! recursionCheck);
  1111. ScopedValueSetter<bool> svs (recursionCheck, true, false);
  1112. if (editorComp != nullptr)
  1113. {
  1114. if (Component* const modalComponent = Component::getCurrentlyModalComponent())
  1115. {
  1116. modalComponent->exitModalState (0);
  1117. if (canDeleteLaterIfModal)
  1118. {
  1119. shouldDeleteEditor = true;
  1120. return;
  1121. }
  1122. }
  1123. #if JUCE_MAC
  1124. if (hostWindow != 0)
  1125. {
  1126. detachComponentFromWindowRefVST (editorComp, hostWindow, useNSView);
  1127. hostWindow = 0;
  1128. }
  1129. #endif
  1130. filter->editorBeingDeleted (editorComp->getEditorComp());
  1131. editorComp = nullptr;
  1132. // there's some kind of component currently modal, but the host
  1133. // is trying to delete our plugin. You should try to avoid this happening..
  1134. jassert (Component::getCurrentlyModalComponent() == nullptr);
  1135. }
  1136. #if JUCE_LINUX
  1137. hostWindow = 0;
  1138. #endif
  1139. }
  1140. }
  1141. VstIntPtr dispatcher (VstInt32 opCode, VstInt32 index, VstIntPtr value, void* ptr, float opt) override
  1142. {
  1143. if (hasShutdown)
  1144. return 0;
  1145. if (opCode == effEditIdle)
  1146. {
  1147. doIdleCallback();
  1148. return 0;
  1149. }
  1150. else if (opCode == effEditOpen)
  1151. {
  1152. checkWhetherMessageThreadIsCorrect();
  1153. const MessageManagerLock mmLock;
  1154. jassert (! recursionCheck);
  1155. startTimer (1000 / 4); // performs misc housekeeping chores
  1156. deleteEditor (true);
  1157. createEditorComp();
  1158. if (editorComp != nullptr)
  1159. {
  1160. editorComp->setOpaque (true);
  1161. editorComp->setVisible (false);
  1162. #if JUCE_WINDOWS
  1163. editorComp->addToDesktop (0, ptr);
  1164. hostWindow = (HWND) ptr;
  1165. #elif JUCE_LINUX
  1166. editorComp->addToDesktop (0, ptr);
  1167. hostWindow = (Window) ptr;
  1168. Window editorWnd = (Window) editorComp->getWindowHandle();
  1169. XReparentWindow (display, editorWnd, hostWindow, 0, 0);
  1170. #else
  1171. hostWindow = attachComponentToWindowRefVST (editorComp, ptr, useNSView);
  1172. #endif
  1173. editorComp->setVisible (true);
  1174. return 1;
  1175. }
  1176. }
  1177. else if (opCode == effEditClose)
  1178. {
  1179. checkWhetherMessageThreadIsCorrect();
  1180. const MessageManagerLock mmLock;
  1181. deleteEditor (true);
  1182. return 0;
  1183. }
  1184. else if (opCode == effEditGetRect)
  1185. {
  1186. checkWhetherMessageThreadIsCorrect();
  1187. const MessageManagerLock mmLock;
  1188. createEditorComp();
  1189. if (editorComp != nullptr)
  1190. {
  1191. editorSize.left = 0;
  1192. editorSize.top = 0;
  1193. editorSize.right = (VstInt16) editorComp->getWidth();
  1194. editorSize.bottom = (VstInt16) editorComp->getHeight();
  1195. *((ERect**) ptr) = &editorSize;
  1196. return (VstIntPtr) (pointer_sized_int) &editorSize;
  1197. }
  1198. return 0;
  1199. }
  1200. return AudioEffectX::dispatcher (opCode, index, value, ptr, opt);
  1201. }
  1202. void resizeHostWindow (int newWidth, int newHeight)
  1203. {
  1204. if (editorComp != nullptr)
  1205. {
  1206. bool sizeWasSuccessful = false;
  1207. if (canHostDo (const_cast<char*> ("sizeWindow")))
  1208. {
  1209. isInSizeWindow = true;
  1210. sizeWasSuccessful = sizeWindow (newWidth, newHeight);
  1211. isInSizeWindow = false;
  1212. }
  1213. if (! sizeWasSuccessful)
  1214. {
  1215. // some hosts don't support the sizeWindow call, so do it manually..
  1216. #if JUCE_MAC
  1217. setNativeHostWindowSizeVST (hostWindow, editorComp, newWidth, newHeight, useNSView);
  1218. #elif JUCE_LINUX
  1219. // (Currently, all linux hosts support sizeWindow, so this should never need to happen)
  1220. editorComp->setSize (newWidth, newHeight);
  1221. #else
  1222. int dw = 0;
  1223. int dh = 0;
  1224. const int frameThickness = GetSystemMetrics (SM_CYFIXEDFRAME);
  1225. HWND w = (HWND) editorComp->getWindowHandle();
  1226. while (w != 0)
  1227. {
  1228. HWND parent = getWindowParent (w);
  1229. if (parent == 0)
  1230. break;
  1231. TCHAR windowType [32] = { 0 };
  1232. GetClassName (parent, windowType, 31);
  1233. if (String (windowType).equalsIgnoreCase ("MDIClient"))
  1234. break;
  1235. RECT windowPos, parentPos;
  1236. GetWindowRect (w, &windowPos);
  1237. GetWindowRect (parent, &parentPos);
  1238. SetWindowPos (w, 0, 0, 0, newWidth + dw, newHeight + dh,
  1239. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  1240. dw = (parentPos.right - parentPos.left) - (windowPos.right - windowPos.left);
  1241. dh = (parentPos.bottom - parentPos.top) - (windowPos.bottom - windowPos.top);
  1242. w = parent;
  1243. if (dw == 2 * frameThickness)
  1244. break;
  1245. if (dw > 100 || dh > 100)
  1246. w = 0;
  1247. }
  1248. if (w != 0)
  1249. SetWindowPos (w, 0, 0, 0, newWidth + dw, newHeight + dh,
  1250. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  1251. #endif
  1252. }
  1253. if (ComponentPeer* peer = editorComp->getPeer())
  1254. {
  1255. peer->handleMovedOrResized();
  1256. peer->getComponent().repaint();
  1257. }
  1258. }
  1259. }
  1260. //==============================================================================
  1261. // A component to hold the AudioProcessorEditor, and cope with some housekeeping
  1262. // chores when it changes or repaints.
  1263. class EditorCompWrapper : public Component
  1264. {
  1265. public:
  1266. EditorCompWrapper (JuceVSTWrapper& w, AudioProcessorEditor* editor)
  1267. : wrapper (w)
  1268. {
  1269. setOpaque (true);
  1270. editor->setOpaque (true);
  1271. setBounds (editor->getBounds());
  1272. editor->setTopLeftPosition (0, 0);
  1273. addAndMakeVisible (editor);
  1274. #if JUCE_WINDOWS
  1275. if (! getHostType().isReceptor())
  1276. addMouseListener (this, true);
  1277. #endif
  1278. ignoreUnused (fakeMouseGenerator);
  1279. }
  1280. ~EditorCompWrapper()
  1281. {
  1282. deleteAllChildren(); // note that we can't use a ScopedPointer because the editor may
  1283. // have been transferred to another parent which takes over ownership.
  1284. }
  1285. void paint (Graphics&) override {}
  1286. #if JUCE_MAC
  1287. bool keyPressed (const KeyPress&) override
  1288. {
  1289. // If we have an unused keypress, move the key-focus to a host window
  1290. // and re-inject the event..
  1291. return forwardCurrentKeyEventToHostVST (this, wrapper.useNSView);
  1292. }
  1293. #endif
  1294. AudioProcessorEditor* getEditorComp() const
  1295. {
  1296. return dynamic_cast<AudioProcessorEditor*> (getChildComponent(0));
  1297. }
  1298. void resized() override
  1299. {
  1300. if (Component* const editorChildComp = getChildComponent(0))
  1301. editorChildComp->setBounds (getLocalBounds());
  1302. #if JUCE_MAC && ! JUCE_64BIT
  1303. if (! wrapper.useNSView)
  1304. updateEditorCompBoundsVST (this);
  1305. #endif
  1306. }
  1307. void childBoundsChanged (Component* child) override
  1308. {
  1309. if (! wrapper.isInSizeWindow)
  1310. {
  1311. child->setTopLeftPosition (0, 0);
  1312. const int cw = child->getWidth();
  1313. const int ch = child->getHeight();
  1314. #if JUCE_MAC
  1315. if (wrapper.useNSView)
  1316. setTopLeftPosition (0, getHeight() - ch);
  1317. #endif
  1318. wrapper.resizeHostWindow (cw, ch);
  1319. #if ! JUCE_LINUX // setSize() on linux causes renoise and energyxt to fail.
  1320. setSize (cw, ch);
  1321. #else
  1322. XResizeWindow (display, (Window) getWindowHandle(), (unsigned int) cw, (unsigned int) ch);
  1323. #endif
  1324. #if JUCE_MAC
  1325. wrapper.resizeHostWindow (cw, ch); // (doing this a second time seems to be necessary in tracktion)
  1326. #endif
  1327. }
  1328. }
  1329. #if JUCE_WINDOWS
  1330. void mouseDown (const MouseEvent&) override
  1331. {
  1332. broughtToFront();
  1333. }
  1334. void broughtToFront() override
  1335. {
  1336. // for hosts like nuendo, need to also pop the MDI container to the
  1337. // front when our comp is clicked on.
  1338. if (! isCurrentlyBlockedByAnotherModalComponent())
  1339. if (HWND parent = findMDIParentOf ((HWND) getWindowHandle()))
  1340. SetWindowPos (parent, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  1341. }
  1342. #endif
  1343. private:
  1344. //==============================================================================
  1345. JuceVSTWrapper& wrapper;
  1346. FakeMouseMoveGenerator fakeMouseGenerator;
  1347. #if JUCE_WINDOWS
  1348. WindowsHooks hooks;
  1349. #endif
  1350. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (EditorCompWrapper)
  1351. };
  1352. //==============================================================================
  1353. private:
  1354. AudioProcessor* filter;
  1355. PluginBusUtilities busUtils;
  1356. juce::MemoryBlock chunkMemory;
  1357. juce::uint32 chunkMemoryTime;
  1358. ScopedPointer<EditorCompWrapper> editorComp;
  1359. ERect editorSize;
  1360. MidiBuffer midiEvents;
  1361. VSTMidiEventList outgoingEvents;
  1362. bool isProcessing, isBypassed, hasShutdown, isInSizeWindow, firstProcessCallback;
  1363. bool shouldDeleteEditor, useNSView;
  1364. VstTempBuffers<float> floatTempBuffers;
  1365. VstTempBuffers<double> doubleTempBuffers;
  1366. int maxNumInChannels, maxNumOutChannels;
  1367. #if JUCE_MAC
  1368. void* hostWindow;
  1369. #elif JUCE_LINUX
  1370. Window hostWindow;
  1371. #else
  1372. HWND hostWindow;
  1373. #endif
  1374. static inline VstInt32 convertHexVersionToDecimal (const unsigned int hexVersion)
  1375. {
  1376. #if JUCE_VST_RETURN_HEX_VERSION_NUMBER_DIRECTLY
  1377. return (VstInt32) hexVersion;
  1378. #else
  1379. return (VstInt32) (((hexVersion >> 24) & 0xff) * 1000
  1380. + ((hexVersion >> 16) & 0xff) * 100
  1381. + ((hexVersion >> 8) & 0xff) * 10
  1382. + (hexVersion & 0xff));
  1383. #endif
  1384. }
  1385. //==============================================================================
  1386. #if JUCE_WINDOWS
  1387. // Workarounds for hosts which attempt to open editor windows on a non-GUI thread.. (Grrrr...)
  1388. static void checkWhetherMessageThreadIsCorrect()
  1389. {
  1390. const PluginHostType host (getHostType());
  1391. if (host.isWavelab() || host.isCubaseBridged() || host.isPremiere())
  1392. {
  1393. if (! messageThreadIsDefinitelyCorrect)
  1394. {
  1395. MessageManager::getInstance()->setCurrentThreadAsMessageThread();
  1396. struct MessageThreadCallback : public CallbackMessage
  1397. {
  1398. MessageThreadCallback (bool& tr) : triggered (tr) {}
  1399. void messageCallback() override { triggered = true; }
  1400. bool& triggered;
  1401. };
  1402. (new MessageThreadCallback (messageThreadIsDefinitelyCorrect))->post();
  1403. }
  1404. }
  1405. }
  1406. #else
  1407. static void checkWhetherMessageThreadIsCorrect() {}
  1408. #endif
  1409. //==============================================================================
  1410. template <typename FloatType>
  1411. void deleteTempChannels (VstTempBuffers<FloatType>& tmpBuffers)
  1412. {
  1413. tmpBuffers.release();
  1414. if (filter != nullptr)
  1415. {
  1416. int numChannels = cEffect.numInputs + cEffect.numOutputs;
  1417. tmpBuffers.tempChannels.insertMultiple (0, nullptr, numChannels);
  1418. }
  1419. }
  1420. void deleteTempChannels()
  1421. {
  1422. deleteTempChannels (floatTempBuffers);
  1423. deleteTempChannels (doubleTempBuffers);
  1424. }
  1425. //==============================================================================
  1426. void findMaxTotalChannels (int& maxTotalIns, int& maxTotalOuts)
  1427. {
  1428. setMaxChannelsOnAllBuses (true);
  1429. setMaxChannelsOnAllBuses (false);
  1430. maxTotalIns = busUtils.findTotalNumChannels (true);
  1431. maxTotalOuts = busUtils.findTotalNumChannels (false);
  1432. }
  1433. void setMaxChannelsOnAllBuses (bool isInput)
  1434. {
  1435. const int n = busUtils.getBusCount (isInput);
  1436. for (int i = 0; i < n; ++i)
  1437. {
  1438. int ch = busUtils.findMaxNumberOfChannelsForBus (isInput, i);
  1439. if (ch == -1)
  1440. {
  1441. // VST-2 requires a maximum number of channels. If you are hitting this assertion
  1442. // then make sure that your setPreferredBusArrangement only accepts layouts
  1443. // up to a maximum number of channels
  1444. jassertfalse;
  1445. // do something sensible if the above assertions was hit
  1446. ch = busUtils.getDefaultLayoutForBus (isInput, i).size();
  1447. }
  1448. AudioChannelSet set =
  1449. busUtils.getDefaultLayoutForChannelNumAndBus (isInput, i, ch);
  1450. bool success = filter->setPreferredBusArrangement (isInput, i, set);
  1451. ignoreUnused (success);
  1452. // If you are hitting this assertsion then please file bug!
  1453. jassert ((! set.isDisabled()) && success);
  1454. }
  1455. }
  1456. //==============================================================================
  1457. void resetAuxChannelsToDefaultLayout (bool isInput) const
  1458. {
  1459. // set side-chain and aux channels to their default layout
  1460. for (int busIdx = 1; busIdx < busUtils.getBusCount (isInput); ++busIdx)
  1461. {
  1462. bool success = filter->setPreferredBusArrangement (isInput, busIdx, busUtils.getDefaultLayoutForBus (isInput, busIdx));
  1463. // VST 2 only supports a static channel layout on aux/sidechain channels
  1464. // You must at least support the default layout regardless of the layout of the main bus.
  1465. // If this is a problem for your plug-in, then consider using VST-3.
  1466. jassert (success);
  1467. ignoreUnused (success);
  1468. }
  1469. }
  1470. bool setBusArrangementFromTotalChannelNum (const int numInChannels, const int numOutChannels)
  1471. {
  1472. PluginBusUtilities::ScopedBusRestorer busRestorer (busUtils);
  1473. const int numIns = busUtils.getBusCount (true);
  1474. const int numOuts = busUtils.getBusCount (false);
  1475. const int n = numIns + numOuts;
  1476. HeapBlock<int> config (static_cast<size_t> (n), true);
  1477. HeapBlock<int> maxChans (static_cast<size_t> (n), true);
  1478. for (int i = 0; i < numIns; ++i)
  1479. maxChans[i] = busUtils.findMaxNumberOfChannelsForBus (true, i, numInChannels);
  1480. for (int i = 0; i < numOuts; ++i)
  1481. maxChans[i + numIns] = busUtils.findMaxNumberOfChannelsForBus (false, i, numOutChannels);
  1482. const int* inConfig = config.getData();
  1483. const int* outConfig = config.getData() + numIns;
  1484. #if JUCE_DEBUG
  1485. bool firstMatch = true;
  1486. AudioProcessor::AudioBusArrangement saveFirstMatch;
  1487. #endif
  1488. for (int i = 0; i < n;)
  1489. {
  1490. if (sumOfConfig (inConfig, numIns) == numInChannels
  1491. && sumOfConfig (outConfig, numOuts) == numOutChannels)
  1492. {
  1493. if (applyConfiguration (inConfig, outConfig))
  1494. {
  1495. #if JUCE_DEBUG
  1496. if (! firstMatch)
  1497. {
  1498. // Unfortunately, VST-2 requires that there is a unique plug-in bus
  1499. // arrangement for every x,y pair where x,y is the total number of
  1500. // input, output channels respectively.
  1501. jassertfalse;
  1502. busUtils.restoreBusArrangement (saveFirstMatch);
  1503. return true;
  1504. }
  1505. saveFirstMatch = filter->busArrangement;
  1506. firstMatch = false;
  1507. #else
  1508. busRestorer.release();
  1509. return true;
  1510. #endif
  1511. }
  1512. }
  1513. for (i = 0; i < n; ++i)
  1514. if ((config[i] = (config[i] + 1) % maxChans[i]) > 0)
  1515. break;
  1516. }
  1517. #if JUCE_DEBUG
  1518. if (! firstMatch)
  1519. {
  1520. busRestorer.release();
  1521. busUtils.restoreBusArrangement (saveFirstMatch);
  1522. return true;
  1523. }
  1524. #endif
  1525. return false;
  1526. }
  1527. bool setBusConfiguration (bool isInput, const int config[], const int n)
  1528. {
  1529. Array<AudioProcessor::AudioProcessorBus>& busArray = isInput ? filter->busArrangement.inputBuses
  1530. : filter->busArrangement.outputBuses;
  1531. int idx;
  1532. for (idx = 0; idx < n; ++idx)
  1533. {
  1534. if (busArray.getReference (idx).channels.size() == (config [idx] + 1))
  1535. continue;
  1536. AudioChannelSet set;
  1537. if ((set = busUtils.getDefaultLayoutForChannelNumAndBus (isInput, idx, config [idx] + 1)).isDisabled())
  1538. break;
  1539. if (! filter->setPreferredBusArrangement (isInput, idx, set))
  1540. break;
  1541. }
  1542. return (idx >= n);
  1543. }
  1544. bool configurationMatches (bool isInput, const int config[], const int n)
  1545. {
  1546. Array<AudioProcessor::AudioProcessorBus>& busArray = isInput ? filter->busArrangement.inputBuses
  1547. : filter->busArrangement.outputBuses;
  1548. int idx;
  1549. for (idx = 0; idx < n; ++idx)
  1550. if (busArray.getReference (idx).channels.size() != (config [idx] + 1))
  1551. break;
  1552. return (idx >= n);
  1553. }
  1554. bool applyConfiguration (const int inConfig[], const int outConfig[])
  1555. {
  1556. const int numIns = busUtils.getBusCount (true);
  1557. const int numOuts = busUtils.getBusCount (false);
  1558. if (! setBusConfiguration (true, inConfig, numIns))
  1559. return false;
  1560. if (! setBusConfiguration (false, outConfig, numOuts))
  1561. return false;
  1562. // re-check configuration
  1563. if (configurationMatches (true, inConfig, numIns) && configurationMatches (false, outConfig, numOuts))
  1564. return true;
  1565. return false;
  1566. }
  1567. //==============================================================================
  1568. bool pluginHasSidechainsOrAuxs() const { return (busUtils.getBusCount (true) > 1 || busUtils.getBusCount (false) > 1); }
  1569. static int sumOfConfig (const int config[], int num) noexcept
  1570. {
  1571. int retval = 0;
  1572. for (int i = 0; i < num; ++i)
  1573. retval += (config [i] + 1);
  1574. return retval;
  1575. }
  1576. //==============================================================================
  1577. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (JuceVSTWrapper)
  1578. };
  1579. //==============================================================================
  1580. namespace
  1581. {
  1582. AEffect* pluginEntryPoint (audioMasterCallback audioMaster)
  1583. {
  1584. JUCE_AUTORELEASEPOOL
  1585. {
  1586. initialiseJuce_GUI();
  1587. try
  1588. {
  1589. if (audioMaster (0, audioMasterVersion, 0, 0, 0, 0) != 0)
  1590. {
  1591. #if JUCE_LINUX
  1592. MessageManagerLock mmLock;
  1593. #endif
  1594. AudioProcessor* const filter = createPluginFilterOfType (AudioProcessor::wrapperType_VST);
  1595. JuceVSTWrapper* const wrapper = new JuceVSTWrapper (audioMaster, filter);
  1596. return wrapper->getAeffect();
  1597. }
  1598. }
  1599. catch (...)
  1600. {}
  1601. }
  1602. return nullptr;
  1603. }
  1604. }
  1605. #if ! JUCE_WINDOWS
  1606. #define JUCE_EXPORTED_FUNCTION extern "C" __attribute__ ((visibility("default")))
  1607. #endif
  1608. //==============================================================================
  1609. // Mac startup code..
  1610. #if JUCE_MAC
  1611. JUCE_EXPORTED_FUNCTION AEffect* VSTPluginMain (audioMasterCallback audioMaster);
  1612. JUCE_EXPORTED_FUNCTION AEffect* VSTPluginMain (audioMasterCallback audioMaster)
  1613. {
  1614. PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_VST;
  1615. initialiseMacVST();
  1616. return pluginEntryPoint (audioMaster);
  1617. }
  1618. JUCE_EXPORTED_FUNCTION AEffect* main_macho (audioMasterCallback audioMaster);
  1619. JUCE_EXPORTED_FUNCTION AEffect* main_macho (audioMasterCallback audioMaster)
  1620. {
  1621. PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_VST;
  1622. initialiseMacVST();
  1623. return pluginEntryPoint (audioMaster);
  1624. }
  1625. //==============================================================================
  1626. // Linux startup code..
  1627. #elif JUCE_LINUX
  1628. JUCE_EXPORTED_FUNCTION AEffect* VSTPluginMain (audioMasterCallback audioMaster);
  1629. JUCE_EXPORTED_FUNCTION AEffect* VSTPluginMain (audioMasterCallback audioMaster)
  1630. {
  1631. PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_VST;
  1632. SharedMessageThread::getInstance();
  1633. return pluginEntryPoint (audioMaster);
  1634. }
  1635. JUCE_EXPORTED_FUNCTION AEffect* main_plugin (audioMasterCallback audioMaster) asm ("main");
  1636. JUCE_EXPORTED_FUNCTION AEffect* main_plugin (audioMasterCallback audioMaster)
  1637. {
  1638. PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_VST;
  1639. return VSTPluginMain (audioMaster);
  1640. }
  1641. // don't put initialiseJuce_GUI or shutdownJuce_GUI in these... it will crash!
  1642. __attribute__((constructor)) void myPluginInit() {}
  1643. __attribute__((destructor)) void myPluginFini() {}
  1644. //==============================================================================
  1645. // Win32 startup code..
  1646. #else
  1647. extern "C" __declspec (dllexport) AEffect* VSTPluginMain (audioMasterCallback audioMaster)
  1648. {
  1649. PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_VST;
  1650. return pluginEntryPoint (audioMaster);
  1651. }
  1652. #ifndef JUCE_64BIT // (can't compile this on win64, but it's not needed anyway with VST2.4)
  1653. extern "C" __declspec (dllexport) int main (audioMasterCallback audioMaster)
  1654. {
  1655. PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_VST;
  1656. return (int) pluginEntryPoint (audioMaster);
  1657. }
  1658. #endif
  1659. #endif
  1660. #endif