From 5ac56a858ae8990579c4242fd637d2d3caae165d Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 27 Dec 2016 03:18:44 -0500 Subject: [PATCH] Fixed bug with ParamWidget serialization, other minor fixes --- include/widgets.hpp | 3 ++- src/core/MidiInterface.cpp | 4 ++-- src/main.cpp | 2 +- src/widgets/ModulePanel.cpp | 4 +--- src/widgets/ModuleWidget.cpp | 4 +++- src/widgets/RackWidget.cpp | 22 +++++++++++++++++++--- src/widgets/Toolbar.cpp | 2 +- src/widgets/WireWidget.cpp | 28 +++++++++++++++------------- 8 files changed, 44 insertions(+), 25 deletions(-) diff --git a/include/widgets.hpp b/include/widgets.hpp index 548244d6..73e49444 100644 --- a/include/widgets.hpp +++ b/include/widgets.hpp @@ -348,8 +348,9 @@ struct RackWidget : OpaqueWidget { }; struct ModulePanel : TransparentWidget { - std::string imageFilename; NVGcolor backgroundColor; + NVGcolor highlightColor; + std::string imageFilename; void draw(NVGcontext *vg); }; diff --git a/src/core/MidiInterface.cpp b/src/core/MidiInterface.cpp index cfcc7818..66d75a7d 100644 --- a/src/core/MidiInterface.cpp +++ b/src/core/MidiInterface.cpp @@ -33,9 +33,9 @@ struct MidiInterface : Module { PortMidiStream *stream = NULL; std::list notes; bool pedal = false; - int note = 64; // C4 + int note = 60; // C4, most modules should use 261.63 Hz int pitchWheel = 64; - bool retrigger = true; + bool retrigger = false; bool retriggered = false; MidiInterface(); diff --git a/src/main.cpp b/src/main.cpp index 9914831a..9ada1bac 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,7 +10,7 @@ namespace rack { std::string gApplicationName = "Virtuoso Rack"; -std::string gApplicationVersion = "v0.0.0"; +std::string gApplicationVersion = "v0.0.0 alpha"; } // namespace rack diff --git a/src/widgets/ModulePanel.cpp b/src/widgets/ModulePanel.cpp index ca208e96..98757df2 100644 --- a/src/widgets/ModulePanel.cpp +++ b/src/widgets/ModulePanel.cpp @@ -10,9 +10,7 @@ void ModulePanel::draw(NVGcontext *vg) { // Background gradient Vec c = box.getTopRight(); float length = box.size.norm(); - NVGcolor color1 = nvgLerpRGBA(backgroundColor, nvgRGBf(1.0, 1.0, 1.0), 0.5); - NVGcolor color2 = backgroundColor; - paint = nvgRadialGradient(vg, c.x, c.y, 0.0, length, color1, color2); + paint = nvgRadialGradient(vg, c.x, c.y, 0.0, length, highlightColor, backgroundColor); nvgFillPaint(vg, paint); nvgFill(vg); // Background image diff --git a/src/widgets/ModuleWidget.cpp b/src/widgets/ModuleWidget.cpp index bfb5f790..2358948b 100644 --- a/src/widgets/ModuleWidget.cpp +++ b/src/widgets/ModuleWidget.cpp @@ -67,7 +67,9 @@ void ModuleWidget::fromJson(json_t *root) { size_t paramId; json_t *paramJ; json_array_foreach(paramsJ, paramId, paramJ) { - params[paramId]->fromJson(paramJ); + if (0 <= paramId && paramId < params.size()) { + params[paramId]->fromJson(paramJ); + } } } diff --git a/src/widgets/RackWidget.cpp b/src/widgets/RackWidget.cpp index be110b34..3ae46de5 100644 --- a/src/widgets/RackWidget.cpp +++ b/src/widgets/RackWidget.cpp @@ -60,6 +60,10 @@ json_t *RackWidget::toJson() { // root json_t *root = json_object(); + // version + json_t *versionJ = json_string(gApplicationVersion.c_str()); + json_object_set_new(root, "version", versionJ); + // modules json_t *modulesJ = json_array(); std::map moduleIds; @@ -86,16 +90,28 @@ json_t *RackWidget::toJson() { // wire json_t *wire = json_object(); { + // Get the modules at each end of the wire ModuleWidget *outputModuleWidget = wireWidget->outputPort->getAncestorOfType(); assert(outputModuleWidget); + int outputModuleId = moduleIds[outputModuleWidget]; + ModuleWidget *inputModuleWidget = wireWidget->inputPort->getAncestorOfType(); assert(inputModuleWidget); - int outputModuleId = moduleIds[outputModuleWidget]; int inputModuleId = moduleIds[inputModuleWidget]; + + // Get output/input ports + auto outputIt = std::find(outputModuleWidget->outputs.begin(), outputModuleWidget->outputs.end(), wireWidget->outputPort); + assert(outputIt != outputModuleWidget->outputs.end()); + int outputId = outputIt - outputModuleWidget->outputs.begin(); + + auto inputIt = std::find(inputModuleWidget->inputs.begin(), inputModuleWidget->inputs.end(), wireWidget->inputPort); + assert(inputIt != inputModuleWidget->inputs.end()); + int inputId = inputIt - inputModuleWidget->inputs.begin(); + json_object_set_new(wire, "outputModuleId", json_integer(outputModuleId)); - json_object_set_new(wire, "outputId", json_integer(wireWidget->outputPort->outputId)); + json_object_set_new(wire, "outputId", json_integer(outputId)); json_object_set_new(wire, "inputModuleId", json_integer(inputModuleId)); - json_object_set_new(wire, "inputId", json_integer(wireWidget->inputPort->inputId)); + json_object_set_new(wire, "inputId", json_integer(inputId)); } json_array_append_new(wires, wire); } diff --git a/src/widgets/Toolbar.cpp b/src/widgets/Toolbar.cpp index f04239f6..27c1920f 100644 --- a/src/widgets/Toolbar.cpp +++ b/src/widgets/Toolbar.cpp @@ -105,7 +105,7 @@ Toolbar::Toolbar() { label->box.pos = Vec(xPos, margin); label->text = gApplicationName + " " + gApplicationVersion; addChild(label); - xPos += 150; + xPos += 175; } xPos += margin; diff --git a/src/widgets/WireWidget.cpp b/src/widgets/WireWidget.cpp index 556ca9d2..63e1860a 100644 --- a/src/widgets/WireWidget.cpp +++ b/src/widgets/WireWidget.cpp @@ -5,32 +5,34 @@ namespace rack { void drawWire(NVGcontext *vg, Vec pos1, Vec pos2, float tension, NVGcolor color) { float dist = pos1.minus(pos2).norm(); - float slump = (1.0 - tension) * (150.0 + 1.0*dist); - Vec pos3 = pos1.plus(pos2).div(2).plus(Vec(0, slump)); - - NVGcolor colorOutline = nvgRGBf(0, 0, 0); + Vec slump; + slump.y = (1.0 - tension) * (150.0 + 1.0*dist); + Vec pos3 = pos1.plus(pos2).div(2).plus(slump); nvgLineJoin(vg, NVG_ROUND); - nvgStrokeWidth(vg, 4); + // Shadow - // Vec pos4 = pos3.plus(slump.mult(0.1)); - // NVGcolor colorShadow = nvgRGBAf(0, 0, 0, 0.2); - // nvgBeginPath(vg); - // nvgMoveTo(vg, pos1.x, pos1.y); - // nvgQuadTo(vg, pos4.x, pos4.y, pos2.x, pos2.y); - // nvgStrokeColor(vg, colorShadow); - // nvgStroke(vg); + Vec pos4 = pos3.plus(slump.mult(0.08)); + NVGcolor colorShadow = nvgRGBAf(0, 0, 0, 0.08); + nvgBeginPath(vg); + nvgMoveTo(vg, pos1.x, pos1.y); + nvgQuadTo(vg, pos4.x, pos4.y, pos2.x, pos2.y); + nvgStrokeColor(vg, colorShadow); + nvgStrokeWidth(vg, 5); + nvgStroke(vg); // Wire outline + NVGcolor colorOutline = nvgRGBf(0, 0, 0); nvgBeginPath(vg); nvgMoveTo(vg, pos1.x, pos1.y); nvgQuadTo(vg, pos3.x, pos3.y, pos2.x, pos2.y); nvgStrokeColor(vg, colorOutline); + nvgStrokeWidth(vg, 4); nvgStroke(vg); // Wire solid - nvgStrokeWidth(vg, 2); nvgStrokeColor(vg, color); + nvgStrokeWidth(vg, 2); nvgStroke(vg); }