@@ -2,7 +2,7 @@ | |||||
#include "app/common.hpp" | #include "app/common.hpp" | ||||
#include "widgets/OpaqueWidget.hpp" | #include "widgets/OpaqueWidget.hpp" | ||||
#include "ui/Menu.hpp" | #include "ui/Menu.hpp" | ||||
#include "app/Port.hpp" | |||||
#include "app/PortWidget.hpp" | |||||
#include "app/ParamWidget.hpp" | #include "app/ParamWidget.hpp" | ||||
#include "plugin/Model.hpp" | #include "plugin/Model.hpp" | ||||
#include "engine/Module.hpp" | #include "engine/Module.hpp" | ||||
@@ -18,14 +18,14 @@ struct ModuleWidget : OpaqueWidget { | |||||
Widget *panel = NULL; | Widget *panel = NULL; | ||||
std::vector<ParamWidget*> params; | std::vector<ParamWidget*> params; | ||||
std::vector<Port*> inputs; | |||||
std::vector<Port*> outputs; | |||||
std::vector<PortWidget*> inputs; | |||||
std::vector<PortWidget*> outputs; | |||||
ModuleWidget(Module *module); | ModuleWidget(Module *module); | ||||
~ModuleWidget(); | ~ModuleWidget(); | ||||
/** Convenience functions for adding special widgets (calls addChild()) */ | /** Convenience functions for adding special widgets (calls addChild()) */ | ||||
void addInput(Port *input); | |||||
void addOutput(Port *output); | |||||
void addInput(PortWidget *input); | |||||
void addOutput(PortWidget *output); | |||||
void addParam(ParamWidget *param); | void addParam(ParamWidget *param); | ||||
void setPanel(std::shared_ptr<SVG> svg); | void setPanel(std::shared_ptr<SVG> svg); | ||||
@@ -8,7 +8,7 @@ | |||||
namespace rack { | namespace rack { | ||||
struct Port : OpaqueWidget { | |||||
struct PortWidget : OpaqueWidget { | |||||
Module *module = NULL; | Module *module = NULL; | ||||
int portId; | int portId; | ||||
@@ -19,8 +19,8 @@ struct Port : OpaqueWidget { | |||||
PortType type = INPUT; | PortType type = INPUT; | ||||
MultiLightWidget *plugLight; | MultiLightWidget *plugLight; | ||||
Port(); | |||||
~Port(); | |||||
PortWidget(); | |||||
~PortWidget(); | |||||
void step() override; | void step() override; | ||||
void draw(NVGcontext *vg) override; | void draw(NVGcontext *vg) override; | ||||
void onButton(event::Button &e) override; | void onButton(event::Button &e) override; |
@@ -1,6 +1,6 @@ | |||||
#pragma once | #pragma once | ||||
#include "app/common.hpp" | #include "app/common.hpp" | ||||
#include "app/Port.hpp" | |||||
#include "app/PortWidget.hpp" | |||||
#include "widgets/FramebufferWidget.hpp" | #include "widgets/FramebufferWidget.hpp" | ||||
#include "widgets/SVGWidget.hpp" | #include "widgets/SVGWidget.hpp" | ||||
#include "app/CircularShadow.hpp" | #include "app/CircularShadow.hpp" | ||||
@@ -9,7 +9,7 @@ | |||||
namespace rack { | namespace rack { | ||||
struct SVGPort : Port, FramebufferWidget { | |||||
struct SVGPort : PortWidget, FramebufferWidget { | |||||
SVGWidget *background; | SVGWidget *background; | ||||
CircularShadow *shadow; | CircularShadow *shadow; | ||||
@@ -1,6 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | #include "common.hpp" | ||||
#include "app/Port.hpp" | |||||
#include "widgets/FramebufferWidget.hpp" | #include "widgets/FramebufferWidget.hpp" | ||||
#include "widgets/SVGWidget.hpp" | #include "widgets/SVGWidget.hpp" | ||||
@@ -2,7 +2,7 @@ | |||||
#include "app/common.hpp" | #include "app/common.hpp" | ||||
#include "widgets/TransparentWidget.hpp" | #include "widgets/TransparentWidget.hpp" | ||||
#include "app/WireWidget.hpp" | #include "app/WireWidget.hpp" | ||||
#include "app/Port.hpp" | |||||
#include "app/PortWidget.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -14,10 +14,10 @@ struct WireContainer : TransparentWidget { | |||||
void setActiveWire(WireWidget *w); | void setActiveWire(WireWidget *w); | ||||
/** "Drops" the wire onto the port, making an engine connection if successful */ | /** "Drops" the wire onto the port, making an engine connection if successful */ | ||||
void commitActiveWire(); | void commitActiveWire(); | ||||
void removeTopWire(Port *port); | |||||
void removeAllWires(Port *port); | |||||
void removeTopWire(PortWidget *port); | |||||
void removeAllWires(PortWidget *port); | |||||
/** Returns the most recently added wire connected to the given Port, i.e. the top of the stack */ | /** Returns the most recently added wire connected to the given Port, i.e. the top of the stack */ | ||||
WireWidget *getTopWire(Port *port); | |||||
WireWidget *getTopWire(PortWidget *port); | |||||
void draw(NVGcontext *vg) override; | void draw(NVGcontext *vg) override; | ||||
}; | }; | ||||
@@ -1,21 +1,18 @@ | |||||
#pragma once | #pragma once | ||||
#include "app/common.hpp" | #include "app/common.hpp" | ||||
#include "widgets/OpaqueWidget.hpp" | #include "widgets/OpaqueWidget.hpp" | ||||
#include "app/Port.hpp" | |||||
#include "app/PortWidget.hpp" | |||||
#include "engine/Wire.hpp" | #include "engine/Wire.hpp" | ||||
namespace rack { | namespace rack { | ||||
struct Port; | |||||
struct WireWidget : OpaqueWidget { | struct WireWidget : OpaqueWidget { | ||||
Port *outputPort = NULL; | |||||
Port *inputPort = NULL; | |||||
Port *hoveredOutputPort = NULL; | |||||
Port *hoveredInputPort = NULL; | |||||
PortWidget *outputPort = NULL; | |||||
PortWidget *inputPort = NULL; | |||||
PortWidget *hoveredOutputPort = NULL; | |||||
PortWidget *hoveredInputPort = NULL; | |||||
Wire *wire = NULL; | Wire *wire = NULL; | ||||
NVGcolor color; | NVGcolor color; | ||||
@@ -2,7 +2,7 @@ | |||||
#include "ui/MenuLabel.hpp" | #include "ui/MenuLabel.hpp" | ||||
#include "ui/MenuItem.hpp" | #include "ui/MenuItem.hpp" | ||||
#include "ui/Menu.hpp" | #include "ui/Menu.hpp" | ||||
#include "app/Port.hpp" | |||||
#include "app/PortWidget.hpp" | |||||
#include "app/ParamQuantity.hpp" | #include "app/ParamQuantity.hpp" | ||||
#include "app/ParamWidget.hpp" | #include "app/ParamWidget.hpp" | ||||
#include "app/Scene.hpp" | #include "app/Scene.hpp" | ||||
@@ -75,42 +75,42 @@ TParamWidget *createParamCentered(math::Vec pos, Module *module, int paramId) { | |||||
return o; | return o; | ||||
} | } | ||||
template <class TPort> | |||||
TPort *createInput(math::Vec pos, Module *module, int inputId) { | |||||
TPort *o = new TPort; | |||||
template <class TPortWidget> | |||||
TPortWidget *createInput(math::Vec pos, Module *module, int inputId) { | |||||
TPortWidget *o = new TPortWidget; | |||||
o->box.pos = pos; | o->box.pos = pos; | ||||
o->module = module; | o->module = module; | ||||
o->type = Port::INPUT; | |||||
o->type = PortWidget::INPUT; | |||||
o->portId = inputId; | o->portId = inputId; | ||||
return o; | return o; | ||||
} | } | ||||
template <class TPort> | |||||
TPort *createInputCentered(math::Vec pos, Module *module, int inputId) { | |||||
TPort *o = new TPort; | |||||
template <class TPortWidget> | |||||
TPortWidget *createInputCentered(math::Vec pos, Module *module, int inputId) { | |||||
TPortWidget *o = new TPortWidget; | |||||
o->box.pos = pos.minus(o->box.size.div(2)); | o->box.pos = pos.minus(o->box.size.div(2)); | ||||
o->module = module; | o->module = module; | ||||
o->type = Port::INPUT; | |||||
o->type = PortWidget::INPUT; | |||||
o->portId = inputId; | o->portId = inputId; | ||||
return o; | return o; | ||||
} | } | ||||
template <class TPort> | |||||
TPort *createOutput(math::Vec pos, Module *module, int outputId) { | |||||
TPort *o = new TPort; | |||||
template <class TPortWidget> | |||||
TPortWidget *createOutput(math::Vec pos, Module *module, int outputId) { | |||||
TPortWidget *o = new TPortWidget; | |||||
o->box.pos = pos; | o->box.pos = pos; | ||||
o->module = module; | o->module = module; | ||||
o->type = Port::OUTPUT; | |||||
o->type = PortWidget::OUTPUT; | |||||
o->portId = outputId; | o->portId = outputId; | ||||
return o; | return o; | ||||
} | } | ||||
template <class TPort> | |||||
TPort *createOutputCentered(math::Vec pos, Module *module, int outputId) { | |||||
TPort *o = new TPort; | |||||
template <class TPortWidget> | |||||
TPortWidget *createOutputCentered(math::Vec pos, Module *module, int outputId) { | |||||
TPortWidget *o = new TPortWidget; | |||||
o->box.pos = pos.minus(o->box.size.div(2)); | o->box.pos = pos.minus(o->box.size.div(2)); | ||||
o->module = module; | o->module = module; | ||||
o->type = Port::OUTPUT; | |||||
o->type = PortWidget::OUTPUT; | |||||
o->portId = outputId; | o->portId = outputId; | ||||
return o; | return o; | ||||
} | } | ||||
@@ -51,7 +51,7 @@ | |||||
#include "app/MomentarySwitch.hpp" | #include "app/MomentarySwitch.hpp" | ||||
#include "app/MultiLightWidget.hpp" | #include "app/MultiLightWidget.hpp" | ||||
#include "app/ParamWidget.hpp" | #include "app/ParamWidget.hpp" | ||||
#include "app/Port.hpp" | |||||
#include "app/PortWidget.hpp" | |||||
#include "app/RackRail.hpp" | #include "app/RackRail.hpp" | ||||
#include "app/Scene.hpp" | #include "app/Scene.hpp" | ||||
#include "app/RackScrollWidget.hpp" | #include "app/RackScrollWidget.hpp" | ||||
@@ -32,14 +32,14 @@ ModuleWidget::~ModuleWidget() { | |||||
} | } | ||||
} | } | ||||
void ModuleWidget::addInput(Port *input) { | |||||
assert(input->type == Port::INPUT); | |||||
void ModuleWidget::addInput(PortWidget *input) { | |||||
assert(input->type == PortWidget::INPUT); | |||||
inputs.push_back(input); | inputs.push_back(input); | ||||
addChild(input); | addChild(input); | ||||
} | } | ||||
void ModuleWidget::addOutput(Port *output) { | |||||
assert(output->type == Port::OUTPUT); | |||||
void ModuleWidget::addOutput(PortWidget *output) { | |||||
assert(output->type == PortWidget::OUTPUT); | |||||
outputs.push_back(output); | outputs.push_back(output); | ||||
addChild(output); | addChild(output); | ||||
} | } | ||||
@@ -251,10 +251,10 @@ void ModuleWidget::saveDialog() { | |||||
} | } | ||||
void ModuleWidget::disconnect() { | void ModuleWidget::disconnect() { | ||||
for (Port *input : inputs) { | |||||
for (PortWidget *input : inputs) { | |||||
context()->scene->rackWidget->wireContainer->removeAllWires(input); | context()->scene->rackWidget->wireContainer->removeAllWires(input); | ||||
} | } | ||||
for (Port *output : outputs) { | |||||
for (PortWidget *output : outputs) { | |||||
context()->scene->rackWidget->wireContainer->removeAllWires(output); | context()->scene->rackWidget->wireContainer->removeAllWires(output); | ||||
} | } | ||||
} | } | ||||
@@ -1,4 +1,4 @@ | |||||
#include "app/Port.hpp" | |||||
#include "app/PortWidget.hpp" | |||||
#include "app/Scene.hpp" | #include "app/Scene.hpp" | ||||
#include "window.hpp" | #include "window.hpp" | ||||
#include "context.hpp" | #include "context.hpp" | ||||
@@ -18,17 +18,17 @@ struct PlugLight : MultiLightWidget { | |||||
}; | }; | ||||
Port::Port() { | |||||
PortWidget::PortWidget() { | |||||
plugLight = new PlugLight; | plugLight = new PlugLight; | ||||
} | } | ||||
Port::~Port() { | |||||
// plugLight is not a child and is thus owned by the Port, so we need to delete it here | |||||
PortWidget::~PortWidget() { | |||||
// plugLight is not a child and is thus owned by the PortWidget, so we need to delete it here | |||||
delete plugLight; | delete plugLight; | ||||
context()->scene->rackWidget->wireContainer->removeAllWires(this); | context()->scene->rackWidget->wireContainer->removeAllWires(this); | ||||
} | } | ||||
void Port::step() { | |||||
void PortWidget::step() { | |||||
std::vector<float> values(2); | std::vector<float> values(2); | ||||
if (type == INPUT) { | if (type == INPUT) { | ||||
values[0] = module->inputs[portId].plugLights[0].getBrightness(); | values[0] = module->inputs[portId].plugLights[0].getBrightness(); | ||||
@@ -41,28 +41,28 @@ void Port::step() { | |||||
plugLight->setValues(values); | plugLight->setValues(values); | ||||
} | } | ||||
void Port::draw(NVGcontext *vg) { | |||||
void PortWidget::draw(NVGcontext *vg) { | |||||
WireWidget *activeWire = context()->scene->rackWidget->wireContainer->activeWire; | WireWidget *activeWire = context()->scene->rackWidget->wireContainer->activeWire; | ||||
if (activeWire) { | if (activeWire) { | ||||
// Dim the Port if the active wire cannot plug into this Port | |||||
// Dim the PortWidget if the active wire cannot plug into this PortWidget | |||||
if (type == INPUT ? activeWire->inputPort : activeWire->outputPort) | if (type == INPUT ? activeWire->inputPort : activeWire->outputPort) | ||||
nvgGlobalAlpha(vg, 0.5); | nvgGlobalAlpha(vg, 0.5); | ||||
} | } | ||||
} | } | ||||
void Port::onButton(event::Button &e) { | |||||
void PortWidget::onButton(event::Button &e) { | |||||
if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_RIGHT) { | if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_RIGHT) { | ||||
context()->scene->rackWidget->wireContainer->removeTopWire(this); | context()->scene->rackWidget->wireContainer->removeTopWire(this); | ||||
// HACK | // HACK | ||||
// Update hovered*Port of active wire if applicable | |||||
// Update hovered*PortWidget of active wire if applicable | |||||
// event::DragEnter eDragEnter; | // event::DragEnter eDragEnter; | ||||
// onDragEnter(eDragEnter); | // onDragEnter(eDragEnter); | ||||
} | } | ||||
e.target = this; | e.target = this; | ||||
} | } | ||||
void Port::onDragStart(event::DragStart &e) { | |||||
void PortWidget::onDragStart(event::DragStart &e) { | |||||
// Try to grab wire on top of stack | // Try to grab wire on top of stack | ||||
WireWidget *wire = NULL; | WireWidget *wire = NULL; | ||||
if (type == INPUT || !context()->window->isModPressed()) { | if (type == INPUT || !context()->window->isModPressed()) { | ||||
@@ -82,14 +82,14 @@ void Port::onDragStart(event::DragStart &e) { | |||||
context()->scene->rackWidget->wireContainer->setActiveWire(wire); | context()->scene->rackWidget->wireContainer->setActiveWire(wire); | ||||
} | } | ||||
void Port::onDragEnd(event::DragEnd &e) { | |||||
void PortWidget::onDragEnd(event::DragEnd &e) { | |||||
// FIXME | // FIXME | ||||
// If the source Port is deleted, this will be called, removing the cable | |||||
// If the source PortWidget is deleted, this will be called, removing the cable | |||||
context()->scene->rackWidget->wireContainer->commitActiveWire(); | context()->scene->rackWidget->wireContainer->commitActiveWire(); | ||||
} | } | ||||
void Port::onDragDrop(event::DragDrop &e) { | |||||
Port *originPort = dynamic_cast<Port*>(e.origin); | |||||
void PortWidget::onDragDrop(event::DragDrop &e) { | |||||
PortWidget *originPort = dynamic_cast<PortWidget*>(e.origin); | |||||
if (!originPort) | if (!originPort) | ||||
return; | return; | ||||
@@ -99,8 +99,8 @@ void Port::onDragDrop(event::DragDrop &e) { | |||||
onDragEnter(eDragEnter); | onDragEnter(eDragEnter); | ||||
} | } | ||||
void Port::onDragEnter(event::DragEnter &e) { | |||||
Port *originPort = dynamic_cast<Port*>(e.origin); | |||||
void PortWidget::onDragEnter(event::DragEnter &e) { | |||||
PortWidget *originPort = dynamic_cast<PortWidget*>(e.origin); | |||||
if (!originPort) | if (!originPort) | ||||
return; | return; | ||||
@@ -117,8 +117,8 @@ void Port::onDragEnter(event::DragEnter &e) { | |||||
} | } | ||||
} | } | ||||
void Port::onDragLeave(event::DragLeave &e) { | |||||
Port *originPort = dynamic_cast<Port*>(e.origin); | |||||
void PortWidget::onDragLeave(event::DragLeave &e) { | |||||
PortWidget *originPort = dynamic_cast<PortWidget*>(e.origin); | |||||
if (!originPort) | if (!originPort) | ||||
return; | return; | ||||
@@ -240,8 +240,8 @@ json_t *RackWidget::toJson() { | |||||
WireWidget *wireWidget = dynamic_cast<WireWidget*>(w); | WireWidget *wireWidget = dynamic_cast<WireWidget*>(w); | ||||
assert(wireWidget); | assert(wireWidget); | ||||
Port *outputPort = wireWidget->outputPort; | |||||
Port *inputPort = wireWidget->inputPort; | |||||
PortWidget *outputPort = wireWidget->outputPort; | |||||
PortWidget *inputPort = wireWidget->inputPort; | |||||
// Only serialize WireWidgets connected on both ends | // Only serialize WireWidgets connected on both ends | ||||
if (!(outputPort && inputPort)) | if (!(outputPort && inputPort)) | ||||
continue; | continue; | ||||
@@ -362,21 +362,21 @@ void RackWidget::fromJson(json_t *rootJ) { | |||||
if (!inputModuleWidget) continue; | if (!inputModuleWidget) continue; | ||||
// Get port widgets | // Get port widgets | ||||
Port *outputPort = NULL; | |||||
Port *inputPort = NULL; | |||||
PortWidget *outputPort = NULL; | |||||
PortWidget *inputPort = NULL; | |||||
if (legacy && legacy <= 1) { | if (legacy && legacy <= 1) { | ||||
// Before 0.6, the index of the "ports" array was the index of the Port in the `outputs` and `inputs` vector. | |||||
// Before 0.6, the index of the "ports" array was the index of the PortWidget in the `outputs` and `inputs` vector. | |||||
outputPort = outputModuleWidget->outputs[outputId]; | outputPort = outputModuleWidget->outputs[outputId]; | ||||
inputPort = inputModuleWidget->inputs[inputId]; | inputPort = inputModuleWidget->inputs[inputId]; | ||||
} | } | ||||
else { | else { | ||||
for (Port *port : outputModuleWidget->outputs) { | |||||
for (PortWidget *port : outputModuleWidget->outputs) { | |||||
if (port->portId == outputId) { | if (port->portId == outputId) { | ||||
outputPort = port; | outputPort = port; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
for (Port *port : inputModuleWidget->inputs) { | |||||
for (PortWidget *port : inputModuleWidget->inputs) { | |||||
if (port->portId == inputId) { | if (port->portId == inputId) { | ||||
inputPort = port; | inputPort = port; | ||||
break; | break; | ||||
@@ -24,7 +24,7 @@ void SVGPort::setSVG(std::shared_ptr<SVG> svg) { | |||||
} | } | ||||
void SVGPort::draw(NVGcontext *vg) { | void SVGPort::draw(NVGcontext *vg) { | ||||
Port::draw(vg); | |||||
PortWidget::draw(vg); | |||||
FramebufferWidget::draw(vg); | FramebufferWidget::draw(vg); | ||||
} | } | ||||
@@ -41,7 +41,7 @@ void WireContainer::commitActiveWire() { | |||||
} | } | ||||
} | } | ||||
void WireContainer::removeTopWire(Port *port) { | |||||
void WireContainer::removeTopWire(PortWidget *port) { | |||||
WireWidget *wire = getTopWire(port); | WireWidget *wire = getTopWire(port); | ||||
if (wire) { | if (wire) { | ||||
removeChild(wire); | removeChild(wire); | ||||
@@ -49,7 +49,7 @@ void WireContainer::removeTopWire(Port *port) { | |||||
} | } | ||||
} | } | ||||
void WireContainer::removeAllWires(Port *port) { | |||||
void WireContainer::removeAllWires(PortWidget *port) { | |||||
// As a convenience, de-hover the active wire so we don't attach them once it is dropped. | // As a convenience, de-hover the active wire so we don't attach them once it is dropped. | ||||
if (activeWire) { | if (activeWire) { | ||||
if (activeWire->hoveredInputPort == port) | if (activeWire->hoveredInputPort == port) | ||||
@@ -80,7 +80,7 @@ void WireContainer::removeAllWires(Port *port) { | |||||
} | } | ||||
} | } | ||||
WireWidget *WireContainer::getTopWire(Port *port) { | |||||
WireWidget *WireContainer::getTopWire(PortWidget *port) { | |||||
for (auto it = children.rbegin(); it != children.rend(); it++) { | for (auto it = children.rbegin(); it != children.rend(); it++) { | ||||
WireWidget *wire = dynamic_cast<WireWidget*>(*it); | WireWidget *wire = dynamic_cast<WireWidget*>(*it); | ||||
assert(wire); | assert(wire); | ||||
@@ -101,8 +101,8 @@ WireWidget::~WireWidget() { | |||||
void WireWidget::updateWire() { | void WireWidget::updateWire() { | ||||
if (inputPort && outputPort) { | if (inputPort && outputPort) { | ||||
// Check correct types | // Check correct types | ||||
assert(inputPort->type == Port::INPUT); | |||||
assert(outputPort->type == Port::OUTPUT); | |||||
assert(inputPort->type == PortWidget::INPUT); | |||||
assert(outputPort->type == PortWidget::OUTPUT); | |||||
if (!wire) { | if (!wire) { | ||||
wire = new Wire; | wire = new Wire; | ||||
@@ -173,7 +173,7 @@ void WireWidget::draw(NVGcontext *vg) { | |||||
opacity = 1.0; | opacity = 1.0; | ||||
} | } | ||||
else { | else { | ||||
Port *hoveredPort = dynamic_cast<Port*>(context()->event->hoveredWidget); | |||||
PortWidget *hoveredPort = dynamic_cast<PortWidget*>(context()->event->hoveredWidget); | |||||
if (hoveredPort && (hoveredPort == outputPort || hoveredPort == inputPort)) | if (hoveredPort && (hoveredPort == outputPort || hoveredPort == inputPort)) | ||||
opacity = 1.0; | opacity = 1.0; | ||||
} | } | ||||