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.

2044 lines
72KB

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