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.

1620 lines
48KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifdef _MSC_VER
  19. #pragma warning (disable : 4996 4100)
  20. #endif
  21. #ifdef _WIN32
  22. #include <windows.h>
  23. #elif defined (LINUX)
  24. #include <X11/Xlib.h>
  25. #include <X11/Xutil.h>
  26. #include <X11/Xatom.h>
  27. #undef KeyPress
  28. #else
  29. #include <Carbon/Carbon.h>
  30. #endif
  31. #ifdef PRAGMA_ALIGN_SUPPORTED
  32. #undef PRAGMA_ALIGN_SUPPORTED
  33. #define PRAGMA_ALIGN_SUPPORTED 1
  34. #endif
  35. #include "../juce_IncludeCharacteristics.h"
  36. #if JucePlugin_Build_VST
  37. //==============================================================================
  38. /* These files come with the Steinberg VST SDK - to get them, you'll need to
  39. visit the Steinberg website and jump through some hoops to sign up as a
  40. VST developer.
  41. Then, you'll need to make sure your include path contains your "vstsdk2.3" or
  42. "vstsdk2.4" directory.
  43. Note that the JUCE_USE_VSTSDK_2_4 macro should be defined in JucePluginCharacteristics.h
  44. */
  45. #if JUCE_USE_VSTSDK_2_4
  46. #ifdef __GNUC__
  47. #define __cdecl
  48. #endif
  49. // VSTSDK V2.4 includes..
  50. #include "public.sdk/source/vst2.x/audioeffectx.h"
  51. #include "public.sdk/source/vst2.x/aeffeditor.h"
  52. #include "public.sdk/source/vst2.x/audioeffectx.cpp"
  53. #include "public.sdk/source/vst2.x/audioeffect.cpp"
  54. #if ! VST_2_4_EXTENSIONS
  55. #error // You're probably trying to include the wrong VSTSDK version - make sure your include path matches the JUCE_USE_VSTSDK_2_4 flag
  56. #endif
  57. #else
  58. // VSTSDK V2.3 includes..
  59. #include "source/common/audioeffectx.h"
  60. #include "source/common/AEffEditor.hpp"
  61. #include "source/common/audioeffectx.cpp"
  62. #include "source/common/AudioEffect.cpp"
  63. #if (! VST_2_3_EXTENSIONS) || VST_2_4_EXTENSIONS
  64. #error // You're probably trying to include the wrong VSTSDK version - make sure your include path matches the JUCE_USE_VSTSDK_2_4 flag
  65. #endif
  66. #define __aeffect__ // (needed for juce_VSTMidiEventList.h to work)
  67. typedef long VstInt32;
  68. typedef long VstIntPtr;
  69. enum Vst2StringConstants
  70. {
  71. kVstMaxNameLen = 64,
  72. kVstMaxLabelLen = 64,
  73. kVstMaxShortLabelLen = 8,
  74. kVstMaxCategLabelLen = 24,
  75. kVstMaxFileNameLen = 100
  76. };
  77. enum VstSmpteFrameRate
  78. {
  79. kVstSmpte24fps = 0, ///< 24 fps
  80. kVstSmpte25fps = 1, ///< 25 fps
  81. kVstSmpte2997fps = 2, ///< 29.97 fps
  82. kVstSmpte30fps = 3, ///< 30 fps
  83. kVstSmpte2997dfps = 4, ///< 29.97 drop
  84. kVstSmpte30dfps = 5, ///< 30 drop
  85. kVstSmpteFilm16mm = 6, ///< Film 16mm
  86. kVstSmpteFilm35mm = 7, ///< Film 35mm
  87. kVstSmpte239fps = 10, ///< HDTV: 23.976 fps
  88. kVstSmpte249fps = 11, ///< HDTV: 24.976 fps
  89. kVstSmpte599fps = 12, ///< HDTV: 59.94 fps
  90. kVstSmpte60fps = 13 ///< HDTV: 60 fps
  91. };
  92. struct VstMidiSysexEvent
  93. {
  94. VstInt32 type; ///< #kVstSysexType
  95. VstInt32 byteSize; ///< sizeof (VstMidiSysexEvent)
  96. VstInt32 deltaFrames; ///< sample frames related to the current block start sample position
  97. VstInt32 flags; ///< none defined yet (should be zero)
  98. VstInt32 dumpBytes; ///< byte size of sysexDump
  99. VstIntPtr resvd1; ///< zero (Reserved for future use)
  100. char* sysexDump; ///< sysex dump
  101. VstIntPtr resvd2; ///< zero (Reserved for future use)
  102. };
  103. typedef int VstSpeakerArrangementType;
  104. #endif
  105. //==============================================================================
  106. #ifdef _MSC_VER
  107. #pragma pack (push, 8)
  108. #endif
  109. #include "../juce_PluginHeaders.h"
  110. #include "../juce_PluginHostType.h"
  111. #ifdef _MSC_VER
  112. #pragma pack (pop)
  113. #endif
  114. #undef MemoryBlock
  115. class JuceVSTWrapper;
  116. static bool recursionCheck = false;
  117. static JUCE_NAMESPACE::uint32 lastMasterIdleCall = 0;
  118. BEGIN_JUCE_NAMESPACE
  119. extern void juce_callAnyTimersSynchronously();
  120. #if JUCE_MAC
  121. extern void initialiseMac();
  122. extern void* attachComponentToWindowRef (Component* component, void* windowRef);
  123. extern void detachComponentFromWindowRef (Component* component, void* nsWindow);
  124. extern void setNativeHostWindowSize (void* nsWindow, Component* editorComp, int newWidth, int newHeight, const PluginHostType& host);
  125. extern void checkWindowVisibility (void* nsWindow, Component* component);
  126. extern void forwardCurrentKeyEventToHost (Component* component);
  127. #endif
  128. #if JUCE_LINUX
  129. extern Display* display;
  130. #endif
  131. END_JUCE_NAMESPACE
  132. //==============================================================================
  133. #if JUCE_WINDOWS
  134. static HWND findMDIParentOf (HWND w)
  135. {
  136. const int frameThickness = GetSystemMetrics (SM_CYFIXEDFRAME);
  137. while (w != 0)
  138. {
  139. HWND parent = GetParent (w);
  140. if (parent == 0)
  141. break;
  142. TCHAR windowType [32];
  143. zeromem (windowType, sizeof (windowType));
  144. GetClassName (parent, windowType, 31);
  145. if (String (windowType).equalsIgnoreCase ("MDIClient"))
  146. {
  147. w = parent;
  148. break;
  149. }
  150. RECT windowPos;
  151. GetWindowRect (w, &windowPos);
  152. RECT parentPos;
  153. GetWindowRect (parent, &parentPos);
  154. const int dw = (parentPos.right - parentPos.left) - (windowPos.right - windowPos.left);
  155. const int dh = (parentPos.bottom - parentPos.top) - (windowPos.bottom - windowPos.top);
  156. if (dw > 100 || dh > 100)
  157. break;
  158. w = parent;
  159. if (dw == 2 * frameThickness)
  160. break;
  161. }
  162. return w;
  163. }
  164. //==============================================================================
  165. #elif JUCE_LINUX
  166. class SharedMessageThread : public Thread
  167. {
  168. public:
  169. SharedMessageThread()
  170. : Thread ("VstMessageThread"),
  171. initialised (false)
  172. {
  173. startThread (7);
  174. while (! initialised)
  175. sleep (1);
  176. }
  177. ~SharedMessageThread()
  178. {
  179. signalThreadShouldExit();
  180. JUCEApplication::quit();
  181. waitForThreadToExit (5000);
  182. clearSingletonInstance();
  183. }
  184. void run()
  185. {
  186. initialiseJuce_GUI();
  187. initialised = true;
  188. MessageManager::getInstance()->setCurrentThreadAsMessageThread();
  189. while ((! threadShouldExit()) && MessageManager::getInstance()->runDispatchLoopUntil (250))
  190. {
  191. }
  192. }
  193. juce_DeclareSingleton (SharedMessageThread, false)
  194. private:
  195. bool initialised;
  196. };
  197. juce_ImplementSingleton (SharedMessageThread)
  198. #endif
  199. static Array<void*> activePlugins;
  200. //==============================================================================
  201. /**
  202. This wraps an AudioProcessor as an AudioEffectX...
  203. */
  204. class JuceVSTWrapper : public AudioEffectX,
  205. private Timer,
  206. public AudioProcessorListener,
  207. public AudioPlayHead
  208. {
  209. public:
  210. //==============================================================================
  211. JuceVSTWrapper (audioMasterCallback audioMaster,
  212. AudioProcessor* const filter_)
  213. : AudioEffectX (audioMaster,
  214. filter_->getNumPrograms(),
  215. filter_->getNumParameters()),
  216. filter (filter_)
  217. {
  218. chunkMemoryTime = 0;
  219. isProcessing = false;
  220. hasShutdown = false;
  221. firstProcessCallback = true;
  222. shouldDeleteEditor = false;
  223. speakerIn = kSpeakerArrEmpty;
  224. speakerOut = kSpeakerArrEmpty;
  225. numInChans = JucePlugin_MaxNumInputChannels;
  226. numOutChans = JucePlugin_MaxNumOutputChannels;
  227. #if JUCE_MAC || JUCE_LINUX
  228. hostWindow = 0;
  229. #endif
  230. filter->setPlayConfigDetails (numInChans, numOutChans, 0, 0);
  231. filter_->setPlayHead (this);
  232. filter_->addListener (this);
  233. cEffect.flags |= effFlagsHasEditor;
  234. cEffect.version = (long) (JucePlugin_VersionCode);
  235. setUniqueID ((int) (JucePlugin_VSTUniqueID));
  236. #if JucePlugin_WantsMidiInput && ! JUCE_USE_VSTSDK_2_4
  237. wantEvents();
  238. #endif
  239. setNumInputs (numInChans);
  240. setNumOutputs (numOutChans);
  241. canProcessReplacing (true);
  242. #if ! JUCE_USE_VSTSDK_2_4
  243. hasVu (false);
  244. hasClip (false);
  245. #endif
  246. isSynth ((JucePlugin_IsSynth) != 0);
  247. noTail (((JucePlugin_SilenceInProducesSilenceOut) != 0) && (JucePlugin_TailLengthSeconds <= 0));
  248. setInitialDelay (filter->getLatencySamples());
  249. programsAreChunks (true);
  250. activePlugins.add (this);
  251. }
  252. ~JuceVSTWrapper()
  253. {
  254. JUCE_AUTORELEASEPOOL
  255. stopTimer();
  256. deleteEditor (false);
  257. hasShutdown = true;
  258. delete filter;
  259. filter = 0;
  260. jassert (editorComp == 0);
  261. channels.free();
  262. deleteTempChannels();
  263. jassert (activePlugins.contains (this));
  264. activePlugins.removeValue (this);
  265. if (activePlugins.size() == 0)
  266. {
  267. #if JUCE_LINUX
  268. SharedMessageThread::deleteInstance();
  269. #endif
  270. shutdownJuce_GUI();
  271. }
  272. }
  273. void open()
  274. {
  275. JUCE_AUTORELEASEPOOL
  276. if (editorComp == 0)
  277. {
  278. checkWhetherWavelabHasChangedThread();
  279. const MessageManagerLock mmLock;
  280. AudioProcessorEditor* const ed = filter->createEditorIfNeeded();
  281. if (ed != 0)
  282. cEffect.flags |= effFlagsHasEditor;
  283. else
  284. cEffect.flags &= ~effFlagsHasEditor;
  285. filter->editorBeingDeleted (ed);
  286. delete ed;
  287. }
  288. startTimer (1000 / 4);
  289. }
  290. void close()
  291. {
  292. JUCE_AUTORELEASEPOOL
  293. const NonWavelabMMLock mmLock;
  294. jassert (! recursionCheck);
  295. stopTimer();
  296. deleteEditor (false);
  297. }
  298. //==============================================================================
  299. bool getEffectName (char* name)
  300. {
  301. String (JucePlugin_Name).copyToCString (name, 64);
  302. return true;
  303. }
  304. bool getVendorString (char* text)
  305. {
  306. String (JucePlugin_Manufacturer).copyToCString (text, 64);
  307. return true;
  308. }
  309. bool getProductString (char* text)
  310. {
  311. return getEffectName (text);
  312. }
  313. VstInt32 getVendorVersion()
  314. {
  315. return JucePlugin_VersionCode;
  316. }
  317. VstPlugCategory getPlugCategory()
  318. {
  319. return JucePlugin_VSTCategory;
  320. }
  321. VstInt32 canDo (char* text)
  322. {
  323. VstInt32 result = 0;
  324. if (strcmp (text, "receiveVstEvents") == 0
  325. || strcmp (text, "receiveVstMidiEvent") == 0
  326. || strcmp (text, "receiveVstMidiEvents") == 0)
  327. {
  328. #if JucePlugin_WantsMidiInput
  329. result = 1;
  330. #else
  331. result = -1;
  332. #endif
  333. }
  334. else if (strcmp (text, "sendVstEvents") == 0
  335. || strcmp (text, "sendVstMidiEvent") == 0
  336. || strcmp (text, "sendVstMidiEvents") == 0)
  337. {
  338. #if JucePlugin_ProducesMidiOutput
  339. result = 1;
  340. #else
  341. result = -1;
  342. #endif
  343. }
  344. else if (strcmp (text, "receiveVstTimeInfo") == 0
  345. || strcmp (text, "conformsToWindowRules") == 0)
  346. {
  347. result = 1;
  348. }
  349. else if (strcmp (text, "openCloseAnyThread" == 0)
  350. {
  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:
  604. rate = AudioPlayHead::fps24;
  605. fps = 24.0;
  606. break;
  607. case kVstSmpte25fps:
  608. rate = AudioPlayHead::fps25;
  609. fps = 25.0;
  610. break;
  611. case kVstSmpte2997fps:
  612. rate = AudioPlayHead::fps2997;
  613. fps = 29.97;
  614. break;
  615. case kVstSmpte30fps:
  616. rate = AudioPlayHead::fps30;
  617. fps = 30.0;
  618. break;
  619. case kVstSmpte2997dfps:
  620. rate = AudioPlayHead::fps2997drop;
  621. fps = 29.97;
  622. break;
  623. case kVstSmpte30dfps:
  624. rate = AudioPlayHead::fps30drop;
  625. fps = 30.0;
  626. break;
  627. case kVstSmpteFilm16mm:
  628. case kVstSmpteFilm35mm:
  629. fps = 24.0;
  630. break;
  631. case kVstSmpte239fps: fps = 23.976; break;
  632. case kVstSmpte249fps: fps = 24.976; break;
  633. case kVstSmpte599fps: fps = 59.94; break;
  634. case kVstSmpte60fps: fps = 60; break;
  635. default:
  636. jassertfalse // unknown frame-rate..
  637. }
  638. info.frameRate = rate;
  639. info.editOriginTime = ti->smpteOffset / (80.0 * fps);
  640. }
  641. else
  642. {
  643. info.frameRate = AudioPlayHead::fpsUnknown;
  644. info.editOriginTime = 0;
  645. }
  646. info.isRecording = (ti->flags & kVstTransportRecording) != 0;
  647. info.isPlaying = (ti->flags & kVstTransportPlaying) != 0 || info.isRecording;
  648. return true;
  649. }
  650. //==============================================================================
  651. VstInt32 getProgram()
  652. {
  653. return filter != 0 ? filter->getCurrentProgram() : 0;
  654. }
  655. void setProgram (VstInt32 program)
  656. {
  657. if (filter != 0)
  658. filter->setCurrentProgram (program);
  659. }
  660. void setProgramName (char* name)
  661. {
  662. if (filter != 0)
  663. filter->changeProgramName (filter->getCurrentProgram(), name);
  664. }
  665. void getProgramName (char* name)
  666. {
  667. if (filter != 0)
  668. filter->getProgramName (filter->getCurrentProgram()).copyToCString (name, 24);
  669. }
  670. bool getProgramNameIndexed (VstInt32 /*category*/, VstInt32 index, char* text)
  671. {
  672. if (filter != 0 && ((unsigned int) index) < (unsigned int) filter->getNumPrograms())
  673. {
  674. filter->getProgramName (index).copyToCString (text, 24);
  675. return true;
  676. }
  677. return false;
  678. }
  679. //==============================================================================
  680. float getParameter (VstInt32 index)
  681. {
  682. if (filter == 0)
  683. return 0.0f;
  684. jassert (((unsigned int) index) < (unsigned int) filter->getNumParameters());
  685. return filter->getParameter (index);
  686. }
  687. void setParameter (VstInt32 index, float value)
  688. {
  689. if (filter != 0)
  690. {
  691. jassert (((unsigned int) index) < (unsigned int) filter->getNumParameters());
  692. filter->setParameter (index, value);
  693. }
  694. }
  695. void getParameterDisplay (VstInt32 index, char* text)
  696. {
  697. if (filter != 0)
  698. {
  699. jassert (((unsigned int) index) < (unsigned int) filter->getNumParameters());
  700. filter->getParameterText (index).copyToCString (text, 24); // length should technically be kVstMaxParamStrLen, which is 8, but hosts will normally allow a bit more.
  701. }
  702. }
  703. void getParameterName (VstInt32 index, char* text)
  704. {
  705. if (filter != 0)
  706. {
  707. jassert (((unsigned int) index) < (unsigned int) filter->getNumParameters());
  708. filter->getParameterName (index).copyToCString (text, 16); // length should technically be kVstMaxParamStrLen, which is 8, but hosts will normally allow a bit more.
  709. }
  710. }
  711. void audioProcessorParameterChanged (AudioProcessor*, int index, float newValue)
  712. {
  713. setParameterAutomated (index, newValue);
  714. }
  715. void audioProcessorParameterChangeGestureBegin (AudioProcessor*, int index)
  716. {
  717. beginEdit (index);
  718. }
  719. void audioProcessorParameterChangeGestureEnd (AudioProcessor*, int index)
  720. {
  721. endEdit (index);
  722. }
  723. void audioProcessorChanged (AudioProcessor*)
  724. {
  725. updateDisplay();
  726. }
  727. bool canParameterBeAutomated (VstInt32 index)
  728. {
  729. return filter != 0 && filter->isParameterAutomatable ((int) index);
  730. }
  731. class ChannelConfigComparator
  732. {
  733. public:
  734. static int compareElements (const short* const first, const short* const second)
  735. {
  736. if (first[0] < second[0])
  737. return -1;
  738. else if (first[0] > second[0])
  739. return 1;
  740. else if (first[1] < second[1])
  741. return -1;
  742. else if (first[1] > second[1])
  743. return 1;
  744. return 0;
  745. }
  746. };
  747. bool setSpeakerArrangement (VstSpeakerArrangement* pluginInput,
  748. VstSpeakerArrangement* pluginOutput)
  749. {
  750. short channelConfigs[][2] = { JucePlugin_PreferredChannelConfigurations };
  751. Array <short*> channelConfigsSorted;
  752. ChannelConfigComparator comp;
  753. for (int i = 0; i < numElementsInArray (channelConfigs); ++i)
  754. channelConfigsSorted.addSorted (comp, channelConfigs[i]);
  755. for (int i = channelConfigsSorted.size(); --i >= 0;)
  756. {
  757. const short* const config = channelConfigsSorted.getUnchecked(i);
  758. bool inCountMatches = (config[0] == pluginInput->numChannels);
  759. bool outCountMatches = (config[1] == pluginOutput->numChannels);
  760. if (inCountMatches && outCountMatches)
  761. {
  762. speakerIn = (VstSpeakerArrangementType) pluginInput->type;
  763. speakerOut = (VstSpeakerArrangementType) pluginOutput->type;
  764. numInChans = pluginInput->numChannels;
  765. numOutChans = pluginOutput->numChannels;
  766. filter->setPlayConfigDetails (numInChans, numOutChans,
  767. filter->getSampleRate(),
  768. filter->getBlockSize());
  769. return true;
  770. }
  771. }
  772. return false;
  773. }
  774. //==============================================================================
  775. VstInt32 getChunk (void** data, bool onlyStoreCurrentProgramData)
  776. {
  777. if (filter == 0)
  778. return 0;
  779. chunkMemory.setSize (0);
  780. if (onlyStoreCurrentProgramData)
  781. filter->getCurrentProgramStateInformation (chunkMemory);
  782. else
  783. filter->getStateInformation (chunkMemory);
  784. *data = (void*) chunkMemory.getData();
  785. // because the chunk is only needed temporarily by the host (or at least you'd
  786. // hope so) we'll give it a while and then free it in the timer callback.
  787. chunkMemoryTime = JUCE_NAMESPACE::Time::getApproximateMillisecondCounter();
  788. return (VstInt32) chunkMemory.getSize();
  789. }
  790. VstInt32 setChunk (void* data, VstInt32 byteSize, bool onlyRestoreCurrentProgramData)
  791. {
  792. if (filter == 0)
  793. return 0;
  794. chunkMemory.setSize (0);
  795. chunkMemoryTime = 0;
  796. if (byteSize > 0 && data != 0)
  797. {
  798. if (onlyRestoreCurrentProgramData)
  799. filter->setCurrentProgramStateInformation (data, byteSize);
  800. else
  801. filter->setStateInformation (data, byteSize);
  802. }
  803. return 0;
  804. }
  805. void timerCallback()
  806. {
  807. if (shouldDeleteEditor)
  808. {
  809. shouldDeleteEditor = false;
  810. deleteEditor (true);
  811. }
  812. if (chunkMemoryTime > 0
  813. && chunkMemoryTime < JUCE_NAMESPACE::Time::getApproximateMillisecondCounter() - 2000
  814. && ! recursionCheck)
  815. {
  816. chunkMemoryTime = 0;
  817. chunkMemory.setSize (0);
  818. }
  819. #if JUCE_MAC
  820. if (hostWindow != 0)
  821. checkWindowVisibility (hostWindow, editorComp);
  822. #endif
  823. tryMasterIdle();
  824. }
  825. void tryMasterIdle()
  826. {
  827. if (Component::isMouseButtonDownAnywhere()
  828. && ! recursionCheck)
  829. {
  830. const JUCE_NAMESPACE::uint32 now = JUCE_NAMESPACE::Time::getMillisecondCounter();
  831. if (now > lastMasterIdleCall + 20 && editorComp != 0)
  832. {
  833. lastMasterIdleCall = now;
  834. recursionCheck = true;
  835. masterIdle();
  836. recursionCheck = false;
  837. }
  838. }
  839. }
  840. void doIdleCallback()
  841. {
  842. // (wavelab calls this on a separate thread and causes a deadlock)..
  843. if (MessageManager::getInstance()->isThisTheMessageThread()
  844. && ! recursionCheck)
  845. {
  846. recursionCheck = true;
  847. juce_callAnyTimersSynchronously();
  848. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  849. ComponentPeer::getPeer (i)->performAnyPendingRepaintsNow();
  850. recursionCheck = false;
  851. }
  852. }
  853. void createEditorComp()
  854. {
  855. if (hasShutdown || filter == 0)
  856. return;
  857. if (editorComp == 0)
  858. {
  859. AudioProcessorEditor* const ed = filter->createEditorIfNeeded();
  860. if (ed != 0)
  861. {
  862. cEffect.flags |= effFlagsHasEditor;
  863. ed->setOpaque (true);
  864. ed->setVisible (true);
  865. editorComp = new EditorCompWrapper (*this, ed);
  866. }
  867. else
  868. {
  869. cEffect.flags &= ~effFlagsHasEditor;
  870. }
  871. }
  872. shouldDeleteEditor = false;
  873. }
  874. void deleteEditor (bool canDeleteLaterIfModal)
  875. {
  876. PopupMenu::dismissAllActiveMenus();
  877. jassert (! recursionCheck);
  878. recursionCheck = true;
  879. if (editorComp != 0)
  880. {
  881. Component* const modalComponent = Component::getCurrentlyModalComponent();
  882. if (modalComponent != 0)
  883. {
  884. modalComponent->exitModalState (0);
  885. if (canDeleteLaterIfModal)
  886. {
  887. shouldDeleteEditor = true;
  888. recursionCheck = false;
  889. return;
  890. }
  891. }
  892. #if JUCE_MAC
  893. if (hostWindow != 0)
  894. {
  895. detachComponentFromWindowRef (editorComp, hostWindow);
  896. hostWindow = 0;
  897. }
  898. #endif
  899. filter->editorBeingDeleted (editorComp->getEditorComp());
  900. editorComp = 0;
  901. // there's some kind of component currently modal, but the host
  902. // is trying to delete our plugin. You should try to avoid this happening..
  903. jassert (Component::getCurrentlyModalComponent() == 0);
  904. }
  905. #if JUCE_LINUX
  906. hostWindow = 0;
  907. #endif
  908. recursionCheck = false;
  909. }
  910. VstIntPtr dispatcher (VstInt32 opCode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
  911. {
  912. if (hasShutdown)
  913. return 0;
  914. if (opCode == effEditIdle)
  915. {
  916. doIdleCallback();
  917. return 0;
  918. }
  919. else if (opCode == effEditOpen)
  920. {
  921. checkWhetherWavelabHasChangedThread();
  922. const MessageManagerLock mmLock;
  923. jassert (! recursionCheck);
  924. deleteEditor (true);
  925. createEditorComp();
  926. if (editorComp != 0)
  927. {
  928. editorComp->setOpaque (true);
  929. editorComp->setVisible (false);
  930. #if JUCE_WINDOWS
  931. editorComp->addToDesktop (0, ptr);
  932. hostWindow = (HWND) ptr;
  933. #elif JUCE_LINUX
  934. editorComp->addToDesktop (0);
  935. hostWindow = (Window) ptr;
  936. Window editorWnd = (Window) editorComp->getWindowHandle();
  937. XReparentWindow (display, editorWnd, hostWindow, 0, 0);
  938. #else
  939. hostWindow = attachComponentToWindowRef (editorComp, (WindowRef) ptr);
  940. #endif
  941. editorComp->setVisible (true);
  942. return 1;
  943. }
  944. }
  945. else if (opCode == effEditClose)
  946. {
  947. checkWhetherWavelabHasChangedThread();
  948. const MessageManagerLock mmLock;
  949. deleteEditor (true);
  950. return 0;
  951. }
  952. else if (opCode == effEditGetRect)
  953. {
  954. checkWhetherWavelabHasChangedThread();
  955. const MessageManagerLock mmLock;
  956. createEditorComp();
  957. if (editorComp != 0)
  958. {
  959. editorSize.left = 0;
  960. editorSize.top = 0;
  961. editorSize.right = (VstInt16) editorComp->getWidth();
  962. editorSize.bottom = (VstInt16) editorComp->getHeight();
  963. *((ERect**) ptr) = &editorSize;
  964. return (VstIntPtr) (pointer_sized_int) &editorSize;
  965. }
  966. else
  967. {
  968. return 0;
  969. }
  970. }
  971. return AudioEffectX::dispatcher (opCode, index, value, ptr, opt);
  972. }
  973. void resizeHostWindow (int newWidth, int newHeight)
  974. {
  975. if (editorComp != 0)
  976. {
  977. #if ! JUCE_LINUX // linux hosts shouldn't be trusted!
  978. if (! (canHostDo (const_cast <char*> ("sizeWindow")) && sizeWindow (newWidth, newHeight)))
  979. #endif
  980. {
  981. // some hosts don't support the sizeWindow call, so do it manually..
  982. #if JUCE_MAC
  983. setNativeHostWindowSize (hostWindow, editorComp, newWidth, newHeight, getHostType());
  984. #elif JUCE_LINUX
  985. Window root;
  986. int x, y;
  987. unsigned int width, height, border, depth;
  988. XGetGeometry (display, hostWindow, &root,
  989. &x, &y, &width, &height, &border, &depth);
  990. newWidth += (width + border) - editorComp->getWidth();
  991. newHeight += (height + border) - editorComp->getHeight();
  992. XResizeWindow (display, hostWindow, newWidth, newHeight);
  993. #else
  994. int dw = 0;
  995. int dh = 0;
  996. const int frameThickness = GetSystemMetrics (SM_CYFIXEDFRAME);
  997. HWND w = (HWND) editorComp->getWindowHandle();
  998. while (w != 0)
  999. {
  1000. HWND parent = GetParent (w);
  1001. if (parent == 0)
  1002. break;
  1003. TCHAR windowType [32];
  1004. zeromem (windowType, sizeof (windowType));
  1005. GetClassName (parent, windowType, 31);
  1006. if (String (windowType).equalsIgnoreCase ("MDIClient"))
  1007. break;
  1008. RECT windowPos;
  1009. GetWindowRect (w, &windowPos);
  1010. RECT parentPos;
  1011. GetWindowRect (parent, &parentPos);
  1012. SetWindowPos (w, 0, 0, 0,
  1013. newWidth + dw,
  1014. newHeight + dh,
  1015. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  1016. dw = (parentPos.right - parentPos.left) - (windowPos.right - windowPos.left);
  1017. dh = (parentPos.bottom - parentPos.top) - (windowPos.bottom - windowPos.top);
  1018. w = parent;
  1019. if (dw == 2 * frameThickness)
  1020. break;
  1021. if (dw > 100 || dh > 100)
  1022. w = 0;
  1023. }
  1024. if (w != 0)
  1025. SetWindowPos (w, 0, 0, 0,
  1026. newWidth + dw,
  1027. newHeight + dh,
  1028. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  1029. #endif
  1030. }
  1031. if (editorComp->getPeer() != 0)
  1032. editorComp->getPeer()->handleMovedOrResized();
  1033. }
  1034. }
  1035. static PluginHostType& getHostType()
  1036. {
  1037. static PluginHostType hostType;
  1038. return hostType;
  1039. }
  1040. //==============================================================================
  1041. // A component to hold the AudioProcessorEditor, and cope with some housekeeping
  1042. // chores when it changes or repaints.
  1043. class EditorCompWrapper : public Component,
  1044. public AsyncUpdater
  1045. {
  1046. public:
  1047. EditorCompWrapper (JuceVSTWrapper& wrapper_, AudioProcessorEditor* editor)
  1048. : wrapper (wrapper_)
  1049. {
  1050. setOpaque (true);
  1051. editor->setOpaque (true);
  1052. setBounds (editor->getBounds());
  1053. editor->setTopLeftPosition (0, 0);
  1054. addAndMakeVisible (editor);
  1055. #if JUCE_WIN
  1056. if (! getHostType().isReceptor())
  1057. addMouseListener (this, true);
  1058. #endif
  1059. }
  1060. ~EditorCompWrapper()
  1061. {
  1062. deleteAllChildren();
  1063. }
  1064. void paint (Graphics&) {}
  1065. void paintOverChildren (Graphics&)
  1066. {
  1067. // this causes an async call to masterIdle() to help
  1068. // creaky old DAWs like Nuendo repaint themselves while we're
  1069. // repainting. Otherwise they just seem to give up and sit there
  1070. // waiting.
  1071. triggerAsyncUpdate();
  1072. }
  1073. #if JUCE_MAC
  1074. bool keyPressed (const KeyPress& kp)
  1075. {
  1076. // If we have an unused keypress, move the key-focus to a host window
  1077. // and re-inject the event..
  1078. forwardCurrentKeyEventToHost (this);
  1079. return true;
  1080. }
  1081. #endif
  1082. AudioProcessorEditor* getEditorComp() const
  1083. {
  1084. return dynamic_cast <AudioProcessorEditor*> (getChildComponent (0));
  1085. }
  1086. void resized()
  1087. {
  1088. Component* const c = getChildComponent (0);
  1089. if (c != 0)
  1090. c->setBounds (0, 0, getWidth(), getHeight());
  1091. }
  1092. void childBoundsChanged (Component* child)
  1093. {
  1094. child->setTopLeftPosition (0, 0);
  1095. const int cw = child->getWidth();
  1096. const int ch = child->getHeight();
  1097. wrapper.resizeHostWindow (cw, ch);
  1098. setSize (cw, ch);
  1099. #if JUCE_MAC
  1100. wrapper.resizeHostWindow (cw, ch); // (doing this a second time seems to be necessary in tracktion)
  1101. #endif
  1102. }
  1103. void handleAsyncUpdate()
  1104. {
  1105. wrapper.tryMasterIdle();
  1106. }
  1107. #if JUCE_WINDOWS
  1108. void mouseDown (const MouseEvent&)
  1109. {
  1110. broughtToFront();
  1111. }
  1112. void broughtToFront()
  1113. {
  1114. // for hosts like nuendo, need to also pop the MDI container to the
  1115. // front when our comp is clicked on.
  1116. HWND parent = findMDIParentOf ((HWND) getWindowHandle());
  1117. if (parent != 0)
  1118. SetWindowPos (parent, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  1119. }
  1120. #endif
  1121. //==============================================================================
  1122. juce_UseDebuggingNewOperator
  1123. private:
  1124. JuceVSTWrapper& wrapper;
  1125. };
  1126. //==============================================================================
  1127. juce_UseDebuggingNewOperator
  1128. private:
  1129. AudioProcessor* filter;
  1130. JUCE_NAMESPACE::MemoryBlock chunkMemory;
  1131. JUCE_NAMESPACE::uint32 chunkMemoryTime;
  1132. ScopedPointer<EditorCompWrapper> editorComp;
  1133. ERect editorSize;
  1134. MidiBuffer midiEvents;
  1135. VSTMidiEventList outgoingEvents;
  1136. bool isProcessing;
  1137. bool hasShutdown;
  1138. bool firstProcessCallback;
  1139. int diffW, diffH;
  1140. VstSpeakerArrangementType speakerIn, speakerOut;
  1141. int numInChans, numOutChans;
  1142. HeapBlock <float*> channels;
  1143. Array<float*> tempChannels; // see note in processReplacing()
  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() || getHostType().isCubaseBridged() ? 0 : new MessageManagerLock()) {}
  1151. ~NonWavelabMMLock() {}
  1152. private:
  1153. ScopedPointer <MessageManagerLock> mm;
  1154. };
  1155. static void checkWhetherWavelabHasChangedThread()
  1156. {
  1157. if (getHostType().isWavelab() || getHostType().isCubaseBridged())
  1158. {
  1159. static bool messageThreadIsDefinitelyCorrect = false;
  1160. if (! messageThreadIsDefinitelyCorrect)
  1161. {
  1162. MessageManager::getInstance()->setCurrentThreadAsMessageThread();
  1163. class MessageThreadCallback : public CallbackMessage
  1164. {
  1165. public:
  1166. MessageThreadCallback (bool& triggered_) : triggered (triggered_) {}
  1167. void messageCallback()
  1168. {
  1169. triggered = true;
  1170. }
  1171. private:
  1172. bool& triggered;
  1173. };
  1174. (new MessageThreadCallback (messageThreadIsDefinitelyCorrect))->post();
  1175. }
  1176. }
  1177. }
  1178. #else
  1179. typedef MessageManagerLock NonWavelabMMLock;
  1180. static void checkWhetherWavelabHasChangedThread() {}
  1181. #endif
  1182. //==============================================================================
  1183. void deleteTempChannels()
  1184. {
  1185. for (int i = tempChannels.size(); --i >= 0;)
  1186. delete[] (tempChannels.getUnchecked(i));
  1187. tempChannels.clear();
  1188. if (filter != 0)
  1189. tempChannels.insertMultiple (0, 0, filter->getNumInputChannels() + filter->getNumOutputChannels());
  1190. }
  1191. const String getHostName()
  1192. {
  1193. char host[256];
  1194. zeromem (host, sizeof (host));
  1195. getHostProductString (host);
  1196. return host;
  1197. }
  1198. #if JUCE_MAC
  1199. void* hostWindow;
  1200. #elif JUCE_LINUX
  1201. Window hostWindow;
  1202. #else
  1203. HWND hostWindow;
  1204. #endif
  1205. };
  1206. //==============================================================================
  1207. /** Somewhere in the codebase of your plugin, you need to implement this function
  1208. and make it create an instance of the filter subclass that you're building.
  1209. */
  1210. extern AudioProcessor* JUCE_CALLTYPE createPluginFilter();
  1211. //==============================================================================
  1212. static AEffect* pluginEntryPoint (audioMasterCallback audioMaster)
  1213. {
  1214. JUCE_AUTORELEASEPOOL
  1215. initialiseJuce_GUI();
  1216. try
  1217. {
  1218. if (audioMaster (0, audioMasterVersion, 0, 0, 0, 0) != 0)
  1219. {
  1220. AudioProcessor* const filter = createPluginFilter();
  1221. if (filter != 0)
  1222. {
  1223. JuceVSTWrapper* const wrapper = new JuceVSTWrapper (audioMaster, filter);
  1224. return wrapper->getAeffect();
  1225. }
  1226. }
  1227. }
  1228. catch (...)
  1229. {}
  1230. return 0;
  1231. }
  1232. //==============================================================================
  1233. // Mac startup code..
  1234. #if JUCE_MAC
  1235. extern "C" __attribute__ ((visibility("default"))) AEffect* VSTPluginMain (audioMasterCallback audioMaster)
  1236. {
  1237. initialiseMac();
  1238. return pluginEntryPoint (audioMaster);
  1239. }
  1240. extern "C" __attribute__ ((visibility("default"))) AEffect* main_macho (audioMasterCallback audioMaster)
  1241. {
  1242. initialiseMac();
  1243. return pluginEntryPoint (audioMaster);
  1244. }
  1245. //==============================================================================
  1246. // Linux startup code..
  1247. #elif JUCE_LINUX
  1248. extern "C" AEffect* VSTPluginMain (audioMasterCallback audioMaster)
  1249. {
  1250. SharedMessageThread::getInstance();
  1251. return pluginEntryPoint (audioMaster);
  1252. }
  1253. extern "C" __attribute__ ((visibility("default"))) AEffect* main_plugin (audioMasterCallback audioMaster) asm ("main");
  1254. extern "C" __attribute__ ((visibility("default"))) AEffect* main_plugin (audioMasterCallback audioMaster)
  1255. {
  1256. return VSTPluginMain (audioMaster);
  1257. }
  1258. __attribute__((constructor)) void myPluginInit()
  1259. {
  1260. // don't put initialiseJuce_GUI here... it will crash !
  1261. }
  1262. __attribute__((destructor)) void myPluginFini()
  1263. {
  1264. // don't put shutdownJuce_GUI here... it will crash !
  1265. }
  1266. //==============================================================================
  1267. // Win32 startup code..
  1268. #else
  1269. extern "C" __declspec (dllexport) AEffect* VSTPluginMain (audioMasterCallback audioMaster)
  1270. {
  1271. return pluginEntryPoint (audioMaster);
  1272. }
  1273. #ifndef _WIN64 // (can't compile this on win64, but it's not needed anyway with VST2.4)
  1274. extern "C" __declspec (dllexport) void* main (audioMasterCallback audioMaster)
  1275. {
  1276. return (void*) pluginEntryPoint (audioMaster);
  1277. }
  1278. #endif
  1279. #if JucePlugin_Build_RTAS
  1280. BOOL WINAPI DllMainVST (HINSTANCE instance, DWORD dwReason, LPVOID)
  1281. #else
  1282. extern "C" BOOL WINAPI DllMain (HINSTANCE instance, DWORD dwReason, LPVOID)
  1283. #endif
  1284. {
  1285. if (dwReason == DLL_PROCESS_ATTACH)
  1286. PlatformUtilities::setCurrentModuleInstanceHandle (instance);
  1287. return TRUE;
  1288. }
  1289. #endif
  1290. #endif