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.

52 lines
1.1KB

  1. #include "widgets.hpp"
  2. namespace rack {
  3. QuantityWidget::QuantityWidget() {
  4. EventChange e;
  5. onChange(e);
  6. }
  7. void QuantityWidget::setValue(float value) {
  8. // printf("xxx QuantityWidget::setValue: value=%f\n", value);
  9. if(isfinite(minValue) && isfinite(maxValue))
  10. {
  11. this->value = clamp(value, fminf(minValue, maxValue), fmaxf(minValue, maxValue));
  12. EventChange e;
  13. onChange(e);
  14. }
  15. else
  16. {
  17. // Rotary knob
  18. this->value = value;
  19. EventChange e;
  20. onChange(e);
  21. }
  22. // printf("xxx QuantityWidget::setValue: LEAVE value=%f\n", value);
  23. }
  24. void QuantityWidget::setLimits(float minValue, float maxValue) {
  25. this->minValue = minValue;
  26. this->maxValue = maxValue;
  27. }
  28. void QuantityWidget::setDefaultValue(float defaultValue) {
  29. this->defaultValue = defaultValue;
  30. setValue(defaultValue);
  31. }
  32. std::string QuantityWidget::getText() {
  33. std::string text = label;
  34. text += ": ";
  35. text += stringf("%.*f", precision, value);
  36. text += unit;
  37. return text;
  38. }
  39. void QuantityWidget::onMouseLeave(EventMouseLeave &e) {
  40. revert_val = INVALID_REVERT_VAL;
  41. }
  42. } // namespace rack