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.

122 lines
3.0KB

  1. #include "Fl_Osc_Widget.H"
  2. #include <rtosc/rtosc.h>
  3. Fl_Osc_Widget::Fl_Osc_Widget(void) //Deprecated
  4. :loc(), osc(NULL)
  5. {}
  6. Fl_Osc_Widget::Fl_Osc_Widget(std::string loc_, Fl_Osc_Interface *osc_)
  7. :loc(loc_), osc(osc_)
  8. {
  9. assert(osc);
  10. }
  11. Fl_Osc_Widget:: Fl_Osc_Widget(Fl_Widget *self)
  12. {
  13. assert(fetch_osc_pane(self));
  14. if(auto *pane = fetch_osc_pane(self)) {
  15. osc = pane->osc;
  16. loc = pane->loc();
  17. }
  18. assert(osc);
  19. }
  20. Fl_Osc_Widget::~Fl_Osc_Widget(void)
  21. {
  22. if(osc)
  23. osc->removeLink(this);
  24. };
  25. void Fl_Osc_Widget::OSC_value(float) {}
  26. void Fl_Osc_Widget::OSC_value(bool) {}
  27. void Fl_Osc_Widget::OSC_value(int) {}
  28. void Fl_Osc_Widget::OSC_value(char) {}
  29. void Fl_Osc_Widget::OSC_value(unsigned,void*) {}
  30. void Fl_Osc_Widget::OSC_value(const char *) {}
  31. //labeled forwarding methods
  32. void Fl_Osc_Widget::OSC_value(float x, const char *) {OSC_value(x);}
  33. void Fl_Osc_Widget::OSC_value(bool x, const char *) {OSC_value(x);}
  34. void Fl_Osc_Widget::OSC_value(int x, const char *) {OSC_value(x);}
  35. void Fl_Osc_Widget::OSC_value(char x, const char *) {OSC_value(x);}
  36. void Fl_Osc_Widget::OSC_value(unsigned x, void *v, const char *) {OSC_value(x,v);}
  37. void Fl_Osc_Widget::OSC_value(const char *x, const char *) {OSC_value(x);}
  38. void Fl_Osc_Widget::OSC_raw(const char *)
  39. {}
  40. void Fl_Osc_Widget::oscWrite(std::string path, const char *args, ...)
  41. {
  42. char buffer[1024];
  43. //puts("writing OSC");
  44. //printf("Path = '%s'\n", path.c_str());
  45. va_list va;
  46. va_start(va, args);
  47. if(rtosc_vmessage(buffer, 1024, (loc+path).c_str(), args, va))
  48. osc->writeRaw(buffer);
  49. else
  50. puts("Dangerous Event ommision");
  51. va_end(va);
  52. ////Try to pretty print basic events
  53. //if(!strcmp(args, "c") || !strcmp(args, "i"))
  54. // printf("Args = ['%d']\n", rtosc_argument(buffer, 0).i);
  55. //if(!strcmp(args, "f"))
  56. // printf("Args = ['%f']\n", rtosc_argument(buffer, 0).f);
  57. //if(!strcmp(args, "T"))
  58. // printf("Args = [True]\n");
  59. //if(!strcmp(args, "F"))
  60. // printf("Args = [False]\n");
  61. }
  62. void Fl_Osc_Widget::oscWrite(std::string path)
  63. {
  64. osc->requestValue(loc+path);
  65. }
  66. void Fl_Osc_Widget::oscRegister(const char *path)
  67. {
  68. osc->createLink(loc+path, this);
  69. osc->requestValue(loc+path);
  70. }
  71. void Fl_Osc_Widget::update(void)
  72. {
  73. if(*((loc+ext).rbegin()) != '/')
  74. osc->requestValue(loc+ext);
  75. }
  76. Fl_Osc_Pane *Fl_Osc_Widget::fetch_osc_pane(Fl_Widget *w)
  77. {
  78. if(!w)
  79. return NULL;
  80. Fl_Osc_Pane *pane = dynamic_cast<Fl_Osc_Pane*>(w->parent());
  81. if(pane)
  82. return pane;
  83. return fetch_osc_pane(w->parent());
  84. }
  85. void Fl_Osc_Widget::rebase(std::string new_base)
  86. {
  87. osc->renameLink(loc+ext, new_base+ext, this);
  88. loc = new_base;
  89. osc->requestValue(loc+ext);
  90. }
  91. void Fl_Osc_Widget::oscMove(std::string new_ext)
  92. {
  93. osc->renameLink(loc+ext, loc+new_ext, this);
  94. ext = new_ext;
  95. osc->requestValue(loc+ext);
  96. }
  97. void Fl_Osc_Widget::oscMove(std::string old_loc, std::string new_loc)
  98. {
  99. osc->renameLink(old_loc, new_loc, this);
  100. osc->requestValue(new_loc);
  101. }