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. using namespace std;
  15. static void callback_fn_choice_nio(Fl_Widget *w, void *);
  16. class Fl_Osc_StrChoice:public Fl_Choice, public Fl_Osc_Widget
  17. {
  18. public:
  19. Fl_Osc_StrChoice(int X, int Y, int W, int H, const char *label = NULL)
  20. :Fl_Choice(X,Y,W,H, label), Fl_Osc_Widget(this), cb_data(NULL, NULL)
  21. {
  22. Fl_Choice::callback(callback_fn_choice_nio, NULL);
  23. }
  24. virtual ~Fl_Osc_StrChoice(void) {};
  25. void init(std::string path_)
  26. {
  27. ext = path_;
  28. Fl_Osc_Pane *pane = fetch_osc_pane(this);
  29. assert(pane);
  30. assert(pane->osc);
  31. osc = pane->osc;
  32. oscRegister(path_.c_str());
  33. };
  34. void OSC_value(const char *S) override
  35. {
  36. for(int i=0; i<size()-1; ++i) {
  37. printf("size = %d, i=%d, text='%s'\n", size(), i, text(i));
  38. if(!strcmp(S, text(i)))
  39. value(i);
  40. }
  41. }
  42. //Refetch parameter information
  43. void update(void)
  44. {
  45. assert(osc);
  46. oscWrite(ext);
  47. }
  48. void callback(Fl_Callback *cb, void *p = NULL)
  49. {
  50. cb_data.first = cb;
  51. cb_data.second = p;
  52. }
  53. void cb(void)
  54. {
  55. assert(osc);
  56. if(text(value()))
  57. oscWrite(ext, "s", text(value()));
  58. if(cb_data.first)
  59. cb_data.first(this, cb_data.second);
  60. }
  61. private:
  62. int min;
  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->update("/io/source-list");
  102. audio_opt->update("/io/sink-list");
  103. resizable(this);
  104. size_range(400, 300);
  105. }
  106. NioUI::~NioUI()
  107. {}
  108. void NioUI::refresh()
  109. {
  110. midi_opt->update("/io/source-list");
  111. audio_opt->update("/io/sink-list");
  112. midi->update();
  113. audio->update();
  114. }
  115. void NioUI::midiCallback(Fl_Widget *c)
  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 *c)
  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. }