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.

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