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.

2077 lines
74KB

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