Browse Source

Fix randomization of snapped params.

tags/v2.0.0
Andrew Belt 4 years ago
parent
commit
8ace079ee5
5 changed files with 32 additions and 5 deletions
  1. +6
    -4
      include/Quantity.hpp
  2. +3
    -0
      include/engine/ParamQuantity.hpp
  3. +1
    -1
      src/app/ParamWidget.cpp
  4. +4
    -0
      src/engine/Module.cpp
  5. +18
    -0
      src/engine/ParamQuantity.cpp

+ 6
- 4
include/Quantity.hpp View File

@@ -72,12 +72,14 @@ struct Quantity {
/** Returns a string representation of the quantity. */
virtual std::string getString();

// Helper methods

/** Resets the value to the default value. */
void reset();
virtual void reset();

/** Sets the value to a uniform random value between the bounds. */
void randomize();
virtual void randomize();

// Helper methods

/** Checks whether the value is at the min value. */
bool isMin();
/** Checks whether the value is at the max value. */


+ 3
- 0
include/engine/ParamQuantity.hpp View File

@@ -68,6 +68,9 @@ struct ParamQuantity : Quantity {
int getDisplayPrecision() override;
std::string getLabel() override;
std::string getUnit() override;
void reset() override;
void randomize() override;

virtual std::string getDescription();
};



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

@@ -288,7 +288,7 @@ void ParamWidget::createContextMenu() {

void ParamWidget::resetAction() {
engine::ParamQuantity* pq = getParamQuantity();
if (pq && pq->resetEnabled) {
if (pq && pq->resetEnabled && pq->isBounded()) {
float oldValue = pq->getValue();
pq->reset();
float newValue = pq->getValue();


+ 4
- 0
src/engine/Module.cpp View File

@@ -246,6 +246,8 @@ void Module::onReset(const ResetEvent& e) {
for (ParamQuantity* pq : paramQuantities) {
if (!pq->resetEnabled)
continue;
if (!pq->isBounded())
continue;
pq->reset();
}
// Call deprecated event
@@ -258,6 +260,8 @@ void Module::onRandomize(const RandomizeEvent& e) {
for (ParamQuantity* pq : paramQuantities) {
if (!pq->randomizeEnabled)
continue;
if (!pq->isBounded())
continue;
pq->randomize();
}
// Call deprecated event


+ 18
- 0
src/engine/ParamQuantity.cpp View File

@@ -122,6 +122,24 @@ std::string ParamQuantity::getUnit() {
return unit;
}

void ParamQuantity::reset() {
// Same as Quantity::reset
setValue(getDefaultValue());
}

void ParamQuantity::randomize() {
if (snapEnabled) {
// Randomize inclusive of the maximum value
float value = math::rescale(random::uniform(), 0.f, 1.f, getMinValue(), getMaxValue() + 1.f);
value = std::floor(value);
setValue(value);
}
else {
// Same as Quantity::randomize
setScaledValue(random::uniform());
}
}

std::string ParamQuantity::getDescription() {
return description;
}


Loading…
Cancel
Save