You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
719B

  1. #include "engine/Param.hpp"
  2. #include "random.hpp"
  3. #include "math.hpp"
  4. namespace rack {
  5. namespace engine {
  6. json_t *Param::toJson() {
  7. json_t *rootJ = json_object();
  8. // Infinite params should serialize to 0
  9. if (isBounded()) {
  10. json_object_set_new(rootJ, "value", json_real(value));
  11. }
  12. return rootJ;
  13. }
  14. void Param::fromJson(json_t *rootJ) {
  15. if (isBounded()) {
  16. json_t *valueJ = json_object_get(rootJ, "value");
  17. if (valueJ)
  18. value = json_number_value(valueJ);
  19. }
  20. }
  21. void Param::reset() {
  22. if (isBounded()) {
  23. value = defaultValue;
  24. }
  25. }
  26. void Param::randomize() {
  27. if (isBounded()) {
  28. value = math::rescale(random::uniform(), 0.f, 1.f, minValue, maxValue);
  29. }
  30. }
  31. } // namespace engine
  32. } // namespace rack