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.

154 lines
4.0KB

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