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.

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