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_VSlider.cpp 2.2KB

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