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.

105 lines
2.9KB

  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 loadAction(std::string filename);
  58. void save(std::string filename);
  59. void loadDialog();
  60. void saveDialog();
  61. /** Disconnects cables from all ports
  62. Called when the user clicks Disconnect Cables in the context menu.
  63. */
  64. void disconnect();
  65. /** Resets the parameters of the module and calls the Module's randomize().
  66. Called when the user clicks Initialize in the context menu.
  67. */
  68. void resetAction();
  69. /** Randomizes the parameters of the module and calls the Module's randomize().
  70. Called when the user clicks Randomize in the context menu.
  71. */
  72. void randomizeAction();
  73. void disconnectAction();
  74. void cloneAction();
  75. void bypassAction();
  76. /** Deletes `this` */
  77. void removeAction();
  78. void createContextMenu();
  79. /** Override to add context menu entries to your subclass.
  80. It is recommended to add a blank ui::MenuEntry first for spacing.
  81. */
  82. virtual void appendContextMenu(ui::Menu* menu) {}
  83. math::Vec& dragPos();
  84. math::Vec& oldPos();
  85. };
  86. } // namespace app
  87. } // namespace rack