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.

Fl_Osc_ListView.cpp 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "Fl_Osc_ListView.H"
  2. #include "Fl_Osc_Pane.H"
  3. #include <cstdio>
  4. #include <rtosc/rtosc.h>
  5. Fl_Osc_ListView::Fl_Osc_ListView(int x,int y, int w, int h, const char *label)
  6. :Fl_Browser(x,y,w,h,label), data(0)
  7. {}
  8. Fl_Osc_ListView::~Fl_Osc_ListView(void)
  9. {
  10. delete data;
  11. };
  12. void Fl_Osc_ListView::init(const char *path_)
  13. {
  14. Fl_Osc_Pane *pane = fetch_osc_pane(this);
  15. assert(pane);
  16. osc = pane->osc;
  17. loc = pane->base;
  18. assert(osc);
  19. path = path_;
  20. data = new Osc_SimpleListModel(osc);
  21. data->callback = [this](Osc_SimpleListModel::list_t l){this->doUpdate(l);};
  22. data->doUpdate(loc+path_);
  23. }
  24. void Fl_Osc_ListView::doUpdate(Osc_SimpleListModel::list_t l)
  25. {
  26. this->clear();
  27. for(int i=0; i<(int)l.size(); ++i) {
  28. this->add(l[i].c_str());
  29. }
  30. }
  31. void Fl_Osc_ListView::update(void)
  32. {
  33. data->doUpdate(loc+path);
  34. }
  35. void Fl_Osc_ListView::insert(std::string s, int offset)
  36. {
  37. assert(offset);
  38. data->list.insert(data->list.begin()+offset-1, s);
  39. data->apply();
  40. //fprintf(stderr, "UNIMPLEMENTED\n");
  41. }
  42. void Fl_Osc_ListView::append(std::string s)
  43. {
  44. data->list.push_back(s);
  45. data->apply();
  46. }
  47. void Fl_Osc_ListView::doMove(int i, int j)
  48. {
  49. assert(i);
  50. assert(j);
  51. auto &list = data->list;
  52. std::string value = list[j-1];
  53. list.erase(list.begin()+j-1);
  54. list.insert(list.begin()+i-1, value);
  55. //std::swap(data->list[i-1], data->list[j-1]);
  56. data->apply();
  57. }
  58. void Fl_Osc_ListView::doRemove(int offset)
  59. {
  60. assert(offset);
  61. data->list.erase(data->list.begin()+offset-1);
  62. data->apply();
  63. }
  64. void Fl_Osc_ListView::sendUpdate() const
  65. {
  66. }