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.

guiclass.cc 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // ----------------------------------------------------------------------
  2. //
  3. // Copyright (C) 2010-2014 Fons Adriaensen <fons@linuxaudio.org>
  4. // Modified by falkTX on Jan 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 AT1 {
  24. int Pbutt0::handle_press (void)
  25. {
  26. _state |= 2;
  27. return PRESS;
  28. }
  29. int Pbutt0::handle_relse (void)
  30. {
  31. _state &= ~2;
  32. return NOP;
  33. }
  34. int Pbutt1::handle_press (void)
  35. {
  36. _state ^= 1;
  37. return PRESS;
  38. }
  39. int Pbutt1::handle_relse (void)
  40. {
  41. return NOP;
  42. }
  43. Rlinctl::Rlinctl (X_window *parent,
  44. X_callback *cbobj,
  45. int cbind,
  46. RotaryGeom *rgeom,
  47. int xp,
  48. int yp,
  49. int cm,
  50. int dd,
  51. double vmin,
  52. double vmax,
  53. double vini) :
  54. RotaryCtl (parent, cbobj, cbind, rgeom, xp, yp),
  55. _cm (cm),
  56. _dd (dd),
  57. _vmin (vmin),
  58. _vmax (vmax),
  59. _form (0)
  60. {
  61. _count = -1;
  62. set_value (vini);
  63. }
  64. void Rlinctl::get_string (char *p, int n)
  65. {
  66. if (_form) snprintf (p, n, _form, _value);
  67. else *p = 0;
  68. }
  69. void Rlinctl::set_value (double v)
  70. {
  71. set_count ((int) floor (_cm * (v - _vmin) / (_vmax - _vmin) + 0.5));
  72. render ();
  73. }
  74. int Rlinctl::handle_button (void)
  75. {
  76. return PRESS;
  77. }
  78. int Rlinctl::handle_motion (int dx, int dy)
  79. {
  80. return set_count (_rcount + dx - dy);
  81. }
  82. int Rlinctl::handle_mwheel (int dw)
  83. {
  84. if (! (_keymod & ShiftMask)) dw *= _dd;
  85. return set_count (_count + dw);
  86. }
  87. int Rlinctl::set_count (int u)
  88. {
  89. if (u < 0) u= 0;
  90. if (u > _cm) u = _cm;
  91. if (u != _count)
  92. {
  93. _count = u;
  94. _value = _vmin + u * (_vmax - _vmin) / _cm;
  95. _angle = 270.0 * ((double) u / _cm - 0.5);
  96. return DELTA;
  97. }
  98. return 0;
  99. }
  100. Rlogctl::Rlogctl (X_window *parent,
  101. X_callback *cbobj,
  102. int cbind,
  103. RotaryGeom *rgeom,
  104. int xp,
  105. int yp,
  106. int cm,
  107. int dd,
  108. double vmin,
  109. double vmax,
  110. double vini) :
  111. RotaryCtl (parent, cbobj, cbind, rgeom, xp, yp),
  112. _cm (cm),
  113. _dd (dd),
  114. _form (0)
  115. {
  116. _count = -1;
  117. _vmin = log (vmin);
  118. _vmax = log (vmax);
  119. set_value (vini);
  120. }
  121. void Rlogctl::get_string (char *p, int n)
  122. {
  123. if (_form) snprintf (p, n, _form, _value);
  124. else *p = 0;
  125. }
  126. void Rlogctl::set_value (double v)
  127. {
  128. set_count ((int) floor (_cm * (log (v) - _vmin) / (_vmax - _vmin) + 0.5));
  129. render ();
  130. }
  131. int Rlogctl::handle_button (void)
  132. {
  133. return PRESS;
  134. }
  135. int Rlogctl::handle_motion (int dx, int dy)
  136. {
  137. return set_count (_rcount + dx - dy);
  138. }
  139. int Rlogctl::handle_mwheel (int dw)
  140. {
  141. if (! (_keymod & ShiftMask)) dw *= _dd;
  142. return set_count (_count + dw);
  143. }
  144. int Rlogctl::set_count (int u)
  145. {
  146. if (u < 0) u= 0;
  147. if (u > _cm) u = _cm;
  148. if (u != _count)
  149. {
  150. _count = u;
  151. _value = exp (_vmin + u * (_vmax - _vmin) / _cm);
  152. _angle = 270.0 * ((double) u / _cm - 0.5);
  153. return DELTA;
  154. }
  155. return 0;
  156. }
  157. }