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.

1576 lines
48KB

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