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.

851 lines
31KB

  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. // Your project must contain an AppConfig.h file with your project-specific settings in it,
  19. // and your header search path must make it accessible to the module's files.
  20. #include "AppConfig.h"
  21. #include "../utility/juce_CheckSettingMacros.h"
  22. #if JucePlugin_Build_AAX && (JUCE_INCLUDED_AAX_IN_MM || defined (_WIN32) || defined (_WIN64))
  23. #ifdef _MSC_VER
  24. #include <windows.h>
  25. #else
  26. #include <Cocoa/Cocoa.h>
  27. #endif
  28. #include "../utility/juce_IncludeModuleHeaders.h"
  29. #undef Component
  30. #ifdef __clang__
  31. #pragma clang diagnostic push
  32. #pragma clang diagnostic ignored "-Wnon-virtual-dtor"
  33. #endif
  34. #include "AAX_Exports.cpp"
  35. #include "AAX_ICollection.h"
  36. #include "AAX_IComponentDescriptor.h"
  37. #include "AAX_IEffectDescriptor.h"
  38. #include "AAX_IPropertyMap.h"
  39. #include "AAX_CEffectParameters.h"
  40. #include "AAX_Errors.h"
  41. #include "AAX_CBinaryTaperDelegate.h"
  42. #include "AAX_CBinaryDisplayDelegate.h"
  43. #include "AAX_CLinearTaperDelegate.h"
  44. #include "AAX_CNumberDisplayDelegate.h"
  45. #include "AAX_CEffectGUI.h"
  46. #include "AAX_IViewContainer.h"
  47. #include "AAX_ITransport.h"
  48. #include "AAX_IMIDINode.h"
  49. #include "AAX_UtilsNative.h"
  50. #ifdef __clang__
  51. #pragma clang diagnostic pop
  52. #endif
  53. #if JUCE_WINDOWS
  54. #ifndef JucePlugin_AAXLibs_path
  55. #error "You need to define the JucePlugin_AAXLibs_path macro. (This is best done via the introjucer)"
  56. #endif
  57. #if JUCE_64BIT
  58. #define JUCE_AAX_LIB "AAXLibrary_x64"
  59. #else
  60. #define JUCE_AAX_LIB "AAXLibrary"
  61. #endif
  62. #if JUCE_DEBUG
  63. #define JUCE_AAX_LIB_PATH "\\Debug\\"
  64. #define JUCE_AAX_LIB_SUFFIX "_D"
  65. #else
  66. #define JUCE_AAX_LIB_PATH "\\Release\\"
  67. #define JUCE_AAX_LIB_SUFFIX ""
  68. #endif
  69. #pragma comment(lib, JucePlugin_AAXLibs_path JUCE_AAX_LIB_PATH JUCE_AAX_LIB JUCE_AAX_LIB_SUFFIX ".lib")
  70. #endif
  71. using juce::Component;
  72. const int32_t juceChunkType = 'juce';
  73. //==============================================================================
  74. struct AAXClasses
  75. {
  76. static void check (AAX_Result result)
  77. {
  78. jassert (result == AAX_SUCCESS); (void) result;
  79. }
  80. static AAX_EStemFormat getFormatForChans (const int numChans) noexcept
  81. {
  82. switch (numChans)
  83. {
  84. case 0: return AAX_eStemFormat_None;
  85. case 1: return AAX_eStemFormat_Mono;
  86. case 2: return AAX_eStemFormat_Stereo;
  87. case 3: return AAX_eStemFormat_LCR;
  88. case 4: return AAX_eStemFormat_Quad;
  89. case 5: return AAX_eStemFormat_5_0;
  90. case 6: return AAX_eStemFormat_5_1;
  91. case 7: return AAX_eStemFormat_6_1;
  92. case 8: return AAX_eStemFormat_7_1_DTS;
  93. default: jassertfalse; break; // hmm - not a valid number of chans..
  94. }
  95. return AAX_eStemFormat_None;
  96. }
  97. static int getNumChannelsForStemFormat (AAX_EStemFormat format) noexcept
  98. {
  99. switch (format)
  100. {
  101. case AAX_eStemFormat_None: return 0;
  102. case AAX_eStemFormat_Mono: return 1;
  103. case AAX_eStemFormat_Stereo: return 2;
  104. case AAX_eStemFormat_LCR: return 3;
  105. case AAX_eStemFormat_Quad: return 4;
  106. case AAX_eStemFormat_5_0: return 5;
  107. case AAX_eStemFormat_5_1: return 6;
  108. case AAX_eStemFormat_6_1: return 7;
  109. case AAX_eStemFormat_7_1_DTS: return 8;
  110. default: jassertfalse; break; // hmm - not a valid number of chans..
  111. }
  112. return 0;
  113. }
  114. //==============================================================================
  115. struct JUCELibraryRefCount
  116. {
  117. JUCELibraryRefCount() { if (getCount()++ == 0) initialise(); }
  118. ~JUCELibraryRefCount() { if (--getCount() == 0) shutdown(); }
  119. private:
  120. static void initialise()
  121. {
  122. initialiseJuce_GUI();
  123. }
  124. static void shutdown()
  125. {
  126. shutdownJuce_GUI();
  127. }
  128. int& getCount() noexcept
  129. {
  130. static int count = 0;
  131. return count;
  132. }
  133. };
  134. //==============================================================================
  135. class JuceAAX_Processor;
  136. struct PluginInstanceInfo
  137. {
  138. PluginInstanceInfo (JuceAAX_Processor& p) : parameters (p) {}
  139. JuceAAX_Processor& parameters;
  140. JUCE_DECLARE_NON_COPYABLE (PluginInstanceInfo)
  141. };
  142. //==============================================================================
  143. struct JUCEAlgorithmContext
  144. {
  145. float** inputChannels;
  146. float** outputChannels;
  147. int32_t* bufferSize;
  148. int32_t* bypass;
  149. #if JucePlugin_WantsMidiInput
  150. AAX_IMIDINode* midiNodeIn;
  151. #endif
  152. #if JucePlugin_ProducesMidiOutput
  153. AAX_IMIDINode* midiNodeOut;
  154. #endif
  155. PluginInstanceInfo* pluginInstance;
  156. int32_t* isPrepared;
  157. };
  158. struct JUCEAlgorithmIDs
  159. {
  160. enum
  161. {
  162. inputChannels = AAX_FIELD_INDEX (JUCEAlgorithmContext, inputChannels),
  163. outputChannels = AAX_FIELD_INDEX (JUCEAlgorithmContext, outputChannels),
  164. bufferSize = AAX_FIELD_INDEX (JUCEAlgorithmContext, bufferSize),
  165. bypass = AAX_FIELD_INDEX (JUCEAlgorithmContext, bypass),
  166. #if JucePlugin_WantsMidiInput
  167. midiNodeIn = AAX_FIELD_INDEX (JUCEAlgorithmContext, midiNodeIn),
  168. #endif
  169. #if JucePlugin_ProducesMidiOutput
  170. midiNodeOut = AAX_FIELD_INDEX (JUCEAlgorithmContext, midiNodeOut),
  171. #endif
  172. pluginInstance = AAX_FIELD_INDEX (JUCEAlgorithmContext, pluginInstance),
  173. preparedFlag = AAX_FIELD_INDEX (JUCEAlgorithmContext, isPrepared)
  174. };
  175. };
  176. #if JucePlugin_WantsMidiInput
  177. static AAX_IMIDINode* getMidiNodeIn (JUCEAlgorithmContext& c) noexcept { return c.midiNodeIn; }
  178. #else
  179. static AAX_IMIDINode* getMidiNodeIn (JUCEAlgorithmContext&) noexcept { return nullptr; }
  180. #endif
  181. #if JucePlugin_ProducesMidiOutput
  182. AAX_IMIDINode* midiNodeOut;
  183. static AAX_IMIDINode* getMidiNodeOut (JUCEAlgorithmContext& c) noexcept { return c.midiNodeOut; }
  184. #else
  185. static AAX_IMIDINode* getMidiNodeOut (JUCEAlgorithmContext&) noexcept { return nullptr; }
  186. #endif
  187. //==============================================================================
  188. class JuceAAX_GUI : public AAX_CEffectGUI
  189. {
  190. public:
  191. JuceAAX_GUI() {}
  192. virtual ~JuceAAX_GUI() { DeleteViewContainer(); }
  193. static AAX_IEffectGUI* AAX_CALLBACK Create() { return new JuceAAX_GUI(); }
  194. void CreateViewContents()
  195. {
  196. if (component == nullptr)
  197. {
  198. if (JuceAAX_Processor* params = dynamic_cast <JuceAAX_Processor*> (GetEffectParameters()))
  199. component = new ContentWrapperComponent (*this, params->getPluginInstance());
  200. else
  201. jassertfalse;
  202. }
  203. }
  204. void CreateViewContainer()
  205. {
  206. CreateViewContents();
  207. if (void* nativeViewToAttachTo = GetViewContainerPtr())
  208. {
  209. #if JUCE_MAC
  210. if (GetViewContainerType() == AAX_eViewContainer_Type_NSView)
  211. #else
  212. if (GetViewContainerType() == AAX_eViewContainer_Type_HWND)
  213. #endif
  214. {
  215. component->setVisible (true);
  216. component->addToDesktop (0, nativeViewToAttachTo);
  217. }
  218. }
  219. }
  220. void DeleteViewContainer()
  221. {
  222. if (component != nullptr)
  223. {
  224. JUCE_AUTORELEASEPOOL
  225. component->removeFromDesktop();
  226. component = nullptr;
  227. }
  228. }
  229. virtual AAX_Result GetViewSize (AAX_Point* viewSize) const
  230. {
  231. if (component != nullptr)
  232. {
  233. viewSize->horz = (float) component->getWidth();
  234. viewSize->vert = (float) component->getHeight();
  235. return AAX_SUCCESS;
  236. }
  237. return AAX_ERROR_NULL_OBJECT;
  238. }
  239. AAX_Result ParameterUpdated (AAX_CParamID /*paramID*/)
  240. {
  241. return AAX_SUCCESS;
  242. }
  243. AAX_Result SetControlHighlightInfo (AAX_CParamID /*paramID*/, AAX_CBoolean /*isHighlighted*/, AAX_EHighlightColor)
  244. {
  245. return AAX_SUCCESS;
  246. }
  247. private:
  248. class ContentWrapperComponent : public juce::Component
  249. {
  250. public:
  251. ContentWrapperComponent (JuceAAX_GUI& gui, AudioProcessor& plugin)
  252. : owner (gui)
  253. {
  254. setOpaque (true);
  255. addAndMakeVisible (pluginEditor = plugin.createEditorIfNeeded());
  256. setBounds (pluginEditor->getLocalBounds());
  257. setBroughtToFrontOnMouseClick (true);
  258. }
  259. ~ContentWrapperComponent()
  260. {
  261. if (pluginEditor != nullptr)
  262. {
  263. PopupMenu::dismissAllActiveMenus();
  264. pluginEditor->getAudioProcessor()->editorBeingDeleted (pluginEditor);
  265. }
  266. }
  267. void paint (Graphics& g)
  268. {
  269. g.fillAll (Colours::black);
  270. }
  271. void childBoundsChanged (Component*)
  272. {
  273. if (pluginEditor != nullptr)
  274. {
  275. const int w = pluginEditor->getWidth();
  276. const int h = pluginEditor->getHeight();
  277. setSize (w, h);
  278. AAX_Point newSize ((float) h, (float) w);
  279. owner.GetViewContainer()->SetViewSize (newSize);
  280. }
  281. }
  282. private:
  283. ScopedPointer<AudioProcessorEditor> pluginEditor;
  284. JuceAAX_GUI& owner;
  285. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ContentWrapperComponent)
  286. };
  287. ScopedPointer<ContentWrapperComponent> component;
  288. JUCELibraryRefCount juceCount;
  289. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (JuceAAX_GUI)
  290. };
  291. //==============================================================================
  292. class JuceAAX_Processor : public AAX_CEffectParameters,
  293. public juce::AudioPlayHead,
  294. public AudioProcessorListener
  295. {
  296. public:
  297. JuceAAX_Processor()
  298. {
  299. pluginInstance = createPluginFilterOfType (AudioProcessor::wrapperType_AAX);
  300. pluginInstance->setPlayHead (this);
  301. pluginInstance->addListener (this);
  302. AAX_CEffectParameters::GetNumberOfChunks (&juceChunkIndex);
  303. }
  304. static AAX_CEffectParameters* AAX_CALLBACK Create() { return new JuceAAX_Processor(); }
  305. AAX_Result EffectInit()
  306. {
  307. addBypassParameter();
  308. addAudioProcessorParameters();
  309. preparePlugin();
  310. return AAX_SUCCESS;
  311. }
  312. AAX_Result GetNumberOfChunks (int32_t* numChunks) const
  313. {
  314. // The juceChunk is the last chunk.
  315. *numChunks = juceChunkIndex + 1;
  316. return AAX_SUCCESS;
  317. }
  318. AAX_Result GetChunkIDFromIndex (int32_t index, AAX_CTypeID* chunkID) const
  319. {
  320. if (index != juceChunkIndex)
  321. return AAX_CEffectParameters::GetChunkIDFromIndex (index, chunkID);
  322. *chunkID = juceChunkType;
  323. return AAX_SUCCESS;
  324. }
  325. AAX_Result GetChunkSize (AAX_CTypeID chunkID, uint32_t* oSize) const
  326. {
  327. if (chunkID != juceChunkType)
  328. return AAX_CEffectParameters::GetChunkSize (chunkID, oSize);
  329. tempFilterData.setSize (0);
  330. pluginInstance->getStateInformation (tempFilterData);
  331. *oSize = (uint32_t) tempFilterData.getSize();
  332. return AAX_SUCCESS;
  333. }
  334. AAX_Result GetChunk (AAX_CTypeID chunkID, AAX_SPlugInChunk* oChunk) const
  335. {
  336. if (chunkID != juceChunkType)
  337. return AAX_CEffectParameters::GetChunk (chunkID, oChunk);
  338. if (tempFilterData.getSize() == 0)
  339. pluginInstance->getStateInformation (tempFilterData);
  340. oChunk->fSize = (uint32_t) tempFilterData.getSize();
  341. tempFilterData.copyTo (oChunk->fData, 0, tempFilterData.getSize());
  342. tempFilterData.setSize (0);
  343. return AAX_SUCCESS;
  344. }
  345. AAX_Result SetChunk (AAX_CTypeID chunkID, const AAX_SPlugInChunk* chunk)
  346. {
  347. if (chunkID != juceChunkType)
  348. return AAX_CEffectParameters::SetChunk (chunkID, chunk);
  349. pluginInstance->setStateInformation ((void*) chunk->fData, chunk->fSize);
  350. return AAX_SUCCESS;
  351. }
  352. AAX_Result ResetFieldData (AAX_CFieldIndex fieldIndex, void* data, uint32_t dataSize) const
  353. {
  354. switch (fieldIndex)
  355. {
  356. case JUCEAlgorithmIDs::pluginInstance:
  357. {
  358. const size_t numObjects = dataSize / sizeof (PluginInstanceInfo);
  359. PluginInstanceInfo* const objects = static_cast <PluginInstanceInfo*> (data);
  360. jassert (numObjects == 1); // not sure how to handle more than one..
  361. for (size_t i = 0; i < numObjects; ++i)
  362. new (objects + i) PluginInstanceInfo (const_cast<JuceAAX_Processor&> (*this));
  363. break;
  364. }
  365. case JUCEAlgorithmIDs::preparedFlag:
  366. {
  367. const_cast<JuceAAX_Processor*>(this)->preparePlugin();
  368. const size_t numObjects = dataSize / sizeof (uint32_t);
  369. uint32_t* const objects = static_cast <uint32_t*> (data);
  370. for (size_t i = 0; i < numObjects; ++i)
  371. new (objects + i) uint32_t (1);
  372. break;
  373. }
  374. }
  375. return AAX_SUCCESS;
  376. //return AAX_ERROR_INVALID_FIELD_INDEX;
  377. }
  378. AAX_Result UpdateParameterNormalizedValue (AAX_CParamID paramID, double value, AAX_EUpdateSource source)
  379. {
  380. AAX_Result result = AAX_CEffectParameters::UpdateParameterNormalizedValue (paramID, value, source);
  381. if (AAX::IsParameterIDEqual (paramID, cDefaultMasterBypassID) == false)
  382. {
  383. const int parameterIndex = atoi (paramID);
  384. pluginInstance->setParameter (parameterIndex, (float) value);
  385. }
  386. return result;
  387. }
  388. AudioProcessor& getPluginInstance() const noexcept { return *pluginInstance; }
  389. bool getCurrentPosition (juce::AudioPlayHead::CurrentPositionInfo& info)
  390. {
  391. const AAX_ITransport& transport = *Transport();
  392. info.bpm = 0.0;
  393. check (transport.GetCurrentTempo (&info.bpm));
  394. info.timeSigNumerator = 4;
  395. info.timeSigDenominator = 4;
  396. transport.GetCurrentMeter (&info.timeSigNumerator, &info.timeSigDenominator);
  397. info.timeInSamples = 0;
  398. check (transport.GetCurrentNativeSampleLocation (&info.timeInSamples));
  399. info.timeInSeconds = info.timeInSamples / getSampleRate();
  400. int64_t ticks = 0;
  401. check (transport.GetCurrentTickPosition (&ticks));
  402. info.ppqPosition = ticks / 960000.0;
  403. info.isLooping = false;
  404. int64_t loopStartTick = 0, loopEndTick = 0;
  405. check (transport.GetCurrentLoopPosition (&info.isLooping, &loopStartTick, &loopEndTick));
  406. info.ppqLoopStart = loopStartTick / 960000.0;
  407. info.ppqLoopEnd = loopEndTick / 960000.0;
  408. // No way to get these: (?)
  409. info.isPlaying = false;
  410. info.isRecording = false;
  411. info.ppqPositionOfLastBarStart = 0;
  412. info.editOriginTime = 0;
  413. info.frameRate = AudioPlayHead::fpsUnknown;
  414. return true;
  415. }
  416. void audioProcessorParameterChanged (AudioProcessor* /*processor*/, int parameterIndex, float newValue)
  417. {
  418. SetParameterNormalizedValue (IndexAsParamID (parameterIndex), (double) newValue);
  419. }
  420. void audioProcessorChanged (AudioProcessor* /*processor*/)
  421. {
  422. // TODO
  423. }
  424. void audioProcessorParameterChangeGestureBegin (AudioProcessor* /*processor*/, int parameterIndex)
  425. {
  426. TouchParameter (IndexAsParamID (parameterIndex));
  427. }
  428. void audioProcessorParameterChangeGestureEnd (AudioProcessor* /*processor*/, int parameterIndex)
  429. {
  430. ReleaseParameter (IndexAsParamID (parameterIndex));
  431. }
  432. void process (const float* const* inputs, float* const* outputs, const int bufferSize,
  433. const bool bypass, AAX_IMIDINode* midiNodeIn, AAX_IMIDINode* midiNodeOut)
  434. {
  435. const int numIns = pluginInstance->getNumInputChannels();
  436. const int numOuts = pluginInstance->getNumOutputChannels();
  437. if (numOuts >= numIns)
  438. {
  439. for (int i = 0; i < numIns; ++i)
  440. memcpy (outputs[i], inputs[i], bufferSize * sizeof (float));
  441. process (outputs, numOuts, bufferSize, bypass, midiNodeIn, midiNodeOut);
  442. }
  443. else
  444. {
  445. if (channelList.size() <= numIns)
  446. channelList.insertMultiple (-1, nullptr, 1 + numIns - channelList.size());
  447. float** channels = channelList.getRawDataPointer();
  448. for (int i = 0; i < numOuts; ++i)
  449. {
  450. memcpy (outputs[i], inputs[i], bufferSize * sizeof (float));
  451. channels[i] = outputs[i];
  452. }
  453. for (int i = numOuts; i < numIns; ++i)
  454. channels[i] = const_cast <float*> (inputs[i]);
  455. process (channels, numIns, bufferSize, bypass, midiNodeIn, midiNodeOut);
  456. }
  457. }
  458. private:
  459. struct IndexAsParamID
  460. {
  461. inline explicit IndexAsParamID (int i) noexcept : index (i) {}
  462. operator AAX_CParamID() noexcept
  463. {
  464. jassert (index >= 0);
  465. char* t = name + sizeof (name);
  466. *--t = 0;
  467. int v = index;
  468. do
  469. {
  470. *--t = (char) ('0' + (v % 10));
  471. v /= 10;
  472. } while (v > 0);
  473. return static_cast <AAX_CParamID> (t);
  474. }
  475. private:
  476. int index;
  477. char name[32];
  478. JUCE_DECLARE_NON_COPYABLE (IndexAsParamID)
  479. };
  480. void process (float* const* channels, const int numChans, const int bufferSize,
  481. const bool bypass, AAX_IMIDINode* midiNodeIn, AAX_IMIDINode* midiNodeOut)
  482. {
  483. AudioSampleBuffer buffer (channels, numChans, bufferSize);
  484. midiBuffer.clear();
  485. #if JucePlugin_WantsMidiInput
  486. {
  487. AAX_CMidiStream* const midiStream = midiNodeIn->GetNodeBuffer();
  488. const uint32_t numMidiEvents = midiStream->mBufferSize;
  489. for (uint32_t i = 0; i < numMidiEvents; ++i)
  490. {
  491. // (This 8-byte alignment is a workaround to a bug in the AAX SDK. Hopefully can be
  492. // removed in future when the packet structure size is fixed)
  493. const AAX_CMidiPacket& m = *addBytesToPointer (midiStream->mBuffer,
  494. i * ((sizeof (AAX_CMidiPacket) + 7) & ~7));
  495. jassert ((int) m.mTimestamp < bufferSize);
  496. midiBuffer.addEvent (m.mData, (int) m.mLength,
  497. jlimit (0, (int) bufferSize - 1, (int) m.mTimestamp));
  498. }
  499. }
  500. #endif
  501. {
  502. const ScopedLock sl (pluginInstance->getCallbackLock());
  503. if (bypass)
  504. pluginInstance->processBlockBypassed (buffer, midiBuffer);
  505. else
  506. pluginInstance->processBlock (buffer, midiBuffer);
  507. }
  508. #if JucePlugin_ProducesMidiOutput
  509. {
  510. const juce::uint8* midiEventData;
  511. int midiEventSize, midiEventPosition;
  512. MidiBuffer::Iterator i (midiBuffer);
  513. AAX_CMidiPacket packet;
  514. packet.mIsImmediate = false;
  515. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  516. {
  517. jassert (isPositiveAndBelow (midiEventPosition, bufferSize));
  518. if (midiEventSize <= 4)
  519. {
  520. packet.mTimestamp = (uint32_t) midiEventPosition;
  521. packet.mLength = (uint32_t) midiEventSize;
  522. memcpy (packet.mData, midiEventData, midiEventSize);
  523. check (midiNodeOut->PostMIDIPacket (&packet));
  524. }
  525. }
  526. }
  527. #endif
  528. }
  529. void addBypassParameter()
  530. {
  531. AAX_IParameter* masterBypass = new AAX_CParameter<bool> (cDefaultMasterBypassID,
  532. AAX_CString ("Master Bypass"),
  533. false,
  534. AAX_CBinaryTaperDelegate<bool>(),
  535. AAX_CBinaryDisplayDelegate<bool> ("bypass", "on"),
  536. true);
  537. masterBypass->SetNumberOfSteps (2);
  538. masterBypass->SetType (AAX_eParameterType_Discrete);
  539. mParameterManager.AddParameter (masterBypass);
  540. mPacketDispatcher.RegisterPacket (cDefaultMasterBypassID, JUCEAlgorithmIDs::bypass);
  541. }
  542. void addAudioProcessorParameters()
  543. {
  544. AudioProcessor& audioProcessor = getPluginInstance();
  545. const int numParameters = audioProcessor.getNumParameters();
  546. for (int parameterIndex = 0; parameterIndex < numParameters; ++parameterIndex)
  547. {
  548. if (audioProcessor.isParameterAutomatable (parameterIndex))
  549. {
  550. AAX_IParameter* parameter
  551. = new AAX_CParameter<float> (IndexAsParamID (parameterIndex),
  552. audioProcessor.getParameterName (parameterIndex).toUTF8().getAddress(),
  553. audioProcessor.getParameter (parameterIndex),
  554. AAX_CLinearTaperDelegate<float, 0>(),
  555. AAX_CNumberDisplayDelegate<float, 3>(),
  556. true);
  557. parameter->SetNumberOfSteps (0x7fffffff);
  558. parameter->SetType (AAX_eParameterType_Continuous);
  559. mParameterManager.AddParameter (parameter);
  560. }
  561. }
  562. }
  563. void preparePlugin()
  564. {
  565. AAX_EStemFormat inputStemFormat = AAX_eStemFormat_None;
  566. check (Controller()->GetInputStemFormat (&inputStemFormat));
  567. const int numberOfInputChannels = getNumChannelsForStemFormat (inputStemFormat);
  568. AAX_EStemFormat outputStemFormat = AAX_eStemFormat_None;
  569. check (Controller()->GetOutputStemFormat (&outputStemFormat));
  570. const int numberOfOutputChannels = getNumChannelsForStemFormat (outputStemFormat);
  571. AudioProcessor& audioProcessor = getPluginInstance();
  572. const AAX_CSampleRate sampleRate = getSampleRate();
  573. const int bufferSize = 0; // how to get this?
  574. audioProcessor.setPlayConfigDetails (numberOfInputChannels, numberOfOutputChannels, sampleRate, bufferSize);
  575. audioProcessor.prepareToPlay (sampleRate, bufferSize);
  576. check (Controller()->SetSignalLatency (audioProcessor.getLatencySamples()));
  577. }
  578. AAX_CSampleRate getSampleRate() const
  579. {
  580. AAX_CSampleRate sampleRate;
  581. check (Controller()->GetSampleRate (&sampleRate));
  582. return sampleRate;
  583. }
  584. JUCELibraryRefCount juceCount;
  585. ScopedPointer<AudioProcessor> pluginInstance;
  586. MidiBuffer midiBuffer;
  587. Array<float*> channelList;
  588. int32_t juceChunkIndex;
  589. // tempFilterData is initialized in GetChunkSize.
  590. // To avoid generating it again in GetChunk, we keep it as a member.
  591. mutable juce::MemoryBlock tempFilterData;
  592. JUCE_DECLARE_NON_COPYABLE (JuceAAX_Processor)
  593. };
  594. //==============================================================================
  595. static void AAX_CALLBACK algorithmProcessCallback (JUCEAlgorithmContext* const instancesBegin[],
  596. const void* const instancesEnd)
  597. {
  598. for (JUCEAlgorithmContext* const* iter = instancesBegin; iter < instancesEnd; ++iter)
  599. {
  600. const JUCEAlgorithmContext& i = **iter;
  601. i.pluginInstance->parameters.process (i.inputChannels, i.outputChannels,
  602. *(i.bufferSize), *(i.bypass) != 0,
  603. getMidiNodeIn(i), getMidiNodeOut(i));
  604. }
  605. }
  606. //==============================================================================
  607. static void createDescriptor (AAX_IComponentDescriptor& desc, int channelConfigIndex,
  608. int numInputs, int numOutputs)
  609. {
  610. check (desc.AddAudioIn (JUCEAlgorithmIDs::inputChannels));
  611. check (desc.AddAudioOut (JUCEAlgorithmIDs::outputChannels));
  612. check (desc.AddAudioBufferLength (JUCEAlgorithmIDs::bufferSize));
  613. check (desc.AddDataInPort (JUCEAlgorithmIDs::bypass, sizeof (int32_t)));
  614. #if JucePlugin_WantsMidiInput
  615. check (desc.AddMIDINode (JUCEAlgorithmIDs::midiNodeIn, AAX_eMIDINodeType_LocalInput,
  616. JucePlugin_Name, 0xffff));
  617. #endif
  618. #if JucePlugin_ProducesMidiOutput
  619. check (desc.AddMIDINode (JUCEAlgorithmIDs::midiNodeOut, AAX_eMIDINodeType_LocalOutput,
  620. JucePlugin_Name " Out", 0xffff));
  621. #endif
  622. check (desc.AddPrivateData (JUCEAlgorithmIDs::pluginInstance, sizeof (PluginInstanceInfo)));
  623. // Create a property map
  624. AAX_IPropertyMap* const properties = desc.NewPropertyMap();
  625. jassert (properties != nullptr);
  626. properties->AddProperty (AAX_eProperty_ManufacturerID, JucePlugin_AAXManufacturerCode);
  627. properties->AddProperty (AAX_eProperty_ProductID, JucePlugin_AAXProductId);
  628. #if JucePlugin_AAXDisableBypass
  629. properties->AddProperty (AAX_eProperty_CanBypass, false);
  630. #else
  631. properties->AddProperty (AAX_eProperty_CanBypass, true);
  632. #endif
  633. properties->AddProperty (AAX_eProperty_InputStemFormat, getFormatForChans (numInputs));
  634. properties->AddProperty (AAX_eProperty_OutputStemFormat, getFormatForChans (numOutputs));
  635. // This value needs to match the RTAS wrapper's Type ID, so that
  636. // the host knows that the RTAS/AAX plugins are equivalent.
  637. properties->AddProperty (AAX_eProperty_PlugInID_Native, 'jcaa' + channelConfigIndex);
  638. check (desc.AddProcessProc_Native (algorithmProcessCallback, properties));
  639. }
  640. static void getPlugInDescription (AAX_IEffectDescriptor& descriptor)
  641. {
  642. descriptor.AddName (JucePlugin_Desc);
  643. descriptor.AddName (JucePlugin_Name);
  644. descriptor.AddCategory (JucePlugin_AAXCategory);
  645. check (descriptor.AddProcPtr ((void*) JuceAAX_GUI::Create, kAAX_ProcPtrID_Create_EffectGUI));
  646. check (descriptor.AddProcPtr ((void*) JuceAAX_Processor::Create, kAAX_ProcPtrID_Create_EffectParameters));
  647. const short channelConfigs[][2] = { JucePlugin_PreferredChannelConfigurations };
  648. const int numConfigs = numElementsInArray (channelConfigs);
  649. // You need to actually add some configurations to the JucePlugin_PreferredChannelConfigurations
  650. // value in your JucePluginCharacteristics.h file..
  651. jassert (numConfigs > 0);
  652. for (int i = 0; i < numConfigs; ++i)
  653. {
  654. if (AAX_IComponentDescriptor* const desc = descriptor.NewComponentDescriptor())
  655. {
  656. createDescriptor (*desc, i,
  657. channelConfigs [i][0],
  658. channelConfigs [i][1]);
  659. check (descriptor.AddComponent (desc));
  660. }
  661. }
  662. }
  663. };
  664. //==============================================================================
  665. AAX_Result JUCE_CDECL GetEffectDescriptions (AAX_ICollection*);
  666. AAX_Result JUCE_CDECL GetEffectDescriptions (AAX_ICollection* collection)
  667. {
  668. AAXClasses::JUCELibraryRefCount libraryRefCount;
  669. if (AAX_IEffectDescriptor* const descriptor = collection->NewDescriptor())
  670. {
  671. AAXClasses::getPlugInDescription (*descriptor);
  672. collection->AddEffect (JUCE_STRINGIFY (JucePlugin_AAXIdentifier), descriptor);
  673. collection->SetManufacturerName (JucePlugin_Manufacturer);
  674. collection->AddPackageName (JucePlugin_Desc);
  675. collection->AddPackageName (JucePlugin_Name);
  676. collection->SetPackageVersion (JucePlugin_VersionCode);
  677. return AAX_SUCCESS;
  678. }
  679. return AAX_ERROR_NULL_OBJECT;
  680. }
  681. #endif