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_DialF.cpp 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. Fl_Osc_DialF.cpp - OSC Powered Real Valued Dial
  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_DialF.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. template<typename A, typename B>
  19. B string_cast(const A &a)
  20. {
  21. std::stringstream s;
  22. s.precision(3);
  23. B b;
  24. s << " " << a << " ";
  25. s >> b;
  26. return b;
  27. }
  28. static void callback_fn_dialf(Fl_Widget *w, void *)
  29. {
  30. ((Fl_Osc_DialF*)w)->cb();
  31. }
  32. Fl_Osc_DialF::Fl_Osc_DialF(int X, int Y, int W, int H, const char *label)
  33. :WidgetPDial(X,Y,W,H, label), Fl_Osc_Widget()
  34. {
  35. //bounds(0.0, 127.0f);
  36. WidgetPDial::callback(callback_fn_dialf);
  37. }
  38. void Fl_Osc_DialF::init(const char *path)
  39. {
  40. Fl_Osc_Pane *pane = fetch_osc_pane(this);
  41. assert(pane);
  42. osc = pane->osc;
  43. ext = path;
  44. loc = pane->base;
  45. oscRegister(path);
  46. integer_step = false;
  47. };
  48. Fl_Osc_DialF::~Fl_Osc_DialF(void)
  49. {}
  50. void Fl_Osc_DialF::callback(Fl_Callback *cb, void *p)
  51. {
  52. cb_data.first = cb;
  53. cb_data.second = p;
  54. }
  55. int Fl_Osc_DialF::handle(int ev)
  56. {
  57. bool middle_mouse = (ev == FL_PUSH && Fl::event_state(FL_BUTTON2) && !Fl::event_shift());
  58. bool ctl_click = (ev == FL_PUSH && Fl::event_state(FL_BUTTON3) && Fl::event_ctrl());
  59. bool shift_middle = (ev == FL_PUSH && Fl::event_state(FL_BUTTON2) && Fl::event_shift());
  60. if(middle_mouse || ctl_click) {
  61. printf("Trying to learn...\n");
  62. osc->write("/learn", "s", (loc+ext).c_str());
  63. return 1;
  64. } else if(shift_middle) {
  65. osc->write("/unlearn", "s", (loc+ext).c_str());
  66. return 1;
  67. }
  68. return WidgetPDial::handle(ev);
  69. }
  70. void Fl_Osc_DialF::OSC_value(float v)
  71. {
  72. value(v);
  73. }
  74. void Fl_Osc_DialF::update(void)
  75. {
  76. oscWrite(ext);
  77. }
  78. void Fl_Osc_DialF::cb(void)
  79. {
  80. assert(osc);
  81. oscWrite(ext, "f", (float)value());
  82. if(cb_data.first)
  83. cb_data.first(this, cb_data.second);
  84. // label_str = string_cast<float,string>(val);
  85. // label(" ");
  86. // label(label_str.c_str());
  87. }