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. #pragma once
  18. #include "FilterGraph.h"
  19. class FilterComponent;
  20. class ConnectorComponent;
  21. class PinComponent;
  22. //==============================================================================
  23. /**
  24. A panel that displays and edits a FilterGraph.
  25. */
  26. class GraphEditorPanel : public Component,
  27. public ChangeListener
  28. {
  29. public:
  30. GraphEditorPanel (FilterGraph& graph);
  31. ~GraphEditorPanel();
  32. void paint (Graphics& g);
  33. void mouseDown (const MouseEvent& e);
  34. void createNewPlugin (const PluginDescription* desc, int x, int y);
  35. FilterComponent* getComponentForFilter (uint32 filterID) const;
  36. ConnectorComponent* getComponentForConnection (const AudioProcessorGraph::Connection& conn) const;
  37. PinComponent* findPinAt (int x, int y) const;
  38. void resized();
  39. void changeListenerCallback (ChangeBroadcaster*);
  40. void updateComponents();
  41. //==============================================================================
  42. void beginConnectorDrag (uint32 sourceFilterID, int sourceFilterChannel,
  43. uint32 destFilterID, int destFilterChannel,
  44. const MouseEvent& e);
  45. void dragConnector (const MouseEvent& e);
  46. void endDraggingConnector (const MouseEvent& e);
  47. //==============================================================================
  48. private:
  49. FilterGraph& graph;
  50. ScopedPointer<ConnectorComponent> draggingConnector;
  51. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GraphEditorPanel)
  52. };
  53. //==============================================================================
  54. /**
  55. A panel that embeds a GraphEditorPanel with a midi keyboard at the bottom.
  56. It also manages the graph itself, and plays it.
  57. */
  58. class GraphDocumentComponent : public Component
  59. {
  60. public:
  61. //==============================================================================
  62. GraphDocumentComponent (AudioPluginFormatManager& formatManager,
  63. AudioDeviceManager* deviceManager);
  64. ~GraphDocumentComponent();
  65. //==============================================================================
  66. void createNewPlugin (const PluginDescription* desc, int x, int y);
  67. inline void setDoublePrecision (bool doublePrecision) { graphPlayer.setDoublePrecisionProcessing (doublePrecision); }
  68. //==============================================================================
  69. ScopedPointer<FilterGraph> graph;
  70. //==============================================================================
  71. void resized();
  72. //==============================================================================
  73. void unfocusKeyboardComponent();
  74. //==============================================================================
  75. void releaseGraph();
  76. private:
  77. //==============================================================================
  78. AudioDeviceManager* deviceManager;
  79. AudioProcessorPlayer graphPlayer;
  80. MidiKeyboardState keyState;
  81. public:
  82. GraphEditorPanel* graphPanel;
  83. private:
  84. Component* keyboardComp;
  85. Component* statusBar;
  86. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GraphDocumentComponent)
  87. };
  88. //==============================================================================
  89. /** A desktop window containing a plugin's UI. */
  90. class PluginWindow : public DocumentWindow
  91. {
  92. public:
  93. enum WindowFormatType
  94. {
  95. Normal = 0,
  96. Generic,
  97. Programs,
  98. Parameters,
  99. AudioIO,
  100. NumTypes
  101. };
  102. PluginWindow (Component* pluginEditor, AudioProcessorGraph::Node*, WindowFormatType);
  103. ~PluginWindow();
  104. static PluginWindow* getWindowFor (AudioProcessorGraph::Node*, WindowFormatType);
  105. static void closeCurrentlyOpenWindowsFor (const uint32 nodeId);
  106. static void closeAllCurrentlyOpenWindows();
  107. void moved() override;
  108. void closeButtonPressed() override;
  109. private:
  110. AudioProcessorGraph::Node* owner;
  111. WindowFormatType type;
  112. float getDesktopScaleFactor() const override { return 1.0f; }
  113. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginWindow)
  114. };
  115. inline String toString (PluginWindow::WindowFormatType type)
  116. {
  117. switch (type)
  118. {
  119. case PluginWindow::Normal: return "Normal";
  120. case PluginWindow::Generic: return "Generic";
  121. case PluginWindow::Programs: return "Programs";
  122. case PluginWindow::Parameters: return "Parameters";
  123. default: return String();
  124. }
  125. }
  126. inline String getLastXProp (PluginWindow::WindowFormatType type) { return "uiLastX_" + toString (type); }
  127. inline String getLastYProp (PluginWindow::WindowFormatType type) { return "uiLastY_" + toString (type); }
  128. inline String getOpenProp (PluginWindow::WindowFormatType type) { return "uiopen_" + toString (type); }