@@ -96,41 +96,32 @@ struct BefacoSlidePot : SpriteKnob { | |||
// Jacks | |||
//////////////////// | |||
template <typename BASE> | |||
struct PJ301M : BASE { | |||
PJ301M() { | |||
this->box.size = Vec(24, 24); | |||
this->spriteOffset = Vec(-2, -2); | |||
this->spriteSize = Vec(30, 30); | |||
this->spriteImage = Image::load("res/ComponentLibrary/PJ301M.png"); | |||
struct PJ301MPort : Port { | |||
PJ301MPort() { | |||
box.size = Vec(24, 24); | |||
spriteOffset = Vec(-2, -2); | |||
spriteSize = Vec(30, 30); | |||
spriteImage = Image::load("res/ComponentLibrary/PJ301M.png"); | |||
} | |||
}; | |||
typedef PJ301M<InputPort> InputPortPJ301M; | |||
typedef PJ301M<OutputPort> OutputPortPJ301M; | |||
template <typename BASE> | |||
struct PJ3410 : BASE { | |||
PJ3410() { | |||
this->box.size = Vec(32, 31); | |||
this->spriteOffset = Vec(-1, -1); | |||
this->spriteSize = Vec(36, 36); | |||
this->spriteImage = Image::load("res/ComponentLibrary/PJ3410.png"); | |||
struct PJ3410Port : Port { | |||
PJ3410Port() { | |||
box.size = Vec(32, 31); | |||
spriteOffset = Vec(-1, -1); | |||
spriteSize = Vec(36, 36); | |||
spriteImage = Image::load("res/ComponentLibrary/PJ3410.png"); | |||
} | |||
}; | |||
typedef PJ3410<InputPort> InputPortPJ3410; | |||
typedef PJ3410<OutputPort> OutputPortPJ3410; | |||
template <typename BASE> | |||
struct CL1362 : BASE { | |||
CL1362() { | |||
this->box.size = Vec(33, 29); | |||
this->spriteOffset = Vec(-2, -2); | |||
this->spriteSize = Vec(39, 36); | |||
this->spriteImage = Image::load("res/ComponentLibrary/CL1362.png"); | |||
struct CL1362Port : Port { | |||
CL1362Port() { | |||
box.size = Vec(33, 29); | |||
spriteOffset = Vec(-2, -2); | |||
spriteSize = Vec(39, 36); | |||
spriteImage = Image::load("res/ComponentLibrary/CL1362.png"); | |||
} | |||
}; | |||
typedef CL1362<InputPort> InputPortCL1362; | |||
typedef CL1362<OutputPort> OutputPortCL1362; | |||
//////////////////// | |||
// Lights | |||
@@ -48,21 +48,23 @@ ParamWidget *createParam(Vec pos, Module *module, int paramId, float minValue, f | |||
return param; | |||
} | |||
template <class TInputPort> | |||
InputPort *createInput(Vec pos, Module *module, int inputId) { | |||
InputPort *port = new TInputPort(); | |||
template <class TPort> | |||
Port *createInput(Vec pos, Module *module, int inputId) { | |||
Port *port = new TPort(); | |||
port->box.pos = pos; | |||
port->module = module; | |||
port->inputId = inputId; | |||
port->type = Port::INPUT; | |||
port->portId = inputId; | |||
return port; | |||
} | |||
template <class TOutputPort> | |||
OutputPort *createOutput(Vec pos, Module *module, int outputId) { | |||
OutputPort *port = new TOutputPort(); | |||
template <class TPort> | |||
Port *createOutput(Vec pos, Module *module, int outputId) { | |||
Port *port = new TPort(); | |||
port->box.pos = pos; | |||
port->module = module; | |||
port->outputId = outputId; | |||
port->type = Port::OUTPUT; | |||
port->portId = outputId; | |||
return port; | |||
} | |||
@@ -12,8 +12,7 @@ struct Wire; | |||
struct RackWidget; | |||
struct ParamWidget; | |||
struct InputPort; | |||
struct OutputPort; | |||
struct Port; | |||
struct Scene; | |||
//////////////////// | |||
@@ -27,15 +26,15 @@ struct ModuleWidget : OpaqueWidget { | |||
/** Owns the module pointer */ | |||
Module *module = NULL; | |||
std::vector<InputPort*> inputs; | |||
std::vector<OutputPort*> outputs; | |||
std::vector<Port*> inputs; | |||
std::vector<Port*> outputs; | |||
std::vector<ParamWidget*> params; | |||
~ModuleWidget(); | |||
void setModule(Module *module); | |||
// Convenience functions for adding special widgets (calls addChild()) | |||
void addInput(InputPort *input); | |||
void addOutput(OutputPort *output); | |||
void addInput(Port *input); | |||
void addOutput(Port *output); | |||
void addParam(ParamWidget *param); | |||
json_t *toJson(); | |||
@@ -56,10 +55,10 @@ struct ModuleWidget : OpaqueWidget { | |||
}; | |||
struct WireWidget : OpaqueWidget { | |||
OutputPort *outputPort = NULL; | |||
InputPort *inputPort = NULL; | |||
OutputPort *hoveredOutputPort = NULL; | |||
InputPort *hoveredInputPort = NULL; | |||
Port *inputPort = NULL; | |||
Port *outputPort = NULL; | |||
Port *hoveredInputPort = NULL; | |||
Port *hoveredOutputPort = NULL; | |||
Wire *wire = NULL; | |||
NVGcolor color; | |||
@@ -182,35 +181,27 @@ struct MomentarySwitch : virtual Switch { | |||
//////////////////// | |||
struct Port : OpaqueWidget, SpriteWidget { | |||
enum PortType { | |||
INPUT, | |||
OUTPUT | |||
}; | |||
Module *module = NULL; | |||
WireWidget *connectedWire = NULL; | |||
PortType type; | |||
int portId; | |||
Port(); | |||
~Port(); | |||
void disconnect(); | |||
void draw(NVGcontext *vg); | |||
void onMouseDown(int button); | |||
void onDragEnd(); | |||
}; | |||
struct InputPort : Port { | |||
int inputId; | |||
void onDragStart(); | |||
void onDragDrop(Widget *origin); | |||
void onDragEnter(Widget *origin); | |||
void onDragLeave(Widget *origin); | |||
void draw(NVGcontext *vg); | |||
}; | |||
struct OutputPort : Port { | |||
int outputId; | |||
void onDragStart(); | |||
void onDragDrop(Widget *origin); | |||
void onDragEnter(Widget *origin); | |||
void onDragLeave(Widget *origin); | |||
void draw(NVGcontext *vg); | |||
}; | |||
//////////////////// | |||
@@ -459,8 +459,8 @@ AudioInterfaceWidget::AudioInterfaceWidget() { | |||
} | |||
yPos += 5; | |||
addInput(createInput<InputPortPJ3410>(Vec(20, yPos), module, AudioInterface::AUDIO1_INPUT)); | |||
addInput(createInput<InputPortPJ3410>(Vec(70, yPos), module, AudioInterface::AUDIO2_INPUT)); | |||
addInput(createInput<PJ3410Port>(Vec(20, yPos), module, AudioInterface::AUDIO1_INPUT)); | |||
addInput(createInput<PJ3410Port>(Vec(70, yPos), module, AudioInterface::AUDIO2_INPUT)); | |||
yPos += 35 + margin; | |||
{ | |||
@@ -472,7 +472,7 @@ AudioInterfaceWidget::AudioInterfaceWidget() { | |||
} | |||
yPos += 5; | |||
addOutput(createOutput<OutputPortPJ3410>(Vec(20, yPos), module, AudioInterface::AUDIO1_OUTPUT)); | |||
addOutput(createOutput<OutputPortPJ3410>(Vec(70, yPos), module, AudioInterface::AUDIO2_OUTPUT)); | |||
addOutput(createOutput<PJ3410Port>(Vec(20, yPos), module, AudioInterface::AUDIO1_OUTPUT)); | |||
addOutput(createOutput<PJ3410Port>(Vec(70, yPos), module, AudioInterface::AUDIO2_OUTPUT)); | |||
yPos += 35 + margin; | |||
} |
@@ -254,8 +254,8 @@ MidiInterfaceWidget::MidiInterfaceWidget() { | |||
} | |||
yPos += 5; | |||
addOutput(createOutput<OutputPortPJ3410>(Vec(20, yPos), module, MidiInterface::PITCH_OUTPUT)); | |||
addOutput(createOutput<OutputPortPJ3410>(Vec(70, yPos), module, MidiInterface::GATE_OUTPUT)); | |||
addOutput(createOutput<PJ3410Port>(Vec(20, yPos), module, MidiInterface::PITCH_OUTPUT)); | |||
addOutput(createOutput<PJ3410Port>(Vec(70, yPos), module, MidiInterface::GATE_OUTPUT)); | |||
yPos += 25 + margin; | |||
{ | |||
@@ -1,53 +0,0 @@ | |||
#include "scene.hpp" | |||
namespace rack { | |||
void InputPort::onDragStart() { | |||
if (connectedWire) { | |||
// Disconnect wire from this port, but set it as the active wire | |||
connectedWire->inputPort = NULL; | |||
connectedWire->updateWire(); | |||
gRackWidget->activeWire = connectedWire; | |||
connectedWire = NULL; | |||
} | |||
else { | |||
connectedWire = new WireWidget(); | |||
connectedWire->inputPort = this; | |||
gRackWidget->wireContainer->addChild(connectedWire); | |||
gRackWidget->activeWire = connectedWire; | |||
} | |||
} | |||
void InputPort::onDragDrop(Widget *origin) { | |||
if (connectedWire) return; | |||
if (gRackWidget->activeWire) { | |||
gRackWidget->activeWire->hoveredInputPort = NULL; | |||
if (gRackWidget->activeWire->inputPort) return; | |||
gRackWidget->activeWire->inputPort = this; | |||
connectedWire = gRackWidget->activeWire; | |||
} | |||
} | |||
void InputPort::onDragEnter(Widget *origin) { | |||
if (connectedWire) return; | |||
if (gRackWidget->activeWire) { | |||
gRackWidget->activeWire->hoveredInputPort = this; | |||
} | |||
} | |||
void InputPort::onDragLeave(Widget *origin) { | |||
if (gRackWidget->activeWire) { | |||
gRackWidget->activeWire->hoveredInputPort = NULL; | |||
} | |||
} | |||
void InputPort::draw(NVGcontext *vg) { | |||
if (gRackWidget->activeWire) { | |||
if (gRackWidget->activeWire->inputPort) | |||
nvgGlobalAlpha(vg, 0.5); | |||
} | |||
SpriteWidget::draw(vg); | |||
} | |||
} // namespace rack |
@@ -22,12 +22,12 @@ void ModuleWidget::setModule(Module *module) { | |||
this->module = module; | |||
} | |||
void ModuleWidget::addInput(InputPort *input) { | |||
void ModuleWidget::addInput(Port *input) { | |||
inputs.push_back(input); | |||
addChild(input); | |||
} | |||
void ModuleWidget::addOutput(OutputPort *output) { | |||
void ModuleWidget::addOutput(Port *output) { | |||
outputs.push_back(output); | |||
addChild(output); | |||
} | |||
@@ -77,10 +77,10 @@ void ModuleWidget::fromJson(json_t *root) { | |||
} | |||
void ModuleWidget::disconnectPorts() { | |||
for (InputPort *input : inputs) { | |||
for (Port *input : inputs) { | |||
input->disconnect(); | |||
} | |||
for (OutputPort *output : outputs) { | |||
for (Port *output : outputs) { | |||
output->disconnect(); | |||
} | |||
} | |||
@@ -1,53 +0,0 @@ | |||
#include "scene.hpp" | |||
namespace rack { | |||
void OutputPort::onDragStart() { | |||
if (connectedWire) { | |||
// Disconnect wire from this port, but set it as the active wire | |||
connectedWire->outputPort = NULL; | |||
connectedWire->updateWire(); | |||
gRackWidget->activeWire = connectedWire; | |||
connectedWire = NULL; | |||
} | |||
else { | |||
connectedWire = new WireWidget(); | |||
connectedWire->outputPort = this; | |||
gRackWidget->wireContainer->addChild(connectedWire); | |||
gRackWidget->activeWire = connectedWire; | |||
} | |||
} | |||
void OutputPort::onDragDrop(Widget *origin) { | |||
if (connectedWire) return; | |||
if (gRackWidget->activeWire) { | |||
gRackWidget->activeWire->hoveredOutputPort = NULL; | |||
if (gRackWidget->activeWire->outputPort) return; | |||
gRackWidget->activeWire->outputPort = this; | |||
connectedWire = gRackWidget->activeWire; | |||
} | |||
} | |||
void OutputPort::onDragEnter(Widget *origin) { | |||
if (connectedWire) return; | |||
if (gRackWidget->activeWire) { | |||
gRackWidget->activeWire->hoveredOutputPort = this; | |||
} | |||
} | |||
void OutputPort::onDragLeave(Widget *origin) { | |||
if (gRackWidget->activeWire) { | |||
gRackWidget->activeWire->hoveredOutputPort = NULL; | |||
} | |||
} | |||
void OutputPort::draw(NVGcontext *vg) { | |||
if (gRackWidget->activeWire) { | |||
if (gRackWidget->activeWire->outputPort) | |||
nvgGlobalAlpha(vg, 0.5); | |||
} | |||
SpriteWidget::draw(vg); | |||
} | |||
} // namespace rack |
@@ -19,6 +19,14 @@ void Port::disconnect() { | |||
} | |||
} | |||
void Port::draw(NVGcontext *vg) { | |||
if (gRackWidget->activeWire) { | |||
if (type == INPUT ? gRackWidget->activeWire->inputPort : gRackWidget->activeWire->outputPort) | |||
nvgGlobalAlpha(vg, 0.5); | |||
} | |||
SpriteWidget::draw(vg); | |||
} | |||
void Port::onMouseDown(int button) { | |||
if (button == 1) { | |||
disconnect(); | |||
@@ -36,4 +44,63 @@ void Port::onDragEnd() { | |||
gRackWidget->activeWire = NULL; | |||
} | |||
void Port::onDragStart() { | |||
if (connectedWire) { | |||
// Disconnect wire from this port, but set it as the active wire | |||
if (type == INPUT) | |||
connectedWire->inputPort = NULL; | |||
else | |||
connectedWire->outputPort = NULL; | |||
connectedWire->updateWire(); | |||
gRackWidget->activeWire = connectedWire; | |||
connectedWire = NULL; | |||
} | |||
else { | |||
connectedWire = new WireWidget(); | |||
if (type == INPUT) | |||
connectedWire->inputPort = this; | |||
else | |||
connectedWire->outputPort = this; | |||
gRackWidget->wireContainer->addChild(connectedWire); | |||
gRackWidget->activeWire = connectedWire; | |||
} | |||
} | |||
void Port::onDragDrop(Widget *origin) { | |||
if (connectedWire) return; | |||
if (gRackWidget->activeWire) { | |||
if (type == INPUT) { | |||
gRackWidget->activeWire->hoveredInputPort = NULL; | |||
if (gRackWidget->activeWire->inputPort) return; | |||
gRackWidget->activeWire->inputPort = this; | |||
} | |||
else { | |||
gRackWidget->activeWire->hoveredOutputPort = NULL; | |||
if (gRackWidget->activeWire->outputPort) return; | |||
gRackWidget->activeWire->outputPort = this; | |||
} | |||
connectedWire = gRackWidget->activeWire; | |||
} | |||
} | |||
void Port::onDragEnter(Widget *origin) { | |||
if (connectedWire) return; | |||
if (gRackWidget->activeWire) { | |||
if (type == INPUT) | |||
gRackWidget->activeWire->hoveredInputPort = this; | |||
else | |||
gRackWidget->activeWire->hoveredOutputPort = this; | |||
} | |||
} | |||
void Port::onDragLeave(Widget *origin) { | |||
if (gRackWidget->activeWire) { | |||
if (type == INPUT) | |||
gRackWidget->activeWire->hoveredInputPort = NULL; | |||
else | |||
gRackWidget->activeWire->hoveredOutputPort = NULL; | |||
} | |||
} | |||
} // namespace rack |
@@ -207,11 +207,11 @@ void RackWidget::fromJson(json_t *root) { | |||
// Get ports | |||
ModuleWidget *outputModuleWidget = moduleWidgets[outputModuleId]; | |||
if (!outputModuleWidget) continue; | |||
OutputPort *outputPort = outputModuleWidget->outputs[outputId]; | |||
Port *outputPort = outputModuleWidget->outputs[outputId]; | |||
if (!outputPort) continue; | |||
ModuleWidget *inputModuleWidget = moduleWidgets[inputModuleId]; | |||
if (!inputModuleWidget) continue; | |||
InputPort *inputPort = inputModuleWidget->inputs[inputId]; | |||
Port *inputPort = inputModuleWidget->inputs[inputId]; | |||
if (!inputPort) continue; | |||
// Create WireWidget | |||
WireWidget *wireWidget = new WireWidget(); | |||
@@ -105,11 +105,15 @@ void WireWidget::updateWire() { | |||
wire = NULL; | |||
} | |||
if (inputPort && outputPort) { | |||
// Check correct types | |||
assert(inputPort->type == Port::INPUT); | |||
assert(outputPort->type == Port::OUTPUT); | |||
wire = new Wire(); | |||
wire->outputModule = outputPort->module; | |||
wire->outputId = outputPort->outputId; | |||
wire->outputId = outputPort->portId; | |||
wire->inputModule = inputPort->module; | |||
wire->inputId = inputPort->inputId; | |||
wire->inputId = inputPort->portId; | |||
engineAddWire(wire); | |||
} | |||
} | |||