@@ -12,15 +12,12 @@ namespace rack { | |||||
struct ParamQuantity : Quantity { | struct ParamQuantity : Quantity { | ||||
Module *module = NULL; | Module *module = NULL; | ||||
int paramId = 0; | 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(); | Param *getParam(); | ||||
ParamInfo *getParamInfo(); | ParamInfo *getParamInfo(); | ||||
void commitSnap(); | |||||
/** Request to the engine to smoothly set the value */ | |||||
void setSmoothValue(float smoothValue); | |||||
float getSmoothValue(); | |||||
void setValue(float value) override; | void setValue(float value) override; | ||||
float getValue() override; | float getValue() override; | ||||
@@ -13,6 +13,7 @@ struct ParamWidget : OpaqueWidget { | |||||
ParamQuantity *paramQuantity = NULL; | ParamQuantity *paramQuantity = NULL; | ||||
float dirtyValue = NAN; | float dirtyValue = NAN; | ||||
Tooltip *tooltip = NULL; | Tooltip *tooltip = NULL; | ||||
bool snap = false; | |||||
~ParamWidget(); | ~ParamWidget(); | ||||
void step() override; | void step() override; | ||||
@@ -34,7 +34,9 @@ struct Engine { | |||||
void addCable(Cable *cable); | void addCable(Cable *cable); | ||||
void removeCable(Cable *cable); | void removeCable(Cable *cable); | ||||
void setParam(Module *module, int paramId, float value); | 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(); | int getNextModuleId(); | ||||
void setSampleRate(float sampleRate); | void setSampleRate(float sampleRate); | ||||
@@ -15,10 +15,9 @@ struct ParamQuantityFactory { | |||||
struct ParamInfo { | struct ParamInfo { | ||||
// For formatting/displaying the value | |||||
/** Set to 0 for linear, nonzero for exponential */ | |||||
std::string label; | std::string label; | ||||
std::string unit; | std::string unit; | ||||
/** Set to 0 for linear, nonzero for exponential */ | |||||
float displayBase = 0.f; | float displayBase = 0.f; | ||||
float displayMultiplier = 1.f; | float displayMultiplier = 1.f; | ||||
std::string description; | std::string description; | ||||
@@ -58,7 +58,8 @@ void Knob::onDragMove(const event::DragMove &e) { | |||||
// Drag slower if Mod is held | // Drag slower if Mod is held | ||||
if (app()->window->isModPressed()) | if (app()->window->isModPressed()) | ||||
delta /= 16.f; | delta /= 16.f; | ||||
paramQuantity->moveValue(delta); | |||||
float oldValue = paramQuantity->getSmoothValue(); | |||||
paramQuantity->setSmoothValue(oldValue + delta); | |||||
} | } | ||||
ParamWidget::onDragMove(e); | ParamWidget::onDragMove(e); | ||||
@@ -1,4 +1,6 @@ | |||||
#include "app/ParamQuantity.hpp" | #include "app/ParamQuantity.hpp" | ||||
#include "app.hpp" | |||||
#include "engine/Engine.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -14,8 +16,15 @@ ParamInfo *ParamQuantity::getParamInfo() { | |||||
return &module->paramInfos[paramId]; | 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) { | void ParamQuantity::setValue(float value) { | ||||
@@ -348,7 +348,11 @@ void Engine::setParam(Module *module, int paramId, float value) { | |||||
module->params[paramId].value = 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 another param is being smoothed, jump value | ||||
if (internal->smoothModule && !(internal->smoothModule == module && internal->smoothParamId == paramId)) { | if (internal->smoothModule && !(internal->smoothModule == module && internal->smoothParamId == paramId)) { | ||||
internal->smoothModule->params[internal->smoothParamId].value = internal->smoothValue; | internal->smoothModule->params[internal->smoothParamId].value = internal->smoothValue; | ||||
@@ -358,6 +362,12 @@ void Engine::setParamSmooth(Module *module, int paramId, float value) { | |||||
internal->smoothModule = module; | 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() { | int Engine::getNextModuleId() { | ||||
return internal->nextModuleId++; | return internal->nextModuleId++; | ||||
} | } | ||||