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.

NioUI.cpp 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #include "NioUI.h"
  2. #include "../Nio/Nio.h"
  3. #include <cstdio>
  4. #include <iostream>
  5. #include <cstring>
  6. #include <FL/Fl_Pack.H>
  7. #include <FL/Fl_Spinner.H>
  8. #include <FL/Enumerations.H>
  9. #include <FL/Fl_Choice.H>
  10. #include <FL/Fl_Tabs.H>
  11. #include <FL/Fl_Group.H>
  12. #include <FL/Fl_Text_Display.H>
  13. #include "Osc_SimpleListModel.h"
  14. #include "Fl_Osc_Pane.H"
  15. using namespace std;
  16. static void callback_fn_choice_nio(Fl_Widget *w, void *);
  17. class Fl_Osc_StrChoice:public Fl_Choice, public Fl_Osc_Widget
  18. {
  19. public:
  20. Fl_Osc_StrChoice(int X, int Y, int W, int H, const char *label = NULL)
  21. :Fl_Choice(X,Y,W,H, label), Fl_Osc_Widget(this), cb_data(NULL, NULL)
  22. {
  23. Fl_Choice::callback(callback_fn_choice_nio, NULL);
  24. }
  25. virtual ~Fl_Osc_StrChoice(void) {};
  26. void init(std::string path_)
  27. {
  28. ext = path_;
  29. Fl_Osc_Pane *pane = fetch_osc_pane(this);
  30. assert(pane);
  31. assert(pane->osc);
  32. osc = pane->osc;
  33. oscRegister(path_.c_str());
  34. };
  35. void OSC_value(const char *S) override
  36. {
  37. for(int i=0; i<size()-1; ++i) {
  38. printf("size = %d, i=%d, text='%s'\n", size(), i, text(i));
  39. if(!strcmp(S, text(i)))
  40. value(i);
  41. }
  42. }
  43. //Refetch parameter information
  44. void update(void)
  45. {
  46. assert(osc);
  47. oscWrite(ext);
  48. }
  49. void callback(Fl_Callback *cb, void *p = NULL)
  50. {
  51. cb_data.first = cb;
  52. cb_data.second = p;
  53. }
  54. void cb(void)
  55. {
  56. assert(osc);
  57. if(text(value()))
  58. oscWrite(ext, "s", text(value()));
  59. if(cb_data.first)
  60. cb_data.first(this, cb_data.second);
  61. }
  62. private:
  63. std::pair<Fl_Callback*, void*> cb_data;
  64. };
  65. static void callback_fn_choice_nio(Fl_Widget *w, void *)
  66. {
  67. ((Fl_Osc_StrChoice*)w)->cb();
  68. }
  69. NioUI::NioUI(Fl_Osc_Interface *osc)
  70. :Fl_Window(200, 100, 400, 400, "New IO Controls")
  71. {
  72. //hm, I appear to be leaking memory
  73. Fl_Osc_Group *settings = new Fl_Osc_Group(0, 20, 400, 400 - 35, "Settings");
  74. {
  75. settings->osc = osc;
  76. audio = new Fl_Osc_StrChoice(60, 80, 100, 25, "Audio");
  77. //audio->callback(audioCallback);
  78. audio->init("/io/sink");
  79. midi = new Fl_Osc_StrChoice(60, 100, 100, 25, "Midi");
  80. //midi->callback(midiCallback);
  81. midi->init("/io/source");
  82. }
  83. settings->end();
  84. //Get options
  85. midi_opt = new Osc_SimpleListModel(osc);
  86. audio_opt = new Osc_SimpleListModel(osc);
  87. using list_t = Osc_SimpleListModel::list_t;
  88. //initialize midi list
  89. midi_opt->callback = [this](list_t list) {
  90. printf("midi list updating...\n");
  91. midi->clear();
  92. for(auto io:list)
  93. midi->add(io.c_str());
  94. };
  95. //initialize audio list
  96. audio_opt->callback = [this](list_t list) {
  97. audio->clear();
  98. for(auto io:list)
  99. audio->add(io.c_str());
  100. };
  101. midi_opt->doUpdate("/io/source-list");
  102. audio_opt->doUpdate("/io/sink-list");
  103. resizable(this);
  104. size_range(400, 300);
  105. }
  106. NioUI::~NioUI()
  107. {}
  108. void NioUI::refresh()
  109. {
  110. midi_opt->doUpdate("/io/source-list");
  111. audio_opt->doUpdate("/io/sink-list");
  112. midi->update();
  113. audio->update();
  114. }
  115. void NioUI::midiCallback(Fl_Widget *)
  116. {
  117. //bool good = Nio::setSource(static_cast<Fl_Choice *>(c)->text());
  118. //static_cast<Fl_Choice *>(c)->textcolor(fl_rgb_color(255 * !good, 0, 0));
  119. }
  120. void NioUI::audioCallback(Fl_Widget *)
  121. {
  122. //bool good = Nio::setSink(static_cast<Fl_Choice *>(c)->text());
  123. //static_cast<Fl_Choice *>(c)->textcolor(fl_rgb_color(255 * !good, 0, 0));
  124. }