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.

126 lines
4.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - 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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-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. #pragma once
  19. #include "../UI/PluginWindow.h"
  20. //==============================================================================
  21. /** A type that encapsulates a PluginDescription and some preferences regarding
  22. how plugins of that description should be instantiated.
  23. */
  24. struct PluginDescriptionAndPreference
  25. {
  26. enum class UseARA { no, yes };
  27. PluginDescriptionAndPreference() = default;
  28. explicit PluginDescriptionAndPreference (PluginDescription pd)
  29. : pluginDescription (std::move (pd)),
  30. useARA (pluginDescription.hasARAExtension ? PluginDescriptionAndPreference::UseARA::yes
  31. : PluginDescriptionAndPreference::UseARA::no)
  32. {}
  33. PluginDescriptionAndPreference (PluginDescription pd, UseARA ara)
  34. : pluginDescription (std::move (pd)), useARA (ara)
  35. {}
  36. PluginDescription pluginDescription;
  37. UseARA useARA = UseARA::no;
  38. };
  39. //==============================================================================
  40. /**
  41. A collection of plugins and some connections between them.
  42. */
  43. class PluginGraph : public FileBasedDocument,
  44. public AudioProcessorListener,
  45. private ChangeListener
  46. {
  47. public:
  48. //==============================================================================
  49. PluginGraph (AudioPluginFormatManager&, KnownPluginList&);
  50. ~PluginGraph() override;
  51. //==============================================================================
  52. using NodeID = AudioProcessorGraph::NodeID;
  53. void addPlugin (const PluginDescriptionAndPreference&, Point<double>);
  54. AudioProcessorGraph::Node::Ptr getNodeForName (const String& name) const;
  55. void setNodePosition (NodeID, Point<double>);
  56. Point<double> getNodePosition (NodeID) const;
  57. //==============================================================================
  58. void clear();
  59. PluginWindow* getOrCreateWindowFor (AudioProcessorGraph::Node*, PluginWindow::Type);
  60. void closeCurrentlyOpenWindowsFor (AudioProcessorGraph::NodeID);
  61. bool closeAnyOpenPluginWindows();
  62. //==============================================================================
  63. void audioProcessorParameterChanged (AudioProcessor*, int, float) override {}
  64. void audioProcessorChanged (AudioProcessor*, const ChangeDetails&) override { changed(); }
  65. //==============================================================================
  66. std::unique_ptr<XmlElement> createXml() const;
  67. void restoreFromXml (const XmlElement&);
  68. static const char* getFilenameSuffix() { return ".filtergraph"; }
  69. static const char* getFilenameWildcard() { return "*.filtergraph"; }
  70. //==============================================================================
  71. void newDocument();
  72. String getDocumentTitle() override;
  73. Result loadDocument (const File& file) override;
  74. Result saveDocument (const File& file) override;
  75. File getLastDocumentOpened() override;
  76. void setLastDocumentOpened (const File& file) override;
  77. static File getDefaultGraphDocumentOnMobile();
  78. //==============================================================================
  79. AudioProcessorGraph graph;
  80. private:
  81. //==============================================================================
  82. AudioPluginFormatManager& formatManager;
  83. KnownPluginList& knownPlugins;
  84. OwnedArray<PluginWindow> activePluginWindows;
  85. NodeID lastUID;
  86. NodeID getNextUID() noexcept;
  87. void createNodeFromXml (const XmlElement&);
  88. void addPluginCallback (std::unique_ptr<AudioPluginInstance>,
  89. const String& error,
  90. Point<double>,
  91. PluginDescriptionAndPreference::UseARA useARA);
  92. void changeListenerCallback (ChangeBroadcaster*) override;
  93. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginGraph)
  94. };