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.

111 lines
3.1KB

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