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 2.0KB

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