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.

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