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.

Fl_Osc_Widget.cpp 3.0KB

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