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.

92 lines
2.0KB

  1. #include "Fl_Osc_DialF.H"
  2. #include "Fl_Osc_Interface.h"
  3. #include "Fl_Osc_Pane.H"
  4. #include <cstdlib>
  5. #include <cstring>
  6. #include <cmath>
  7. #include <cassert>
  8. #include <sstream>
  9. template<typename A, typename B>
  10. B string_cast(const A &a)
  11. {
  12. std::stringstream s;
  13. s.precision(3);
  14. B b;
  15. s << " " << a << " ";
  16. s >> b;
  17. return b;
  18. }
  19. static void callback_fn_dialf(Fl_Widget *w, void *)
  20. {
  21. ((Fl_Osc_DialF*)w)->cb();
  22. }
  23. Fl_Osc_DialF::Fl_Osc_DialF(int X, int Y, int W, int H, const char *label)
  24. :WidgetPDial(X,Y,W,H, label), Fl_Osc_Widget()
  25. {
  26. //bounds(0.0, 127.0f);
  27. WidgetPDial::callback(callback_fn_dialf);
  28. }
  29. void Fl_Osc_DialF::init(const char *path)
  30. {
  31. Fl_Osc_Pane *pane = fetch_osc_pane(this);
  32. assert(pane);
  33. osc = pane->osc;
  34. ext = path;
  35. loc = pane->base;
  36. oscRegister(path);
  37. integer_step = false;
  38. };
  39. Fl_Osc_DialF::~Fl_Osc_DialF(void)
  40. {}
  41. void Fl_Osc_DialF::callback(Fl_Callback *cb, void *p)
  42. {
  43. cb_data.first = cb;
  44. cb_data.second = p;
  45. }
  46. int Fl_Osc_DialF::handle(int ev)
  47. {
  48. bool middle_mouse = (ev == FL_PUSH && Fl::event_state(FL_BUTTON2) && !Fl::event_shift());
  49. bool ctl_click = (ev == FL_PUSH && Fl::event_state(FL_BUTTON1) && Fl::event_ctrl());
  50. bool shift_middle = (ev == FL_PUSH && Fl::event_state(FL_BUTTON2) && Fl::event_shift());
  51. if(middle_mouse || ctl_click) {
  52. printf("Trying to learn...\n");
  53. osc->write("/learn", "s", (loc+ext).c_str());
  54. return 1;
  55. } else if(shift_middle) {
  56. osc->write("/unlearn", "s", (loc+ext).c_str());
  57. return 1;
  58. }
  59. return WidgetPDial::handle(ev);
  60. }
  61. void Fl_Osc_DialF::OSC_value(float v)
  62. {
  63. value(v);
  64. }
  65. void Fl_Osc_DialF::update(void)
  66. {
  67. oscWrite(ext);
  68. }
  69. void Fl_Osc_DialF::cb(void)
  70. {
  71. assert(osc);
  72. oscWrite(ext, "f", (float)value());
  73. if(cb_data.first)
  74. cb_data.first(this, cb_data.second);
  75. // label_str = string_cast<float,string>(val);
  76. // label(" ");
  77. // label(label_str.c_str());
  78. }