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.

81 lines
1.7KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. Fl_Osc_Choice.cpp - OSC Powered Dropdown Choice
  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_Choice.H"
  11. #include "Fl_Osc_Interface.h"
  12. #include "Fl_Osc_Pane.H"
  13. #include <cstdlib>
  14. #include <cstring>
  15. #include <cmath>
  16. #include <cassert>
  17. #include <sstream>
  18. static void callback_fn_choice(Fl_Widget *w, void *)
  19. {
  20. ((Fl_Osc_Choice*)w)->cb();
  21. }
  22. Fl_Osc_Choice::Fl_Osc_Choice(int X, int Y, int W, int H, const char *label)
  23. :Fl_Choice(X,Y,W,H, label), Fl_Osc_Widget(this), cb_data(NULL, NULL)
  24. {
  25. min = 0;
  26. Fl_Choice::callback(callback_fn_choice, NULL);
  27. }
  28. void Fl_Osc_Choice::init(std::string path_, int base)
  29. {
  30. min = base;
  31. ext = path_;
  32. Fl_Osc_Pane *pane = fetch_osc_pane(this);
  33. assert(pane);
  34. assert(pane->osc);
  35. osc = pane->osc;
  36. oscRegister(path_.c_str());
  37. };
  38. Fl_Osc_Choice::~Fl_Osc_Choice(void)
  39. {}
  40. void Fl_Osc_Choice::callback(Fl_Callback *cb, void *p)
  41. {
  42. cb_data.first = cb;
  43. cb_data.second = p;
  44. }
  45. void Fl_Osc_Choice::OSC_value(int v)
  46. {
  47. if(v-min == value())
  48. return;
  49. value(v-min);
  50. if(cb_data.first)
  51. cb_data.first(this, cb_data.second);
  52. }
  53. void Fl_Osc_Choice::OSC_value(char v)
  54. {
  55. OSC_value((int)v);
  56. }
  57. void Fl_Osc_Choice::cb(void)
  58. {
  59. assert(osc);
  60. oscWrite(ext, "i", value()+min);
  61. if(cb_data.first)
  62. cb_data.first(this, cb_data.second);
  63. }
  64. void Fl_Osc_Choice::update(void)
  65. {
  66. assert(osc);
  67. oscWrite(ext);
  68. }