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.

170 lines
5.8KB

  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. GraphEditorPanel* graphPanel;
  83. Component* keyboardComp;
  84. Component* statusBar;
  85. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GraphDocumentComponent)
  86. };
  87. //==============================================================================
  88. /** A desktop window containing a plugin's UI. */
  89. class PluginWindow : public DocumentWindow
  90. {
  91. public:
  92. enum WindowFormatType
  93. {
  94. Normal = 0,
  95. Generic,
  96. Programs,
  97. Parameters,
  98. NumTypes
  99. };
  100. PluginWindow (Component* pluginEditor, AudioProcessorGraph::Node*, WindowFormatType);
  101. ~PluginWindow();
  102. static PluginWindow* getWindowFor (AudioProcessorGraph::Node*, WindowFormatType);
  103. static void closeCurrentlyOpenWindowsFor (const uint32 nodeId);
  104. static void closeAllCurrentlyOpenWindows();
  105. void moved() override;
  106. void closeButtonPressed() override;
  107. private:
  108. AudioProcessorGraph::Node* owner;
  109. WindowFormatType type;
  110. float getDesktopScaleFactor() const override { return 1.0f; }
  111. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginWindow)
  112. };
  113. inline String toString (PluginWindow::WindowFormatType type)
  114. {
  115. switch (type)
  116. {
  117. case PluginWindow::Normal: return "Normal";
  118. case PluginWindow::Generic: return "Generic";
  119. case PluginWindow::Programs: return "Programs";
  120. case PluginWindow::Parameters: return "Parameters";
  121. default: return String();
  122. }
  123. }
  124. inline String getLastXProp (PluginWindow::WindowFormatType type) { return "uiLastX_" + toString (type); }
  125. inline String getLastYProp (PluginWindow::WindowFormatType type) { return "uiLastY_" + toString (type); }
  126. inline String getOpenProp (PluginWindow::WindowFormatType type) { return "uiopen_" + toString (type); }
  127. #endif // __GRAPHEDITORPANEL_JUCEHEADER__