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.

102 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. /** 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*> 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) : 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. /** Overriding these is deprecated.
  50. Use Module::dataToJson() and dataFromJson() instead
  51. */
  52. virtual json_t* toJson();
  53. virtual void fromJson(json_t* rootJ);
  54. /** Serializes/unserializes the module state */
  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. };
  84. } // namespace app
  85. } // namespace rack