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.

50 lines
1015B

  1. #include "app/ParamWidget.hpp"
  2. #include "random.hpp"
  3. namespace rack {
  4. void ParamWidget::step() {
  5. if (quantity) {
  6. float value = quantity->getValue();
  7. // Trigger change event when quantity value changes
  8. if (value != dirtyValue) {
  9. dirtyValue = value;
  10. event::Change eChange;
  11. onChange(eChange);
  12. }
  13. }
  14. OpaqueWidget::step();
  15. }
  16. void ParamWidget::fromJson(json_t *rootJ) {
  17. json_t *valueJ = json_object_get(rootJ, "value");
  18. if (valueJ) {
  19. if (quantity)
  20. quantity->setValue(json_number_value(valueJ));
  21. }
  22. }
  23. void ParamWidget::onButton(const event::Button &e) {
  24. // Right click to reset
  25. if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_RIGHT) {
  26. if (quantity)
  27. quantity->reset();
  28. // Here's another way of doing it, but either works.
  29. // dynamic_cast<ParamQuantity*>(quantity)->getParam()->reset();
  30. }
  31. OpaqueWidget::onButton(e);
  32. }
  33. void ParamWidget::onDragMove(const event::DragMove &e) {
  34. if (quantity) {
  35. DEBUG("%s", quantity->getString().c_str());
  36. }
  37. }
  38. } // namespace rack