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.

1564 lines
46KB

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