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.

124 lines
2.9KB

  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)
  10. {}
  11. void Fl_Osc_Window::init(Fl_Osc_Interface *osc_, std::string loc_)
  12. {
  13. osc = osc_;
  14. base = loc_;
  15. }
  16. std::string Fl_Osc_Window::loc(void) const
  17. {
  18. return base;
  19. }
  20. static void nested_update(Fl_Group *g)
  21. {
  22. unsigned nchildren = g->children();
  23. for(unsigned i=0; i < nchildren; ++i) {
  24. Fl_Widget *widget = g->child(i);
  25. if(Fl_Osc_Widget *o = dynamic_cast<Fl_Osc_Widget*>(widget)) {
  26. o->update();
  27. } else if(Fl_Group *o = dynamic_cast<Fl_Group*>(widget)) {
  28. nested_update(o);
  29. }
  30. }
  31. }
  32. void Fl_Osc_Window::update(void)
  33. {
  34. unsigned nchildren = this->children();
  35. for(unsigned i=0; i < nchildren; ++i) {
  36. Fl_Widget *widget = this->child(i);
  37. if(Fl_Osc_Widget *o = dynamic_cast<Fl_Osc_Widget*>(widget)) {
  38. o->update();
  39. }
  40. if(dynamic_cast<Fl_Group*>(widget))
  41. nested_update(dynamic_cast<Fl_Group*>(widget));
  42. }
  43. }
  44. static void nested_rebase(Fl_Group *g, std::string new_base)
  45. {
  46. unsigned nchildren = g->children();
  47. for(unsigned i=0; i < nchildren; ++i) {
  48. Fl_Widget *widget = g->child(i);
  49. if(Fl_Osc_Widget *o = dynamic_cast<Fl_Osc_Widget*>(widget)) {
  50. o->rebase(new_base);
  51. } else if(Fl_Osc_Group *o = dynamic_cast<Fl_Osc_Group*>(widget)) {
  52. o->rebase(new_base);
  53. } else if(Fl_Group *o = dynamic_cast<Fl_Group*>(widget)) {
  54. nested_rebase(o, new_base);
  55. }
  56. }
  57. }
  58. void Fl_Osc_Window::rebase(std::string new_base)
  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->rebase(new_base);
  65. }
  66. if(Fl_Osc_Group *o = dynamic_cast<Fl_Osc_Group*>(widget))
  67. o->rebase(new_base);
  68. else if(dynamic_cast<Fl_Group*>(widget))
  69. nested_rebase(dynamic_cast<Fl_Group*>(widget), new_base);
  70. }
  71. }
  72. static Fl_Osc_Pane *find_osc_pane(Fl_Widget *root)
  73. {
  74. if(!root)
  75. return NULL;
  76. Fl_Group *next = root->parent();
  77. if(auto *p = dynamic_cast<Fl_Osc_Pane*>(next))
  78. return p;
  79. else
  80. return find_osc_pane(next);
  81. }
  82. Fl_Osc_Group::Fl_Osc_Group(int x, int y, int w, int h, const char *L)
  83. :Fl_Group(x,y,w,h,L)
  84. {
  85. if(auto *p = find_osc_pane(this)) {
  86. osc = p->osc;
  87. base = p->loc();
  88. assert(osc);
  89. }
  90. };
  91. std::string Fl_Osc_Group::loc(void) const
  92. {
  93. return base + ext;
  94. }
  95. void Fl_Osc_Group::rebase(std::string new_base)
  96. {
  97. nested_rebase(this, new_base+ext);
  98. base = new_base;
  99. }
  100. void Fl_Osc_Group::reext(std::string new_ext)
  101. {
  102. nested_rebase(this, base+new_ext);
  103. ext = new_ext;
  104. }