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.

80 lines
2.1KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. Osc_SimpleListModel.h - OSC List View
  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_SimpleListModel:public Fl_Osc_Widget
  16. {
  17. public:
  18. Osc_SimpleListModel(Fl_Osc_Interface *osc_)
  19. :Fl_Osc_Widget("", osc_), list_size(0)
  20. {
  21. assert(osc);
  22. }
  23. typedef std::vector<std::string> list_t;
  24. list_t list;
  25. std::function<void(list_t)> callback;
  26. unsigned list_size;
  27. void doUpdate(std::string url)
  28. {
  29. if(!ext.empty())
  30. osc->removeLink(this);
  31. ext = url;
  32. oscRegister(ext.c_str());
  33. }
  34. void apply()
  35. {
  36. if(list.size() == 0) {
  37. oscWrite("", "I");
  38. }
  39. char types[list.size()+1];
  40. rtosc_arg_t args[list.size()];
  41. //zero out data
  42. memset(types, 0, sizeof(types));
  43. memset(args, 0, sizeof(args));
  44. for(int i=0; i<(int)list.size(); ++i) {
  45. types[i] = 's';
  46. args[i].s = list[i].c_str();
  47. }
  48. char buffer[1024*5];
  49. rtosc_amessage(buffer, sizeof(buffer), ext.c_str(), types, args);
  50. osc->writeRaw(buffer);
  51. }
  52. //Raw messages
  53. virtual void OSC_raw(const char *msg)
  54. {
  55. std::string args = rtosc_argument_string(msg);
  56. const int list_size = args.length();
  57. for(int i=0; i<list_size; ++i)
  58. if(args[i] != 's')
  59. return;
  60. list.clear();
  61. list.resize(list_size);
  62. for(int idx=0; idx<list_size; ++idx)
  63. list[idx] = rtosc_argument(msg, idx).s;
  64. if(callback)
  65. callback(list);
  66. }
  67. };