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.

119 lines
4.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 7 technical preview.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For the technical preview this file cannot be licensed commercially.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. #pragma once
  14. #include "../UI/PluginWindow.h"
  15. //==============================================================================
  16. /** A type that encapsulates a PluginDescription and some preferences regarding
  17. how plugins of that description should be instantiated.
  18. */
  19. struct PluginDescriptionAndPreference
  20. {
  21. enum class UseARA { no, yes };
  22. PluginDescriptionAndPreference() = default;
  23. explicit PluginDescriptionAndPreference (PluginDescription pd)
  24. : pluginDescription (std::move (pd)),
  25. useARA (pluginDescription.hasARAExtension ? PluginDescriptionAndPreference::UseARA::yes
  26. : PluginDescriptionAndPreference::UseARA::no)
  27. {}
  28. PluginDescriptionAndPreference (PluginDescription pd, UseARA ara)
  29. : pluginDescription (std::move (pd)), useARA (ara)
  30. {}
  31. PluginDescription pluginDescription;
  32. UseARA useARA = UseARA::no;
  33. };
  34. //==============================================================================
  35. /**
  36. A collection of plugins and some connections between them.
  37. */
  38. class PluginGraph : public FileBasedDocument,
  39. public AudioProcessorListener,
  40. private ChangeListener
  41. {
  42. public:
  43. //==============================================================================
  44. PluginGraph (AudioPluginFormatManager&, KnownPluginList&);
  45. ~PluginGraph() override;
  46. //==============================================================================
  47. using NodeID = AudioProcessorGraph::NodeID;
  48. void addPlugin (const PluginDescriptionAndPreference&, Point<double>);
  49. AudioProcessorGraph::Node::Ptr getNodeForName (const String& name) const;
  50. void setNodePosition (NodeID, Point<double>);
  51. Point<double> getNodePosition (NodeID) const;
  52. //==============================================================================
  53. void clear();
  54. PluginWindow* getOrCreateWindowFor (AudioProcessorGraph::Node*, PluginWindow::Type);
  55. void closeCurrentlyOpenWindowsFor (AudioProcessorGraph::NodeID);
  56. bool closeAnyOpenPluginWindows();
  57. //==============================================================================
  58. void audioProcessorParameterChanged (AudioProcessor*, int, float) override {}
  59. void audioProcessorChanged (AudioProcessor*, const ChangeDetails&) override { changed(); }
  60. //==============================================================================
  61. std::unique_ptr<XmlElement> createXml() const;
  62. void restoreFromXml (const XmlElement&);
  63. static const char* getFilenameSuffix() { return ".filtergraph"; }
  64. static const char* getFilenameWildcard() { return "*.filtergraph"; }
  65. //==============================================================================
  66. void newDocument();
  67. String getDocumentTitle() override;
  68. Result loadDocument (const File& file) override;
  69. Result saveDocument (const File& file) override;
  70. File getLastDocumentOpened() override;
  71. void setLastDocumentOpened (const File& file) override;
  72. static File getDefaultGraphDocumentOnMobile();
  73. //==============================================================================
  74. AudioProcessorGraph graph;
  75. private:
  76. //==============================================================================
  77. AudioPluginFormatManager& formatManager;
  78. KnownPluginList& knownPlugins;
  79. OwnedArray<PluginWindow> activePluginWindows;
  80. NodeID lastUID;
  81. NodeID getNextUID() noexcept;
  82. void createNodeFromXml (const XmlElement&);
  83. void addPluginCallback (std::unique_ptr<AudioPluginInstance>,
  84. const String& error,
  85. Point<double>,
  86. PluginDescriptionAndPreference::UseARA useARA);
  87. void changeListenerCallback (ChangeBroadcaster*) override;
  88. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginGraph)
  89. };