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.

128 lines
3.6KB

  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 onHover(const HoverEvent& e) override;
  61. void onHoverKey(const HoverKeyEvent& e) override;
  62. void onButton(const ButtonEvent& e) override;
  63. void onDragStart(const DragStartEvent& e) override;
  64. void onDragEnd(const DragEndEvent& e) override;
  65. void onDragMove(const DragMoveEvent& e) override;
  66. void onDragHover(const DragHoverEvent& e) override;
  67. json_t* toJson();
  68. void fromJson(json_t* rootJ);
  69. void copyClipboard();
  70. void pasteClipboardAction();
  71. void load(std::string filename);
  72. void loadAction(std::string filename);
  73. void loadTemplate();
  74. void loadDialog();
  75. void save(std::string filename);
  76. void saveTemplate();
  77. void saveTemplateDialog();
  78. bool hasTemplate();
  79. void clearTemplate();
  80. void clearTemplateDialog();
  81. void saveDialog();
  82. /** Disconnects cables from all ports
  83. Called when the user clicks Disconnect Cables in the context menu.
  84. */
  85. void disconnect();
  86. /** Resets the parameters of the module and calls the Module's randomize().
  87. Called when the user clicks Initialize in the context menu.
  88. */
  89. void resetAction();
  90. /** Randomizes the parameters of the module and calls the Module's randomize().
  91. Called when the user clicks Randomize in the context menu.
  92. */
  93. void randomizeAction();
  94. void appendDisconnectActions(history::ComplexAction* complexAction);
  95. void disconnectAction();
  96. void cloneAction();
  97. void bypassAction(bool bypassed);
  98. /** Deletes `this` */
  99. void removeAction();
  100. void createContextMenu();
  101. INTERNAL math::Vec& dragOffset();
  102. INTERNAL bool& dragEnabled();
  103. INTERNAL math::Vec& oldPos();
  104. INTERNAL engine::Module* releaseModule();
  105. INTERNAL bool& selected();
  106. };
  107. } // namespace app
  108. } // namespace rack