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.

174 lines
4.3KB

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