Browse Source

Add param smoothing when moving Knob

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
6dad6ec000
7 changed files with 32 additions and 13 deletions
  1. +3
    -6
      include/app/ParamQuantity.hpp
  2. +1
    -0
      include/app/ParamWidget.hpp
  3. +3
    -1
      include/engine/Engine.hpp
  4. +1
    -2
      include/engine/ParamInfo.hpp
  5. +2
    -1
      src/app/Knob.cpp
  6. +11
    -2
      src/app/ParamQuantity.cpp
  7. +11
    -1
      src/engine/Engine.cpp

+ 3
- 6
include/app/ParamQuantity.hpp View File

@@ -12,15 +12,12 @@ namespace rack {
struct ParamQuantity : Quantity {
Module *module = NULL;
int paramId = 0;
/** Use engine smoothing of Param values */
bool smooth = false;
/** Snap to the nearest integer */
bool snap = false;
float snapValue = 0.f;

Param *getParam();
ParamInfo *getParamInfo();
void commitSnap();
/** Request to the engine to smoothly set the value */
void setSmoothValue(float smoothValue);
float getSmoothValue();

void setValue(float value) override;
float getValue() override;


+ 1
- 0
include/app/ParamWidget.hpp View File

@@ -13,6 +13,7 @@ struct ParamWidget : OpaqueWidget {
ParamQuantity *paramQuantity = NULL;
float dirtyValue = NAN;
Tooltip *tooltip = NULL;
bool snap = false;

~ParamWidget();
void step() override;


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

@@ -34,7 +34,9 @@ struct Engine {
void addCable(Cable *cable);
void removeCable(Cable *cable);
void setParam(Module *module, int paramId, float value);
void setParamSmooth(Module *module, int paramId, float value);
float getParam(Module *module, int paramId);
void setSmoothParam(Module *module, int paramId, float value);
float getSmoothParam(Module *module, int paramId);
int getNextModuleId();

void setSampleRate(float sampleRate);


+ 1
- 2
include/engine/ParamInfo.hpp View File

@@ -15,10 +15,9 @@ struct ParamQuantityFactory {


struct ParamInfo {
// For formatting/displaying the value
/** Set to 0 for linear, nonzero for exponential */
std::string label;
std::string unit;
/** Set to 0 for linear, nonzero for exponential */
float displayBase = 0.f;
float displayMultiplier = 1.f;
std::string description;


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

@@ -58,7 +58,8 @@ void Knob::onDragMove(const event::DragMove &e) {
// Drag slower if Mod is held
if (app()->window->isModPressed())
delta /= 16.f;
paramQuantity->moveValue(delta);
float oldValue = paramQuantity->getSmoothValue();
paramQuantity->setSmoothValue(oldValue + delta);
}

ParamWidget::onDragMove(e);


+ 11
- 2
src/app/ParamQuantity.cpp View File

@@ -1,4 +1,6 @@
#include "app/ParamQuantity.hpp"
#include "app.hpp"
#include "engine/Engine.hpp"


namespace rack {
@@ -14,8 +16,15 @@ ParamInfo *ParamQuantity::getParamInfo() {
return &module->paramInfos[paramId];
}

void ParamQuantity::commitSnap() {
// TODO
void ParamQuantity::setSmoothValue(float smoothValue) {
if (!module)
return;
smoothValue = math::clamp(smoothValue, getMinValue(), getMaxValue());
app()->engine->setSmoothParam(module, paramId, smoothValue);
}

float ParamQuantity::getSmoothValue() {
return app()->engine->getSmoothParam(module, paramId);
}

void ParamQuantity::setValue(float value) {


+ 11
- 1
src/engine/Engine.cpp View File

@@ -348,7 +348,11 @@ void Engine::setParam(Module *module, int paramId, float value) {
module->params[paramId].value = value;
}

void Engine::setParamSmooth(Module *module, int paramId, float value) {
float Engine::getParam(Module *module, int paramId) {
return module->params[paramId].value;
}

void Engine::setSmoothParam(Module *module, int paramId, float value) {
// If another param is being smoothed, jump value
if (internal->smoothModule && !(internal->smoothModule == module && internal->smoothParamId == paramId)) {
internal->smoothModule->params[internal->smoothParamId].value = internal->smoothValue;
@@ -358,6 +362,12 @@ void Engine::setParamSmooth(Module *module, int paramId, float value) {
internal->smoothModule = module;
}

float Engine::getSmoothParam(Module *module, int paramId) {
if (internal->smoothModule == module && internal->smoothParamId == paramId)
return internal->smoothValue;
return getParam(module, paramId);
}

int Engine::getNextModuleId() {
return internal->nextModuleId++;
}


Loading…
Cancel
Save