From 3f7ce8b01b00d7617b17d9df4e2d4f11906e4f75 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Fri, 8 Dec 2017 06:04:27 -0500 Subject: [PATCH] A few random changes from the last week --- include/app.hpp | 3 ++- include/dsp/samplerate.hpp | 10 ++++++++++ include/engine.hpp | 2 +- src/app/Knob.cpp | 2 +- src/app/RackRail.cpp | 9 +++++++++ src/app/RackWidget.cpp | 29 +++++++++++++++++++++++++---- src/app/SVGSwitch.cpp | 4 ---- 7 files changed, 48 insertions(+), 11 deletions(-) diff --git a/include/app.hpp b/include/app.hpp index 5acb6bef..4b795dd3 100644 --- a/include/app.hpp +++ b/include/app.hpp @@ -199,6 +199,8 @@ struct ParamWidget : OpaqueWidget, QuantityWidget { struct Knob : ParamWidget { /** Snap to nearest integer while dragging */ bool snap = false; + /** Multiplier for mouse movement to adjust knob value */ + float speed = 1.0; float dragValue; void onDragStart(EventDragStart &e) override; void onDragMove(EventDragMove &e) override; @@ -249,7 +251,6 @@ struct SVGSwitch : virtual Switch, FramebufferWidget { SVGSwitch(); /** Adds an SVG file to represent the next switch position */ void addFrame(std::shared_ptr svg); - void step() override; void onChange(EventChange &e) override; }; diff --git a/include/dsp/samplerate.hpp b/include/dsp/samplerate.hpp index 7cc988cf..3a87d640 100644 --- a/include/dsp/samplerate.hpp +++ b/include/dsp/samplerate.hpp @@ -2,6 +2,7 @@ #include #include +#include #include "frame.hpp" @@ -33,6 +34,15 @@ struct SampleRateConverter { } /** `in` and `out` are interlaced with the number of channels */ void process(const Frame *in, int *inFrames, Frame *out, int *outFrames) { + /* + if (nearf(data.src_ratio, 1.0)) { + int len = mini(*inFrames, *outFrames); + memcpy(out, in, len * sizeof(Frame)); + *inFrames = len; + *outFrames = len; + return; + } + */ // Old versions of libsamplerate use float* here instead of const float* data.data_in = (float*) in; data.input_frames = *inFrames; diff --git a/include/engine.hpp b/include/engine.hpp index ad3cf9e5..289b47ad 100644 --- a/include/engine.hpp +++ b/include/engine.hpp @@ -16,7 +16,7 @@ struct Light { float value = 0.0; float getBrightness(); void setBrightness(float brightness) { - value = brightness * brightness; + value = (brightness > 0.f) ? brightness * brightness : 0.f; } void setBrightnessSmooth(float brightness); }; diff --git a/src/app/Knob.cpp b/src/app/Knob.cpp index 4495b98e..fbb5ee37 100644 --- a/src/app/Knob.cpp +++ b/src/app/Knob.cpp @@ -18,7 +18,7 @@ void Knob::onDragStart(EventDragStart &e) { void Knob::onDragMove(EventDragMove &e) { // Drag slower if Mod - float delta = KNOB_SENSITIVITY * (maxValue - minValue) * -e.mouseRel.y; + float delta = KNOB_SENSITIVITY * (maxValue - minValue) * -e.mouseRel.y * speed; if (guiIsModPressed()) delta /= 16.0; dragValue += delta; diff --git a/src/app/RackRail.cpp b/src/app/RackRail.cpp index e126f38a..8dc97e27 100644 --- a/src/app/RackRail.cpp +++ b/src/app/RackRail.cpp @@ -46,6 +46,15 @@ void RackRail::draw(NVGcontext *vg) { nvgLineTo(vg, box.size.x, railY + RACK_GRID_HEIGHT - 0.5); nvgStroke(vg); } + + + // Useful for screenshots + if (0) { + nvgBeginPath(vg); + nvgRect(vg, 0.0, 0.0, box.size.x, box.size.y); + nvgFillColor(vg, nvgRGBf(1.0, 1.0, 1.0)); + nvgFill(vg); + } } diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index a7bf58be..2cbb7a52 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -38,6 +38,25 @@ void RackWidget::clear() { wireContainer->clearChildren(); moduleContainer->clearChildren(); lastPath = ""; + +/* + // Add all modules to rack + Vec pos; + for (Plugin *plugin : gPlugins) { + for (Model *model : plugin->models) { + ModuleWidget *moduleWidget = model->createModuleWidget(); + moduleContainer->addChild(moduleWidget); + // Move module nearest to the mouse position + Rect box; + box.size = moduleWidget->box.size; + box.pos = pos; + requestModuleBoxNearest(moduleWidget, box); + pos.x += box.size.x; + } + pos.y += RACK_GRID_HEIGHT; + pos.x = 0; + } +*/ } void RackWidget::reset() { @@ -127,8 +146,10 @@ json_t *RackWidget::toJson() { json_t *rootJ = json_object(); // version - json_t *versionJ = json_string(gApplicationVersion.c_str()); - json_object_set_new(rootJ, "version", versionJ); + if (!gApplicationVersion.empty()) { + json_t *versionJ = json_string(gApplicationVersion.c_str()); + json_object_set_new(rootJ, "version", versionJ); + } // modules json_t *modulesJ = json_array(); @@ -323,8 +344,8 @@ bool RackWidget::requestModuleBoxNearest(ModuleWidget *m, Rect box) { int x0 = roundf(box.pos.x / RACK_GRID_WIDTH); int y0 = roundf(box.pos.y / RACK_GRID_HEIGHT); std::vector positions; - for (int y = maxi(0, y0 - 4); y < y0 + 4; y++) { - for (int x = maxi(0, x0 - 200); x < x0 + 200; x++) { + for (int y = maxi(0, y0 - 8); y < y0 + 8; y++) { + for (int x = maxi(0, x0 - 400); x < x0 + 400; x++) { positions.push_back(Vec(x * RACK_GRID_WIDTH, y * RACK_GRID_HEIGHT)); } } diff --git a/src/app/SVGSwitch.cpp b/src/app/SVGSwitch.cpp index eda234cc..eecaeb1e 100644 --- a/src/app/SVGSwitch.cpp +++ b/src/app/SVGSwitch.cpp @@ -18,10 +18,6 @@ void SVGSwitch::addFrame(std::shared_ptr svg) { } } -void SVGSwitch::step() { - FramebufferWidget::step(); -} - void SVGSwitch::onChange(EventChange &e) { assert(frames.size() > 0); float valueScaled = rescalef(value, minValue, maxValue, 0, frames.size() - 1);