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.

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