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.

1003 lines
32KB

  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. #ifdef _MSC_VER
  24. // (this is a workaround for a build problem in VC9)
  25. #define _DO_NOT_DECLARE_INTERLOCKED_INTRINSICS_IN_MEMORY
  26. #include <intrin.h>
  27. #endif
  28. #include "juce_RTAS_DigiCode_Header.h"
  29. #if JucePlugin_Build_RTAS
  30. #ifdef _MSC_VER
  31. #include "Mac2Win.H"
  32. #endif
  33. /* Note about include paths
  34. ------------------------
  35. To be able to include all the Digidesign headers correctly, you'll need to add this
  36. lot to your include path:
  37. c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\EffectClasses
  38. c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\ProcessClasses
  39. c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\ProcessClasses\Interfaces
  40. c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\Utilities
  41. c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\RTASP_Adapt
  42. c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\CoreClasses
  43. c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\Controls
  44. c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\Meters
  45. c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\ViewClasses
  46. c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\DSPClasses
  47. c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\PluginLibrary\Interfaces
  48. c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\common
  49. c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\common\Platform
  50. c:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugins\SignalProcessing\Public
  51. C:\yourdirectory\PT_80_SDK\AlturaPorts\TDMPlugIns\DSPManager\Interfaces
  52. c:\yourdirectory\PT_80_SDK\AlturaPorts\SADriver\Interfaces
  53. c:\yourdirectory\PT_80_SDK\AlturaPorts\DigiPublic\Interfaces
  54. c:\yourdirectory\PT_80_SDK\AlturaPorts\Fic\Interfaces\DAEClient
  55. c:\yourdirectory\PT_80_SDK\AlturaPorts\NewFileLibs\Cmn
  56. c:\yourdirectory\PT_80_SDK\AlturaPorts\NewFileLibs\DOA
  57. c:\yourdirectory\PT_80_SDK\AlturaPorts\AlturaSource\PPC_H
  58. c:\yourdirectory\PT_80_SDK\AlturaPorts\AlturaSource\AppSupport
  59. c:\yourdirectory\PT_80_SDK\AvidCode\AVX2sdk\AVX\avx2\avx2sdk\inc
  60. C:\yourdirectory\PT_80_SDK\xplat\AVX\avx2\avx2sdk\inc
  61. NB. If you hit a huge pile of bugs around here, make sure that you've not got the
  62. Apple QuickTime headers before the PT headers in your path, because there are
  63. some filename clashes between them.
  64. */
  65. #include "CEffectGroupMIDI.h"
  66. #include "CEffectProcessMIDI.h"
  67. #include "CEffectProcessRTAS.h"
  68. #include "CCustomView.h"
  69. #include "CEffectTypeRTAS.h"
  70. #include "CPluginControl.h"
  71. #include "CPluginControl_OnOff.h"
  72. #include "FicProcessTokens.h"
  73. //==============================================================================
  74. #ifdef _MSC_VER
  75. #pragma pack (push, 8)
  76. #endif
  77. #include "../juce_PluginHeaders.h"
  78. #ifdef _MSC_VER
  79. #pragma pack (pop)
  80. #if JUCE_DEBUG
  81. #define PT_LIB_PATH JucePlugin_WinBag_path "\\Debug\\lib\\"
  82. #else
  83. #define PT_LIB_PATH JucePlugin_WinBag_path "\\Release\\lib\\"
  84. #endif
  85. #pragma comment(lib, PT_LIB_PATH "DAE.lib")
  86. #pragma comment(lib, PT_LIB_PATH "DigiExt.lib")
  87. #pragma comment(lib, PT_LIB_PATH "DSI.lib")
  88. #pragma comment(lib, PT_LIB_PATH "PluginLib.lib")
  89. #endif
  90. #undef Component
  91. #undef MemoryBlock
  92. //==============================================================================
  93. #if JUCE_WIN32
  94. extern void JUCE_CALLTYPE attachSubWindow (void* hostWindow, int& titleW, int& titleH, JUCE_NAMESPACE::Component* comp);
  95. extern void JUCE_CALLTYPE resizeHostWindow (void* hostWindow, int& titleW, int& titleH, JUCE_NAMESPACE::Component* comp);
  96. #if ! JucePlugin_EditorRequiresKeyboardFocus
  97. extern void JUCE_CALLTYPE passFocusToHostWindow (void* hostWindow);
  98. #endif
  99. #else
  100. extern void* attachSubWindow (void* hostWindowRef, JUCE_NAMESPACE::Component* comp);
  101. extern void removeSubWindow (void* nsWindow, JUCE_NAMESPACE::Component* comp);
  102. #endif
  103. const int midiBufferSize = 1024;
  104. const OSType juceChunkType = 'juce';
  105. static const int bypassControlIndex = 1;
  106. //==============================================================================
  107. /** Somewhere in the codebase of your plugin, you need to implement this function
  108. and make it return a new instance of the filter subclass that you're building.
  109. */
  110. extern AudioProcessor* JUCE_CALLTYPE createPluginFilter();
  111. //==============================================================================
  112. static float longToFloat (const long n) throw()
  113. {
  114. return (float) ((((double) n) + (double) 0x80000000) / (double) 0xffffffff);
  115. }
  116. static long floatToLong (const float n) throw()
  117. {
  118. return roundDoubleToInt (jlimit (-(double) 0x80000000,
  119. (double) 0x7fffffff,
  120. n * (double) 0xffffffff - (double) 0x80000000));
  121. }
  122. static int numInstances = 0;
  123. //==============================================================================
  124. class JucePlugInProcess : public CEffectProcessMIDI,
  125. public CEffectProcessRTAS,
  126. public AudioProcessorListener,
  127. public AudioPlayHead,
  128. public AsyncUpdater
  129. {
  130. public:
  131. //==============================================================================
  132. JucePlugInProcess()
  133. : midiBufferNode (0),
  134. midiTransport (0),
  135. channels (0),
  136. prepared (false),
  137. sampleRate (44100.0)
  138. {
  139. juceFilter = createPluginFilter();
  140. jassert (juceFilter != 0);
  141. AddChunk (juceChunkType, "Juce Audio Plugin Data");
  142. ++numInstances;
  143. }
  144. ~JucePlugInProcess()
  145. {
  146. if (mLoggedIn)
  147. MIDILogOut();
  148. deleteAndZero (midiBufferNode);
  149. deleteAndZero (midiTransport);
  150. if (prepared)
  151. juceFilter->releaseResources();
  152. delete juceFilter;
  153. juce_free (channels);
  154. if (--numInstances == 0)
  155. shutdownJuce_GUI();
  156. }
  157. //==============================================================================
  158. class JuceCustomUIView : public CCustomView,
  159. public Timer
  160. {
  161. public:
  162. //==============================================================================
  163. JuceCustomUIView (AudioProcessor* const filter_,
  164. JucePlugInProcess* const process_)
  165. : filter (filter_),
  166. process (process_),
  167. wrapper (0),
  168. editorComp (0)
  169. {
  170. // setting the size in here crashes PT for some reason, so keep it simple..
  171. }
  172. ~JuceCustomUIView()
  173. {
  174. deleteEditorComp();
  175. }
  176. //==============================================================================
  177. void updateSize()
  178. {
  179. if (editorComp == 0)
  180. {
  181. editorComp = filter->createEditorIfNeeded();
  182. jassert (editorComp != 0);
  183. }
  184. Rect oldRect;
  185. GetRect (&oldRect);
  186. Rect r;
  187. r.left = 0;
  188. r.top = 0;
  189. r.right = editorComp->getWidth();
  190. r.bottom = editorComp->getHeight();
  191. SetRect (&r);
  192. if ((oldRect.right != r.right) || (oldRect.bottom != r.bottom))
  193. startTimer (50);
  194. }
  195. void timerCallback()
  196. {
  197. if (! JUCE_NAMESPACE::Component::isMouseButtonDownAnywhere())
  198. {
  199. stopTimer();
  200. // Send a token to the host to tell it about the resize
  201. SSetProcessWindowResizeToken token (process->fRootNameId, process->fRootNameId);
  202. FicSDSDispatchToken (&token);
  203. }
  204. }
  205. void attachToWindow (GrafPtr port)
  206. {
  207. if (port != 0)
  208. {
  209. updateSize();
  210. #if JUCE_WIN32
  211. void* const hostWindow = (void*) ASI_GethWnd ((WindowPtr) port);
  212. #else
  213. void* const hostWindow = (void*) GetWindowFromPort (port);
  214. #endif
  215. deleteAndZero (wrapper);
  216. wrapper = new EditorCompWrapper (hostWindow, editorComp, this);
  217. }
  218. else
  219. {
  220. deleteEditorComp();
  221. }
  222. }
  223. void DrawContents (Rect*)
  224. {
  225. #if JUCE_WIN32
  226. if (wrapper != 0)
  227. {
  228. ComponentPeer* const peer = wrapper->getPeer();
  229. if (peer != 0)
  230. {
  231. // (seems to be required in PT6.4, but not in 7.x)
  232. peer->repaint (0, 0, wrapper->getWidth(), wrapper->getHeight());
  233. }
  234. }
  235. #endif
  236. }
  237. void DrawBackground (Rect*) {}
  238. //==============================================================================
  239. private:
  240. AudioProcessor* const filter;
  241. JucePlugInProcess* const process;
  242. JUCE_NAMESPACE::Component* wrapper;
  243. AudioProcessorEditor* editorComp;
  244. void deleteEditorComp()
  245. {
  246. if (editorComp != 0 || wrapper != 0)
  247. {
  248. #if JUCE_MAC
  249. const ScopedAutoReleasePool pool;
  250. #endif
  251. PopupMenu::dismissAllActiveMenus();
  252. JUCE_NAMESPACE::Component* const modalComponent = JUCE_NAMESPACE::Component::getCurrentlyModalComponent();
  253. if (modalComponent != 0)
  254. modalComponent->exitModalState (0);
  255. filter->editorBeingDeleted (editorComp);
  256. deleteAndZero (editorComp);
  257. deleteAndZero (wrapper);
  258. }
  259. }
  260. //==============================================================================
  261. // A component to hold the AudioProcessorEditor, and cope with some housekeeping
  262. // chores when it changes or repaints.
  263. class EditorCompWrapper : public JUCE_NAMESPACE::Component
  264. #if ! JUCE_MAC
  265. , public FocusChangeListener
  266. #endif
  267. {
  268. public:
  269. EditorCompWrapper (void* const hostWindow_,
  270. Component* const editorComp,
  271. JuceCustomUIView* const owner_)
  272. : hostWindow (hostWindow_),
  273. owner (owner_),
  274. titleW (0),
  275. titleH (0)
  276. {
  277. #if JucePlugin_EditorRequiresKeyboardFocus
  278. setWantsKeyboardFocus (true);
  279. #else
  280. setComponentProperty ("juce_disallowFocus", true);
  281. setWantsKeyboardFocus (false);
  282. #endif
  283. setOpaque (true);
  284. setBroughtToFrontOnMouseClick (true);
  285. setBounds (editorComp->getBounds());
  286. editorComp->setTopLeftPosition (0, 0);
  287. addAndMakeVisible (editorComp);
  288. #if JUCE_WIN32
  289. attachSubWindow (hostWindow, titleW, titleH, this);
  290. #else
  291. nsWindow = attachSubWindow (hostWindow, this);
  292. #endif
  293. setVisible (true);
  294. #if JUCE_WIN32 && ! JucePlugin_EditorRequiresKeyboardFocus
  295. Desktop::getInstance().addFocusChangeListener (this);
  296. #endif
  297. }
  298. ~EditorCompWrapper()
  299. {
  300. #if JUCE_WIN32 && ! JucePlugin_EditorRequiresKeyboardFocus
  301. Desktop::getInstance().removeFocusChangeListener (this);
  302. #endif
  303. #if JUCE_MAC
  304. removeSubWindow (nsWindow, this);
  305. #endif
  306. }
  307. void paint (Graphics&)
  308. {
  309. }
  310. void resized()
  311. {
  312. JUCE_NAMESPACE::Component* const c = getChildComponent (0);
  313. if (c != 0)
  314. c->setBounds (0, 0, getWidth(), getHeight());
  315. repaint();
  316. }
  317. #if JUCE_WIN32
  318. void globalFocusChanged (JUCE_NAMESPACE::Component*)
  319. {
  320. #if ! JucePlugin_EditorRequiresKeyboardFocus
  321. if (hasKeyboardFocus (true))
  322. passFocusToHostWindow (hostWindow);
  323. #endif
  324. }
  325. #endif
  326. void childBoundsChanged (JUCE_NAMESPACE::Component* child)
  327. {
  328. setSize (child->getWidth(), child->getHeight());
  329. child->setTopLeftPosition (0, 0);
  330. #if JUCE_WIN32
  331. resizeHostWindow (hostWindow, titleW, titleH, this);
  332. #endif
  333. owner->updateSize();
  334. }
  335. void userTriedToCloseWindow()
  336. {
  337. }
  338. //==============================================================================
  339. juce_UseDebuggingNewOperator
  340. private:
  341. void* const hostWindow;
  342. void* nsWindow;
  343. JuceCustomUIView* const owner;
  344. int titleW, titleH;
  345. };
  346. };
  347. JuceCustomUIView* getView() const
  348. {
  349. return dynamic_cast <JuceCustomUIView*> (fOurPlugInView);
  350. }
  351. void GetViewRect (Rect* size)
  352. {
  353. if (getView() != 0)
  354. getView()->updateSize();
  355. CEffectProcessRTAS::GetViewRect (size);
  356. }
  357. CPlugInView* CreateCPlugInView()
  358. {
  359. return new JuceCustomUIView (juceFilter, this);
  360. }
  361. void SetViewPort (GrafPtr port)
  362. {
  363. CEffectProcessRTAS::SetViewPort (port);
  364. if (getView() != 0)
  365. getView()->attachToWindow (port);
  366. }
  367. //==============================================================================
  368. protected:
  369. ComponentResult GetDelaySamplesLong (long* aNumSamples)
  370. {
  371. if (aNumSamples != 0)
  372. *aNumSamples = juceFilter != 0 ? juceFilter->getLatencySamples() : 0;
  373. return noErr;
  374. }
  375. //==============================================================================
  376. void EffectInit()
  377. {
  378. SFicPlugInStemFormats stems;
  379. GetProcessType()->GetStemFormats (&stems);
  380. juceFilter->setPlayConfigDetails (fNumInputs, fNumOutputs,
  381. juceFilter->getSampleRate(), juceFilter->getBlockSize());
  382. AddControl (new CPluginControl_OnOff ('bypa', "Master Bypass\nMastrByp\nMByp\nByp", false, true));
  383. DefineMasterBypassControlIndex (bypassControlIndex);
  384. for (int i = 0; i < juceFilter->getNumParameters(); ++i)
  385. AddControl (new JucePluginControl (juceFilter, i));
  386. // we need to do this midi log-in to get timecode, regardless of whether
  387. // the plugin actually uses midi...
  388. if (MIDILogIn() == noErr)
  389. {
  390. #if JucePlugin_WantsMidiInput
  391. CEffectType* const type = dynamic_cast <CEffectType*> (this->GetProcessType());
  392. if (type != 0)
  393. {
  394. char nodeName [64];
  395. type->GetProcessTypeName (63, nodeName);
  396. p2cstrcpy (nodeName, reinterpret_cast <unsigned char*> (nodeName));
  397. midiBufferNode = new CEffectMIDIOtherBufferedNode (&mMIDIWorld,
  398. 8192,
  399. eLocalNode,
  400. nodeName,
  401. midiBuffer);
  402. midiBufferNode->Initialize (1, true);
  403. }
  404. #endif
  405. }
  406. midiTransport = new CEffectMIDITransport (&mMIDIWorld);
  407. juceFilter->setPlayHead (this);
  408. juceFilter->addListener (this);
  409. }
  410. void handleAsyncUpdate()
  411. {
  412. if (! prepared)
  413. {
  414. sampleRate = gProcessGroup->GetSampleRate();
  415. jassert (sampleRate > 0);
  416. juce_free (channels);
  417. channels = (float**) juce_calloc (sizeof (float*) * jmax (juceFilter->getNumInputChannels(),
  418. juceFilter->getNumOutputChannels()));
  419. juceFilter->setPlayConfigDetails (fNumInputs, fNumOutputs,
  420. sampleRate, mRTGlobals->mHWBufferSizeInSamples);
  421. juceFilter->prepareToPlay (sampleRate,
  422. mRTGlobals->mHWBufferSizeInSamples);
  423. prepared = true;
  424. }
  425. }
  426. void RenderAudio (float** inputs, float** outputs, long numSamples)
  427. {
  428. if (! prepared)
  429. {
  430. triggerAsyncUpdate();
  431. bypassBuffers (inputs, outputs, numSamples);
  432. return;
  433. }
  434. if (mBypassed)
  435. {
  436. bypassBuffers (inputs, outputs, numSamples);
  437. return;
  438. }
  439. #if JucePlugin_WantsMidiInput
  440. midiEvents.clear();
  441. const Cmn_UInt32 bufferSize = mRTGlobals->mHWBufferSizeInSamples;
  442. if (midiBufferNode->GetAdvanceScheduleTime() != bufferSize)
  443. midiBufferNode->SetAdvanceScheduleTime (bufferSize);
  444. if (midiBufferNode->FillMIDIBuffer (mRTGlobals->mRunningTime, numSamples) == noErr)
  445. {
  446. jassert (midiBufferNode->GetBufferPtr() != 0);
  447. const int numMidiEvents = midiBufferNode->GetBufferSize();
  448. for (int i = 0; i < numMidiEvents; ++i)
  449. {
  450. const DirectMidiPacket& m = midiBuffer[i];
  451. jassert ((int) m.mTimestamp < numSamples);
  452. midiEvents.addEvent (m.mData, m.mLength,
  453. jlimit (0, (int) numSamples - 1, (int) m.mTimestamp));
  454. }
  455. }
  456. #endif
  457. #if defined (JUCE_DEBUG) || JUCE_LOG_ASSERTIONS
  458. const int numMidiEventsComingIn = midiEvents.getNumEvents();
  459. (void) numMidiEventsComingIn;
  460. #endif
  461. {
  462. const ScopedLock sl (juceFilter->getCallbackLock());
  463. const int numIn = juceFilter->getNumInputChannels();
  464. const int numOut = juceFilter->getNumOutputChannels();
  465. const int totalChans = jmax (numIn, numOut);
  466. if (juceFilter->isSuspended())
  467. {
  468. for (int i = 0; i < numOut; ++i)
  469. zeromem (outputs [i], sizeof (float) * numSamples);
  470. }
  471. else
  472. {
  473. {
  474. int i;
  475. for (i = 0; i < numOut; ++i)
  476. {
  477. channels[i] = outputs [i];
  478. if (i < numIn && inputs != outputs)
  479. memcpy (outputs [i], inputs[i], sizeof (float) * numSamples);
  480. }
  481. for (; i < numIn; ++i)
  482. channels [i] = inputs [i];
  483. }
  484. AudioSampleBuffer chans (channels, totalChans, numSamples);
  485. juceFilter->processBlock (chans, midiEvents);
  486. }
  487. }
  488. if (! midiEvents.isEmpty())
  489. {
  490. #if JucePlugin_ProducesMidiOutput
  491. const juce::uint8* midiEventData;
  492. int midiEventSize, midiEventPosition;
  493. MidiBuffer::Iterator i (midiEvents);
  494. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  495. {
  496. // jassert (midiEventPosition >= 0 && midiEventPosition < (int) numSamples);
  497. //xxx
  498. }
  499. #else
  500. // if your plugin creates midi messages, you'll need to set
  501. // the JucePlugin_ProducesMidiOutput macro to 1 in your
  502. // JucePluginCharacteristics.h file
  503. jassert (midiEvents.getNumEvents() <= numMidiEventsComingIn);
  504. #endif
  505. midiEvents.clear();
  506. }
  507. }
  508. //==============================================================================
  509. ComponentResult GetChunkSize (OSType chunkID, long* size)
  510. {
  511. if (chunkID == juceChunkType)
  512. {
  513. tempFilterData.setSize (0);
  514. juceFilter->getStateInformation (tempFilterData);
  515. *size = sizeof (SFicPlugInChunkHeader) + tempFilterData.getSize();
  516. return noErr;
  517. }
  518. return CEffectProcessMIDI::GetChunkSize (chunkID, size);
  519. }
  520. ComponentResult GetChunk (OSType chunkID, SFicPlugInChunk* chunk)
  521. {
  522. if (chunkID == juceChunkType)
  523. {
  524. if (tempFilterData.getSize() == 0)
  525. juceFilter->getStateInformation (tempFilterData);
  526. chunk->fSize = sizeof (SFicPlugInChunkHeader) + tempFilterData.getSize();
  527. tempFilterData.copyTo ((void*) chunk->fData, 0, tempFilterData.getSize());
  528. tempFilterData.setSize (0);
  529. return noErr;
  530. }
  531. return CEffectProcessMIDI::GetChunk (chunkID, chunk);
  532. }
  533. ComponentResult SetChunk (OSType chunkID, SFicPlugInChunk* chunk)
  534. {
  535. if (chunkID == juceChunkType)
  536. {
  537. tempFilterData.setSize (0);
  538. if (chunk->fSize - sizeof (SFicPlugInChunkHeader) > 0)
  539. {
  540. juceFilter->setStateInformation ((void*) chunk->fData,
  541. chunk->fSize - sizeof (SFicPlugInChunkHeader));
  542. }
  543. return noErr;
  544. }
  545. return CEffectProcessMIDI::SetChunk (chunkID, chunk);
  546. }
  547. //==============================================================================
  548. ComponentResult UpdateControlValue (long controlIndex, long value)
  549. {
  550. if (controlIndex != bypassControlIndex)
  551. juceFilter->setParameter (controlIndex - 2, longToFloat (value));
  552. else
  553. mBypassed = (value > 0);
  554. return CProcess::UpdateControlValue (controlIndex, value);
  555. }
  556. //==============================================================================
  557. bool getCurrentPosition (AudioPlayHead::CurrentPositionInfo& info)
  558. {
  559. // this method can only be called while the plugin is running
  560. jassert (prepared);
  561. Cmn_Float64 bpm = 120.0;
  562. Cmn_Int32 num = 4, denom = 4;
  563. Cmn_Int64 ticks = 0;
  564. Cmn_Bool isPlaying = false;
  565. if (midiTransport != 0)
  566. {
  567. midiTransport->GetCurrentTempo (&bpm);
  568. midiTransport->IsTransportPlaying (&isPlaying);
  569. midiTransport->GetCurrentMeter (&num, &denom);
  570. midiTransport->GetCurrentTickPosition (&ticks);
  571. }
  572. info.bpm = bpm;
  573. info.timeSigNumerator = num;
  574. info.timeSigDenominator = denom;
  575. info.isPlaying = isPlaying;
  576. info.isRecording = false;
  577. info.ppqPosition = ticks / 960000.0;
  578. info.ppqPositionOfLastBarStart = 0; //xxx no idea how to get this correctly..
  579. // xxx incorrect if there are tempo changes, but there's no
  580. // other way of getting this info..
  581. info.timeInSeconds = ticks * (60.0 / 960000.0) / bpm;
  582. double framesPerSec = 24.0;
  583. switch (fTimeCodeInfo.mFrameRate)
  584. {
  585. case ficFrameRate_24Frame:
  586. info.frameRate = AudioPlayHead::fps24;
  587. break;
  588. case ficFrameRate_25Frame:
  589. info.frameRate = AudioPlayHead::fps25;
  590. framesPerSec = 25.0;
  591. break;
  592. case ficFrameRate_2997NonDrop:
  593. info.frameRate = AudioPlayHead::fps2997;
  594. framesPerSec = 29.97002997;
  595. break;
  596. case ficFrameRate_2997DropFrame:
  597. info.frameRate = AudioPlayHead::fps2997drop;
  598. framesPerSec = 29.97002997;
  599. break;
  600. case ficFrameRate_30NonDrop:
  601. info.frameRate = AudioPlayHead::fps30;
  602. framesPerSec = 30.0;
  603. break;
  604. case ficFrameRate_30DropFrame:
  605. info.frameRate = AudioPlayHead::fps30drop;
  606. framesPerSec = 30.0;
  607. break;
  608. case ficFrameRate_23976:
  609. // xxx not strictly true..
  610. info.frameRate = AudioPlayHead::fps24;
  611. framesPerSec = 23.976;
  612. break;
  613. default:
  614. info.frameRate = AudioPlayHead::fpsUnknown;
  615. break;
  616. }
  617. info.editOriginTime = fTimeCodeInfo.mFrameOffset / framesPerSec;
  618. return true;
  619. }
  620. void audioProcessorParameterChanged (AudioProcessor*, int index, float newValue)
  621. {
  622. SetControlValue (index + 2, floatToLong (newValue));
  623. }
  624. void audioProcessorParameterChangeGestureBegin (AudioProcessor*, int index)
  625. {
  626. TouchControl (index + 2);
  627. }
  628. void audioProcessorParameterChangeGestureEnd (AudioProcessor*, int index)
  629. {
  630. ReleaseControl (index + 2);
  631. }
  632. void audioProcessorChanged (AudioProcessor*)
  633. {
  634. // xxx is there an RTAS equivalent?
  635. }
  636. //==============================================================================
  637. private:
  638. AudioProcessor* juceFilter;
  639. MidiBuffer midiEvents;
  640. CEffectMIDIOtherBufferedNode* midiBufferNode;
  641. CEffectMIDITransport* midiTransport;
  642. DirectMidiPacket midiBuffer [midiBufferSize];
  643. JUCE_NAMESPACE::MemoryBlock tempFilterData;
  644. float** channels;
  645. bool prepared;
  646. double sampleRate;
  647. void bypassBuffers (float** const inputs, float** const outputs, const long numSamples) const
  648. {
  649. for (int i = fNumOutputs; --i >= 0;)
  650. {
  651. if (i < fNumInputs)
  652. memcpy (outputs[i], inputs[i], numSamples * sizeof (float));
  653. else
  654. zeromem (outputs[i], numSamples * sizeof (float));
  655. }
  656. }
  657. //==============================================================================
  658. class JucePluginControl : public CPluginControl
  659. {
  660. public:
  661. //==============================================================================
  662. JucePluginControl (AudioProcessor* const juceFilter_, const int index_)
  663. : juceFilter (juceFilter_),
  664. index (index_)
  665. {
  666. }
  667. ~JucePluginControl()
  668. {
  669. }
  670. //==============================================================================
  671. OSType GetID() const { return index + 1; }
  672. long GetDefaultValue() const { return floatToLong (0); }
  673. void SetDefaultValue (long) {}
  674. long GetNumSteps() const { return 0xffffffff; }
  675. long ConvertStringToValue (const char* valueString) const
  676. {
  677. return floatToLong (String (valueString).getFloatValue());
  678. }
  679. Cmn_Bool IsKeyValid (long key) const { return true; }
  680. void GetNameOfLength (char* name, int maxLength, OSType inControllerType) const
  681. {
  682. juceFilter->getParameterName (index).copyToBuffer (name, maxLength);
  683. }
  684. long GetPriority() const { return kFicCooperativeTaskPriority; }
  685. long GetOrientation() const
  686. {
  687. return kDAE_LeftMinRightMax | kDAE_BottomMinTopMax
  688. | kDAE_RotarySingleDotMode | kDAE_RotaryLeftMinRightMax;
  689. }
  690. long GetControlType() const { return kDAE_ContinuousValues; }
  691. void GetValueString (char* valueString, int maxLength, long value) const
  692. {
  693. juceFilter->getParameterText (index).copyToBuffer (valueString, maxLength);
  694. }
  695. Cmn_Bool IsAutomatable() const
  696. {
  697. return juceFilter->isParameterAutomatable (index);
  698. }
  699. private:
  700. //==============================================================================
  701. AudioProcessor* const juceFilter;
  702. const int index;
  703. JucePluginControl (const JucePluginControl&);
  704. const JucePluginControl& operator= (const JucePluginControl&);
  705. };
  706. };
  707. //==============================================================================
  708. class JucePlugInGroup : public CEffectGroupMIDI
  709. {
  710. public:
  711. //==============================================================================
  712. JucePlugInGroup()
  713. {
  714. DefineManufacturerNamesAndID (JucePlugin_Manufacturer, JucePlugin_RTASManufacturerCode);
  715. DefinePlugInNamesAndVersion (createRTASName(), JucePlugin_VersionCode);
  716. #ifndef JUCE_DEBUG
  717. AddGestalt (pluginGestalt_IsCacheable);
  718. #endif
  719. }
  720. ~JucePlugInGroup()
  721. {
  722. shutdownJuce_GUI();
  723. shutdownJuce_NonGUI();
  724. }
  725. //==============================================================================
  726. void CreateEffectTypes()
  727. {
  728. const short channelConfigs[][2] = { JucePlugin_PreferredChannelConfigurations };
  729. const int numConfigs = numElementsInArray (channelConfigs);
  730. // You need to actually add some configurations to the JucePlugin_PreferredChannelConfigurations
  731. // value in your JucePluginCharacteristics.h file..
  732. jassert (numConfigs > 0);
  733. for (int i = 0; i < numConfigs; ++i)
  734. {
  735. CEffectType* const type
  736. = new CEffectTypeRTAS ('jcaa' + i,
  737. JucePlugin_RTASProductId,
  738. JucePlugin_RTASCategory);
  739. type->DefineTypeNames (createRTASName());
  740. type->DefineSampleRateSupport (eSupports48kAnd96kAnd192k);
  741. type->DefineStemFormats (getFormatForChans (channelConfigs [i][0] != 0 ? channelConfigs [i][0] : channelConfigs [i][1]),
  742. getFormatForChans (channelConfigs [i][1] != 0 ? channelConfigs [i][1] : channelConfigs [i][0]));
  743. type->AddGestalt (pluginGestalt_CanBypass);
  744. type->AddGestalt (pluginGestalt_SupportsVariableQuanta);
  745. type->AttachEffectProcessCreator (createNewProcess);
  746. AddEffectType (type);
  747. }
  748. }
  749. void Initialize()
  750. {
  751. CEffectGroupMIDI::Initialize();
  752. }
  753. //==============================================================================
  754. private:
  755. static CEffectProcess* createNewProcess()
  756. {
  757. // Juce setup
  758. #if JUCE_WIN32
  759. PlatformUtilities::setCurrentModuleInstanceHandle (gThisModule);
  760. #endif
  761. initialiseJuce_GUI();
  762. return new JucePlugInProcess();
  763. }
  764. static const String createRTASName()
  765. {
  766. return String (JucePlugin_Name) + T("\n")
  767. + String (JucePlugin_Name).substring (0, 4);
  768. }
  769. static EPlugIn_StemFormat getFormatForChans (const int numChans) throw()
  770. {
  771. switch (numChans)
  772. {
  773. case 0:
  774. return ePlugIn_StemFormat_Generic;
  775. case 1:
  776. return ePlugIn_StemFormat_Mono;
  777. case 2:
  778. return ePlugIn_StemFormat_Stereo;
  779. case 3:
  780. return ePlugIn_StemFormat_LCR;
  781. case 4:
  782. return ePlugIn_StemFormat_Quad;
  783. case 5:
  784. return ePlugIn_StemFormat_5dot0;
  785. case 6:
  786. return ePlugIn_StemFormat_5dot1;
  787. case 7:
  788. return ePlugIn_StemFormat_6dot1;
  789. case 8:
  790. return ePlugIn_StemFormat_7dot1;
  791. default:
  792. jassertfalse // hmm - not a valid number of chans for RTAS..
  793. break;
  794. }
  795. return ePlugIn_StemFormat_Generic;
  796. }
  797. };
  798. void initialiseMacRTAS();
  799. CProcessGroupInterface* CProcessGroup::CreateProcessGroup()
  800. {
  801. #if JUCE_MAC
  802. initialiseMacRTAS();
  803. #endif
  804. initialiseJuce_NonGUI();
  805. return new JucePlugInGroup();
  806. }
  807. #endif