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.

75 lines
1.9KB

  1. #pragma once
  2. #ifdef OSC_ENABLE
  3. struct OSCDriver;
  4. struct oscControl
  5. {
  6. public:
  7. virtual ~oscControl() {};
  8. void Draw(OSCDriver *drv, bool force = false);
  9. bool isDirty() { return m_dirty; }
  10. bool Intersect(std::string address)
  11. {
  12. return m_address.compare(address) == 0;
  13. }
  14. void ChangeFromGUI(OSCDriver *drv); // gui updated: the new value is already in the binded parameter
  15. void onOscMsg(Module *pModule, OSCMsg msg)
  16. {
  17. setValue(pModule, msg.value);
  18. }
  19. bool DetectGUIChanges() { return getValue() != m_lastDrawnValue; }
  20. int ID() { return is_light ? pBindedLight->firstLightId : pBindedParam->paramId; }
  21. void bindWidget(ModuleLightWidget *p) { pBindedLight = p; is_light = true; }
  22. void bindWidget(ParamWidget *p) { pBindedParam = p; }
  23. oscControl(std::string address)
  24. {
  25. m_address = address;
  26. is_light = false;
  27. pBindedLight = NULL;
  28. pBindedParam = NULL;
  29. m_dirty = true;
  30. m_lastDrawnValue = -10202020;
  31. }
  32. private:
  33. float getValue() { return is_light ? pBindedLight->module->lights[pBindedLight->firstLightId].getBrightness() : pBindedParam->value; }
  34. void setValue(Module *pModule, float v)
  35. {
  36. if(is_light)
  37. pBindedLight->module->lights[pBindedLight->firstLightId].value = v;
  38. else
  39. {
  40. v = rescale(v, 0.0, 1.0, pBindedParam->minValue, pBindedParam->maxValue);
  41. SVGKnob *pk = (SVGKnob *)dynamic_cast<SVGKnob *>(pBindedParam);
  42. if(pk != NULL)
  43. {
  44. pModule->params[pBindedParam->paramId].value = pBindedParam->value = v;
  45. pk->dirty = true;
  46. } else
  47. {
  48. SVGFader *pk1 = (SVGFader *)dynamic_cast<SVGFader *>(pBindedParam);
  49. if(pk1 != NULL)
  50. {
  51. pModule->params[pBindedParam->paramId].value = pBindedParam->value = v;
  52. pk1->dirty = true;
  53. } else
  54. pBindedParam->setValue(v);
  55. }
  56. }
  57. m_lastDrawnValue = v;
  58. m_dirty = false;
  59. }
  60. std::string m_address;
  61. ModuleLightWidget *pBindedLight;
  62. ParamWidget *pBindedParam;
  63. bool m_dirty;
  64. float m_lastDrawnValue;
  65. bool is_light;
  66. };
  67. #endif // OSC