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.

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