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.

151 lines
3.7KB

  1. #include "Fl_Osc_Pane.H"
  2. #include "Fl_Osc_Widget.H"
  3. #include <cassert>
  4. #include <cstdio>
  5. Fl_Osc_Pane::Fl_Osc_Pane(void)
  6. :osc(NULL), base()
  7. {}
  8. Fl_Osc_Window::Fl_Osc_Window(int w, int h, const char *L)
  9. :Fl_Double_Window(w,h,L), title_ext(NULL)
  10. {}
  11. void Fl_Osc_Window::init(Fl_Osc_Interface *osc_, std::string loc_)
  12. {
  13. title_ext = new Osc_DataModel(osc_);
  14. title_ext->doUpdate("/ui/title");
  15. title_ext->callback = [this](string next) {
  16. //printf("old: %s\n", title_orig.c_str());
  17. const char *orig = title_orig.c_str();
  18. // 12345678901
  19. const char *sub = strstr(orig, "zynaddsubfx");
  20. if(!sub)
  21. sub = strstr(orig, "ZynAddSubFX");
  22. title_new = "";
  23. while(*orig) {
  24. if(orig == sub) {
  25. title_new += next;
  26. orig += 11;
  27. } else
  28. title_new += *orig++;
  29. }
  30. //title_new = title_orig + next;
  31. this->label(title_new.c_str());
  32. };
  33. title_orig = label();
  34. osc = osc_;
  35. base = loc_;
  36. }
  37. Fl_Osc_Window::~Fl_Osc_Window(void)
  38. {
  39. delete title_ext;
  40. }
  41. std::string Fl_Osc_Window::loc(void) const
  42. {
  43. return base;
  44. }
  45. static void nested_update(Fl_Group *g)
  46. {
  47. unsigned nchildren = g->children();
  48. for(unsigned i=0; i < nchildren; ++i) {
  49. Fl_Widget *widget = g->child(i);
  50. if(Fl_Osc_Widget *o = dynamic_cast<Fl_Osc_Widget*>(widget)) {
  51. o->update();
  52. } else if(Fl_Group *o = dynamic_cast<Fl_Group*>(widget)) {
  53. nested_update(o);
  54. }
  55. }
  56. }
  57. void Fl_Osc_Window::update(void)
  58. {
  59. unsigned nchildren = this->children();
  60. for(unsigned i=0; i < nchildren; ++i) {
  61. Fl_Widget *widget = this->child(i);
  62. if(Fl_Osc_Widget *o = dynamic_cast<Fl_Osc_Widget*>(widget)) {
  63. o->update();
  64. }
  65. if(dynamic_cast<Fl_Group*>(widget))
  66. nested_update(dynamic_cast<Fl_Group*>(widget));
  67. }
  68. }
  69. static void nested_rebase(Fl_Group *g, std::string new_base)
  70. {
  71. unsigned nchildren = g->children();
  72. for(unsigned i=0; i < nchildren; ++i) {
  73. Fl_Widget *widget = g->child(i);
  74. if(Fl_Osc_Widget *o = dynamic_cast<Fl_Osc_Widget*>(widget)) {
  75. o->rebase(new_base);
  76. } else if(Fl_Osc_Group *o = dynamic_cast<Fl_Osc_Group*>(widget)) {
  77. o->rebase(new_base);
  78. } else if(Fl_Group *o = dynamic_cast<Fl_Group*>(widget)) {
  79. nested_rebase(o, new_base);
  80. }
  81. }
  82. }
  83. void Fl_Osc_Window::rebase(std::string new_base)
  84. {
  85. unsigned nchildren = this->children();
  86. for(unsigned i=0; i < nchildren; ++i) {
  87. Fl_Widget *widget = this->child(i);
  88. if(Fl_Osc_Widget *o = dynamic_cast<Fl_Osc_Widget*>(widget)) {
  89. o->rebase(new_base);
  90. }
  91. if(Fl_Osc_Group *o = dynamic_cast<Fl_Osc_Group*>(widget))
  92. o->rebase(new_base);
  93. else if(dynamic_cast<Fl_Group*>(widget))
  94. nested_rebase(dynamic_cast<Fl_Group*>(widget), new_base);
  95. }
  96. }
  97. static Fl_Osc_Pane *find_osc_pane(Fl_Widget *root)
  98. {
  99. if(!root)
  100. return NULL;
  101. Fl_Group *next = root->parent();
  102. if(auto *p = dynamic_cast<Fl_Osc_Pane*>(next))
  103. return p;
  104. else
  105. return find_osc_pane(next);
  106. }
  107. Fl_Osc_Group::Fl_Osc_Group(int x, int y, int w, int h, const char *L)
  108. :Fl_Group(x,y,w,h,L)
  109. {
  110. if(auto *p = find_osc_pane(this)) {
  111. osc = p->osc;
  112. base = p->loc();
  113. assert(osc);
  114. }
  115. };
  116. std::string Fl_Osc_Group::loc(void) const
  117. {
  118. return base + ext;
  119. }
  120. void Fl_Osc_Group::rebase(std::string new_base)
  121. {
  122. nested_rebase(this, new_base+ext);
  123. base = new_base;
  124. }
  125. void Fl_Osc_Group::reext(std::string new_ext)
  126. {
  127. nested_rebase(this, base+new_ext);
  128. ext = new_ext;
  129. }