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.

175 lines
6.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef __GRAPHEDITORPANEL_JUCEHEADER__
  18. #define __GRAPHEDITORPANEL_JUCEHEADER__
  19. #include "FilterGraph.h"
  20. class FilterComponent;
  21. class ConnectorComponent;
  22. class PinComponent;
  23. //==============================================================================
  24. /**
  25. A panel that displays and edits a FilterGraph.
  26. */
  27. class GraphEditorPanel : public Component,
  28. public ChangeListener
  29. {
  30. public:
  31. GraphEditorPanel (FilterGraph& graph);
  32. ~GraphEditorPanel();
  33. void paint (Graphics& g);
  34. void mouseDown (const MouseEvent& e);
  35. void createNewPlugin (const PluginDescription* desc, int x, int y);
  36. FilterComponent* getComponentForFilter (uint32 filterID) const;
  37. ConnectorComponent* getComponentForConnection (const AudioProcessorGraph::Connection& conn) const;
  38. PinComponent* findPinAt (int x, int y) const;
  39. void resized();
  40. void changeListenerCallback (ChangeBroadcaster*);
  41. void updateComponents();
  42. //==============================================================================
  43. void beginConnectorDrag (uint32 sourceFilterID, int sourceFilterChannel,
  44. uint32 destFilterID, int destFilterChannel,
  45. const MouseEvent& e);
  46. void dragConnector (const MouseEvent& e);
  47. void endDraggingConnector (const MouseEvent& e);
  48. //==============================================================================
  49. private:
  50. FilterGraph& graph;
  51. ScopedPointer<ConnectorComponent> draggingConnector;
  52. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GraphEditorPanel)
  53. };
  54. //==============================================================================
  55. /**
  56. A panel that embeds a GraphEditorPanel with a midi keyboard at the bottom.
  57. It also manages the graph itself, and plays it.
  58. */
  59. class GraphDocumentComponent : public Component
  60. {
  61. public:
  62. //==============================================================================
  63. GraphDocumentComponent (AudioPluginFormatManager& formatManager,
  64. AudioDeviceManager* deviceManager);
  65. ~GraphDocumentComponent();
  66. //==============================================================================
  67. void createNewPlugin (const PluginDescription* desc, int x, int y);
  68. inline void setDoublePrecision (bool doublePrecision) { graphPlayer.setDoublePrecisionProcessing (doublePrecision); }
  69. //==============================================================================
  70. ScopedPointer<FilterGraph> graph;
  71. //==============================================================================
  72. void resized();
  73. //==============================================================================
  74. void unfocusKeyboardComponent();
  75. //==============================================================================
  76. void releaseGraph();
  77. private:
  78. //==============================================================================
  79. AudioDeviceManager* deviceManager;
  80. AudioProcessorPlayer graphPlayer;
  81. MidiKeyboardState keyState;
  82. public:
  83. GraphEditorPanel* graphPanel;
  84. private:
  85. Component* keyboardComp;
  86. Component* statusBar;
  87. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GraphDocumentComponent)
  88. };
  89. //==============================================================================
  90. /** A desktop window containing a plugin's UI. */
  91. class PluginWindow : public DocumentWindow
  92. {
  93. public:
  94. enum WindowFormatType
  95. {
  96. Normal = 0,
  97. Generic,
  98. Programs,
  99. Parameters,
  100. AudioIO,
  101. NumTypes
  102. };
  103. PluginWindow (Component* pluginEditor, AudioProcessorGraph::Node*, WindowFormatType, AudioProcessorGraph&);
  104. ~PluginWindow();
  105. static PluginWindow* getWindowFor (AudioProcessorGraph::Node*, WindowFormatType, AudioProcessorGraph&);
  106. static void closeCurrentlyOpenWindowsFor (const uint32 nodeId);
  107. static void closeAllCurrentlyOpenWindows();
  108. void moved() override;
  109. void closeButtonPressed() override;
  110. private:
  111. AudioProcessorGraph& graph;
  112. AudioProcessorGraph::Node* owner;
  113. WindowFormatType type;
  114. float getDesktopScaleFactor() const override { return 1.0f; }
  115. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginWindow)
  116. };
  117. inline String toString (PluginWindow::WindowFormatType type)
  118. {
  119. switch (type)
  120. {
  121. case PluginWindow::Normal: return "Normal";
  122. case PluginWindow::Generic: return "Generic";
  123. case PluginWindow::Programs: return "Programs";
  124. case PluginWindow::Parameters: return "Parameters";
  125. default: return String();
  126. }
  127. }
  128. inline String getLastXProp (PluginWindow::WindowFormatType type) { return "uiLastX_" + toString (type); }
  129. inline String getLastYProp (PluginWindow::WindowFormatType type) { return "uiLastY_" + toString (type); }
  130. inline String getOpenProp (PluginWindow::WindowFormatType type) { return "uiopen_" + toString (type); }
  131. #endif // __GRAPHEDITORPANEL_JUCEHEADER__