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.

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