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.

1563 lines
46KB

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