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.

172 lines
5.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. #include "FilterGraph.h"
  21. struct FilterComponent;
  22. struct ConnectorComponent;
  23. struct PinComponent;
  24. //==============================================================================
  25. /**
  26. A panel that displays and edits a FilterGraph.
  27. */
  28. class GraphEditorPanel : public Component,
  29. public ChangeListener
  30. {
  31. public:
  32. GraphEditorPanel (FilterGraph& graph);
  33. ~GraphEditorPanel();
  34. void paint (Graphics& g);
  35. void mouseDown (const MouseEvent& e);
  36. void createNewPlugin (const PluginDescription&, Point<int> position);
  37. FilterComponent* getComponentForFilter (uint32 filterID) const;
  38. ConnectorComponent* getComponentForConnection (const AudioProcessorGraph::Connection& conn) const;
  39. PinComponent* findPinAt (Point<float>) const;
  40. void resized();
  41. void changeListenerCallback (ChangeBroadcaster*);
  42. void updateComponents();
  43. //==============================================================================
  44. void beginConnectorDrag (uint32 sourceFilterID, int sourceFilterChannel,
  45. uint32 destFilterID, int destFilterChannel,
  46. const MouseEvent& e);
  47. void dragConnector (const MouseEvent& e);
  48. void endDraggingConnector (const MouseEvent& e);
  49. //==============================================================================
  50. private:
  51. FilterGraph& graph;
  52. ScopedPointer<ConnectorComponent> draggingConnector;
  53. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GraphEditorPanel)
  54. };
  55. //==============================================================================
  56. /**
  57. A panel that embeds a GraphEditorPanel with a midi keyboard at the bottom.
  58. It also manages the graph itself, and plays it.
  59. */
  60. class GraphDocumentComponent : public Component
  61. {
  62. public:
  63. //==============================================================================
  64. GraphDocumentComponent (AudioPluginFormatManager& formatManager,
  65. AudioDeviceManager& deviceManager);
  66. ~GraphDocumentComponent();
  67. //==============================================================================
  68. void createNewPlugin (const PluginDescription&, Point<int> position);
  69. void setDoublePrecision (bool doublePrecision);
  70. //==============================================================================
  71. ScopedPointer<FilterGraph> graph;
  72. //==============================================================================
  73. void resized();
  74. //==============================================================================
  75. void unfocusKeyboardComponent();
  76. //==============================================================================
  77. void releaseGraph();
  78. private:
  79. //==============================================================================
  80. AudioDeviceManager& deviceManager;
  81. AudioProcessorPlayer graphPlayer;
  82. MidiKeyboardState keyState;
  83. public:
  84. GraphEditorPanel* graphPanel;
  85. private:
  86. Component* keyboardComp;
  87. Component* statusBar;
  88. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GraphDocumentComponent)
  89. };
  90. //==============================================================================
  91. /** A desktop window containing a plugin's UI. */
  92. class PluginWindow : public DocumentWindow
  93. {
  94. public:
  95. enum WindowFormatType
  96. {
  97. Normal = 0,
  98. Generic,
  99. Programs,
  100. Parameters,
  101. AudioIO,
  102. NumTypes
  103. };
  104. PluginWindow (AudioProcessorEditor*, AudioProcessorGraph::Node*, WindowFormatType);
  105. ~PluginWindow();
  106. static PluginWindow* getWindowFor (AudioProcessorGraph::Node*, WindowFormatType);
  107. static void closeCurrentlyOpenWindowsFor (const uint32 nodeId);
  108. static void closeAllCurrentlyOpenWindows();
  109. void moved() override;
  110. void closeButtonPressed() override;
  111. private:
  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); }