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.

1389 lines
45KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #include <JuceHeader.h>
  19. #include "GraphEditorPanel.h"
  20. #include "../Plugins/InternalPlugins.h"
  21. #include "MainHostWindow.h"
  22. //==============================================================================
  23. #if JUCE_IOS
  24. class AUScanner
  25. {
  26. public:
  27. AUScanner (KnownPluginList& list)
  28. : knownPluginList (list), pool (5)
  29. {
  30. knownPluginList.clearBlacklistedFiles();
  31. paths = formatToScan.getDefaultLocationsToSearch();
  32. startScan();
  33. }
  34. private:
  35. KnownPluginList& knownPluginList;
  36. AudioUnitPluginFormat formatToScan;
  37. std::unique_ptr<PluginDirectoryScanner> scanner;
  38. FileSearchPath paths;
  39. ThreadPool pool;
  40. void startScan()
  41. {
  42. auto deadMansPedalFile = getAppProperties().getUserSettings()
  43. ->getFile().getSiblingFile ("RecentlyCrashedPluginsList");
  44. scanner.reset (new PluginDirectoryScanner (knownPluginList, formatToScan, paths,
  45. true, deadMansPedalFile, true));
  46. for (int i = 5; --i >= 0;)
  47. pool.addJob (new ScanJob (*this), true);
  48. }
  49. bool doNextScan()
  50. {
  51. String pluginBeingScanned;
  52. if (scanner->scanNextFile (true, pluginBeingScanned))
  53. return true;
  54. return false;
  55. }
  56. struct ScanJob : public ThreadPoolJob
  57. {
  58. ScanJob (AUScanner& s) : ThreadPoolJob ("pluginscan"), scanner (s) {}
  59. JobStatus runJob()
  60. {
  61. while (scanner.doNextScan() && ! shouldExit())
  62. {}
  63. return jobHasFinished;
  64. }
  65. AUScanner& scanner;
  66. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ScanJob)
  67. };
  68. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AUScanner)
  69. };
  70. #endif
  71. //==============================================================================
  72. struct GraphEditorPanel::PinComponent : public Component,
  73. public SettableTooltipClient
  74. {
  75. PinComponent (GraphEditorPanel& p, AudioProcessorGraph::NodeAndChannel pinToUse, bool isIn)
  76. : panel (p), graph (p.graph), pin (pinToUse), isInput (isIn)
  77. {
  78. if (auto node = graph.graph.getNodeForId (pin.nodeID))
  79. {
  80. String tip;
  81. if (pin.isMIDI())
  82. {
  83. tip = isInput ? "MIDI Input"
  84. : "MIDI Output";
  85. }
  86. else
  87. {
  88. auto& processor = *node->getProcessor();
  89. auto channel = processor.getOffsetInBusBufferForAbsoluteChannelIndex (isInput, pin.channelIndex, busIdx);
  90. if (auto* bus = processor.getBus (isInput, busIdx))
  91. tip = bus->getName() + ": " + AudioChannelSet::getAbbreviatedChannelTypeName (bus->getCurrentLayout().getTypeOfChannel (channel));
  92. else
  93. tip = (isInput ? "Main Input: "
  94. : "Main Output: ") + String (pin.channelIndex + 1);
  95. }
  96. setTooltip (tip);
  97. }
  98. setSize (16, 16);
  99. }
  100. void paint (Graphics& g) override
  101. {
  102. auto w = (float) getWidth();
  103. auto h = (float) getHeight();
  104. Path p;
  105. p.addEllipse (w * 0.25f, h * 0.25f, w * 0.5f, h * 0.5f);
  106. p.addRectangle (w * 0.4f, isInput ? (0.5f * h) : 0.0f, w * 0.2f, h * 0.5f);
  107. auto colour = (pin.isMIDI() ? Colours::red : Colours::green);
  108. g.setColour (colour.withRotatedHue ((float) busIdx / 5.0f));
  109. g.fillPath (p);
  110. }
  111. void mouseDown (const MouseEvent& e) override
  112. {
  113. AudioProcessorGraph::NodeAndChannel dummy { {}, 0 };
  114. panel.beginConnectorDrag (isInput ? dummy : pin,
  115. isInput ? pin : dummy,
  116. e);
  117. }
  118. void mouseDrag (const MouseEvent& e) override
  119. {
  120. panel.dragConnector (e);
  121. }
  122. void mouseUp (const MouseEvent& e) override
  123. {
  124. panel.endDraggingConnector (e);
  125. }
  126. GraphEditorPanel& panel;
  127. PluginGraph& graph;
  128. AudioProcessorGraph::NodeAndChannel pin;
  129. const bool isInput;
  130. int busIdx = 0;
  131. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PinComponent)
  132. };
  133. //==============================================================================
  134. struct GraphEditorPanel::PluginComponent : public Component,
  135. public Timer,
  136. private AudioProcessorParameter::Listener,
  137. private AsyncUpdater
  138. {
  139. PluginComponent (GraphEditorPanel& p, AudioProcessorGraph::NodeID id) : panel (p), graph (p.graph), pluginID (id)
  140. {
  141. shadow.setShadowProperties (DropShadow (Colours::black.withAlpha (0.5f), 3, { 0, 1 }));
  142. setComponentEffect (&shadow);
  143. if (auto f = graph.graph.getNodeForId (pluginID))
  144. {
  145. if (auto* processor = f->getProcessor())
  146. {
  147. if (auto* bypassParam = processor->getBypassParameter())
  148. bypassParam->addListener (this);
  149. }
  150. }
  151. setSize (150, 60);
  152. }
  153. PluginComponent (const PluginComponent&) = delete;
  154. PluginComponent& operator= (const PluginComponent&) = delete;
  155. ~PluginComponent() override
  156. {
  157. if (auto f = graph.graph.getNodeForId (pluginID))
  158. {
  159. if (auto* processor = f->getProcessor())
  160. {
  161. if (auto* bypassParam = processor->getBypassParameter())
  162. bypassParam->removeListener (this);
  163. }
  164. }
  165. }
  166. void mouseDown (const MouseEvent& e) override
  167. {
  168. originalPos = localPointToGlobal (Point<int>());
  169. toFront (true);
  170. if (isOnTouchDevice())
  171. {
  172. startTimer (750);
  173. }
  174. else
  175. {
  176. if (e.mods.isPopupMenu())
  177. showPopupMenu();
  178. }
  179. }
  180. void mouseDrag (const MouseEvent& e) override
  181. {
  182. if (isOnTouchDevice() && e.getDistanceFromDragStart() > 5)
  183. stopTimer();
  184. if (! e.mods.isPopupMenu())
  185. {
  186. auto pos = originalPos + e.getOffsetFromDragStart();
  187. if (getParentComponent() != nullptr)
  188. pos = getParentComponent()->getLocalPoint (nullptr, pos);
  189. pos += getLocalBounds().getCentre();
  190. graph.setNodePosition (pluginID,
  191. { pos.x / (double) getParentWidth(),
  192. pos.y / (double) getParentHeight() });
  193. panel.updateComponents();
  194. }
  195. }
  196. void mouseUp (const MouseEvent& e) override
  197. {
  198. if (isOnTouchDevice())
  199. {
  200. stopTimer();
  201. callAfterDelay (250, []() { PopupMenu::dismissAllActiveMenus(); });
  202. }
  203. if (e.mouseWasDraggedSinceMouseDown())
  204. {
  205. graph.setChangedFlag (true);
  206. }
  207. else if (e.getNumberOfClicks() == 2)
  208. {
  209. if (auto f = graph.graph.getNodeForId (pluginID))
  210. if (auto* w = graph.getOrCreateWindowFor (f, PluginWindow::Type::normal))
  211. w->toFront (true);
  212. }
  213. }
  214. bool hitTest (int x, int y) override
  215. {
  216. for (auto* child : getChildren())
  217. if (child->getBounds().contains (x, y))
  218. return true;
  219. return x >= 3 && x < getWidth() - 6 && y >= pinSize && y < getHeight() - pinSize;
  220. }
  221. void paint (Graphics& g) override
  222. {
  223. auto boxArea = getLocalBounds().reduced (4, pinSize);
  224. bool isBypassed = false;
  225. if (auto* f = graph.graph.getNodeForId (pluginID))
  226. isBypassed = f->isBypassed();
  227. auto boxColour = findColour (TextEditor::backgroundColourId);
  228. if (isBypassed)
  229. boxColour = boxColour.brighter();
  230. g.setColour (boxColour);
  231. g.fillRect (boxArea.toFloat());
  232. g.setColour (findColour (TextEditor::textColourId));
  233. g.setFont (font);
  234. g.drawFittedText (getName(), boxArea, Justification::centred, 2);
  235. }
  236. void resized() override
  237. {
  238. if (auto f = graph.graph.getNodeForId (pluginID))
  239. {
  240. if (auto* processor = f->getProcessor())
  241. {
  242. for (auto* pin : pins)
  243. {
  244. const bool isInput = pin->isInput;
  245. auto channelIndex = pin->pin.channelIndex;
  246. int busIdx = 0;
  247. processor->getOffsetInBusBufferForAbsoluteChannelIndex (isInput, channelIndex, busIdx);
  248. const int total = isInput ? numIns : numOuts;
  249. const int index = pin->pin.isMIDI() ? (total - 1) : channelIndex;
  250. auto totalSpaces = static_cast<float> (total) + (static_cast<float> (jmax (0, processor->getBusCount (isInput) - 1)) * 0.5f);
  251. auto indexPos = static_cast<float> (index) + (static_cast<float> (busIdx) * 0.5f);
  252. pin->setBounds (proportionOfWidth ((1.0f + indexPos) / (totalSpaces + 1.0f)) - pinSize / 2,
  253. pin->isInput ? 0 : (getHeight() - pinSize),
  254. pinSize, pinSize);
  255. }
  256. }
  257. }
  258. }
  259. Point<float> getPinPos (int index, bool isInput) const
  260. {
  261. for (auto* pin : pins)
  262. if (pin->pin.channelIndex == index && isInput == pin->isInput)
  263. return getPosition().toFloat() + pin->getBounds().getCentre().toFloat();
  264. return {};
  265. }
  266. void update()
  267. {
  268. const AudioProcessorGraph::Node::Ptr f (graph.graph.getNodeForId (pluginID));
  269. jassert (f != nullptr);
  270. auto& processor = *f->getProcessor();
  271. numIns = processor.getTotalNumInputChannels();
  272. if (processor.acceptsMidi())
  273. ++numIns;
  274. numOuts = processor.getTotalNumOutputChannels();
  275. if (processor.producesMidi())
  276. ++numOuts;
  277. int w = 100;
  278. int h = 60;
  279. w = jmax (w, (jmax (numIns, numOuts) + 1) * 20);
  280. const int textWidth = font.getStringWidth (processor.getName());
  281. w = jmax (w, 16 + jmin (textWidth, 300));
  282. if (textWidth > 300)
  283. h = 100;
  284. setSize (w, h);
  285. setName (processor.getName() + formatSuffix);
  286. {
  287. auto p = graph.getNodePosition (pluginID);
  288. setCentreRelative ((float) p.x, (float) p.y);
  289. }
  290. if (numIns != numInputs || numOuts != numOutputs)
  291. {
  292. numInputs = numIns;
  293. numOutputs = numOuts;
  294. pins.clear();
  295. for (int i = 0; i < processor.getTotalNumInputChannels(); ++i)
  296. addAndMakeVisible (pins.add (new PinComponent (panel, { pluginID, i }, true)));
  297. if (processor.acceptsMidi())
  298. addAndMakeVisible (pins.add (new PinComponent (panel, { pluginID, AudioProcessorGraph::midiChannelIndex }, true)));
  299. for (int i = 0; i < processor.getTotalNumOutputChannels(); ++i)
  300. addAndMakeVisible (pins.add (new PinComponent (panel, { pluginID, i }, false)));
  301. if (processor.producesMidi())
  302. addAndMakeVisible (pins.add (new PinComponent (panel, { pluginID, AudioProcessorGraph::midiChannelIndex }, false)));
  303. resized();
  304. }
  305. }
  306. AudioProcessor* getProcessor() const
  307. {
  308. if (auto node = graph.graph.getNodeForId (pluginID))
  309. return node->getProcessor();
  310. return {};
  311. }
  312. void showPopupMenu()
  313. {
  314. menu.reset (new PopupMenu);
  315. menu->addItem ("Delete this filter", [this] { graph.graph.removeNode (pluginID); });
  316. menu->addItem ("Disconnect all pins", [this] { graph.graph.disconnectNode (pluginID); });
  317. menu->addItem ("Toggle Bypass", [this]
  318. {
  319. if (auto* node = graph.graph.getNodeForId (pluginID))
  320. node->setBypassed (! node->isBypassed());
  321. repaint();
  322. });
  323. menu->addSeparator();
  324. if (getProcessor()->hasEditor())
  325. menu->addItem ("Show plugin GUI", [this] { showWindow (PluginWindow::Type::normal); });
  326. menu->addItem ("Show all programs", [this] { showWindow (PluginWindow::Type::programs); });
  327. menu->addItem ("Show all parameters", [this] { showWindow (PluginWindow::Type::generic); });
  328. menu->addItem ("Show debug log", [this] { showWindow (PluginWindow::Type::debug); });
  329. if (autoScaleOptionAvailable)
  330. addPluginAutoScaleOptionsSubMenu (dynamic_cast<AudioPluginInstance*> (getProcessor()), *menu);
  331. menu->addSeparator();
  332. menu->addItem ("Configure Audio I/O", [this] { showWindow (PluginWindow::Type::audioIO); });
  333. menu->addItem ("Test state save/load", [this] { testStateSaveLoad(); });
  334. #if ! JUCE_IOS && ! JUCE_ANDROID
  335. menu->addSeparator();
  336. menu->addItem ("Save plugin state", [this] { savePluginState(); });
  337. menu->addItem ("Load plugin state", [this] { loadPluginState(); });
  338. #endif
  339. menu->showMenuAsync ({});
  340. }
  341. void testStateSaveLoad()
  342. {
  343. if (auto* processor = getProcessor())
  344. {
  345. MemoryBlock state;
  346. processor->getStateInformation (state);
  347. processor->setStateInformation (state.getData(), (int) state.getSize());
  348. }
  349. }
  350. void showWindow (PluginWindow::Type type)
  351. {
  352. if (auto node = graph.graph.getNodeForId (pluginID))
  353. if (auto* w = graph.getOrCreateWindowFor (node, type))
  354. w->toFront (true);
  355. }
  356. void timerCallback() override
  357. {
  358. // this should only be called on touch devices
  359. jassert (isOnTouchDevice());
  360. stopTimer();
  361. showPopupMenu();
  362. }
  363. void parameterValueChanged (int, float) override
  364. {
  365. // Parameter changes might come from the audio thread or elsewhere, but
  366. // we can only call repaint from the message thread.
  367. triggerAsyncUpdate();
  368. }
  369. void parameterGestureChanged (int, bool) override {}
  370. void handleAsyncUpdate() override { repaint(); }
  371. void savePluginState()
  372. {
  373. fileChooser = std::make_unique<FileChooser> ("Save plugin state");
  374. const auto onChosen = [ref = SafePointer<PluginComponent> (this)] (const FileChooser& chooser)
  375. {
  376. if (ref == nullptr)
  377. return;
  378. const auto result = chooser.getResult();
  379. if (result == File())
  380. return;
  381. if (auto* node = ref->graph.graph.getNodeForId (ref->pluginID))
  382. {
  383. MemoryBlock block;
  384. node->getProcessor()->getStateInformation (block);
  385. result.replaceWithData (block.getData(), block.getSize());
  386. }
  387. };
  388. fileChooser->launchAsync (FileBrowserComponent::saveMode | FileBrowserComponent::warnAboutOverwriting, onChosen);
  389. }
  390. void loadPluginState()
  391. {
  392. fileChooser = std::make_unique<FileChooser> ("Load plugin state");
  393. const auto onChosen = [ref = SafePointer<PluginComponent> (this)] (const FileChooser& chooser)
  394. {
  395. if (ref == nullptr)
  396. return;
  397. const auto result = chooser.getResult();
  398. if (result == File())
  399. return;
  400. if (auto* node = ref->graph.graph.getNodeForId (ref->pluginID))
  401. {
  402. if (auto stream = result.createInputStream())
  403. {
  404. MemoryBlock block;
  405. stream->readIntoMemoryBlock (block);
  406. node->getProcessor()->setStateInformation (block.getData(), (int) block.getSize());
  407. }
  408. }
  409. };
  410. fileChooser->launchAsync (FileBrowserComponent::openMode | FileBrowserComponent::canSelectFiles, onChosen);
  411. }
  412. GraphEditorPanel& panel;
  413. PluginGraph& graph;
  414. const AudioProcessorGraph::NodeID pluginID;
  415. OwnedArray<PinComponent> pins;
  416. int numInputs = 0, numOutputs = 0;
  417. int pinSize = 16;
  418. Point<int> originalPos;
  419. Font font { 13.0f, Font::bold };
  420. int numIns = 0, numOuts = 0;
  421. DropShadowEffect shadow;
  422. std::unique_ptr<PopupMenu> menu;
  423. std::unique_ptr<FileChooser> fileChooser;
  424. const String formatSuffix = getFormatSuffix (getProcessor());
  425. };
  426. //==============================================================================
  427. struct GraphEditorPanel::ConnectorComponent : public Component,
  428. public SettableTooltipClient
  429. {
  430. explicit ConnectorComponent (GraphEditorPanel& p)
  431. : panel (p), graph (p.graph)
  432. {
  433. setAlwaysOnTop (true);
  434. }
  435. void setInput (AudioProcessorGraph::NodeAndChannel newSource)
  436. {
  437. if (connection.source != newSource)
  438. {
  439. connection.source = newSource;
  440. update();
  441. }
  442. }
  443. void setOutput (AudioProcessorGraph::NodeAndChannel newDest)
  444. {
  445. if (connection.destination != newDest)
  446. {
  447. connection.destination = newDest;
  448. update();
  449. }
  450. }
  451. void dragStart (Point<float> pos)
  452. {
  453. lastInputPos = pos;
  454. resizeToFit();
  455. }
  456. void dragEnd (Point<float> pos)
  457. {
  458. lastOutputPos = pos;
  459. resizeToFit();
  460. }
  461. void update()
  462. {
  463. Point<float> p1, p2;
  464. getPoints (p1, p2);
  465. if (lastInputPos != p1 || lastOutputPos != p2)
  466. resizeToFit();
  467. }
  468. void resizeToFit()
  469. {
  470. Point<float> p1, p2;
  471. getPoints (p1, p2);
  472. auto newBounds = Rectangle<float> (p1, p2).expanded (4.0f).getSmallestIntegerContainer();
  473. if (newBounds != getBounds())
  474. setBounds (newBounds);
  475. else
  476. resized();
  477. repaint();
  478. }
  479. void getPoints (Point<float>& p1, Point<float>& p2) const
  480. {
  481. p1 = lastInputPos;
  482. p2 = lastOutputPos;
  483. if (auto* src = panel.getComponentForPlugin (connection.source.nodeID))
  484. p1 = src->getPinPos (connection.source.channelIndex, false);
  485. if (auto* dest = panel.getComponentForPlugin (connection.destination.nodeID))
  486. p2 = dest->getPinPos (connection.destination.channelIndex, true);
  487. }
  488. void paint (Graphics& g) override
  489. {
  490. if (connection.source.isMIDI() || connection.destination.isMIDI())
  491. g.setColour (Colours::red);
  492. else
  493. g.setColour (Colours::green);
  494. g.fillPath (linePath);
  495. }
  496. bool hitTest (int x, int y) override
  497. {
  498. auto pos = Point<int> (x, y).toFloat();
  499. if (hitPath.contains (pos))
  500. {
  501. double distanceFromStart, distanceFromEnd;
  502. getDistancesFromEnds (pos, distanceFromStart, distanceFromEnd);
  503. // avoid clicking the connector when over a pin
  504. return distanceFromStart > 7.0 && distanceFromEnd > 7.0;
  505. }
  506. return false;
  507. }
  508. void mouseDown (const MouseEvent&) override
  509. {
  510. dragging = false;
  511. }
  512. void mouseDrag (const MouseEvent& e) override
  513. {
  514. if (dragging)
  515. {
  516. panel.dragConnector (e);
  517. }
  518. else if (e.mouseWasDraggedSinceMouseDown())
  519. {
  520. dragging = true;
  521. graph.graph.removeConnection (connection);
  522. double distanceFromStart, distanceFromEnd;
  523. getDistancesFromEnds (getPosition().toFloat() + e.position, distanceFromStart, distanceFromEnd);
  524. const bool isNearerSource = (distanceFromStart < distanceFromEnd);
  525. AudioProcessorGraph::NodeAndChannel dummy { {}, 0 };
  526. panel.beginConnectorDrag (isNearerSource ? dummy : connection.source,
  527. isNearerSource ? connection.destination : dummy,
  528. e);
  529. }
  530. }
  531. void mouseUp (const MouseEvent& e) override
  532. {
  533. if (dragging)
  534. panel.endDraggingConnector (e);
  535. }
  536. void resized() override
  537. {
  538. Point<float> p1, p2;
  539. getPoints (p1, p2);
  540. lastInputPos = p1;
  541. lastOutputPos = p2;
  542. p1 -= getPosition().toFloat();
  543. p2 -= getPosition().toFloat();
  544. linePath.clear();
  545. linePath.startNewSubPath (p1);
  546. linePath.cubicTo (p1.x, p1.y + (p2.y - p1.y) * 0.33f,
  547. p2.x, p1.y + (p2.y - p1.y) * 0.66f,
  548. p2.x, p2.y);
  549. PathStrokeType wideStroke (8.0f);
  550. wideStroke.createStrokedPath (hitPath, linePath);
  551. PathStrokeType stroke (2.5f);
  552. stroke.createStrokedPath (linePath, linePath);
  553. auto arrowW = 5.0f;
  554. auto arrowL = 4.0f;
  555. Path arrow;
  556. arrow.addTriangle (-arrowL, arrowW,
  557. -arrowL, -arrowW,
  558. arrowL, 0.0f);
  559. arrow.applyTransform (AffineTransform()
  560. .rotated (MathConstants<float>::halfPi - (float) atan2 (p2.x - p1.x, p2.y - p1.y))
  561. .translated ((p1 + p2) * 0.5f));
  562. linePath.addPath (arrow);
  563. linePath.setUsingNonZeroWinding (true);
  564. }
  565. void getDistancesFromEnds (Point<float> p, double& distanceFromStart, double& distanceFromEnd) const
  566. {
  567. Point<float> p1, p2;
  568. getPoints (p1, p2);
  569. distanceFromStart = p1.getDistanceFrom (p);
  570. distanceFromEnd = p2.getDistanceFrom (p);
  571. }
  572. GraphEditorPanel& panel;
  573. PluginGraph& graph;
  574. AudioProcessorGraph::Connection connection { { {}, 0 }, { {}, 0 } };
  575. Point<float> lastInputPos, lastOutputPos;
  576. Path linePath, hitPath;
  577. bool dragging = false;
  578. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConnectorComponent)
  579. };
  580. //==============================================================================
  581. GraphEditorPanel::GraphEditorPanel (PluginGraph& g) : graph (g)
  582. {
  583. graph.addChangeListener (this);
  584. setOpaque (true);
  585. }
  586. GraphEditorPanel::~GraphEditorPanel()
  587. {
  588. graph.removeChangeListener (this);
  589. draggingConnector = nullptr;
  590. nodes.clear();
  591. connectors.clear();
  592. }
  593. void GraphEditorPanel::paint (Graphics& g)
  594. {
  595. g.fillAll (getLookAndFeel().findColour (ResizableWindow::backgroundColourId));
  596. }
  597. void GraphEditorPanel::mouseDown (const MouseEvent& e)
  598. {
  599. if (isOnTouchDevice())
  600. {
  601. originalTouchPos = e.position.toInt();
  602. startTimer (750);
  603. }
  604. if (e.mods.isPopupMenu())
  605. showPopupMenu (e.position.toInt());
  606. }
  607. void GraphEditorPanel::mouseUp (const MouseEvent&)
  608. {
  609. if (isOnTouchDevice())
  610. {
  611. stopTimer();
  612. callAfterDelay (250, []() { PopupMenu::dismissAllActiveMenus(); });
  613. }
  614. }
  615. void GraphEditorPanel::mouseDrag (const MouseEvent& e)
  616. {
  617. if (isOnTouchDevice() && e.getDistanceFromDragStart() > 5)
  618. stopTimer();
  619. }
  620. void GraphEditorPanel::createNewPlugin (const PluginDescription& desc, Point<int> position)
  621. {
  622. graph.addPlugin (desc, position.toDouble() / Point<double> ((double) getWidth(), (double) getHeight()));
  623. }
  624. GraphEditorPanel::PluginComponent* GraphEditorPanel::getComponentForPlugin (AudioProcessorGraph::NodeID nodeID) const
  625. {
  626. for (auto* fc : nodes)
  627. if (fc->pluginID == nodeID)
  628. return fc;
  629. return nullptr;
  630. }
  631. GraphEditorPanel::ConnectorComponent* GraphEditorPanel::getComponentForConnection (const AudioProcessorGraph::Connection& conn) const
  632. {
  633. for (auto* cc : connectors)
  634. if (cc->connection == conn)
  635. return cc;
  636. return nullptr;
  637. }
  638. GraphEditorPanel::PinComponent* GraphEditorPanel::findPinAt (Point<float> pos) const
  639. {
  640. for (auto* fc : nodes)
  641. {
  642. // NB: A Visual Studio optimiser error means we have to put this Component* in a local
  643. // variable before trying to cast it, or it gets mysteriously optimised away..
  644. auto* comp = fc->getComponentAt (pos.toInt() - fc->getPosition());
  645. if (auto* pin = dynamic_cast<PinComponent*> (comp))
  646. return pin;
  647. }
  648. return nullptr;
  649. }
  650. void GraphEditorPanel::resized()
  651. {
  652. updateComponents();
  653. }
  654. void GraphEditorPanel::changeListenerCallback (ChangeBroadcaster*)
  655. {
  656. updateComponents();
  657. }
  658. void GraphEditorPanel::updateComponents()
  659. {
  660. for (int i = nodes.size(); --i >= 0;)
  661. if (graph.graph.getNodeForId (nodes.getUnchecked(i)->pluginID) == nullptr)
  662. nodes.remove (i);
  663. for (int i = connectors.size(); --i >= 0;)
  664. if (! graph.graph.isConnected (connectors.getUnchecked(i)->connection))
  665. connectors.remove (i);
  666. for (auto* fc : nodes)
  667. fc->update();
  668. for (auto* cc : connectors)
  669. cc->update();
  670. for (auto* f : graph.graph.getNodes())
  671. {
  672. if (getComponentForPlugin (f->nodeID) == nullptr)
  673. {
  674. auto* comp = nodes.add (new PluginComponent (*this, f->nodeID));
  675. addAndMakeVisible (comp);
  676. comp->update();
  677. }
  678. }
  679. for (auto& c : graph.graph.getConnections())
  680. {
  681. if (getComponentForConnection (c) == nullptr)
  682. {
  683. auto* comp = connectors.add (new ConnectorComponent (*this));
  684. addAndMakeVisible (comp);
  685. comp->setInput (c.source);
  686. comp->setOutput (c.destination);
  687. }
  688. }
  689. }
  690. void GraphEditorPanel::showPopupMenu (Point<int> mousePos)
  691. {
  692. menu.reset (new PopupMenu);
  693. if (auto* mainWindow = findParentComponentOfClass<MainHostWindow>())
  694. {
  695. mainWindow->addPluginsToMenu (*menu);
  696. menu->showMenuAsync ({},
  697. ModalCallbackFunction::create ([this, mousePos] (int r)
  698. {
  699. if (r > 0)
  700. if (auto* mainWin = findParentComponentOfClass<MainHostWindow>())
  701. createNewPlugin (mainWin->getChosenType (r), mousePos);
  702. }));
  703. }
  704. }
  705. void GraphEditorPanel::beginConnectorDrag (AudioProcessorGraph::NodeAndChannel source,
  706. AudioProcessorGraph::NodeAndChannel dest,
  707. const MouseEvent& e)
  708. {
  709. auto* c = dynamic_cast<ConnectorComponent*> (e.originalComponent);
  710. connectors.removeObject (c, false);
  711. draggingConnector.reset (c);
  712. if (draggingConnector == nullptr)
  713. draggingConnector.reset (new ConnectorComponent (*this));
  714. draggingConnector->setInput (source);
  715. draggingConnector->setOutput (dest);
  716. addAndMakeVisible (draggingConnector.get());
  717. draggingConnector->toFront (false);
  718. dragConnector (e);
  719. }
  720. void GraphEditorPanel::dragConnector (const MouseEvent& e)
  721. {
  722. auto e2 = e.getEventRelativeTo (this);
  723. if (draggingConnector != nullptr)
  724. {
  725. draggingConnector->setTooltip ({});
  726. auto pos = e2.position;
  727. if (auto* pin = findPinAt (pos))
  728. {
  729. auto connection = draggingConnector->connection;
  730. if (connection.source.nodeID == AudioProcessorGraph::NodeID() && ! pin->isInput)
  731. {
  732. connection.source = pin->pin;
  733. }
  734. else if (connection.destination.nodeID == AudioProcessorGraph::NodeID() && pin->isInput)
  735. {
  736. connection.destination = pin->pin;
  737. }
  738. if (graph.graph.canConnect (connection))
  739. {
  740. pos = (pin->getParentComponent()->getPosition() + pin->getBounds().getCentre()).toFloat();
  741. draggingConnector->setTooltip (pin->getTooltip());
  742. }
  743. }
  744. if (draggingConnector->connection.source.nodeID == AudioProcessorGraph::NodeID())
  745. draggingConnector->dragStart (pos);
  746. else
  747. draggingConnector->dragEnd (pos);
  748. }
  749. }
  750. void GraphEditorPanel::endDraggingConnector (const MouseEvent& e)
  751. {
  752. if (draggingConnector == nullptr)
  753. return;
  754. draggingConnector->setTooltip ({});
  755. auto e2 = e.getEventRelativeTo (this);
  756. auto connection = draggingConnector->connection;
  757. draggingConnector = nullptr;
  758. if (auto* pin = findPinAt (e2.position))
  759. {
  760. if (connection.source.nodeID == AudioProcessorGraph::NodeID())
  761. {
  762. if (pin->isInput)
  763. return;
  764. connection.source = pin->pin;
  765. }
  766. else
  767. {
  768. if (! pin->isInput)
  769. return;
  770. connection.destination = pin->pin;
  771. }
  772. graph.graph.addConnection (connection);
  773. }
  774. }
  775. void GraphEditorPanel::timerCallback()
  776. {
  777. // this should only be called on touch devices
  778. jassert (isOnTouchDevice());
  779. stopTimer();
  780. showPopupMenu (originalTouchPos);
  781. }
  782. //==============================================================================
  783. struct GraphDocumentComponent::TooltipBar : public Component,
  784. private Timer
  785. {
  786. TooltipBar()
  787. {
  788. startTimer (100);
  789. }
  790. void paint (Graphics& g) override
  791. {
  792. g.setFont (Font ((float) getHeight() * 0.7f, Font::bold));
  793. g.setColour (Colours::black);
  794. g.drawFittedText (tip, 10, 0, getWidth() - 12, getHeight(), Justification::centredLeft, 1);
  795. }
  796. void timerCallback() override
  797. {
  798. String newTip;
  799. if (auto* underMouse = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse())
  800. if (auto* ttc = dynamic_cast<TooltipClient*> (underMouse))
  801. if (! (underMouse->isMouseButtonDown() || underMouse->isCurrentlyBlockedByAnotherModalComponent()))
  802. newTip = ttc->getTooltip();
  803. if (newTip != tip)
  804. {
  805. tip = newTip;
  806. repaint();
  807. }
  808. }
  809. String tip;
  810. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TooltipBar)
  811. };
  812. //==============================================================================
  813. class GraphDocumentComponent::TitleBarComponent : public Component,
  814. private Button::Listener
  815. {
  816. public:
  817. explicit TitleBarComponent (GraphDocumentComponent& graphDocumentComponent)
  818. : owner (graphDocumentComponent)
  819. {
  820. static const unsigned char burgerMenuPathData[]
  821. = { 110,109,0,0,128,64,0,0,32,65,108,0,0,224,65,0,0,32,65,98,254,212,232,65,0,0,32,65,0,0,240,65,252,
  822. 169,17,65,0,0,240,65,0,0,0,65,98,0,0,240,65,8,172,220,64,254,212,232,65,0,0,192,64,0,0,224,65,0,0,
  823. 192,64,108,0,0,128,64,0,0,192,64,98,16,88,57,64,0,0,192,64,0,0,0,64,8,172,220,64,0,0,0,64,0,0,0,65,
  824. 98,0,0,0,64,252,169,17,65,16,88,57,64,0,0,32,65,0,0,128,64,0,0,32,65,99,109,0,0,224,65,0,0,96,65,108,
  825. 0,0,128,64,0,0,96,65,98,16,88,57,64,0,0,96,65,0,0,0,64,4,86,110,65,0,0,0,64,0,0,128,65,98,0,0,0,64,
  826. 254,212,136,65,16,88,57,64,0,0,144,65,0,0,128,64,0,0,144,65,108,0,0,224,65,0,0,144,65,98,254,212,232,
  827. 65,0,0,144,65,0,0,240,65,254,212,136,65,0,0,240,65,0,0,128,65,98,0,0,240,65,4,86,110,65,254,212,232,
  828. 65,0,0,96,65,0,0,224,65,0,0,96,65,99,109,0,0,224,65,0,0,176,65,108,0,0,128,64,0,0,176,65,98,16,88,57,
  829. 64,0,0,176,65,0,0,0,64,2,43,183,65,0,0,0,64,0,0,192,65,98,0,0,0,64,254,212,200,65,16,88,57,64,0,0,208,
  830. 65,0,0,128,64,0,0,208,65,108,0,0,224,65,0,0,208,65,98,254,212,232,65,0,0,208,65,0,0,240,65,254,212,
  831. 200,65,0,0,240,65,0,0,192,65,98,0,0,240,65,2,43,183,65,254,212,232,65,0,0,176,65,0,0,224,65,0,0,176,
  832. 65,99,101,0,0 };
  833. static const unsigned char pluginListPathData[]
  834. = { 110,109,193,202,222,64,80,50,21,64,108,0,0,48,65,0,0,0,0,108,160,154,112,65,80,50,21,64,108,0,0,48,65,80,
  835. 50,149,64,108,193,202,222,64,80,50,21,64,99,109,0,0,192,64,251,220,127,64,108,160,154,32,65,165,135,202,
  836. 64,108,160,154,32,65,250,220,47,65,108,0,0,192,64,102,144,10,65,108,0,0,192,64,251,220,127,64,99,109,0,0,
  837. 128,65,251,220,127,64,108,0,0,128,65,103,144,10,65,108,96,101,63,65,251,220,47,65,108,96,101,63,65,166,135,
  838. 202,64,108,0,0,128,65,251,220,127,64,99,109,96,101,79,65,148,76,69,65,108,0,0,136,65,0,0,32,65,108,80,
  839. 77,168,65,148,76,69,65,108,0,0,136,65,40,153,106,65,108,96,101,79,65,148,76,69,65,99,109,0,0,64,65,63,247,
  840. 95,65,108,80,77,128,65,233,161,130,65,108,80,77,128,65,125,238,167,65,108,0,0,64,65,51,72,149,65,108,0,0,64,
  841. 65,63,247,95,65,99,109,0,0,176,65,63,247,95,65,108,0,0,176,65,51,72,149,65,108,176,178,143,65,125,238,167,65,
  842. 108,176,178,143,65,233,161,130,65,108,0,0,176,65,63,247,95,65,99,109,12,86,118,63,148,76,69,65,108,0,0,160,
  843. 64,0,0,32,65,108,159,154,16,65,148,76,69,65,108,0,0,160,64,40,153,106,65,108,12,86,118,63,148,76,69,65,99,
  844. 109,0,0,0,0,63,247,95,65,108,62,53,129,64,233,161,130,65,108,62,53,129,64,125,238,167,65,108,0,0,0,0,51,
  845. 72,149,65,108,0,0,0,0,63,247,95,65,99,109,0,0,32,65,63,247,95,65,108,0,0,32,65,51,72,149,65,108,193,202,190,
  846. 64,125,238,167,65,108,193,202,190,64,233,161,130,65,108,0,0,32,65,63,247,95,65,99,101,0,0 };
  847. {
  848. Path p;
  849. p.loadPathFromData (burgerMenuPathData, sizeof (burgerMenuPathData));
  850. burgerButton.setShape (p, true, true, false);
  851. }
  852. {
  853. Path p;
  854. p.loadPathFromData (pluginListPathData, sizeof (pluginListPathData));
  855. pluginButton.setShape (p, true, true, false);
  856. }
  857. burgerButton.addListener (this);
  858. addAndMakeVisible (burgerButton);
  859. pluginButton.addListener (this);
  860. addAndMakeVisible (pluginButton);
  861. titleLabel.setJustificationType (Justification::centredLeft);
  862. addAndMakeVisible (titleLabel);
  863. setOpaque (true);
  864. }
  865. private:
  866. void paint (Graphics& g) override
  867. {
  868. auto titleBarBackgroundColour = getLookAndFeel().findColour (ResizableWindow::backgroundColourId).darker();
  869. g.setColour (titleBarBackgroundColour);
  870. g.fillRect (getLocalBounds());
  871. }
  872. void resized() override
  873. {
  874. auto r = getLocalBounds();
  875. burgerButton.setBounds (r.removeFromLeft (40).withSizeKeepingCentre (20, 20));
  876. pluginButton.setBounds (r.removeFromRight (40).withSizeKeepingCentre (20, 20));
  877. titleLabel.setFont (Font (static_cast<float> (getHeight()) * 0.5f, Font::plain));
  878. titleLabel.setBounds (r);
  879. }
  880. void buttonClicked (Button* b) override
  881. {
  882. owner.showSidePanel (b == &burgerButton);
  883. }
  884. GraphDocumentComponent& owner;
  885. Label titleLabel {"titleLabel", "Plugin Host"};
  886. ShapeButton burgerButton {"burgerButton", Colours::lightgrey, Colours::lightgrey, Colours::white};
  887. ShapeButton pluginButton {"pluginButton", Colours::lightgrey, Colours::lightgrey, Colours::white};
  888. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TitleBarComponent)
  889. };
  890. //==============================================================================
  891. struct GraphDocumentComponent::PluginListBoxModel : public ListBoxModel,
  892. public ChangeListener,
  893. public MouseListener
  894. {
  895. PluginListBoxModel (ListBox& lb, KnownPluginList& kpl)
  896. : owner (lb),
  897. knownPlugins (kpl)
  898. {
  899. knownPlugins.addChangeListener (this);
  900. owner.addMouseListener (this, true);
  901. #if JUCE_IOS
  902. scanner.reset (new AUScanner (knownPlugins));
  903. #endif
  904. }
  905. int getNumRows() override
  906. {
  907. return knownPlugins.getNumTypes();
  908. }
  909. void paintListBoxItem (int rowNumber, Graphics& g,
  910. int width, int height, bool rowIsSelected) override
  911. {
  912. g.fillAll (rowIsSelected ? Colour (0xff42A2C8)
  913. : Colour (0xff263238));
  914. g.setColour (rowIsSelected ? Colours::black : Colours::white);
  915. if (rowNumber < knownPlugins.getNumTypes())
  916. g.drawFittedText (knownPlugins.getTypes()[rowNumber].name, { 0, 0, width, height - 2 }, Justification::centred, 1);
  917. g.setColour (Colours::black.withAlpha (0.4f));
  918. g.drawRect (0, height - 1, width, 1);
  919. }
  920. var getDragSourceDescription (const SparseSet<int>& selectedRows) override
  921. {
  922. if (! isOverSelectedRow)
  923. return var();
  924. return String ("PLUGIN: " + String (selectedRows[0]));
  925. }
  926. void changeListenerCallback (ChangeBroadcaster*) override
  927. {
  928. owner.updateContent();
  929. }
  930. void mouseDown (const MouseEvent& e) override
  931. {
  932. isOverSelectedRow = owner.getRowPosition (owner.getSelectedRow(), true)
  933. .contains (e.getEventRelativeTo (&owner).getMouseDownPosition());
  934. }
  935. ListBox& owner;
  936. KnownPluginList& knownPlugins;
  937. bool isOverSelectedRow = false;
  938. #if JUCE_IOS
  939. std::unique_ptr<AUScanner> scanner;
  940. #endif
  941. JUCE_DECLARE_NON_COPYABLE (PluginListBoxModel)
  942. };
  943. //==============================================================================
  944. GraphDocumentComponent::GraphDocumentComponent (AudioPluginFormatManager& fm,
  945. AudioDeviceManager& dm,
  946. KnownPluginList& kpl)
  947. : graph (new PluginGraph (fm, kpl)),
  948. deviceManager (dm),
  949. pluginList (kpl),
  950. graphPlayer (getAppProperties().getUserSettings()->getBoolValue ("doublePrecisionProcessing", false))
  951. {
  952. init();
  953. deviceManager.addChangeListener (graphPanel.get());
  954. deviceManager.addAudioCallback (&graphPlayer);
  955. deviceManager.addMidiInputDeviceCallback ({}, &graphPlayer.getMidiMessageCollector());
  956. deviceManager.addChangeListener (this);
  957. }
  958. void GraphDocumentComponent::init()
  959. {
  960. updateMidiOutput();
  961. graphPanel.reset (new GraphEditorPanel (*graph));
  962. addAndMakeVisible (graphPanel.get());
  963. graphPlayer.setProcessor (&graph->graph);
  964. keyState.addListener (&graphPlayer.getMidiMessageCollector());
  965. keyboardComp.reset (new MidiKeyboardComponent (keyState, MidiKeyboardComponent::horizontalKeyboard));
  966. addAndMakeVisible (keyboardComp.get());
  967. statusBar.reset (new TooltipBar());
  968. addAndMakeVisible (statusBar.get());
  969. graphPanel->updateComponents();
  970. if (isOnTouchDevice())
  971. {
  972. titleBarComponent.reset (new TitleBarComponent (*this));
  973. addAndMakeVisible (titleBarComponent.get());
  974. pluginListBoxModel.reset (new PluginListBoxModel (pluginListBox, pluginList));
  975. pluginListBox.setModel (pluginListBoxModel.get());
  976. pluginListBox.setRowHeight (40);
  977. pluginListSidePanel.setContent (&pluginListBox, false);
  978. mobileSettingsSidePanel.setContent (new AudioDeviceSelectorComponent (deviceManager,
  979. 0, 2, 0, 2,
  980. true, true, true, false));
  981. addAndMakeVisible (pluginListSidePanel);
  982. addAndMakeVisible (mobileSettingsSidePanel);
  983. }
  984. }
  985. GraphDocumentComponent::~GraphDocumentComponent()
  986. {
  987. if (midiOutput != nullptr)
  988. midiOutput->stopBackgroundThread();
  989. releaseGraph();
  990. keyState.removeListener (&graphPlayer.getMidiMessageCollector());
  991. }
  992. void GraphDocumentComponent::resized()
  993. {
  994. auto r = [this]
  995. {
  996. auto bounds = getLocalBounds();
  997. if (auto* display = Desktop::getInstance().getDisplays().getDisplayForRect (getScreenBounds()))
  998. return display->safeAreaInsets.subtractedFrom (bounds);
  999. return bounds;
  1000. }();
  1001. const int titleBarHeight = 40;
  1002. const int keysHeight = 60;
  1003. const int statusHeight = 20;
  1004. if (isOnTouchDevice())
  1005. titleBarComponent->setBounds (r.removeFromTop(titleBarHeight));
  1006. keyboardComp->setBounds (r.removeFromBottom (keysHeight));
  1007. statusBar->setBounds (r.removeFromBottom (statusHeight));
  1008. graphPanel->setBounds (r);
  1009. checkAvailableWidth();
  1010. }
  1011. void GraphDocumentComponent::createNewPlugin (const PluginDescription& desc, Point<int> pos)
  1012. {
  1013. graphPanel->createNewPlugin (desc, pos);
  1014. }
  1015. void GraphDocumentComponent::releaseGraph()
  1016. {
  1017. deviceManager.removeAudioCallback (&graphPlayer);
  1018. deviceManager.removeMidiInputDeviceCallback ({}, &graphPlayer.getMidiMessageCollector());
  1019. if (graphPanel != nullptr)
  1020. {
  1021. deviceManager.removeChangeListener (graphPanel.get());
  1022. graphPanel = nullptr;
  1023. }
  1024. keyboardComp = nullptr;
  1025. statusBar = nullptr;
  1026. graphPlayer.setProcessor (nullptr);
  1027. graph = nullptr;
  1028. }
  1029. bool GraphDocumentComponent::isInterestedInDragSource (const SourceDetails& details)
  1030. {
  1031. return ((dynamic_cast<ListBox*> (details.sourceComponent.get()) != nullptr)
  1032. && details.description.toString().startsWith ("PLUGIN"));
  1033. }
  1034. void GraphDocumentComponent::itemDropped (const SourceDetails& details)
  1035. {
  1036. // don't allow items to be dropped behind the sidebar
  1037. if (pluginListSidePanel.getBounds().contains (details.localPosition))
  1038. return;
  1039. auto pluginTypeIndex = details.description.toString()
  1040. .fromFirstOccurrenceOf ("PLUGIN: ", false, false)
  1041. .getIntValue();
  1042. // must be a valid index!
  1043. jassert (isPositiveAndBelow (pluginTypeIndex, pluginList.getNumTypes()));
  1044. createNewPlugin (pluginList.getTypes()[pluginTypeIndex], details.localPosition);
  1045. }
  1046. void GraphDocumentComponent::showSidePanel (bool showSettingsPanel)
  1047. {
  1048. if (showSettingsPanel)
  1049. mobileSettingsSidePanel.showOrHide (true);
  1050. else
  1051. pluginListSidePanel.showOrHide (true);
  1052. checkAvailableWidth();
  1053. lastOpenedSidePanel = showSettingsPanel ? &mobileSettingsSidePanel
  1054. : &pluginListSidePanel;
  1055. }
  1056. void GraphDocumentComponent::hideLastSidePanel()
  1057. {
  1058. if (lastOpenedSidePanel != nullptr)
  1059. lastOpenedSidePanel->showOrHide (false);
  1060. if (mobileSettingsSidePanel.isPanelShowing()) lastOpenedSidePanel = &mobileSettingsSidePanel;
  1061. else if (pluginListSidePanel.isPanelShowing()) lastOpenedSidePanel = &pluginListSidePanel;
  1062. else lastOpenedSidePanel = nullptr;
  1063. }
  1064. void GraphDocumentComponent::checkAvailableWidth()
  1065. {
  1066. if (mobileSettingsSidePanel.isPanelShowing() && pluginListSidePanel.isPanelShowing())
  1067. {
  1068. if (getWidth() - (mobileSettingsSidePanel.getWidth() + pluginListSidePanel.getWidth()) < 150)
  1069. hideLastSidePanel();
  1070. }
  1071. }
  1072. void GraphDocumentComponent::setDoublePrecision (bool doublePrecision)
  1073. {
  1074. graphPlayer.setDoublePrecisionProcessing (doublePrecision);
  1075. }
  1076. bool GraphDocumentComponent::closeAnyOpenPluginWindows()
  1077. {
  1078. return graphPanel->graph.closeAnyOpenPluginWindows();
  1079. }
  1080. void GraphDocumentComponent::changeListenerCallback (ChangeBroadcaster*)
  1081. {
  1082. updateMidiOutput();
  1083. }
  1084. void GraphDocumentComponent::updateMidiOutput()
  1085. {
  1086. auto* defaultMidiOutput = deviceManager.getDefaultMidiOutput();
  1087. if (midiOutput != defaultMidiOutput)
  1088. {
  1089. midiOutput = defaultMidiOutput;
  1090. if (midiOutput != nullptr)
  1091. midiOutput->startBackgroundThread();
  1092. graphPlayer.setMidiOutput (midiOutput);
  1093. }
  1094. }