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.

108 lines
3.0KB

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