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_SimpleListModel.h 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #include "Fl_Osc_Widget.H"
  3. #include <functional>
  4. #include <vector>
  5. #include <rtosc/rtosc.h>
  6. class Osc_SimpleListModel:public Fl_Osc_Widget
  7. {
  8. public:
  9. Osc_SimpleListModel(Fl_Osc_Interface *osc_)
  10. :Fl_Osc_Widget("", osc_), list_size(0)
  11. {
  12. assert(osc);
  13. }
  14. typedef std::vector<std::string> list_t;
  15. list_t list;
  16. std::function<void(list_t)> callback;
  17. unsigned list_size;
  18. void update(std::string url)
  19. {
  20. if(!ext.empty())
  21. osc->removeLink(this);
  22. ext = url;
  23. oscRegister(ext.c_str());
  24. }
  25. void apply()
  26. {
  27. if(list.size() == 0) {
  28. oscWrite("", "I");
  29. }
  30. char types[list.size()+1];
  31. rtosc_arg_t args[list.size()];
  32. //zero out data
  33. memset(types, 0, sizeof(types));
  34. memset(args, 0, sizeof(args));
  35. for(int i=0; i<(int)list.size(); ++i) {
  36. types[i] = 's';
  37. args[i].s = list[i].c_str();
  38. }
  39. char buffer[1024*5];
  40. rtosc_amessage(buffer, sizeof(buffer), ext.c_str(), types, args);
  41. osc->writeRaw(buffer);
  42. }
  43. //Raw messages
  44. virtual void OSC_raw(const char *msg)
  45. {
  46. std::string args = rtosc_argument_string(msg);
  47. const int list_size = args.length();
  48. for(int i=0; i<list_size; ++i)
  49. if(args[i] != 's')
  50. return;
  51. list.clear();
  52. list.resize(list_size);
  53. for(int idx=0; idx<list_size; ++idx)
  54. list[idx] = rtosc_argument(msg, idx).s;
  55. if(callback)
  56. callback(list);
  57. }
  58. };