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_Check.cpp 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. Fl_Osc_Check.cpp - OSC Powered Check Button
  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_Check.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. Fl_Osc_Check::Fl_Osc_Check(int X, int Y, int W, int H, const char *label)
  19. :Fl_Check_Button(X,Y,W,H,label), Fl_Osc_Widget(this), is_osc(false), cb_data(NULL, NULL)
  20. {
  21. Fl_Check_Button::callback(Fl_Osc_Check::_cb);
  22. }
  23. Fl_Osc_Check::~Fl_Osc_Check(void)
  24. {}
  25. void Fl_Osc_Check::OSC_value(bool v)
  26. {
  27. value(v);
  28. is_osc = true;
  29. if(cb_data.first)
  30. cb_data.first(this, cb_data.second);
  31. is_osc = false;
  32. }
  33. void Fl_Osc_Check::init(std::string path, char type)
  34. {
  35. this->ext = path;
  36. this->type = type;
  37. oscRegister(path.c_str());
  38. }
  39. void Fl_Osc_Check::cb(void)
  40. {
  41. //Order is significant for takeback style callbacks
  42. if(cb_data.first)
  43. cb_data.first(this, cb_data.second);
  44. if(type == 'T')
  45. oscWrite(ext, value() ? "T" : "F");
  46. else {
  47. if(type=='c')
  48. fprintf(stderr, "invalid `c' from checkbox %s%s, using `i'\n", loc.c_str(), ext.c_str());
  49. oscWrite(ext, "i", value());
  50. }
  51. }
  52. void Fl_Osc_Check::callback(Fl_Callback *cb, void *p)
  53. {
  54. cb_data.first = cb;
  55. cb_data.second = p;
  56. }
  57. void Fl_Osc_Check::_cb(Fl_Widget *w, void *)
  58. {
  59. static_cast<Fl_Osc_Check*>(w)->cb();
  60. }