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_Slider.cpp 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include <FL/Fl.H>
  2. #include "Fl_Osc_Slider.H"
  3. #include "Fl_Osc_Interface.h"
  4. #include "Fl_Osc_Pane.H"
  5. #include <cstdlib>
  6. #include <cstring>
  7. #include <cmath>
  8. #include <cassert>
  9. #include <sstream>
  10. static double min__(double a, double b)
  11. {
  12. return a<b?a:b;
  13. }
  14. Fl_Osc_Slider::Fl_Osc_Slider(int X, int Y, int W, int H, const char *label)
  15. :Fl_Slider(X,Y,W,H,label), Fl_Osc_Widget(this), cb_data(NULL, NULL)
  16. {
  17. //bounds(0.0f,1.0f);
  18. Fl_Slider::callback(Fl_Osc_Slider::_cb);
  19. }
  20. void Fl_Osc_Slider::init(std::string path_, char type_)
  21. {
  22. osc_type = type_;
  23. ext = path_;
  24. oscRegister(ext.c_str());
  25. }
  26. Fl_Osc_Slider::~Fl_Osc_Slider(void)
  27. {}
  28. void Fl_Osc_Slider::OSC_value(int v)
  29. {
  30. const float min_ = min__(minimum(), maximum());//flipped sliders
  31. Fl_Slider::value(v+min_+fmodf(value(),1.0));
  32. }
  33. void Fl_Osc_Slider::OSC_value(float v)
  34. {
  35. const float min_ = min__(minimum(), maximum());//flipped sliders
  36. Fl_Slider::value(v+min_);
  37. }
  38. void Fl_Osc_Slider::OSC_value(char v)
  39. {
  40. const float min_ = min__(minimum(), maximum());//flipped sliders
  41. Fl_Slider::value(v+min_+fmodf(value(),1.0));
  42. }
  43. void Fl_Osc_Slider::cb(void)
  44. {
  45. const float min_ = min__(minimum(), maximum());//flipped sliders
  46. const float val = Fl_Slider::value();
  47. if(osc_type == 'f')
  48. oscWrite(ext, "f", val-min_);
  49. else if(osc_type == 'i')
  50. oscWrite(ext, "i", (int)(val-min_));
  51. else {
  52. fprintf(stderr, "invalid `c' from slider %s%s, using `i'\n", loc.c_str(), ext.c_str());
  53. oscWrite(ext, "i", (int)(val-min_));
  54. }
  55. //OSC_value(val);
  56. if(cb_data.first)
  57. cb_data.first(this, cb_data.second);
  58. }
  59. void Fl_Osc_Slider::callback(Fl_Callback *cb, void *p)
  60. {
  61. cb_data.first = cb;
  62. cb_data.second = p;
  63. }
  64. int Fl_Osc_Slider::handle(int ev)
  65. {
  66. bool middle_mouse = (ev == FL_PUSH && Fl::event_state(FL_BUTTON2) && !Fl::event_shift());
  67. bool ctl_click = (ev == FL_PUSH && Fl::event_state(FL_BUTTON1) && Fl::event_ctrl());
  68. bool shift_middle = (ev == FL_PUSH && Fl::event_state(FL_BUTTON2) && Fl::event_shift());
  69. if(middle_mouse || ctl_click) {
  70. printf("Trying to learn...\n");
  71. osc->write("/learn", "s", (loc+ext).c_str());
  72. return 1;
  73. } else if(shift_middle) {
  74. osc->write("/unlearn", "s", (loc+ext).c_str());
  75. return 1;
  76. }
  77. return Fl_Slider::handle(ev);
  78. }
  79. void Fl_Osc_Slider::update(void)
  80. {
  81. oscWrite(ext, "");
  82. }
  83. void Fl_Osc_Slider::_cb(Fl_Widget *w, void *)
  84. {
  85. static_cast<Fl_Osc_Slider*>(w)->cb();
  86. }