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
3.5KB

  1. #pragma once
  2. #include <app/common.hpp>
  3. #include <widget/OpaqueWidget.hpp>
  4. #include <ui/Menu.hpp>
  5. #include <app/PortWidget.hpp>
  6. #include <app/ParamWidget.hpp>
  7. #include <plugin/Model.hpp>
  8. #include <engine/Module.hpp>
  9. #include <history.hpp>
  10. #include <list>
  11. namespace rack {
  12. namespace app {
  13. /** Manages an engine::Module in the rack. */
  14. struct ModuleWidget : widget::OpaqueWidget {
  15. struct Internal;
  16. Internal* internal;
  17. plugin::Model* model = NULL;
  18. /** Owned */
  19. engine::Module* module = NULL;
  20. ModuleWidget();
  21. DEPRECATED ModuleWidget(engine::Module* module) : ModuleWidget() {
  22. setModule(module);
  23. }
  24. ~ModuleWidget();
  25. plugin::Model* getModel();
  26. void setModel(plugin::Model* model);
  27. engine::Module* getModule();
  28. /** Associates this ModuleWidget with the Module.
  29. Transfers ownership.
  30. */
  31. void setModule(engine::Module* module);
  32. /** Sets the panel and sets the size of the ModuleWidget from the panel.
  33. Transfers ownership.
  34. */
  35. void setPanel(widget::Widget* panel);
  36. /** Use `setPanel(createPanel(svg))` instead. */
  37. void setPanel(std::shared_ptr<Svg> svg);
  38. /** Convenience functions for adding special widgets.
  39. Just calls addChild() with additional checking.
  40. It is not required to call this method. You may instead use addChild() in a child widget for example.
  41. */
  42. void addParam(ParamWidget* param);
  43. void addInput(PortWidget* input);
  44. void addOutput(PortWidget* output);
  45. /** Scans children widgets recursively for a ParamWidget with the given paramId. */
  46. ParamWidget* getParam(int paramId);
  47. PortWidget* getInput(int portId);
  48. PortWidget* getOutput(int portId);
  49. /** Scans children widgets recursively for all ParamWidgets. */
  50. std::list<ParamWidget*> getParams();
  51. std::list<PortWidget*> getPorts();
  52. std::list<PortWidget*> getInputs();
  53. std::list<PortWidget*> getOutputs();
  54. void draw(const DrawArgs& args) override;
  55. void drawShadow(const DrawArgs& args);
  56. /** Override to add context menu entries to your subclass.
  57. It is recommended to add a blank `ui::MenuSeparator` first for spacing.
  58. */
  59. virtual void appendContextMenu(ui::Menu* menu) {}
  60. void onHoverKey(const HoverKeyEvent& e) override;
  61. void onButton(const ButtonEvent& e) override;
  62. void onDragStart(const DragStartEvent& e) override;
  63. void onDragEnd(const DragEndEvent& e) override;
  64. void onDragMove(const DragMoveEvent& e) override;
  65. json_t* toJson();
  66. void fromJson(json_t* rootJ);
  67. void copyClipboard();
  68. void pasteClipboardAction();
  69. void load(std::string filename);
  70. void loadAction(std::string filename);
  71. void loadTemplate();
  72. void loadDialog();
  73. void save(std::string filename);
  74. void saveTemplate();
  75. void saveTemplateDialog();
  76. bool hasTemplate();
  77. void clearTemplate();
  78. void clearTemplateDialog();
  79. void saveDialog();
  80. /** Disconnects cables from all ports
  81. Called when the user clicks Disconnect Cables in the context menu.
  82. */
  83. void disconnect();
  84. /** Resets the parameters of the module and calls the Module's randomize().
  85. Called when the user clicks Initialize in the context menu.
  86. */
  87. void resetAction();
  88. /** Randomizes the parameters of the module and calls the Module's randomize().
  89. Called when the user clicks Randomize in the context menu.
  90. */
  91. void randomizeAction();
  92. void appendDisconnectActions(history::ComplexAction* complexAction);
  93. void disconnectAction();
  94. void cloneAction();
  95. void bypassAction(bool bypassed);
  96. /** Deletes `this` */
  97. void removeAction();
  98. void createContextMenu();
  99. INTERNAL math::Vec& dragOffset();
  100. INTERNAL bool& dragEnabled();
  101. INTERNAL math::Vec& oldPos();
  102. INTERNAL engine::Module* releaseModule();
  103. INTERNAL bool& selected();
  104. };
  105. } // namespace app
  106. } // namespace rack