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