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.

ModuleWidget.hpp 2.7KB

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