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.

1544 lines
49KB

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