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.

1598 lines
47KB

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