Browse Source

Move reset and randomize from Param to ParamWidget.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
6fe14dca06
12 changed files with 45 additions and 37 deletions
  1. +2
    -0
      include/app/Knob.hpp
  2. +2
    -0
      include/app/ParamWidget.hpp
  3. +2
    -0
      include/app/Switch.hpp
  4. +0
    -2
      include/engine/Module.hpp
  5. +0
    -4
      include/engine/Param.hpp
  6. +16
    -0
      src/app/Knob.cpp
  7. +6
    -0
      src/app/ModuleWidget.cpp
  8. +1
    -2
      src/app/ParamWidget.cpp
  9. +14
    -0
      src/app/Switch.cpp
  10. +2
    -2
      src/engine/Engine.cpp
  11. +0
    -15
      src/engine/Module.cpp
  12. +0
    -12
      src/engine/Param.cpp

+ 2
- 0
include/app/Knob.hpp View File

@@ -25,6 +25,8 @@ struct Knob : ParamWidget {
void onDragStart(const widget::DragStartEvent &e) override;
void onDragEnd(const widget::DragEndEvent &e) override;
void onDragMove(const widget::DragMoveEvent &e) override;
void reset() override;
void randomize() override;
};




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

@@ -28,6 +28,8 @@ struct ParamWidget : widget::OpaqueWidget {
void fromJson(json_t *rootJ);
void createContextMenu();
void resetAction();
virtual void reset() {}
virtual void randomize() {}
};




+ 2
- 0
include/app/Switch.hpp View File

@@ -19,6 +19,8 @@ struct Switch : ParamWidget {
void onDoubleClick(const widget::DoubleClickEvent &e) override;
void onDragStart(const widget::DragStartEvent &e) override;
void onDragEnd(const widget::DragEndEvent &e) override;
void reset() override;
void randomize() override;
};




+ 0
- 2
include/engine/Module.hpp View File

@@ -54,8 +54,6 @@ struct Module {
void config(int numParams, int numInputs, int numOutputs, int numLights = 0);
json_t *toJson();
void fromJson(json_t *rootJ);
void reset();
void randomize();

struct ProcessArgs {
float sampleRate;


+ 0
- 4
include/engine/Param.hpp View File

@@ -48,8 +48,6 @@ struct Param {
/** An optional one-sentence description of the parameter. */
std::string description;
ParamQuantityFactory *paramQuantityFactory = NULL;
/** Determines whether this Param will be randomized when the user requests to randomize the Module. */
bool randomizable = true;

~Param() {
if (paramQuantityFactory)
@@ -93,8 +91,6 @@ struct Param {

json_t *toJson();
void fromJson(json_t *rootJ);
void reset();
void randomize();
};




+ 16
- 0
src/app/Knob.cpp View File

@@ -1,6 +1,7 @@
#include "app/Knob.hpp"
#include "app.hpp"
#include "app/Scene.hpp"
#include "random.hpp"
#include "history.hpp"


@@ -98,6 +99,21 @@ void Knob::onDragMove(const widget::DragMoveEvent &e) {
ParamWidget::onDragMove(e);
}

void Knob::reset() {
if (paramQuantity && paramQuantity->isBounded()) {
paramQuantity->reset();
}
}

void Knob::randomize() {
if (paramQuantity && paramQuantity->isBounded()) {
float value = math::rescale(random::uniform(), 0.f, 1.f, paramQuantity->getMinValue(), paramQuantity->getMaxValue());
if (snap)
value = std::round(value);
paramQuantity->setValue(value);
}
}


} // namespace app
} // namespace rack

+ 6
- 0
src/app/ModuleWidget.cpp View File

@@ -651,6 +651,9 @@ void ModuleWidget::resetAction() {
h->moduleId = module->id;
h->oldModuleJ = toJson();

for (ParamWidget *param : params) {
param->reset();
}
APP->engine->resetModule(module);

h->newModuleJ = toJson();
@@ -666,6 +669,9 @@ void ModuleWidget::randomizeAction() {
h->moduleId = module->id;
h->oldModuleJ = toJson();

for (ParamWidget *param : params) {
param->randomize();
}
APP->engine->randomizeModule(module);

h->newModuleJ = toJson();


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

@@ -6,7 +6,6 @@
#include "app.hpp"
#include "engine/Engine.hpp"
#include "settings.hpp"
#include "random.hpp"
#include "history.hpp"
#include "helpers.hpp"

@@ -230,7 +229,7 @@ void ParamWidget::createContextMenu() {
void ParamWidget::resetAction() {
if (paramQuantity && paramQuantity->isBounded()) {
float oldValue = paramQuantity->getValue();
paramQuantity->reset();
reset();
float newValue = paramQuantity->getValue();

if (oldValue != newValue) {


+ 14
- 0
src/app/Switch.cpp View File

@@ -1,6 +1,7 @@
#include "app/Switch.hpp"
#include "app.hpp"
#include "app/Scene.hpp"
#include "random.hpp"
#include "history.hpp"


@@ -69,6 +70,19 @@ void Switch::onDragEnd(const widget::DragEndEvent &e) {
}
}

void Switch::reset() {
if (paramQuantity && !momentary) {
paramQuantity->reset();
}
}

void Switch::randomize() {
if (paramQuantity && !momentary) {
float value = paramQuantity->getMinValue() + std::floor(random::uniform() * (paramQuantity->getRange() + 1));
paramQuantity->setValue(value);
}
}


} // namespace app
} // namespace rack

+ 2
- 2
src/engine/Engine.cpp View File

@@ -507,7 +507,7 @@ void Engine::resetModule(Module *module) {
VIPLock vipLock(internal->vipMutex);
std::lock_guard<std::recursive_mutex> lock(internal->mutex);

module->reset();
module->onReset();
}

void Engine::randomizeModule(Module *module) {
@@ -515,7 +515,7 @@ void Engine::randomizeModule(Module *module) {
VIPLock vipLock(internal->vipMutex);
std::lock_guard<std::recursive_mutex> lock(internal->mutex);

module->randomize();
module->onRandomize();
}

void Engine::bypassModule(Module *module, bool bypass) {


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

@@ -89,21 +89,6 @@ void Module::fromJson(json_t *rootJ) {
rightModuleId = json_integer_value(rightModuleIdJ);
}

void Module::reset() {
for (Param &param : params) {
param.reset();
}
onReset();
}

void Module::randomize() {
for (Param &param : params) {
if (param.randomizable)
param.randomize();
}
onRandomize();
}


} // namespace engine
} // namespace rack

+ 0
- 12
src/engine/Param.cpp View File

@@ -26,18 +26,6 @@ void Param::fromJson(json_t *rootJ) {
}
}

void Param::reset() {
if (isBounded()) {
value = defaultValue;
}
}

void Param::randomize() {
if (isBounded()) {
value = math::rescale(random::uniform(), 0.f, 1.f, minValue, maxValue);
}
}


} // namespace engine
} // namespace rack

Loading…
Cancel
Save