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.

161 lines
3.5KB

  1. // ----------------------------------------------------------------------
  2. //
  3. // Copyright (C) 2010 Fons Adriaensen <fons@linuxaudio.org>
  4. // Modified by falkTX on Jan-Apr 2015 for inclusion in Carla
  5. //
  6. // This program is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU General Public License as published by
  8. // the Free Software Foundation; either version 2 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // This program is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU General Public License
  17. // along with this program; if not, write to the Free Software
  18. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. //
  20. // ----------------------------------------------------------------------
  21. #include <math.h>
  22. #include "guiclass.h"
  23. namespace REV1 {
  24. Rlinctl::Rlinctl (X_window *parent,
  25. X_callback *cbobj,
  26. RotaryImg *image,
  27. int xp,
  28. int yp,
  29. int cm,
  30. int dd,
  31. double vmin,
  32. double vmax,
  33. double vini,
  34. int cbind) :
  35. RotaryCtl (parent, cbobj, image, xp, yp, cbind),
  36. _cm (cm),
  37. _dd (dd),
  38. _vmin (vmin),
  39. _vmax (vmax),
  40. _form (0)
  41. {
  42. _count = -1;
  43. set_value (vini);
  44. }
  45. void Rlinctl::get_string (char *p, int n)
  46. {
  47. if (_form) snprintf (p, n, _form, _value);
  48. else *p = 0;
  49. }
  50. void Rlinctl::set_value (double v)
  51. {
  52. set_count ((int) floor (_cm * (v - _vmin) / (_vmax - _vmin) + 0.5));
  53. render ();
  54. }
  55. int Rlinctl::handle_button (void)
  56. {
  57. return PRESS;
  58. }
  59. int Rlinctl::handle_motion (int dx, int dy)
  60. {
  61. return set_count (_rcount + dx - dy);
  62. }
  63. int Rlinctl::handle_mwheel (int dw)
  64. {
  65. if (! (_keymod & ShiftMask)) dw *= _dd;
  66. return set_count (_count + dw);
  67. }
  68. int Rlinctl::set_count (int u)
  69. {
  70. if (u < 0) u= 0;
  71. if (u > _cm) u = _cm;
  72. if (u != _count)
  73. {
  74. _count = u;
  75. _value = _vmin + u * (_vmax - _vmin) / _cm;
  76. _angle = 270.0 * ((double) u / _cm - 0.5);
  77. return DELTA;
  78. }
  79. return 0;
  80. }
  81. Rlogctl::Rlogctl (X_window *parent,
  82. X_callback *cbobj,
  83. RotaryImg *image,
  84. int xp,
  85. int yp,
  86. int cm,
  87. int dd,
  88. double vmin,
  89. double vmax,
  90. double vini,
  91. int cbind) :
  92. RotaryCtl (parent, cbobj, image, xp, yp, cbind),
  93. _cm (cm),
  94. _dd (dd),
  95. _form (0)
  96. {
  97. _count = -1;
  98. _vmin = log (vmin);
  99. _vmax = log (vmax);
  100. set_value (vini);
  101. }
  102. void Rlogctl::get_string (char *p, int n)
  103. {
  104. if (_form) snprintf (p, n, _form, _value);
  105. else *p = 0;
  106. }
  107. void Rlogctl::set_value (double v)
  108. {
  109. set_count ((int) floor (_cm * (log (v) - _vmin) / (_vmax - _vmin) + 0.5));
  110. render ();
  111. }
  112. int Rlogctl::handle_button (void)
  113. {
  114. return PRESS;
  115. }
  116. int Rlogctl::handle_motion (int dx, int dy)
  117. {
  118. return set_count (_rcount + dx - dy);
  119. }
  120. int Rlogctl::handle_mwheel (int dw)
  121. {
  122. if (! (_keymod & ShiftMask)) dw *= _dd;
  123. return set_count (_count + dw);
  124. }
  125. int Rlogctl::set_count (int u)
  126. {
  127. if (u < 0) u= 0;
  128. if (u > _cm) u = _cm;
  129. if (u != _count)
  130. {
  131. _count = u;
  132. _value = exp (_vmin + u * (_vmax - _vmin) / _cm);
  133. _angle = 270.0 * ((double) u / _cm - 0.5);
  134. return DELTA;
  135. }
  136. return 0;
  137. }
  138. }