Audio plugin host https://kx.studio/carla
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.

Osc_IntModel.h 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #pragma once
  2. #include "Fl_Osc_Widget.H"
  3. #include <functional>
  4. #include <vector>
  5. #include <rtosc/rtosc.h>
  6. class Osc_IntModel:public Fl_Osc_Widget
  7. {
  8. public:
  9. Osc_IntModel(Fl_Osc_Interface *osc_)
  10. :Fl_Osc_Widget("", osc_), value(0)
  11. {
  12. assert(osc);
  13. }
  14. typedef int value_t;
  15. value_t value;
  16. std::function<void(value_t)> callback;
  17. void updateVal(value_t v)
  18. {
  19. value = v;
  20. oscWrite(ext, "i", v);
  21. }
  22. void doUpdate(std::string url)
  23. {
  24. if(!ext.empty())
  25. osc->removeLink(this);
  26. ext = url;
  27. oscRegister(ext.c_str());
  28. }
  29. //Raw messages
  30. virtual void OSC_raw(const char *msg)
  31. {
  32. std::string args = rtosc_argument_string(msg);
  33. if(args == "i") {
  34. value = rtosc_argument(msg, 0).i;
  35. if(callback)
  36. callback(value);
  37. } else if(args == "T") {
  38. value = 1;
  39. if(callback)
  40. callback(value);
  41. } else if(args == "F") {
  42. value = 0;
  43. if(callback)
  44. callback(value);
  45. }
  46. }
  47. };