VCV Rack API v2
Loading...
Searching...
No Matches
ModuleWidget.hpp
Go to the documentation of this file.
1#pragma once
2#include <app/common.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#include <history.hpp>
10
11
12namespace rack {
13namespace app {
14
15
18 struct Internal;
19 Internal* internal;
20
24 engine::Module* module = NULL;
25
31
35
39 template <class TModule>
40 TModule* getModule() {
41 return dynamic_cast<TModule*>(getModule());
42 }
47
53 void setPanel(std::shared_ptr<window::Svg> svg);
54
59 void addParam(ParamWidget* param);
60 void addInput(PortWidget* input);
61 void addOutput(PortWidget* output);
63 ParamWidget* getParam(int paramId);
64 PortWidget* getInput(int portId);
65 PortWidget* getOutput(int portId);
67 std::vector<ParamWidget*> getParams();
68 std::vector<PortWidget*> getPorts();
69 std::vector<PortWidget*> getInputs();
70 std::vector<PortWidget*> getOutputs();
71
72 void draw(const DrawArgs& args) override;
73 void drawLayer(const DrawArgs& args, int layer) override;
74
78 virtual void appendContextMenu(ui::Menu* menu) {}
79
80 void onHover(const HoverEvent& e) override;
81 void onHoverKey(const HoverKeyEvent& e) override;
82 void onButton(const ButtonEvent& e) override;
83 void onDragStart(const DragStartEvent& e) override;
84 void onDragEnd(const DragEndEvent& e) override;
85 void onDragMove(const DragMoveEvent& e) override;
86 void onDragHover(const DragHoverEvent& e) override;
87
88 json_t* toJson();
89 void fromJson(json_t* rootJ);
91 bool pasteJsonAction(json_t* rootJ);
94 void load(std::string filename);
95 void loadAction(std::string filename);
97 void loadDialog();
98 void save(std::string filename);
105
110
121 void cloneAction(bool cloneCables = true);
122 void bypassAction(bool bypassed);
126
127 // Returns the rack position in grid coordinates
132
136};
137
138
139} // namespace app
140} // namespace rack
#define PRIVATE
Attribute for private functions not intended to be called by plugins.
Definition common.hpp:32
#define DEPRECATED
Attribute for deprecated functions and symbols.
Definition common.hpp:26
const char * filename
Definition logger.hpp:41
Root namespace for the Rack API.
Definition AudioDisplay.hpp:9
Manages an engine::Module in the rack.
Definition ModuleWidget.hpp:17
Internal * internal
Definition ModuleWidget.hpp:19
PRIVATE bool & dragEnabled()
PortWidget * getOutput(int portId)
PRIVATE math::Vec & dragOffset()
void addParam(ParamWidget *param)
Convenience functions for adding special widgets.
void onDragStart(const DragStartEvent &e) override
std::vector< ParamWidget * > getParams()
Scans children widgets recursively for all ParamWidgets.
void disconnect()
Disconnects cables from all ports Called when the user clicks Disconnect Cables in the context menu.
void onHover(const HoverEvent &e) override
void bypassAction(bool bypassed)
PortWidget * getInput(int portId)
std::vector< PortWidget * > getInputs()
void draw(const DrawArgs &args) override
Draws the widget to the NanoVG context.
PRIVATE engine::Module * releaseModule()
void onButton(const ButtonEvent &e) override
engine::Module * getModule()
Returns Module attached to this ModuleWidget.
void appendDisconnectActions(history::ComplexAction *complexAction)
void setGridPosition(math::Vec pos)
void drawLayer(const DrawArgs &args, int layer) override
Draw additional layers.
void onHoverKey(const HoverKeyEvent &e) override
void save(std::string filename)
ParamWidget * getParam(int paramId)
Scans children widgets recursively for a ParamWidget with the given paramId.
void addOutput(PortWidget *output)
plugin::Model * model
Not owned.
Definition ModuleWidget.hpp:22
void load(std::string filename)
virtual void appendContextMenu(ui::Menu *menu)
Override to add context menu entries to your subclass.
Definition ModuleWidget.hpp:78
void removeAction()
Deletes this
widget::Widget * getPanel()
void fromJson(json_t *rootJ)
std::vector< PortWidget * > getOutputs()
void randomizeAction()
Randomizes the parameters of the module and calls the Module's randomize().
void setPanel(widget::Widget *panel)
Sets the panel and sets the size of the ModuleWidget from the panel.
void resetAction()
Resets the parameters of the module and calls the Module's randomize().
std::vector< PortWidget * > getPorts()
void addInput(PortWidget *input)
void setModule(engine::Module *module)
Associates this ModuleWidget with the Module.
DEPRECATED ModuleWidget(engine::Module *module)
Definition ModuleWidget.hpp:27
void onDragHover(const DragHoverEvent &e) override
void setModel(plugin::Model *model)
void setPanel(std::shared_ptr< window::Svg > svg)
TModule * getModule()
Returns Module attached to this ModuleWidget, casted to the given Module type.
Definition ModuleWidget.hpp:40
void onDragEnd(const DragEndEvent &e) override
math::Vec getGridPosition()
void onDragMove(const DragMoveEvent &e) override
plugin::Model * getModel()
Returns the Model instance of this ModuleWidget.
bool pasteJsonAction(json_t *rootJ)
Returns whether paste was successful.
void cloneAction(bool cloneCables=true)
void loadAction(std::string filename)
Manages an engine::Param on a ModuleWidget.
Definition ParamWidget.hpp:14
Manages an engine::Port on a ModuleWidget.
Definition PortWidget.hpp:14
DSP processor instance for your module.
Definition Module.hpp:29
Batches multiple actions into one.
Definition history.hpp:52
2-dimensional rectangle for graphics.
Definition math.hpp:301
2-dimensional vector of floats, representing a point on the plane for graphics.
Definition math.hpp:189
Type information for a module.
Definition Model.hpp:34
Definition Menu.hpp:11
A Widget that stops propagation of all recursive PositionEvents (such as ButtonEvent) but gives a cha...
Definition OpaqueWidget.hpp:12
Occurs each mouse button press or release.
Definition Widget.hpp:237
Occurs when a Widget stops being dragged by releasing the mouse button.
Definition Widget.hpp:375
Occurs every frame when the mouse is hovering over a Widget while another Widget (possibly the same o...
Definition Widget.hpp:391
Occurs every frame on the dragged Widget.
Definition Widget.hpp:381
Occurs when a Widget begins being dragged.
Definition Widget.hpp:369
Definition Widget.hpp:141
Occurs every frame when the mouse is hovering over a Widget.
Definition Widget.hpp:225
Occurs when a key is pressed, released, or repeated while the mouse is hovering a Widget.
Definition Widget.hpp:294
A node in the 2D scene graph.
Definition Widget.hpp:21