diff --git a/include/engine/Param.hpp b/include/engine/Param.hpp index 3590252c..ac6f32bf 100644 --- a/include/engine/Param.hpp +++ b/include/engine/Param.hpp @@ -34,6 +34,7 @@ struct Param { /** Set to 0 for linear, nonzero for exponential */ float displayBase = 0.f; float displayMultiplier = 1.f; + float displayOffset = 0.f; /** An optional one-sentence description of the parameter */ std::string description; ParamQuantityFactory *paramQuantityFactory = NULL; @@ -44,7 +45,7 @@ struct Param { } template - void config(float minValue, float maxValue, float defaultValue, std::string label = "", std::string unit = "", float displayBase = 0.f, float displayMultiplier = 1.f) { + void config(float minValue, float maxValue, float defaultValue, std::string label = "", std::string unit = "", float displayBase = 0.f, float displayMultiplier = 1.f, float displayOffset = 0.f) { this->value = defaultValue; this->minValue = minValue; this->maxValue = maxValue; @@ -54,6 +55,7 @@ struct Param { this->unit = unit; this->displayBase = displayBase; this->displayMultiplier = displayMultiplier; + this->displayOffset = displayOffset; struct TParamQuantityFactory : ParamQuantityFactory { ParamQuantity *create() override {return new TParamQuantity;} diff --git a/src/app/Knob.cpp b/src/app/Knob.cpp index 8e70c25c..3b9c1b43 100644 --- a/src/app/Knob.cpp +++ b/src/app/Knob.cpp @@ -67,11 +67,12 @@ void Knob::onDragMove(const event::DragMove &e) { float delta = KNOB_SENSITIVITY * -e.mouseDelta.y * speed * range; // Drag slower if mod is held - if ((app()->window->getMods() & WINDOW_MOD_MASK) == WINDOW_MOD_CTRL) { + int mods = app()->window->getMods(); + if ((mods & WINDOW_MOD_MASK) == WINDOW_MOD_CTRL) { delta /= 16.f; } // Drag even slower if mod+shift is held - if ((app()->window->getMods() & WINDOW_MOD_MASK) == (WINDOW_MOD_CTRL | GLFW_MOD_SHIFT)) { + if ((mods & WINDOW_MOD_MASK) == (WINDOW_MOD_CTRL | GLFW_MOD_SHIFT)) { delta /= 256.f; } diff --git a/src/app/ParamQuantity.cpp b/src/app/ParamQuantity.cpp index a422c0ce..29b17e79 100644 --- a/src/app/ParamQuantity.cpp +++ b/src/app/ParamQuantity.cpp @@ -58,45 +58,39 @@ float ParamQuantity::getDefaultValue() { float ParamQuantity::getDisplayValue() { if (!module) return Quantity::getDisplayValue(); + float v = getSmoothValue(); float displayBase = getParam()->displayBase; if (displayBase == 0.f) { // Linear - return getSmoothValue() * getParam()->displayMultiplier; - } - else if (displayBase == 1.f) { - // Fixed (special case of exponential) - return getParam()->displayMultiplier; } else if (displayBase < 0.f) { // Logarithmic - return std::log(getSmoothValue()) / std::log(-displayBase) * getParam()->displayMultiplier; + v = std::log(v) / std::log(-displayBase); } else { // Exponential - return std::pow(displayBase, getSmoothValue()) * getParam()->displayMultiplier; + v = std::pow(displayBase, v); } + return v * getParam()->displayMultiplier + getParam()->displayOffset; } void ParamQuantity::setDisplayValue(float displayValue) { if (!module) return; + float v = (displayValue - getParam()->displayOffset) / getParam()->displayMultiplier; float displayBase = getParam()->displayBase; if (displayBase == 0.f) { // Linear - setValue(displayValue / getParam()->displayMultiplier); - } - else if (displayBase == 1.f) { - // Fixed - setValue(getParam()->displayMultiplier); } else if (displayBase < 0.f) { // Logarithmic - setValue(std::pow(displayBase, displayValue / getParam()->displayMultiplier)); + v = std::pow(displayBase, v); } else { // Exponential - setValue(std::log(displayValue / getParam()->displayMultiplier) / std::log(displayBase)); + v = std::log(v) / std::log(displayBase); } + setValue(v); } int ParamQuantity::getDisplayPrecision() { diff --git a/src/app/ParamWidget.cpp b/src/app/ParamWidget.cpp index 6cb6ab52..db4d2d27 100644 --- a/src/app/ParamWidget.cpp +++ b/src/app/ParamWidget.cpp @@ -89,7 +89,7 @@ struct ParamResetItem : MenuItem { ParamWidget *paramWidget; ParamResetItem() { text = "Initialize"; - rightText = WINDOW_MOD_CTRL_NAME "+Click"; + rightText = WINDOW_MOD_SHIFT_NAME "+Click"; } void onAction(const event::Action &e) override { paramWidget->resetAction(); @@ -100,7 +100,7 @@ struct ParamResetItem : MenuItem { struct ParamFineItem : MenuItem { ParamFineItem() { text = "Fine adjust"; - rightText = WINDOW_MOD_SHIFT_NAME "+Drag"; + rightText = WINDOW_MOD_CTRL_NAME "+Drag"; disabled = true; } }; @@ -201,8 +201,8 @@ void ParamWidget::createContextMenu() { resetItem->paramWidget = this; menu->addChild(resetItem); - ParamFineItem *fineItem = new ParamFineItem; - menu->addChild(fineItem); + // ParamFineItem *fineItem = new ParamFineItem; + // menu->addChild(fineItem); } void ParamWidget::resetAction() {