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.

847 lines
27KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-7 by Raw Material Software ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the
  7. GNU General Public License, as published by the Free Software Foundation;
  8. either version 2 of the License, or (at your option) any later version.
  9. JUCE is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with JUCE; if not, visit www.gnu.org/licenses or write to the
  15. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  16. Boston, MA 02111-1307 USA
  17. ------------------------------------------------------------------------------
  18. If you'd like to release a closed-source product which uses JUCE, commercial
  19. licenses are also available: visit www.rawmaterialsoftware.com/juce for
  20. more information.
  21. ==============================================================================
  22. */
  23. #include <AudioUnit/AudioUnit.h>
  24. #include "AUMIDIEffectBase.h"
  25. #include "AUCarbonViewBase.h"
  26. #include "../../juce_AudioFilterBase.h"
  27. #include "../../juce_IncludeCharacteristics.h"
  28. //==============================================================================
  29. #define juceFilterObjectPropertyID 0x1a45ffe9
  30. static VoidArray activePlugins;
  31. static const short channelConfigs[][2] = { JucePlugin_PreferredChannelConfigurations };
  32. static const int numChannelConfigs = numElementsInArray (channelConfigs);
  33. BEGIN_JUCE_NAMESPACE
  34. extern void juce_setCurrentExecutableFileNameFromBundleId (const String& bundleId) throw();
  35. END_JUCE_NAMESPACE
  36. //==============================================================================
  37. class JuceAU : public AUMIDIEffectBase,
  38. public AudioFilterBase::FilterNativeCallbacks
  39. {
  40. public:
  41. //==============================================================================
  42. JuceAU (AudioUnit component)
  43. : AUMIDIEffectBase (component),
  44. juceFilter (0),
  45. bufferSpace (2, 16),
  46. channels (0),
  47. prepared (false)
  48. {
  49. CreateElements();
  50. if (activePlugins.size() == 0)
  51. {
  52. initialiseJuce_GUI();
  53. #ifdef JucePlugin_CFBundleIdentifier
  54. juce_setCurrentExecutableFileNameFromBundleId (JucePlugin_CFBundleIdentifier);
  55. #endif
  56. MessageManager::getInstance()->setTimeBeforeShowingWaitCursor (0);
  57. }
  58. juceFilter = createPluginFilter();
  59. juceFilter->initialiseInternal (this);
  60. jassert (juceFilter != 0);
  61. Globals()->UseIndexedParameters (juceFilter->getNumParameters());
  62. activePlugins.add (this);
  63. }
  64. ~JuceAU()
  65. {
  66. delete juceFilter;
  67. juceFilter = 0;
  68. juce_free (channels);
  69. channels = 0;
  70. jassert (activePlugins.contains (this));
  71. activePlugins.removeValue (this);
  72. if (activePlugins.size() == 0)
  73. shutdownJuce_GUI();
  74. }
  75. //==============================================================================
  76. ComponentResult GetPropertyInfo (AudioUnitPropertyID inID,
  77. AudioUnitScope inScope,
  78. AudioUnitElement inElement,
  79. UInt32& outDataSize,
  80. Boolean& outWritable)
  81. {
  82. if (inScope == kAudioUnitScope_Global)
  83. {
  84. if (inID == juceFilterObjectPropertyID)
  85. {
  86. outWritable = false;
  87. outDataSize = sizeof (void*);
  88. return noErr;
  89. }
  90. }
  91. return AUMIDIEffectBase::GetPropertyInfo (inID, inScope, inElement, outDataSize, outWritable);
  92. }
  93. ComponentResult GetProperty (AudioUnitPropertyID inID,
  94. AudioUnitScope inScope,
  95. AudioUnitElement inElement,
  96. void* outData)
  97. {
  98. if (inScope == kAudioUnitScope_Global)
  99. {
  100. if (inID == juceFilterObjectPropertyID)
  101. {
  102. *((void**) outData) = (void*) juceFilter;
  103. return noErr;
  104. }
  105. }
  106. return AUMIDIEffectBase::GetProperty (inID, inScope, inElement, outData);
  107. }
  108. ComponentResult SaveState (CFPropertyListRef* outData)
  109. {
  110. ComponentResult err = AUMIDIEffectBase::SaveState (outData);
  111. if (err != noErr)
  112. return err;
  113. jassert (CFGetTypeID (*outData) == CFDictionaryGetTypeID());
  114. CFMutableDictionaryRef dict = (CFMutableDictionaryRef) *outData;
  115. if (juceFilter != 0)
  116. {
  117. JUCE_NAMESPACE::MemoryBlock state;
  118. juceFilter->getStateInformation (state);
  119. if (state.getSize() > 0)
  120. {
  121. CFDataRef ourState = CFDataCreate (kCFAllocatorDefault, (const uint8*) state, state.getSize());
  122. CFDictionarySetValue (dict, CFSTR("jucePluginState"), ourState);
  123. CFRelease (ourState);
  124. }
  125. }
  126. return noErr;
  127. }
  128. ComponentResult RestoreState (CFPropertyListRef inData)
  129. {
  130. ComponentResult err = AUMIDIEffectBase::RestoreState (inData);
  131. if (err != noErr)
  132. return err;
  133. if (juceFilter != 0)
  134. {
  135. CFDictionaryRef dict = (CFDictionaryRef) inData;
  136. CFDataRef data = 0;
  137. if (CFDictionaryGetValueIfPresent (dict, CFSTR("jucePluginState"),
  138. (const void**) &data))
  139. {
  140. if (data != 0)
  141. {
  142. const int numBytes = (int) CFDataGetLength (data);
  143. const uint8* const rawBytes = CFDataGetBytePtr (data);
  144. if (numBytes > 0)
  145. juceFilter->setStateInformation (rawBytes, numBytes);
  146. }
  147. }
  148. }
  149. return noErr;
  150. }
  151. UInt32 SupportedNumChannels (const AUChannelInfo** outInfo)
  152. {
  153. if (juceFilter == 0)
  154. return 0;
  155. // You need to actually add some configurations to the JucePlugin_PreferredChannelConfigurations
  156. // value in your JucePluginCharacteristics.h file..
  157. jassert (numChannelConfigs > 0);
  158. if (outInfo != 0)
  159. {
  160. for (int i = 0; i < numChannelConfigs; ++i)
  161. {
  162. channelInfo[i].inChannels = channelConfigs[i][0];
  163. channelInfo[i].outChannels = channelConfigs[i][1];
  164. outInfo[i] = channelInfo + i;
  165. }
  166. }
  167. return numChannelConfigs;
  168. }
  169. //==============================================================================
  170. ComponentResult GetParameterInfo (AudioUnitScope inScope,
  171. AudioUnitParameterID inParameterID,
  172. AudioUnitParameterInfo& outParameterInfo)
  173. {
  174. if (inScope == kAudioUnitScope_Global && juceFilter != 0)
  175. {
  176. outParameterInfo.flags = kAudioUnitParameterFlag_IsWritable
  177. | kAudioUnitParameterFlag_IsReadable
  178. | kAudioUnitParameterFlag_HasCFNameString;
  179. outParameterInfo.name[0] = 0;
  180. outParameterInfo.cfNameString = PlatformUtilities::juceStringToCFString (juceFilter->getParameterName ((int) inParameterID));
  181. outParameterInfo.minValue = 0.0f;
  182. outParameterInfo.maxValue = 1.0f;
  183. outParameterInfo.defaultValue = 0.0f;
  184. outParameterInfo.unit = kAudioUnitParameterUnit_Generic;
  185. return noErr;
  186. }
  187. else
  188. {
  189. return kAudioUnitErr_InvalidParameter;
  190. }
  191. }
  192. ComponentResult GetParameter (AudioUnitParameterID inID,
  193. AudioUnitScope inScope,
  194. AudioUnitElement inElement,
  195. Float32& outValue)
  196. {
  197. if (inScope == kAudioUnitScope_Global && juceFilter != 0)
  198. {
  199. outValue = juceFilter->getParameter ((int) inID);
  200. return noErr;
  201. }
  202. return AUBase::GetParameter (inID, inScope, inElement, outValue);
  203. }
  204. ComponentResult SetParameter (AudioUnitParameterID inID,
  205. AudioUnitScope inScope,
  206. AudioUnitElement inElement,
  207. Float32 inValue,
  208. UInt32 inBufferOffsetInFrames)
  209. {
  210. if (inScope == kAudioUnitScope_Global && juceFilter != 0)
  211. {
  212. juceFilter->setParameter ((int) inID, inValue);
  213. return noErr;
  214. }
  215. return AUBase::SetParameter (inID, inScope, inElement, inValue, inBufferOffsetInFrames);
  216. }
  217. //==============================================================================
  218. ComponentResult Version() { return JucePlugin_VersionCode; }
  219. bool SupportsTail() { return true; }
  220. Float64 GetTailTime() { return 0; }
  221. Float64 GetLatency()
  222. {
  223. jassert (GetSampleRate() > 0);
  224. if (GetSampleRate() <= 0)
  225. return 0.0;
  226. return (JucePlugin_Latency) / GetSampleRate();
  227. }
  228. //==============================================================================
  229. int GetNumCustomUIComponents() { return 1; }
  230. void GetUIComponentDescs (ComponentDescription* inDescArray)
  231. {
  232. inDescArray[0].componentType = kAudioUnitCarbonViewComponentType;
  233. inDescArray[0].componentSubType = JucePlugin_AUSubType;
  234. inDescArray[0].componentManufacturer = JucePlugin_AUManufacturerCode;
  235. inDescArray[0].componentFlags = 0;
  236. inDescArray[0].componentFlagsMask = 0;
  237. }
  238. //==============================================================================
  239. bool getCurrentPositionInfo (AudioFilterBase::CurrentPositionInfo& info)
  240. {
  241. info.timeSigNumerator = 0;
  242. info.timeSigDenominator = 0;
  243. info.timeInSeconds = 0;
  244. info.editOriginTime = 0;
  245. info.ppqPositionOfLastBarStart = 0;
  246. info.isPlaying = false;
  247. info.isRecording = false;
  248. switch (lastSMPTETime.mType)
  249. {
  250. case kSMPTETimeType24:
  251. info.frameRate = AudioFilterBase::CurrentPositionInfo::fps24;
  252. break;
  253. case kSMPTETimeType25:
  254. info.frameRate = AudioFilterBase::CurrentPositionInfo::fps25;
  255. break;
  256. case kSMPTETimeType30Drop:
  257. info.frameRate = AudioFilterBase::CurrentPositionInfo::fps30drop;
  258. break;
  259. case kSMPTETimeType30:
  260. info.frameRate = AudioFilterBase::CurrentPositionInfo::fps30;
  261. break;
  262. case kSMPTETimeType2997:
  263. info.frameRate = AudioFilterBase::CurrentPositionInfo::fps2997;
  264. break;
  265. case kSMPTETimeType2997Drop:
  266. info.frameRate = AudioFilterBase::CurrentPositionInfo::fps2997drop;
  267. break;
  268. //case kSMPTETimeType60:
  269. //case kSMPTETimeType5994:
  270. default:
  271. info.frameRate = AudioFilterBase::CurrentPositionInfo::fpsUnknown;
  272. break;
  273. }
  274. if (CallHostBeatAndTempo (&info.ppqPosition, &info.bpm) != noErr)
  275. {
  276. info.ppqPosition = 0;
  277. info.bpm = 0;
  278. }
  279. UInt32 outDeltaSampleOffsetToNextBeat;
  280. double outCurrentMeasureDownBeat;
  281. float num;
  282. UInt32 den;
  283. if (CallHostMusicalTimeLocation (&outDeltaSampleOffsetToNextBeat, &num, &den,
  284. &outCurrentMeasureDownBeat) == noErr)
  285. {
  286. info.timeSigNumerator = (int) num;
  287. info.timeSigDenominator = den;
  288. info.ppqPositionOfLastBarStart = outCurrentMeasureDownBeat;
  289. }
  290. double outCurrentSampleInTimeLine, outCycleStartBeat, outCycleEndBeat;
  291. Boolean playing, playchanged, looping;
  292. if (CallHostTransportState (&playing,
  293. &playchanged,
  294. &outCurrentSampleInTimeLine,
  295. &looping,
  296. &outCycleStartBeat,
  297. &outCycleEndBeat) == noErr)
  298. {
  299. info.isPlaying = playing;
  300. info.timeInSeconds = outCurrentSampleInTimeLine / GetSampleRate();
  301. }
  302. return true;
  303. }
  304. void informHostOfParameterChange (int index, float newValue)
  305. {
  306. if (juceFilter != 0)
  307. {
  308. juceFilter->setParameter (index, newValue);
  309. if (AUEventListenerNotify != 0)
  310. {
  311. AudioUnitEvent e;
  312. e.mEventType = kAudioUnitEvent_ParameterValueChange;
  313. e.mArgument.mParameter.mAudioUnit = GetComponentInstance();
  314. e.mArgument.mParameter.mParameterID = (AudioUnitParameterID) index;
  315. e.mArgument.mParameter.mScope = kAudioUnitScope_Global;
  316. e.mArgument.mParameter.mElement = 0;
  317. AUEventListenerNotify (0, 0, &e);
  318. }
  319. }
  320. }
  321. //==============================================================================
  322. ComponentResult Initialize()
  323. {
  324. AUMIDIEffectBase::Initialize();
  325. prepareToPlay();
  326. return noErr;
  327. }
  328. void Cleanup()
  329. {
  330. AUMIDIEffectBase::Cleanup();
  331. if (juceFilter != 0)
  332. juceFilter->releaseResources();
  333. bufferSpace.setSize (2, 16);
  334. midiEvents.clear();
  335. prepared = false;
  336. }
  337. ComponentResult Reset (AudioUnitScope inScope, AudioUnitElement inElement)
  338. {
  339. if (! prepared)
  340. prepareToPlay();
  341. return AUMIDIEffectBase::Reset (inScope, inElement);
  342. }
  343. void prepareToPlay()
  344. {
  345. if (juceFilter != 0)
  346. {
  347. juceFilter->numInputChannels = GetInput(0)->GetStreamFormat().mChannelsPerFrame;
  348. juceFilter->numOutputChannels = GetOutput(0)->GetStreamFormat().mChannelsPerFrame;
  349. bufferSpace.setSize (juceFilter->numInputChannels + juceFilter->numOutputChannels,
  350. GetMaxFramesPerSlice() + 32);
  351. juceFilter->prepareToPlay (GetSampleRate(),
  352. GetMaxFramesPerSlice());
  353. midiEvents.clear();
  354. juce_free (channels);
  355. channels = (float**) juce_calloc (sizeof (float*) * jmax (juceFilter->numInputChannels,
  356. juceFilter->numOutputChannels) + 4);
  357. prepared = true;
  358. }
  359. }
  360. ComponentResult Render (AudioUnitRenderActionFlags &ioActionFlags,
  361. const AudioTimeStamp& inTimeStamp,
  362. UInt32 nFrames)
  363. {
  364. lastSMPTETime = inTimeStamp.mSMPTETime;
  365. return AUMIDIEffectBase::Render (ioActionFlags, inTimeStamp, nFrames);
  366. }
  367. OSStatus ProcessBufferLists (AudioUnitRenderActionFlags& ioActionFlags,
  368. const AudioBufferList& inBuffer,
  369. AudioBufferList& outBuffer,
  370. UInt32 numSamples)
  371. {
  372. if (juceFilter != 0)
  373. {
  374. jassert (prepared);
  375. int numOutChans = 0;
  376. int nextSpareBufferChan = 0;
  377. bool needToReinterleave = false;
  378. const int numIn = juceFilter->numInputChannels;
  379. const int numOut = juceFilter->numOutputChannels;
  380. unsigned int i;
  381. for (i = 0; i < outBuffer.mNumberBuffers; ++i)
  382. {
  383. AudioBuffer& buf = outBuffer.mBuffers[i];
  384. if (buf.mNumberChannels == 1)
  385. {
  386. channels [numOutChans++] = (float*) buf.mData;
  387. }
  388. else
  389. {
  390. needToReinterleave = true;
  391. for (unsigned int subChan = 0; subChan < buf.mNumberChannels && numOutChans < numOut; ++subChan)
  392. channels [numOutChans++] = bufferSpace.getSampleData (nextSpareBufferChan++);
  393. }
  394. if (numOutChans >= numOut)
  395. break;
  396. }
  397. int numInChans = 0;
  398. for (i = 0; i < inBuffer.mNumberBuffers; ++i)
  399. {
  400. const AudioBuffer& buf = inBuffer.mBuffers[i];
  401. if (buf.mNumberChannels == 1)
  402. {
  403. if (numInChans < numOut)
  404. memcpy (channels [numInChans], (const float*) buf.mData, sizeof (float) * numSamples);
  405. else
  406. channels [numInChans] = (float*) buf.mData;
  407. }
  408. else
  409. {
  410. // need to de-interleave..
  411. for (unsigned int subChan = 0; subChan < buf.mNumberChannels && numInChans < numIn; ++subChan)
  412. {
  413. float* dest;
  414. if (numInChans >= numOut)
  415. {
  416. dest = bufferSpace.getSampleData (nextSpareBufferChan++);
  417. channels [numInChans++] = dest;
  418. }
  419. else
  420. {
  421. dest = channels [numInChans++];
  422. }
  423. const float* src = ((const float*) buf.mData) + subChan;
  424. for (int j = numSamples; --j >= 0;)
  425. {
  426. *dest++ = *src;
  427. src += buf.mNumberChannels;
  428. }
  429. }
  430. }
  431. if (numInChans >= numIn)
  432. break;
  433. }
  434. {
  435. AudioSampleBuffer buffer (channels, jmax (numIn, numOut), numSamples);
  436. const ScopedLock sl (juceFilter->getCallbackLock());
  437. if (juceFilter->suspended)
  438. {
  439. for (int i = 0; i < numOut; ++i)
  440. zeromem (channels [i], sizeof (float) * numSamples);
  441. }
  442. else
  443. {
  444. juceFilter->processBlock (buffer, midiEvents);
  445. }
  446. }
  447. if (! midiEvents.isEmpty())
  448. {
  449. #if JucePlugin_ProducesMidiOutput
  450. const uint8* midiEventData;
  451. int midiEventSize, midiEventPosition;
  452. MidiBuffer::Iterator i (midiEvents);
  453. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  454. {
  455. jassert (midiEventPosition >= 0 && midiEventPosition < (int) numSamples);
  456. //xxx
  457. }
  458. #else
  459. // if your plugin creates midi messages, you'll need to set
  460. // the JucePlugin_ProducesMidiOutput macro to 1 in your
  461. // JucePluginCharacteristics.h file
  462. //jassert (midiEvents.getNumEvents() <= numMidiEventsComingIn);
  463. #endif
  464. midiEvents.clear();
  465. }
  466. if (needToReinterleave)
  467. {
  468. nextSpareBufferChan = 0;
  469. for (i = 0; i < outBuffer.mNumberBuffers; ++i)
  470. {
  471. AudioBuffer& buf = outBuffer.mBuffers[i];
  472. if (buf.mNumberChannels > 1)
  473. {
  474. for (unsigned int subChan = 0; subChan < buf.mNumberChannels; ++subChan)
  475. {
  476. const float* src = bufferSpace.getSampleData (nextSpareBufferChan++);
  477. float* dest = ((float*) buf.mData) + subChan;
  478. for (int j = numSamples; --j >= 0;)
  479. {
  480. *dest = *src++;
  481. dest += buf.mNumberChannels;
  482. }
  483. }
  484. }
  485. }
  486. }
  487. #if ! JucePlugin_SilenceInProducesSilenceOut
  488. ioActionFlags &= ~kAudioUnitRenderAction_OutputIsSilence;
  489. #endif
  490. }
  491. return noErr;
  492. }
  493. protected:
  494. OSStatus HandleMidiEvent (UInt8 nStatus,
  495. UInt8 inChannel,
  496. UInt8 inData1,
  497. UInt8 inData2,
  498. long inStartFrame)
  499. {
  500. #if JucePlugin_WantsMidiInput
  501. uint8 data [4];
  502. data[0] = nStatus | inChannel;
  503. data[1] = inData1;
  504. data[2] = inData2;
  505. midiEvents.addEvent (data, 3, inStartFrame);
  506. #endif
  507. return noErr;
  508. }
  509. //==============================================================================
  510. private:
  511. AudioFilterBase* juceFilter;
  512. AudioSampleBuffer bufferSpace;
  513. float** channels;
  514. MidiBuffer midiEvents;
  515. bool prepared;
  516. SMPTETime lastSMPTETime;
  517. AUChannelInfo channelInfo [numChannelConfigs];
  518. };
  519. //==============================================================================
  520. class JuceAUComponentHolder : public Component
  521. {
  522. public:
  523. JuceAUComponentHolder (Component* const editorComp)
  524. {
  525. addAndMakeVisible (editorComp);
  526. setOpaque (true);
  527. setVisible (true);
  528. setBroughtToFrontOnMouseClick (true);
  529. #if ! JucePlugin_EditorRequiresKeyboardFocus
  530. setWantsKeyboardFocus (false);
  531. #endif
  532. }
  533. ~JuceAUComponentHolder()
  534. {
  535. }
  536. void resized()
  537. {
  538. if (getNumChildComponents() > 0)
  539. getChildComponent (0)->setBounds (0, 0, getWidth(), getHeight());
  540. }
  541. void paint (Graphics& g)
  542. {
  543. }
  544. };
  545. //==============================================================================
  546. class JuceAUView : public AUCarbonViewBase,
  547. public ComponentListener,
  548. public MouseListener,
  549. public Timer
  550. {
  551. AudioFilterBase* juceFilter;
  552. AudioFilterEditor* editorComp;
  553. Component* windowComp;
  554. bool recursive;
  555. int mx, my;
  556. public:
  557. JuceAUView (AudioUnitCarbonView auview)
  558. : AUCarbonViewBase (auview),
  559. juceFilter (0),
  560. editorComp (0),
  561. windowComp (0),
  562. recursive (false),
  563. mx (0),
  564. my (0)
  565. {
  566. }
  567. ~JuceAUView()
  568. {
  569. deleteUI();
  570. }
  571. ComponentResult CreateUI (Float32 inXOffset, Float32 inYOffset)
  572. {
  573. if (juceFilter == 0)
  574. {
  575. UInt32 propertySize = sizeof (&juceFilter);
  576. AudioUnitGetProperty (GetEditAudioUnit(),
  577. juceFilterObjectPropertyID,
  578. kAudioUnitScope_Global,
  579. 0,
  580. &juceFilter,
  581. &propertySize);
  582. }
  583. if (juceFilter != 0)
  584. {
  585. deleteUI();
  586. editorComp = juceFilter->createEditorIfNeeded();
  587. const int w = editorComp->getWidth();
  588. const int h = editorComp->getHeight();
  589. editorComp->setOpaque (true);
  590. editorComp->setVisible (true);
  591. windowComp = new JuceAUComponentHolder (editorComp);
  592. windowComp->setBounds ((int) inXOffset, (int) inYOffset, w, h);
  593. windowComp->addToDesktop (0, (void*) mCarbonPane);
  594. SizeControl (mCarbonPane, w, h);
  595. editorComp->addComponentListener (this);
  596. windowComp->addMouseListener (this, true);
  597. startTimer (20);
  598. }
  599. else
  600. {
  601. jassertfalse // can't get a pointer to our effect
  602. }
  603. return noErr;
  604. }
  605. void componentMovedOrResized (Component& component,
  606. bool wasMoved,
  607. bool wasResized)
  608. {
  609. if (! recursive)
  610. {
  611. recursive = true;
  612. if (editorComp != 0 && wasResized)
  613. {
  614. const int w = jmax (32, editorComp->getWidth());
  615. const int h = jmax (32, editorComp->getHeight());
  616. SizeControl (mCarbonPane, w, h);
  617. if (windowComp->getWidth() != w
  618. || windowComp->getHeight() != h)
  619. {
  620. windowComp->setSize (w, h);
  621. }
  622. editorComp->repaint();
  623. }
  624. recursive = false;
  625. }
  626. }
  627. void timerCallback()
  628. {
  629. // for some stupid Apple-related reason, mouse move events just don't seem to get sent
  630. // to the windows in an AU, so we have to bodge it here and simulate them with a
  631. // timer..
  632. if (editorComp != 0)
  633. {
  634. int x, y;
  635. Desktop::getInstance().getMousePosition (x, y);
  636. if (x != mx || y != my)
  637. {
  638. mx = x;
  639. my = y;
  640. if (! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  641. {
  642. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  643. {
  644. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  645. const int rx = x - peer->getComponent()->getX();
  646. const int ry = y - peer->getComponent()->getY();
  647. if (peer->contains (rx, ry, false) && peer->getComponent()->isShowing())
  648. {
  649. peer->handleMouseMove (rx, ry, Time::currentTimeMillis());
  650. break;
  651. }
  652. }
  653. }
  654. }
  655. }
  656. }
  657. void mouseMove (const MouseEvent& e)
  658. {
  659. Desktop::getInstance().getMousePosition (mx, my);
  660. startTimer (20);
  661. }
  662. private:
  663. void deleteUI()
  664. {
  665. PopupMenu::dismissAllActiveMenus();
  666. // there's some kind of component currently modal, but the host
  667. // is trying to delete our plugin..
  668. jassert (Component::getCurrentlyModalComponent() == 0);
  669. if (editorComp != 0)
  670. juceFilter->editorBeingDeleted (editorComp);
  671. deleteAndZero (editorComp);
  672. deleteAndZero (windowComp);
  673. }
  674. };
  675. //==============================================================================
  676. #define JUCE_COMPONENT_ENTRYX(Class, Name, Suffix) \
  677. extern "C" __attribute__((visibility("default"))) ComponentResult Name ## Suffix (ComponentParameters* params, Class* obj); \
  678. extern "C" __attribute__((visibility("default"))) ComponentResult Name ## Suffix (ComponentParameters* params, Class* obj) \
  679. { \
  680. return ComponentEntryPoint<Class>::Dispatch(params, obj); \
  681. }
  682. #define JUCE_COMPONENT_ENTRY(Class, Name, Suffix) JUCE_COMPONENT_ENTRYX(Class, Name, Suffix)
  683. JUCE_COMPONENT_ENTRY (JuceAU, JucePlugin_AUExportPrefix, Entry)
  684. JUCE_COMPONENT_ENTRY (JuceAUView, JucePlugin_AUExportPrefix, ViewEntry)