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.

98 lines
2.7KB

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