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.

1532 lines
50KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. // Your project must contain an AppConfig.h file with your project-specific settings in it,
  19. // and your header search path must make it accessible to the module's files.
  20. #include "AppConfig.h"
  21. #include "../utility/juce_CheckSettingMacros.h"
  22. #if JucePlugin_Build_VST
  23. #ifdef _MSC_VER
  24. #pragma warning (disable : 4996 4100)
  25. #endif
  26. #ifdef _WIN32
  27. #undef _WIN32_WINNT
  28. #define _WIN32_WINNT 0x500
  29. #undef STRICT
  30. #define STRICT 1
  31. #include <windows.h>
  32. #elif defined (LINUX)
  33. #include <X11/Xlib.h>
  34. #include <X11/Xutil.h>
  35. #include <X11/Xatom.h>
  36. #undef KeyPress
  37. #else
  38. #include <Carbon/Carbon.h>
  39. #endif
  40. #ifdef PRAGMA_ALIGN_SUPPORTED
  41. #undef PRAGMA_ALIGN_SUPPORTED
  42. #define PRAGMA_ALIGN_SUPPORTED 1
  43. #endif
  44. //==============================================================================
  45. /* These files come with the Steinberg VST SDK - to get them, you'll need to
  46. visit the Steinberg website and jump through some hoops to sign up as a
  47. VST developer.
  48. Then, you'll need to make sure your include path contains your "vstsdk2.4" directory.
  49. */
  50. #ifndef _MSC_VER
  51. #define __cdecl
  52. #endif
  53. #ifdef __clang__
  54. #pragma clang diagnostic push
  55. #pragma clang diagnostic ignored "-Wconversion"
  56. #pragma clang diagnostic ignored "-Wshadow"
  57. #endif
  58. // VSTSDK V2.4 includes..
  59. #include <public.sdk/source/vst2.x/audioeffectx.h>
  60. #include <public.sdk/source/vst2.x/aeffeditor.h>
  61. #include <public.sdk/source/vst2.x/audioeffectx.cpp>
  62. #include <public.sdk/source/vst2.x/audioeffect.cpp>
  63. #if ! VST_2_4_EXTENSIONS
  64. #error "It looks like you're trying to include an out-of-date VSTSDK version - make sure you have at least version 2.4"
  65. #endif
  66. #ifdef __clang__
  67. #pragma clang diagnostic pop
  68. #endif
  69. //==============================================================================
  70. #ifdef _MSC_VER
  71. #pragma pack (push, 8)
  72. #endif
  73. #include "../utility/juce_IncludeModuleHeaders.h"
  74. #include "../utility/juce_FakeMouseMoveGenerator.h"
  75. #include "../utility/juce_PluginHostType.h"
  76. #ifdef _MSC_VER
  77. #pragma pack (pop)
  78. #endif
  79. #undef MemoryBlock
  80. class JuceVSTWrapper;
  81. static bool recursionCheck = false;
  82. static juce::uint32 lastMasterIdleCall = 0;
  83. namespace juce
  84. {
  85. #if JUCE_MAC
  86. extern void initialiseMac();
  87. extern void* attachComponentToWindowRef (Component* component, void* windowRef);
  88. extern void detachComponentFromWindowRef (Component* component, void* nsWindow);
  89. extern void setNativeHostWindowSize (void* nsWindow, Component* editorComp, int newWidth, int newHeight, const PluginHostType& host);
  90. extern void checkWindowVisibility (void* nsWindow, Component* component);
  91. extern bool forwardCurrentKeyEventToHost (Component* component);
  92. #endif
  93. #if JUCE_LINUX
  94. extern Display* display;
  95. #endif
  96. }
  97. //==============================================================================
  98. #if JUCE_WINDOWS
  99. namespace
  100. {
  101. HWND findMDIParentOf (HWND w)
  102. {
  103. const int frameThickness = GetSystemMetrics (SM_CYFIXEDFRAME);
  104. while (w != 0)
  105. {
  106. HWND parent = GetParent (w);
  107. if (parent == 0)
  108. break;
  109. TCHAR windowType[32] = { 0 };
  110. GetClassName (parent, windowType, 31);
  111. if (String (windowType).equalsIgnoreCase ("MDIClient"))
  112. return parent;
  113. RECT windowPos, parentPos;
  114. GetWindowRect (w, &windowPos);
  115. GetWindowRect (parent, &parentPos);
  116. const int dw = (parentPos.right - parentPos.left) - (windowPos.right - windowPos.left);
  117. const int dh = (parentPos.bottom - parentPos.top) - (windowPos.bottom - windowPos.top);
  118. if (dw > 100 || dh > 100)
  119. break;
  120. w = parent;
  121. if (dw == 2 * frameThickness)
  122. break;
  123. }
  124. return w;
  125. }
  126. //==============================================================================
  127. static HHOOK mouseWheelHook = 0;
  128. static int mouseHookUsers = 0;
  129. LRESULT CALLBACK mouseWheelHookCallback (int nCode, WPARAM wParam, LPARAM lParam)
  130. {
  131. if (nCode >= 0 && wParam == WM_MOUSEWHEEL)
  132. {
  133. const MOUSEHOOKSTRUCTEX& hs = *(MOUSEHOOKSTRUCTEX*) lParam;
  134. if (Component* const comp = Desktop::getInstance().findComponentAt (Point<int> (hs.pt.x, hs.pt.y)))
  135. if (comp->getWindowHandle() != 0)
  136. return PostMessage ((HWND) comp->getWindowHandle(), WM_MOUSEWHEEL,
  137. hs.mouseData & 0xffff0000, (hs.pt.x & 0xffff) | (hs.pt.y << 16));
  138. }
  139. return CallNextHookEx (mouseWheelHook, nCode, wParam, lParam);
  140. }
  141. void registerMouseWheelHook()
  142. {
  143. if (mouseHookUsers++ == 0)
  144. mouseWheelHook = SetWindowsHookEx (WH_MOUSE, mouseWheelHookCallback,
  145. (HINSTANCE) Process::getCurrentModuleInstanceHandle(),
  146. GetCurrentThreadId());
  147. }
  148. void unregisterMouseWheelHook()
  149. {
  150. if (--mouseHookUsers == 0 && mouseWheelHook != 0)
  151. {
  152. UnhookWindowsHookEx (mouseWheelHook);
  153. mouseWheelHook = 0;
  154. }
  155. }
  156. #if JUCE_WINDOWS
  157. static bool messageThreadIsDefinitelyCorrect = false;
  158. #endif
  159. }
  160. //==============================================================================
  161. #elif JUCE_LINUX
  162. class SharedMessageThread : public Thread
  163. {
  164. public:
  165. SharedMessageThread()
  166. : Thread ("VstMessageThread"),
  167. initialised (false)
  168. {
  169. startThread (7);
  170. while (! initialised)
  171. sleep (1);
  172. }
  173. ~SharedMessageThread()
  174. {
  175. signalThreadShouldExit();
  176. JUCEApplication::quit();
  177. waitForThreadToExit (5000);
  178. clearSingletonInstance();
  179. }
  180. void run()
  181. {
  182. initialiseJuce_GUI();
  183. initialised = true;
  184. MessageManager::getInstance()->setCurrentThreadAsMessageThread();
  185. while ((! threadShouldExit()) && MessageManager::getInstance()->runDispatchLoopUntil (250))
  186. {}
  187. }
  188. juce_DeclareSingleton (SharedMessageThread, false);
  189. private:
  190. bool initialised;
  191. };
  192. juce_ImplementSingleton (SharedMessageThread)
  193. #endif
  194. static Array<void*> activePlugins;
  195. //==============================================================================
  196. /**
  197. This is an AudioEffectX object that holds and wraps our AudioProcessor...
  198. */
  199. class JuceVSTWrapper : public AudioEffectX,
  200. private Timer,
  201. public AudioProcessorListener,
  202. public AudioPlayHead
  203. {
  204. public:
  205. //==============================================================================
  206. JuceVSTWrapper (audioMasterCallback audioMaster, AudioProcessor* const filter_)
  207. : AudioEffectX (audioMaster, filter_->getNumPrograms(), filter_->getNumParameters()),
  208. filter (filter_),
  209. chunkMemoryTime (0),
  210. speakerIn (kSpeakerArrEmpty),
  211. speakerOut (kSpeakerArrEmpty),
  212. numInChans (JucePlugin_MaxNumInputChannels),
  213. numOutChans (JucePlugin_MaxNumOutputChannels),
  214. isProcessing (false),
  215. hasShutdown (false),
  216. firstProcessCallback (true),
  217. shouldDeleteEditor (false),
  218. hostWindow (0)
  219. {
  220. filter->setPlayConfigDetails (numInChans, numOutChans, 0, 0);
  221. filter->setPlayHead (this);
  222. filter->addListener (this);
  223. cEffect.flags |= effFlagsHasEditor;
  224. cEffect.version = (long) (JucePlugin_VersionCode);
  225. setUniqueID ((int) (JucePlugin_VSTUniqueID));
  226. setNumInputs (numInChans);
  227. setNumOutputs (numOutChans);
  228. canProcessReplacing (true);
  229. isSynth ((JucePlugin_IsSynth) != 0);
  230. noTail (((JucePlugin_SilenceInProducesSilenceOut) != 0) && (JucePlugin_TailLengthSeconds <= 0));
  231. setInitialDelay (filter->getLatencySamples());
  232. programsAreChunks (true);
  233. activePlugins.add (this);
  234. }
  235. ~JuceVSTWrapper()
  236. {
  237. JUCE_AUTORELEASEPOOL
  238. {
  239. #if JUCE_LINUX
  240. MessageManagerLock mmLock;
  241. #endif
  242. stopTimer();
  243. deleteEditor (false);
  244. hasShutdown = true;
  245. delete filter;
  246. filter = 0;
  247. jassert (editorComp == 0);
  248. channels.free();
  249. deleteTempChannels();
  250. jassert (activePlugins.contains (this));
  251. activePlugins.removeFirstMatchingValue (this);
  252. }
  253. if (activePlugins.size() == 0)
  254. {
  255. #if JUCE_LINUX
  256. SharedMessageThread::deleteInstance();
  257. #endif
  258. shutdownJuce_GUI();
  259. #if JUCE_WINDOWS
  260. messageThreadIsDefinitelyCorrect = false;
  261. #endif
  262. }
  263. }
  264. void open()
  265. {
  266. // Note: most hosts call this on the UI thread, but wavelab doesn't, so be careful in here.
  267. if (filter->hasEditor())
  268. cEffect.flags |= effFlagsHasEditor;
  269. else
  270. cEffect.flags &= ~effFlagsHasEditor;
  271. }
  272. void close()
  273. {
  274. // Note: most hosts call this on the UI thread, but wavelab doesn't, so be careful in here.
  275. stopTimer();
  276. if (MessageManager::getInstance()->isThisTheMessageThread())
  277. deleteEditor (false);
  278. }
  279. //==============================================================================
  280. bool getEffectName (char* name)
  281. {
  282. String (JucePlugin_Name).copyToUTF8 (name, 64);
  283. return true;
  284. }
  285. bool getVendorString (char* text)
  286. {
  287. String (JucePlugin_Manufacturer).copyToUTF8 (text, 64);
  288. return true;
  289. }
  290. bool getProductString (char* text) { return getEffectName (text); }
  291. VstInt32 getVendorVersion() { return JucePlugin_VersionCode; }
  292. VstPlugCategory getPlugCategory() { return JucePlugin_VSTCategory; }
  293. bool keysRequired() { return (JucePlugin_EditorRequiresKeyboardFocus) != 0; }
  294. VstInt32 canDo (char* text)
  295. {
  296. VstInt32 result = 0;
  297. if (strcmp (text, "receiveVstEvents") == 0
  298. || strcmp (text, "receiveVstMidiEvent") == 0
  299. || strcmp (text, "receiveVstMidiEvents") == 0)
  300. {
  301. #if JucePlugin_WantsMidiInput
  302. result = 1;
  303. #else
  304. result = -1;
  305. #endif
  306. }
  307. else if (strcmp (text, "sendVstEvents") == 0
  308. || strcmp (text, "sendVstMidiEvent") == 0
  309. || strcmp (text, "sendVstMidiEvents") == 0)
  310. {
  311. #if JucePlugin_ProducesMidiOutput
  312. result = 1;
  313. #else
  314. result = -1;
  315. #endif
  316. }
  317. else if (strcmp (text, "receiveVstTimeInfo") == 0
  318. || strcmp (text, "conformsToWindowRules") == 0)
  319. {
  320. result = 1;
  321. }
  322. else if (strcmp (text, "openCloseAnyThread") == 0)
  323. {
  324. // This tells Wavelab to use the UI thread to invoke open/close,
  325. // like all other hosts do.
  326. result = -1;
  327. }
  328. return result;
  329. }
  330. bool getInputProperties (VstInt32 index, VstPinProperties* properties)
  331. {
  332. if (filter == nullptr || index >= JucePlugin_MaxNumInputChannels)
  333. return false;
  334. setPinProperties (*properties, filter->getInputChannelName ((int) index),
  335. speakerIn, filter->isInputChannelStereoPair ((int) index));
  336. return true;
  337. }
  338. bool getOutputProperties (VstInt32 index, VstPinProperties* properties)
  339. {
  340. if (filter == nullptr || index >= JucePlugin_MaxNumOutputChannels)
  341. return false;
  342. setPinProperties (*properties, filter->getOutputChannelName ((int) index),
  343. speakerOut, filter->isOutputChannelStereoPair ((int) index));
  344. return true;
  345. }
  346. static void setPinProperties (VstPinProperties& properties, const String& name,
  347. VstSpeakerArrangementType type, const bool isPair)
  348. {
  349. name.copyToUTF8 (properties.label, kVstMaxLabelLen - 1);
  350. name.copyToUTF8 (properties.shortLabel, kVstMaxShortLabelLen - 1);
  351. if (type != kSpeakerArrEmpty)
  352. {
  353. properties.flags = kVstPinUseSpeaker;
  354. properties.arrangementType = type;
  355. }
  356. else
  357. {
  358. properties.flags = kVstPinIsActive;
  359. properties.arrangementType = 0;
  360. if (isPair)
  361. properties.flags |= kVstPinIsStereo;
  362. }
  363. }
  364. //==============================================================================
  365. VstInt32 processEvents (VstEvents* events)
  366. {
  367. #if JucePlugin_WantsMidiInput
  368. VSTMidiEventList::addEventsToMidiBuffer (events, midiEvents);
  369. return 1;
  370. #else
  371. return 0;
  372. #endif
  373. }
  374. void process (float** inputs, float** outputs, VstInt32 numSamples)
  375. {
  376. const int numIn = numInChans;
  377. const int numOut = numOutChans;
  378. AudioSampleBuffer temp (numIn, numSamples);
  379. for (int i = numIn; --i >= 0;)
  380. memcpy (temp.getSampleData (i), outputs[i], sizeof (float) * numSamples);
  381. processReplacing (inputs, outputs, numSamples);
  382. AudioSampleBuffer dest (outputs, numOut, numSamples);
  383. for (int i = jmin (numIn, numOut); --i >= 0;)
  384. dest.addFrom (i, 0, temp, i, 0, numSamples);
  385. }
  386. void processReplacing (float** inputs, float** outputs, VstInt32 numSamples)
  387. {
  388. if (firstProcessCallback)
  389. {
  390. firstProcessCallback = false;
  391. // if this fails, the host hasn't called resume() before processing
  392. jassert (isProcessing);
  393. // (tragically, some hosts actually need this, although it's stupid to have
  394. // to do it here..)
  395. if (! isProcessing)
  396. resume();
  397. filter->setNonRealtime (getCurrentProcessLevel() == 4 /* kVstProcessLevelOffline */);
  398. #if JUCE_WINDOWS
  399. if (GetThreadPriority (GetCurrentThread()) <= THREAD_PRIORITY_NORMAL
  400. && GetThreadPriority (GetCurrentThread()) >= THREAD_PRIORITY_LOWEST)
  401. filter->setNonRealtime (true);
  402. #endif
  403. }
  404. #if JUCE_DEBUG && ! JucePlugin_ProducesMidiOutput
  405. const int numMidiEventsComingIn = midiEvents.getNumEvents();
  406. #endif
  407. jassert (activePlugins.contains (this));
  408. {
  409. const ScopedLock sl (filter->getCallbackLock());
  410. const int numIn = numInChans;
  411. const int numOut = numOutChans;
  412. if (filter->isSuspended())
  413. {
  414. for (int i = 0; i < numOut; ++i)
  415. zeromem (outputs[i], sizeof (float) * numSamples);
  416. }
  417. else
  418. {
  419. int i;
  420. for (i = 0; i < numOut; ++i)
  421. {
  422. float* chan = tempChannels.getUnchecked(i);
  423. if (chan == nullptr)
  424. {
  425. chan = outputs[i];
  426. // if some output channels are disabled, some hosts supply the same buffer
  427. // for multiple channels - this buggers up our method of copying the
  428. // inputs over the outputs, so we need to create unique temp buffers in this case..
  429. for (int j = i; --j >= 0;)
  430. {
  431. if (outputs[j] == chan)
  432. {
  433. chan = new float [blockSize * 2];
  434. tempChannels.set (i, chan);
  435. break;
  436. }
  437. }
  438. }
  439. if (i < numIn && chan != inputs[i])
  440. memcpy (chan, inputs[i], sizeof (float) * numSamples);
  441. channels[i] = chan;
  442. }
  443. for (; i < numIn; ++i)
  444. channels[i] = inputs[i];
  445. {
  446. AudioSampleBuffer chans (channels, jmax (numIn, numOut), numSamples);
  447. filter->processBlock (chans, midiEvents);
  448. }
  449. // copy back any temp channels that may have been used..
  450. for (i = 0; i < numOut; ++i)
  451. if (const float* const chan = tempChannels.getUnchecked(i))
  452. memcpy (outputs[i], chan, sizeof (float) * numSamples);
  453. }
  454. }
  455. if (! midiEvents.isEmpty())
  456. {
  457. #if JucePlugin_ProducesMidiOutput
  458. const int numEvents = midiEvents.getNumEvents();
  459. outgoingEvents.ensureSize (numEvents);
  460. outgoingEvents.clear();
  461. const juce::uint8* midiEventData;
  462. int midiEventSize, midiEventPosition;
  463. MidiBuffer::Iterator i (midiEvents);
  464. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  465. {
  466. jassert (midiEventPosition >= 0 && midiEventPosition < numSamples);
  467. outgoingEvents.addEvent (midiEventData, midiEventSize, midiEventPosition);
  468. }
  469. sendVstEventsToHost (outgoingEvents.events);
  470. #elif JUCE_DEBUG
  471. /* This assertion is caused when you've added some events to the
  472. midiMessages array in your processBlock() method, which usually means
  473. that you're trying to send them somewhere. But in this case they're
  474. getting thrown away.
  475. If your plugin does want to send midi messages, you'll need to set
  476. the JucePlugin_ProducesMidiOutput macro to 1 in your
  477. JucePluginCharacteristics.h file.
  478. If you don't want to produce any midi output, then you should clear the
  479. midiMessages array at the end of your processBlock() method, to
  480. indicate that you don't want any of the events to be passed through
  481. to the output.
  482. */
  483. jassert (midiEvents.getNumEvents() <= numMidiEventsComingIn);
  484. #endif
  485. midiEvents.clear();
  486. }
  487. }
  488. //==============================================================================
  489. VstInt32 startProcess() { return 0; }
  490. VstInt32 stopProcess() { return 0; }
  491. void resume()
  492. {
  493. if (filter != nullptr)
  494. {
  495. isProcessing = true;
  496. channels.calloc (numInChans + numOutChans);
  497. double rate = getSampleRate();
  498. jassert (rate > 0);
  499. if (rate <= 0.0)
  500. rate = 44100.0;
  501. const int blockSize = getBlockSize();
  502. jassert (blockSize > 0);
  503. firstProcessCallback = true;
  504. filter->setNonRealtime (getCurrentProcessLevel() == 4 /* kVstProcessLevelOffline */);
  505. filter->setPlayConfigDetails (numInChans, numOutChans, rate, blockSize);
  506. deleteTempChannels();
  507. filter->prepareToPlay (rate, blockSize);
  508. midiEvents.ensureSize (2048);
  509. midiEvents.clear();
  510. setInitialDelay (filter->getLatencySamples());
  511. AudioEffectX::resume();
  512. #if JucePlugin_ProducesMidiOutput
  513. outgoingEvents.ensureSize (512);
  514. #endif
  515. }
  516. }
  517. void suspend()
  518. {
  519. if (filter != nullptr)
  520. {
  521. AudioEffectX::suspend();
  522. filter->releaseResources();
  523. outgoingEvents.freeEvents();
  524. isProcessing = false;
  525. channels.free();
  526. deleteTempChannels();
  527. }
  528. }
  529. bool getCurrentPosition (AudioPlayHead::CurrentPositionInfo& info)
  530. {
  531. const VstTimeInfo* const ti = getTimeInfo (kVstPpqPosValid | kVstTempoValid | kVstBarsValid | kVstCyclePosValid
  532. | kVstTimeSigValid | kVstSmpteValid | kVstClockValid);
  533. if (ti == nullptr || ti->sampleRate <= 0)
  534. return false;
  535. info.bpm = (ti->flags & kVstTempoValid) != 0 ? ti->tempo : 0.0;
  536. if ((ti->flags & kVstTimeSigValid) != 0)
  537. {
  538. info.timeSigNumerator = ti->timeSigNumerator;
  539. info.timeSigDenominator = ti->timeSigDenominator;
  540. }
  541. else
  542. {
  543. info.timeSigNumerator = 4;
  544. info.timeSigDenominator = 4;
  545. }
  546. info.timeInSamples = (int64) ti->samplePos;
  547. info.timeInSeconds = ti->samplePos / ti->sampleRate;
  548. info.ppqPosition = (ti->flags & kVstPpqPosValid) != 0 ? ti->ppqPos : 0.0;
  549. info.ppqPositionOfLastBarStart = (ti->flags & kVstBarsValid) != 0 ? ti->barStartPos : 0.0;
  550. if ((ti->flags & kVstSmpteValid) != 0)
  551. {
  552. AudioPlayHead::FrameRateType rate = AudioPlayHead::fpsUnknown;
  553. double fps = 1.0;
  554. switch (ti->smpteFrameRate)
  555. {
  556. case kVstSmpte24fps: rate = AudioPlayHead::fps24; fps = 24.0; break;
  557. case kVstSmpte25fps: rate = AudioPlayHead::fps25; fps = 25.0; break;
  558. case kVstSmpte2997fps: rate = AudioPlayHead::fps2997; fps = 29.97; break;
  559. case kVstSmpte30fps: rate = AudioPlayHead::fps30; fps = 30.0; break;
  560. case kVstSmpte2997dfps: rate = AudioPlayHead::fps2997drop; fps = 29.97; break;
  561. case kVstSmpte30dfps: rate = AudioPlayHead::fps30drop; fps = 30.0; break;
  562. case kVstSmpteFilm16mm:
  563. case kVstSmpteFilm35mm: fps = 24.0; break;
  564. case kVstSmpte239fps: fps = 23.976; break;
  565. case kVstSmpte249fps: fps = 24.976; break;
  566. case kVstSmpte599fps: fps = 59.94; break;
  567. case kVstSmpte60fps: fps = 60; break;
  568. default: jassertfalse; // unknown frame-rate..
  569. }
  570. info.frameRate = rate;
  571. info.editOriginTime = ti->smpteOffset / (80.0 * fps);
  572. }
  573. else
  574. {
  575. info.frameRate = AudioPlayHead::fpsUnknown;
  576. info.editOriginTime = 0;
  577. }
  578. info.isRecording = (ti->flags & kVstTransportRecording) != 0;
  579. info.isPlaying = (ti->flags & (kVstTransportRecording | kVstTransportPlaying)) != 0;
  580. info.isLooping = (ti->flags & kVstTransportCycleActive) != 0;
  581. if ((ti->flags & kVstCyclePosValid) != 0)
  582. {
  583. info.ppqLoopStart = ti->cycleStartPos;
  584. info.ppqLoopEnd = ti->cycleEndPos;
  585. }
  586. else
  587. {
  588. info.ppqLoopStart = 0;
  589. info.ppqLoopEnd = 0;
  590. }
  591. return true;
  592. }
  593. //==============================================================================
  594. VstInt32 getProgram()
  595. {
  596. return filter != nullptr ? filter->getCurrentProgram() : 0;
  597. }
  598. void setProgram (VstInt32 program)
  599. {
  600. if (filter != nullptr)
  601. filter->setCurrentProgram (program);
  602. }
  603. void setProgramName (char* name)
  604. {
  605. if (filter != nullptr)
  606. filter->changeProgramName (filter->getCurrentProgram(), name);
  607. }
  608. void getProgramName (char* name)
  609. {
  610. if (filter != nullptr)
  611. filter->getProgramName (filter->getCurrentProgram()).copyToUTF8 (name, 24);
  612. }
  613. bool getProgramNameIndexed (VstInt32 /*category*/, VstInt32 index, char* text)
  614. {
  615. if (filter != nullptr && isPositiveAndBelow (index, filter->getNumPrograms()))
  616. {
  617. filter->getProgramName (index).copyToUTF8 (text, 24);
  618. return true;
  619. }
  620. return false;
  621. }
  622. //==============================================================================
  623. float getParameter (VstInt32 index)
  624. {
  625. if (filter == nullptr)
  626. return 0.0f;
  627. jassert (isPositiveAndBelow (index, filter->getNumParameters()));
  628. return filter->getParameter (index);
  629. }
  630. void setParameter (VstInt32 index, float value)
  631. {
  632. if (filter != nullptr)
  633. {
  634. jassert (isPositiveAndBelow (index, filter->getNumParameters()));
  635. filter->setParameter (index, value);
  636. }
  637. }
  638. void getParameterDisplay (VstInt32 index, char* text)
  639. {
  640. if (filter != nullptr)
  641. {
  642. jassert (isPositiveAndBelow (index, filter->getNumParameters()));
  643. filter->getParameterText (index).copyToUTF8 (text, 24); // length should technically be kVstMaxParamStrLen, which is 8, but hosts will normally allow a bit more.
  644. }
  645. }
  646. void getParameterName (VstInt32 index, char* text)
  647. {
  648. if (filter != nullptr)
  649. {
  650. jassert (isPositiveAndBelow (index, filter->getNumParameters()));
  651. filter->getParameterName (index).copyToUTF8 (text, 16); // length should technically be kVstMaxParamStrLen, which is 8, but hosts will normally allow a bit more.
  652. }
  653. }
  654. void audioProcessorParameterChanged (AudioProcessor*, int index, float newValue)
  655. {
  656. setParameterAutomated (index, newValue);
  657. }
  658. void audioProcessorParameterChangeGestureBegin (AudioProcessor*, int index) { beginEdit (index); }
  659. void audioProcessorParameterChangeGestureEnd (AudioProcessor*, int index) { endEdit (index); }
  660. void audioProcessorChanged (AudioProcessor*)
  661. {
  662. setInitialDelay (filter->getLatencySamples());
  663. ioChanged();
  664. updateDisplay();
  665. }
  666. bool canParameterBeAutomated (VstInt32 index)
  667. {
  668. return filter != nullptr && filter->isParameterAutomatable ((int) index);
  669. }
  670. struct ChannelConfigComparator
  671. {
  672. static int compareElements (const short* const first, const short* const second) noexcept
  673. {
  674. if (first[0] < second[0]) return -1;
  675. if (first[0] > second[0]) return 1;
  676. if (first[1] < second[1]) return -1;
  677. if (first[1] > second[1]) return 1;
  678. return 0;
  679. }
  680. };
  681. bool setSpeakerArrangement (VstSpeakerArrangement* pluginInput,
  682. VstSpeakerArrangement* pluginOutput)
  683. {
  684. short channelConfigs[][2] = { JucePlugin_PreferredChannelConfigurations };
  685. Array <short*> channelConfigsSorted;
  686. ChannelConfigComparator comp;
  687. for (int i = 0; i < numElementsInArray (channelConfigs); ++i)
  688. channelConfigsSorted.addSorted (comp, channelConfigs[i]);
  689. for (int i = channelConfigsSorted.size(); --i >= 0;)
  690. {
  691. const short* const config = channelConfigsSorted.getUnchecked(i);
  692. bool inCountMatches = (config[0] == pluginInput->numChannels);
  693. bool outCountMatches = (config[1] == pluginOutput->numChannels);
  694. if (inCountMatches && outCountMatches)
  695. {
  696. speakerIn = (VstSpeakerArrangementType) pluginInput->type;
  697. speakerOut = (VstSpeakerArrangementType) pluginOutput->type;
  698. numInChans = pluginInput->numChannels;
  699. numOutChans = pluginOutput->numChannels;
  700. filter->setPlayConfigDetails (numInChans, numOutChans,
  701. filter->getSampleRate(),
  702. filter->getBlockSize());
  703. filter->setSpeakerArrangement (getSpeakerArrangementString (speakerIn),
  704. getSpeakerArrangementString (speakerOut));
  705. return true;
  706. }
  707. }
  708. filter->setSpeakerArrangement (String::empty, String::empty);
  709. return false;
  710. }
  711. static const char* getSpeakerArrangementString (VstSpeakerArrangementType type) noexcept
  712. {
  713. switch (type)
  714. {
  715. case kSpeakerArrMono: return "M";
  716. case kSpeakerArrStereo: return "L R";
  717. case kSpeakerArrStereoSurround: return "Ls Rs";
  718. case kSpeakerArrStereoCenter: return "Lc Rc";
  719. case kSpeakerArrStereoSide: return "Sl Sr";
  720. case kSpeakerArrStereoCLfe: return "C Lfe";
  721. case kSpeakerArr30Cine: return "L R C";
  722. case kSpeakerArr30Music: return "L R S";
  723. case kSpeakerArr31Cine: return "L R C Lfe";
  724. case kSpeakerArr31Music: return "L R Lfe S";
  725. case kSpeakerArr40Cine: return "L R C S";
  726. case kSpeakerArr40Music: return "L R Ls Rs";
  727. case kSpeakerArr41Cine: return "L R C Lfe S";
  728. case kSpeakerArr41Music: return "L R Lfe Ls Rs";
  729. case kSpeakerArr50: return "L R C Ls Rs" ;
  730. case kSpeakerArr51: return "L R C Lfe Ls Rs";
  731. case kSpeakerArr60Cine: return "L R C Ls Rs Cs";
  732. case kSpeakerArr60Music: return "L R Ls Rs Sl Sr ";
  733. case kSpeakerArr61Cine: return "L R C Lfe Ls Rs Cs";
  734. case kSpeakerArr61Music: return "L R Lfe Ls Rs Sl Sr";
  735. case kSpeakerArr70Cine: return "L R C Ls Rs Lc Rc ";
  736. case kSpeakerArr70Music: return "L R C Ls Rs Sl Sr";
  737. case kSpeakerArr71Cine: return "L R C Lfe Ls Rs Lc Rc";
  738. case kSpeakerArr71Music: return "L R C Lfe Ls Rs Sl Sr";
  739. case kSpeakerArr80Cine: return "L R C Ls Rs Lc Rc Cs";
  740. case kSpeakerArr80Music: return "L R C Ls Rs Cs Sl Sr";
  741. case kSpeakerArr81Cine: return "L R C Lfe Ls Rs Lc Rc Cs";
  742. case kSpeakerArr81Music: return "L R C Lfe Ls Rs Cs Sl Sr" ;
  743. case kSpeakerArr102: return "L R C Lfe Ls Rs Tfl Tfc Tfr Trl Trr Lfe2";
  744. default: break;
  745. }
  746. return nullptr;
  747. }
  748. //==============================================================================
  749. VstInt32 getChunk (void** data, bool onlyStoreCurrentProgramData)
  750. {
  751. if (filter == nullptr)
  752. return 0;
  753. chunkMemory.setSize (0);
  754. if (onlyStoreCurrentProgramData)
  755. filter->getCurrentProgramStateInformation (chunkMemory);
  756. else
  757. filter->getStateInformation (chunkMemory);
  758. *data = (void*) chunkMemory.getData();
  759. // because the chunk is only needed temporarily by the host (or at least you'd
  760. // hope so) we'll give it a while and then free it in the timer callback.
  761. chunkMemoryTime = juce::Time::getApproximateMillisecondCounter();
  762. return (VstInt32) chunkMemory.getSize();
  763. }
  764. VstInt32 setChunk (void* data, VstInt32 byteSize, bool onlyRestoreCurrentProgramData)
  765. {
  766. if (filter != nullptr)
  767. {
  768. chunkMemory.setSize (0);
  769. chunkMemoryTime = 0;
  770. if (byteSize > 0 && data != nullptr)
  771. {
  772. if (onlyRestoreCurrentProgramData)
  773. filter->setCurrentProgramStateInformation (data, byteSize);
  774. else
  775. filter->setStateInformation (data, byteSize);
  776. }
  777. }
  778. return 0;
  779. }
  780. void timerCallback()
  781. {
  782. if (shouldDeleteEditor)
  783. {
  784. shouldDeleteEditor = false;
  785. deleteEditor (true);
  786. }
  787. if (chunkMemoryTime > 0
  788. && chunkMemoryTime < juce::Time::getApproximateMillisecondCounter() - 2000
  789. && ! recursionCheck)
  790. {
  791. chunkMemoryTime = 0;
  792. chunkMemory.setSize (0);
  793. }
  794. #if JUCE_MAC
  795. if (hostWindow != 0)
  796. checkWindowVisibility (hostWindow, editorComp);
  797. #endif
  798. tryMasterIdle();
  799. }
  800. void tryMasterIdle()
  801. {
  802. if (Component::isMouseButtonDownAnywhere() && ! recursionCheck)
  803. {
  804. const juce::uint32 now = juce::Time::getMillisecondCounter();
  805. if (now > lastMasterIdleCall + 20 && editorComp != nullptr)
  806. {
  807. lastMasterIdleCall = now;
  808. recursionCheck = true;
  809. masterIdle();
  810. recursionCheck = false;
  811. }
  812. }
  813. }
  814. void doIdleCallback()
  815. {
  816. // (wavelab calls this on a separate thread and causes a deadlock)..
  817. if (MessageManager::getInstance()->isThisTheMessageThread()
  818. && ! recursionCheck)
  819. {
  820. recursionCheck = true;
  821. JUCE_AUTORELEASEPOOL
  822. Timer::callPendingTimersSynchronously();
  823. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  824. ComponentPeer::getPeer (i)->performAnyPendingRepaintsNow();
  825. recursionCheck = false;
  826. }
  827. }
  828. void createEditorComp()
  829. {
  830. if (hasShutdown || filter == nullptr)
  831. return;
  832. if (editorComp == nullptr)
  833. {
  834. if (AudioProcessorEditor* const ed = filter->createEditorIfNeeded())
  835. {
  836. cEffect.flags |= effFlagsHasEditor;
  837. ed->setOpaque (true);
  838. ed->setVisible (true);
  839. editorComp = new EditorCompWrapper (*this, ed);
  840. }
  841. else
  842. {
  843. cEffect.flags &= ~effFlagsHasEditor;
  844. }
  845. }
  846. shouldDeleteEditor = false;
  847. }
  848. void deleteEditor (bool canDeleteLaterIfModal)
  849. {
  850. JUCE_AUTORELEASEPOOL
  851. PopupMenu::dismissAllActiveMenus();
  852. jassert (! recursionCheck);
  853. recursionCheck = true;
  854. if (editorComp != nullptr)
  855. {
  856. if (Component* const modalComponent = Component::getCurrentlyModalComponent())
  857. {
  858. modalComponent->exitModalState (0);
  859. if (canDeleteLaterIfModal)
  860. {
  861. shouldDeleteEditor = true;
  862. recursionCheck = false;
  863. return;
  864. }
  865. }
  866. #if JUCE_MAC
  867. if (hostWindow != 0)
  868. {
  869. detachComponentFromWindowRef (editorComp, hostWindow);
  870. hostWindow = 0;
  871. }
  872. #endif
  873. filter->editorBeingDeleted (editorComp->getEditorComp());
  874. editorComp = nullptr;
  875. // there's some kind of component currently modal, but the host
  876. // is trying to delete our plugin. You should try to avoid this happening..
  877. jassert (Component::getCurrentlyModalComponent() == nullptr);
  878. }
  879. #if JUCE_LINUX
  880. hostWindow = 0;
  881. #endif
  882. recursionCheck = false;
  883. }
  884. VstIntPtr dispatcher (VstInt32 opCode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
  885. {
  886. if (hasShutdown)
  887. return 0;
  888. if (opCode == effEditIdle)
  889. {
  890. doIdleCallback();
  891. return 0;
  892. }
  893. else if (opCode == effEditOpen)
  894. {
  895. checkWhetherMessageThreadIsCorrect();
  896. const MessageManagerLock mmLock;
  897. jassert (! recursionCheck);
  898. startTimer (1000 / 4); // performs misc housekeeping chores
  899. deleteEditor (true);
  900. createEditorComp();
  901. if (editorComp != nullptr)
  902. {
  903. editorComp->setOpaque (true);
  904. editorComp->setVisible (false);
  905. #if JUCE_WINDOWS
  906. editorComp->addToDesktop (0, ptr);
  907. hostWindow = (HWND) ptr;
  908. #elif JUCE_LINUX
  909. editorComp->addToDesktop (0);
  910. hostWindow = (Window) ptr;
  911. Window editorWnd = (Window) editorComp->getWindowHandle();
  912. XReparentWindow (display, editorWnd, hostWindow, 0, 0);
  913. #else
  914. hostWindow = attachComponentToWindowRef (editorComp, ptr);
  915. #endif
  916. editorComp->setVisible (true);
  917. return 1;
  918. }
  919. }
  920. else if (opCode == effEditClose)
  921. {
  922. checkWhetherMessageThreadIsCorrect();
  923. const MessageManagerLock mmLock;
  924. deleteEditor (true);
  925. return 0;
  926. }
  927. else if (opCode == effEditGetRect)
  928. {
  929. checkWhetherMessageThreadIsCorrect();
  930. const MessageManagerLock mmLock;
  931. createEditorComp();
  932. if (editorComp != nullptr)
  933. {
  934. editorSize.left = 0;
  935. editorSize.top = 0;
  936. editorSize.right = (VstInt16) editorComp->getWidth();
  937. editorSize.bottom = (VstInt16) editorComp->getHeight();
  938. *((ERect**) ptr) = &editorSize;
  939. return (VstIntPtr) (pointer_sized_int) &editorSize;
  940. }
  941. else
  942. {
  943. return 0;
  944. }
  945. }
  946. return AudioEffectX::dispatcher (opCode, index, value, ptr, opt);
  947. }
  948. void resizeHostWindow (int newWidth, int newHeight)
  949. {
  950. if (editorComp != nullptr)
  951. {
  952. if (! (canHostDo (const_cast <char*> ("sizeWindow")) && sizeWindow (newWidth, newHeight)))
  953. {
  954. // some hosts don't support the sizeWindow call, so do it manually..
  955. #if JUCE_MAC
  956. setNativeHostWindowSize (hostWindow, editorComp, newWidth, newHeight, getHostType());
  957. #elif JUCE_LINUX
  958. // (Currently, all linux hosts support sizeWindow, so this should never need to happen)
  959. editorComp->setSize (newWidth, newHeight);
  960. #else
  961. int dw = 0;
  962. int dh = 0;
  963. const int frameThickness = GetSystemMetrics (SM_CYFIXEDFRAME);
  964. HWND w = (HWND) editorComp->getWindowHandle();
  965. while (w != 0)
  966. {
  967. HWND parent = GetParent (w);
  968. if (parent == 0)
  969. break;
  970. TCHAR windowType [32] = { 0 };
  971. GetClassName (parent, windowType, 31);
  972. if (String (windowType).equalsIgnoreCase ("MDIClient"))
  973. break;
  974. RECT windowPos, parentPos;
  975. GetWindowRect (w, &windowPos);
  976. GetWindowRect (parent, &parentPos);
  977. SetWindowPos (w, 0, 0, 0, newWidth + dw, newHeight + dh,
  978. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  979. dw = (parentPos.right - parentPos.left) - (windowPos.right - windowPos.left);
  980. dh = (parentPos.bottom - parentPos.top) - (windowPos.bottom - windowPos.top);
  981. w = parent;
  982. if (dw == 2 * frameThickness)
  983. break;
  984. if (dw > 100 || dh > 100)
  985. w = 0;
  986. }
  987. if (w != 0)
  988. SetWindowPos (w, 0, 0, 0, newWidth + dw, newHeight + dh,
  989. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  990. #endif
  991. }
  992. if (ComponentPeer* peer = editorComp->getPeer())
  993. peer->handleMovedOrResized();
  994. }
  995. }
  996. static PluginHostType& getHostType()
  997. {
  998. static PluginHostType hostType;
  999. return hostType;
  1000. }
  1001. //==============================================================================
  1002. // A component to hold the AudioProcessorEditor, and cope with some housekeeping
  1003. // chores when it changes or repaints.
  1004. class EditorCompWrapper : public Component,
  1005. public AsyncUpdater
  1006. {
  1007. public:
  1008. EditorCompWrapper (JuceVSTWrapper& wrapper_, AudioProcessorEditor* editor)
  1009. : wrapper (wrapper_)
  1010. {
  1011. setOpaque (true);
  1012. editor->setOpaque (true);
  1013. setBounds (editor->getBounds());
  1014. editor->setTopLeftPosition (0, 0);
  1015. addAndMakeVisible (editor);
  1016. #if JUCE_WINDOWS
  1017. if (! getHostType().isReceptor())
  1018. addMouseListener (this, true);
  1019. registerMouseWheelHook();
  1020. #endif
  1021. }
  1022. ~EditorCompWrapper()
  1023. {
  1024. #if JUCE_WINDOWS
  1025. unregisterMouseWheelHook();
  1026. #endif
  1027. deleteAllChildren(); // note that we can't use a ScopedPointer because the editor may
  1028. // have been transferred to another parent which takes over ownership.
  1029. }
  1030. void paint (Graphics&) {}
  1031. void paintOverChildren (Graphics&)
  1032. {
  1033. // this causes an async call to masterIdle() to help
  1034. // creaky old DAWs like Nuendo repaint themselves while we're
  1035. // repainting. Otherwise they just seem to give up and sit there
  1036. // waiting.
  1037. triggerAsyncUpdate();
  1038. }
  1039. #if JUCE_MAC
  1040. bool keyPressed (const KeyPress&)
  1041. {
  1042. // If we have an unused keypress, move the key-focus to a host window
  1043. // and re-inject the event..
  1044. return forwardCurrentKeyEventToHost (this);
  1045. }
  1046. #endif
  1047. AudioProcessorEditor* getEditorComp() const
  1048. {
  1049. return dynamic_cast <AudioProcessorEditor*> (getChildComponent (0));
  1050. }
  1051. void resized()
  1052. {
  1053. if (Component* const editor = getChildComponent(0))
  1054. editor->setBounds (getLocalBounds());
  1055. }
  1056. void childBoundsChanged (Component* child)
  1057. {
  1058. child->setTopLeftPosition (0, 0);
  1059. const int cw = child->getWidth();
  1060. const int ch = child->getHeight();
  1061. #if JUCE_MAC && JUCE_64BIT
  1062. setTopLeftPosition (0, getHeight() - ch);
  1063. #endif
  1064. wrapper.resizeHostWindow (cw, ch);
  1065. #if ! JUCE_LINUX // setSize() on linux causes renoise and energyxt to fail.
  1066. setSize (cw, ch);
  1067. #else
  1068. XResizeWindow (display, (Window) getWindowHandle(), cw, ch);
  1069. #endif
  1070. #if JUCE_MAC
  1071. wrapper.resizeHostWindow (cw, ch); // (doing this a second time seems to be necessary in tracktion)
  1072. #endif
  1073. }
  1074. void handleAsyncUpdate()
  1075. {
  1076. wrapper.tryMasterIdle();
  1077. }
  1078. #if JUCE_WINDOWS
  1079. void mouseDown (const MouseEvent&)
  1080. {
  1081. broughtToFront();
  1082. }
  1083. void broughtToFront()
  1084. {
  1085. // for hosts like nuendo, need to also pop the MDI container to the
  1086. // front when our comp is clicked on.
  1087. HWND parent = findMDIParentOf ((HWND) getWindowHandle());
  1088. if (parent != 0)
  1089. SetWindowPos (parent, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  1090. }
  1091. #endif
  1092. private:
  1093. //==============================================================================
  1094. JuceVSTWrapper& wrapper;
  1095. FakeMouseMoveGenerator fakeMouseGenerator;
  1096. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (EditorCompWrapper);
  1097. };
  1098. //==============================================================================
  1099. private:
  1100. AudioProcessor* filter;
  1101. juce::MemoryBlock chunkMemory;
  1102. juce::uint32 chunkMemoryTime;
  1103. ScopedPointer<EditorCompWrapper> editorComp;
  1104. ERect editorSize;
  1105. MidiBuffer midiEvents;
  1106. VSTMidiEventList outgoingEvents;
  1107. VstSpeakerArrangementType speakerIn, speakerOut;
  1108. int numInChans, numOutChans;
  1109. bool isProcessing, hasShutdown, firstProcessCallback, shouldDeleteEditor;
  1110. HeapBlock<float*> channels;
  1111. Array<float*> tempChannels; // see note in processReplacing()
  1112. #if JUCE_MAC
  1113. void* hostWindow;
  1114. #elif JUCE_LINUX
  1115. Window hostWindow;
  1116. #else
  1117. HWND hostWindow;
  1118. #endif
  1119. //==============================================================================
  1120. #if JUCE_WINDOWS
  1121. // Workarounds for Wavelab's happy-go-lucky use of threads.
  1122. static void checkWhetherMessageThreadIsCorrect()
  1123. {
  1124. if (getHostType().isWavelab() || getHostType().isCubaseBridged())
  1125. {
  1126. if (! messageThreadIsDefinitelyCorrect)
  1127. {
  1128. MessageManager::getInstance()->setCurrentThreadAsMessageThread();
  1129. class MessageThreadCallback : public CallbackMessage
  1130. {
  1131. public:
  1132. MessageThreadCallback (bool& triggered_) : triggered (triggered_) {}
  1133. void messageCallback()
  1134. {
  1135. triggered = true;
  1136. }
  1137. private:
  1138. bool& triggered;
  1139. };
  1140. (new MessageThreadCallback (messageThreadIsDefinitelyCorrect))->post();
  1141. }
  1142. }
  1143. }
  1144. #else
  1145. static void checkWhetherMessageThreadIsCorrect() {}
  1146. #endif
  1147. //==============================================================================
  1148. void deleteTempChannels()
  1149. {
  1150. for (int i = tempChannels.size(); --i >= 0;)
  1151. delete[] (tempChannels.getUnchecked(i));
  1152. tempChannels.clear();
  1153. if (filter != nullptr)
  1154. tempChannels.insertMultiple (0, 0, filter->getNumInputChannels() + filter->getNumOutputChannels());
  1155. }
  1156. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (JuceVSTWrapper);
  1157. };
  1158. //==============================================================================
  1159. /** Somewhere in the codebase of your plugin, you need to implement this function
  1160. and make it create an instance of the filter subclass that you're building.
  1161. */
  1162. extern AudioProcessor* JUCE_CALLTYPE createPluginFilter();
  1163. //==============================================================================
  1164. namespace
  1165. {
  1166. AEffect* pluginEntryPoint (audioMasterCallback audioMaster)
  1167. {
  1168. JUCE_AUTORELEASEPOOL
  1169. initialiseJuce_GUI();
  1170. try
  1171. {
  1172. if (audioMaster (0, audioMasterVersion, 0, 0, 0, 0) != 0)
  1173. {
  1174. #if JUCE_LINUX
  1175. MessageManagerLock mmLock;
  1176. #endif
  1177. if (AudioProcessor* const filter = createPluginFilter())
  1178. {
  1179. filter->wrapperType = AudioProcessor::wrapperType_VST;
  1180. JuceVSTWrapper* const wrapper = new JuceVSTWrapper (audioMaster, filter);
  1181. return wrapper->getAeffect();
  1182. }
  1183. }
  1184. }
  1185. catch (...)
  1186. {}
  1187. return nullptr;
  1188. }
  1189. }
  1190. #if ! JUCE_WINDOWS
  1191. #define JUCE_EXPORTED_FUNCTION extern "C" __attribute__ ((visibility("default")))
  1192. #endif
  1193. //==============================================================================
  1194. // Mac startup code..
  1195. #if JUCE_MAC
  1196. JUCE_EXPORTED_FUNCTION AEffect* VSTPluginMain (audioMasterCallback audioMaster);
  1197. JUCE_EXPORTED_FUNCTION AEffect* VSTPluginMain (audioMasterCallback audioMaster)
  1198. {
  1199. initialiseMac();
  1200. return pluginEntryPoint (audioMaster);
  1201. }
  1202. JUCE_EXPORTED_FUNCTION AEffect* main_macho (audioMasterCallback audioMaster);
  1203. JUCE_EXPORTED_FUNCTION AEffect* main_macho (audioMasterCallback audioMaster)
  1204. {
  1205. initialiseMac();
  1206. return pluginEntryPoint (audioMaster);
  1207. }
  1208. //==============================================================================
  1209. // Linux startup code..
  1210. #elif JUCE_LINUX
  1211. JUCE_EXPORTED_FUNCTION AEffect* VSTPluginMain (audioMasterCallback audioMaster);
  1212. JUCE_EXPORTED_FUNCTION AEffect* VSTPluginMain (audioMasterCallback audioMaster)
  1213. {
  1214. SharedMessageThread::getInstance();
  1215. return pluginEntryPoint (audioMaster);
  1216. }
  1217. JUCE_EXPORTED_FUNCTION AEffect* main_plugin (audioMasterCallback audioMaster) asm ("main");
  1218. JUCE_EXPORTED_FUNCTION AEffect* main_plugin (audioMasterCallback audioMaster)
  1219. {
  1220. return VSTPluginMain (audioMaster);
  1221. }
  1222. // don't put initialiseJuce_GUI or shutdownJuce_GUI in these... it will crash!
  1223. __attribute__((constructor)) void myPluginInit() {}
  1224. __attribute__((destructor)) void myPluginFini() {}
  1225. //==============================================================================
  1226. // Win32 startup code..
  1227. #else
  1228. extern "C" __declspec (dllexport) AEffect* VSTPluginMain (audioMasterCallback audioMaster)
  1229. {
  1230. return pluginEntryPoint (audioMaster);
  1231. }
  1232. #ifndef JUCE_64BIT // (can't compile this on win64, but it's not needed anyway with VST2.4)
  1233. extern "C" __declspec (dllexport) int main (audioMasterCallback audioMaster)
  1234. {
  1235. return (int) pluginEntryPoint (audioMaster);
  1236. }
  1237. #endif
  1238. #endif
  1239. #endif