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.

119 lines
3.2KB

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