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.

1527 lines
49KB

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