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.

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