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.

159 lines
3.8KB

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