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.

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