Browse Source

Add Param::displayOffset. Switch around param key commands and param context menu again.

tags/v1.0.0
Andrew Belt 6 years ago
parent
commit
0f08886aae
4 changed files with 18 additions and 21 deletions
  1. +3
    -1
      include/engine/Param.hpp
  2. +3
    -2
      src/app/Knob.cpp
  3. +8
    -14
      src/app/ParamQuantity.cpp
  4. +4
    -4
      src/app/ParamWidget.cpp

+ 3
- 1
include/engine/Param.hpp View File

@@ -34,6 +34,7 @@ struct Param {
/** Set to 0 for linear, nonzero for exponential */ /** Set to 0 for linear, nonzero for exponential */
float displayBase = 0.f; float displayBase = 0.f;
float displayMultiplier = 1.f; float displayMultiplier = 1.f;
float displayOffset = 0.f;
/** An optional one-sentence description of the parameter */ /** An optional one-sentence description of the parameter */
std::string description; std::string description;
ParamQuantityFactory *paramQuantityFactory = NULL; ParamQuantityFactory *paramQuantityFactory = NULL;
@@ -44,7 +45,7 @@ struct Param {
} }


template<class TParamQuantity = ParamQuantity> template<class TParamQuantity = ParamQuantity>
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->value = defaultValue;
this->minValue = minValue; this->minValue = minValue;
this->maxValue = maxValue; this->maxValue = maxValue;
@@ -54,6 +55,7 @@ struct Param {
this->unit = unit; this->unit = unit;
this->displayBase = displayBase; this->displayBase = displayBase;
this->displayMultiplier = displayMultiplier; this->displayMultiplier = displayMultiplier;
this->displayOffset = displayOffset;


struct TParamQuantityFactory : ParamQuantityFactory { struct TParamQuantityFactory : ParamQuantityFactory {
ParamQuantity *create() override {return new TParamQuantity;} ParamQuantity *create() override {return new TParamQuantity;}


+ 3
- 2
src/app/Knob.cpp View File

@@ -67,11 +67,12 @@ void Knob::onDragMove(const event::DragMove &e) {
float delta = KNOB_SENSITIVITY * -e.mouseDelta.y * speed * range; float delta = KNOB_SENSITIVITY * -e.mouseDelta.y * speed * range;


// Drag slower if mod is held // 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; delta /= 16.f;
} }
// Drag even slower if mod+shift is held // 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; delta /= 256.f;
} }




+ 8
- 14
src/app/ParamQuantity.cpp View File

@@ -58,45 +58,39 @@ float ParamQuantity::getDefaultValue() {
float ParamQuantity::getDisplayValue() { float ParamQuantity::getDisplayValue() {
if (!module) if (!module)
return Quantity::getDisplayValue(); return Quantity::getDisplayValue();
float v = getSmoothValue();
float displayBase = getParam()->displayBase; float displayBase = getParam()->displayBase;
if (displayBase == 0.f) { if (displayBase == 0.f) {
// Linear // Linear
return getSmoothValue() * getParam()->displayMultiplier;
}
else if (displayBase == 1.f) {
// Fixed (special case of exponential)
return getParam()->displayMultiplier;
} }
else if (displayBase < 0.f) { else if (displayBase < 0.f) {
// Logarithmic // Logarithmic
return std::log(getSmoothValue()) / std::log(-displayBase) * getParam()->displayMultiplier;
v = std::log(v) / std::log(-displayBase);
} }
else { else {
// Exponential // Exponential
return std::pow(displayBase, getSmoothValue()) * getParam()->displayMultiplier;
v = std::pow(displayBase, v);
} }
return v * getParam()->displayMultiplier + getParam()->displayOffset;
} }


void ParamQuantity::setDisplayValue(float displayValue) { void ParamQuantity::setDisplayValue(float displayValue) {
if (!module) if (!module)
return; return;
float v = (displayValue - getParam()->displayOffset) / getParam()->displayMultiplier;
float displayBase = getParam()->displayBase; float displayBase = getParam()->displayBase;
if (displayBase == 0.f) { if (displayBase == 0.f) {
// Linear // Linear
setValue(displayValue / getParam()->displayMultiplier);
}
else if (displayBase == 1.f) {
// Fixed
setValue(getParam()->displayMultiplier);
} }
else if (displayBase < 0.f) { else if (displayBase < 0.f) {
// Logarithmic // Logarithmic
setValue(std::pow(displayBase, displayValue / getParam()->displayMultiplier));
v = std::pow(displayBase, v);
} }
else { else {
// Exponential // Exponential
setValue(std::log(displayValue / getParam()->displayMultiplier) / std::log(displayBase));
v = std::log(v) / std::log(displayBase);
} }
setValue(v);
} }


int ParamQuantity::getDisplayPrecision() { int ParamQuantity::getDisplayPrecision() {


+ 4
- 4
src/app/ParamWidget.cpp View File

@@ -89,7 +89,7 @@ struct ParamResetItem : MenuItem {
ParamWidget *paramWidget; ParamWidget *paramWidget;
ParamResetItem() { ParamResetItem() {
text = "Initialize"; text = "Initialize";
rightText = WINDOW_MOD_CTRL_NAME "+Click";
rightText = WINDOW_MOD_SHIFT_NAME "+Click";
} }
void onAction(const event::Action &e) override { void onAction(const event::Action &e) override {
paramWidget->resetAction(); paramWidget->resetAction();
@@ -100,7 +100,7 @@ struct ParamResetItem : MenuItem {
struct ParamFineItem : MenuItem { struct ParamFineItem : MenuItem {
ParamFineItem() { ParamFineItem() {
text = "Fine adjust"; text = "Fine adjust";
rightText = WINDOW_MOD_SHIFT_NAME "+Drag";
rightText = WINDOW_MOD_CTRL_NAME "+Drag";
disabled = true; disabled = true;
} }
}; };
@@ -201,8 +201,8 @@ void ParamWidget::createContextMenu() {
resetItem->paramWidget = this; resetItem->paramWidget = this;
menu->addChild(resetItem); menu->addChild(resetItem);


ParamFineItem *fineItem = new ParamFineItem;
menu->addChild(fineItem);
// ParamFineItem *fineItem = new ParamFineItem;
// menu->addChild(fineItem);
} }


void ParamWidget::resetAction() { void ParamWidget::resetAction() {


Loading…
Cancel
Save