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.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. Osc_IntModel.h - OSC Updated Integer
  4. Copyright (C) 2016 Mark McCurry
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. */
  10. #pragma once
  11. #include "Fl_Osc_Widget.H"
  12. #include <functional>
  13. #include <vector>
  14. #include <rtosc/rtosc.h>
  15. class Osc_IntModel:public Fl_Osc_Widget
  16. {
  17. public:
  18. Osc_IntModel(Fl_Osc_Interface *osc_)
  19. :Fl_Osc_Widget("", osc_), value(0)
  20. {
  21. assert(osc);
  22. }
  23. typedef int value_t;
  24. value_t value;
  25. std::function<void(value_t)> callback;
  26. void updateVal(value_t v)
  27. {
  28. value = v;
  29. oscWrite(ext, "i", v);
  30. }
  31. void doUpdate(std::string url)
  32. {
  33. if(!ext.empty())
  34. osc->removeLink(this);
  35. ext = url;
  36. oscRegister(ext.c_str());
  37. }
  38. //Raw messages
  39. virtual void OSC_raw(const char *msg)
  40. {
  41. std::string args = rtosc_argument_string(msg);
  42. if(args == "i") {
  43. value = rtosc_argument(msg, 0).i;
  44. if(callback)
  45. callback(value);
  46. } else if(args == "T") {
  47. value = 1;
  48. if(callback)
  49. callback(value);
  50. } else if(args == "F") {
  51. value = 0;
  52. if(callback)
  53. callback(value);
  54. }
  55. }
  56. };