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.

134 lines
3.4KB

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