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.

101 lines
2.8KB

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