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.

260 lines
5.6KB

  1. // ----------------------------------------------------------------------
  2. //
  3. // Copyright (C) 2011 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 <stdlib.h>
  22. #include <stdio.h>
  23. #include <math.h>
  24. #include "styles.h"
  25. #include "global.h"
  26. #include "mainwin.h"
  27. namespace BLS1 {
  28. Mainwin::Mainwin (X_rootwin *parent, X_resman *xres, int xp, int yp, ValueChangedCallback* valuecb) :
  29. A_thread ("Main"),
  30. X_window (parent, xp, yp, XSIZE, YSIZE, XftColors [C_MAIN_BG]->pixel),
  31. _stop (false),
  32. _xres (xres),
  33. _touch (false),
  34. _valuecb (valuecb)
  35. {
  36. X_hints H;
  37. int i;
  38. _atom = XInternAtom (dpy (), "WM_DELETE_WINDOW", True);
  39. XSetWMProtocols (dpy (), win (), &_atom, 1);
  40. _atom = XInternAtom (dpy (), "WM_PROTOCOLS", True);
  41. H.position (xp, yp);
  42. H.minsize (XSIZE, YSIZE);
  43. H.maxsize (XSIZE, YSIZE);
  44. H.rname (xres->rname ());
  45. H.rclas (xres->rclas ());
  46. x_apply (&H);
  47. RotaryCtl::init (disp ());
  48. _rotary [INPBAL] = new Rlinctl (this, this, &inpbal_img, 20, 0, 120, 4, -3.0f, 3.0f, 0.0f, INPBAL);
  49. _rotary [HPFILT] = new Rlogctl (this, this, &hpfilt_img, 20, 0, 120, 4, 10.0f, 320.0f, 40.0f, HPFILT);
  50. _rotary [SHGAIN] = new Rlinctl (this, this, &shgain_img, 190, 0, 120, 5, 0.0f, 24.0f, 15.0f, SHGAIN);
  51. _rotary [SHFREQ] = new Rlogctl (this, this, &shfreq_img, 190, 0, 192, 8, 125.0f, 2e3f, 5e2f, SHFREQ);
  52. _rotary [LFFREQ] = new Rlogctl (this, this, &lffreq_img, 410, 0, 192, 8, 20.0f, 320.0f, 80.0f, LFFREQ);
  53. _rotary [LFGAIN] = new Rlinctl (this, this, &lfgain_img, 410, 0, 180, 5, -9.0f, 9.0f, 0.0f, LFGAIN);
  54. for (i = 0; i < NROTARY; i++) _rotary [i]->x_map ();
  55. _numtext = new X_textip (this, 0, &tstyle1, 0, 0, 45, 15, 15);
  56. _numtext->set_align (0);
  57. _parmind = -1;
  58. _timeout = 0;
  59. x_add_events (ExposureMask);
  60. x_map ();
  61. set_time (0);
  62. inc_time (250000);
  63. }
  64. Mainwin::~Mainwin (void)
  65. {
  66. RotaryCtl::fini ();
  67. }
  68. int Mainwin::process (void)
  69. {
  70. int e;
  71. if (_stop) handle_stop ();
  72. e = get_event_timed ();
  73. switch (e)
  74. {
  75. case EV_TIME:
  76. handle_time ();
  77. break;
  78. }
  79. return e;
  80. }
  81. void Mainwin::handle_event (XEvent *E)
  82. {
  83. switch (E->type)
  84. {
  85. case Expose:
  86. expose ((XExposeEvent *) E);
  87. break;
  88. case ClientMessage:
  89. clmesg ((XClientMessageEvent *) E);
  90. break;
  91. }
  92. }
  93. void Mainwin::expose (XExposeEvent *E)
  94. {
  95. if (E->count) return;
  96. redraw ();
  97. }
  98. void Mainwin::clmesg (XClientMessageEvent *E)
  99. {
  100. if (E->message_type == _atom) _stop = true;
  101. }
  102. void Mainwin::handle_time (void)
  103. {
  104. if (_timeout)
  105. {
  106. if (--_timeout == 0) numdisp (-1);
  107. }
  108. if (_touch)
  109. {
  110. double v1 = _rotary [SHGAIN]->value (), v2 = _rotary [SHFREQ]->value ();
  111. _valuecb->valueChangedCallback (SHGAIN, v1);
  112. _valuecb->valueChangedCallback (SHFREQ, v2);
  113. _touch = 0;
  114. }
  115. inc_time (5000);
  116. XFlush (dpy ());
  117. }
  118. void Mainwin::handle_stop (void)
  119. {
  120. put_event (EV_EXIT, 1);
  121. }
  122. void Mainwin::handle_callb (int type, X_window *W, XEvent *E)
  123. {
  124. RotaryCtl *R;
  125. int k;
  126. double v, v2;
  127. switch (type)
  128. {
  129. case RotaryCtl::PRESS:
  130. R = (RotaryCtl *) W;
  131. k = R->cbind ();
  132. switch (k)
  133. {
  134. default:
  135. numdisp (-1);
  136. }
  137. break;
  138. case RotaryCtl::DELTA:
  139. R = (RotaryCtl *) W;
  140. k = R->cbind ();
  141. switch (k)
  142. {
  143. case INPBAL:
  144. v = _rotary [INPBAL]->value ();
  145. _valuecb->valueChangedCallback (INPBAL, v);
  146. break;
  147. case HPFILT:
  148. v = _rotary [HPFILT]->value ();
  149. _valuecb->valueChangedCallback (HPFILT, v);
  150. break;
  151. case SHGAIN:
  152. case SHFREQ:
  153. _touch++;
  154. break;
  155. case LFFREQ:
  156. case LFGAIN:
  157. v = _rotary [LFGAIN]->value ();
  158. v2 = _rotary [LFFREQ]->value ();
  159. _valuecb->valueChangedCallback (LFGAIN, v);
  160. _valuecb->valueChangedCallback (LFFREQ, v2);
  161. break;
  162. }
  163. break;
  164. }
  165. }
  166. void Mainwin::redraw (void)
  167. {
  168. XPutImage (dpy (), win (), dgc (), inputsect, 0, 0, 20, 0, 130, 75);
  169. XPutImage (dpy (), win (), dgc (), shuffsect, 0, 0, 190, 0, 170, 75);
  170. XPutImage (dpy (), win (), dgc (), lfshfsect, 0, 0, 410, 0, 105, 75);
  171. }
  172. void Mainwin::numdisp (int k)
  173. {
  174. int y = 0;
  175. _timeout = 10;
  176. if (k >= 0) fmtfreq (k);
  177. if (k == _parmind) return;
  178. if (k < 0)
  179. {
  180. _numtext->x_unmap ();
  181. _parmind = -1;
  182. }
  183. else
  184. {
  185. switch (k)
  186. {
  187. default:
  188. ;
  189. }
  190. _numtext->x_move (1, y + 3);
  191. _numtext->x_map ();
  192. _parmind = k;
  193. }
  194. }
  195. void Mainwin::fmtfreq (int k)
  196. {
  197. double v;
  198. char t [16];
  199. const char *f;
  200. v = _rotary [k]->value ();
  201. if (v <= 3e1) f = "%1.1lf";
  202. else if (v <= 1e3) f = "%1.0lf";
  203. else if (v <= 3e3)
  204. {
  205. f = "%1.2lfk";
  206. v *= 1e-3;
  207. }
  208. else
  209. {
  210. f = "%1.1lfk";
  211. v *= 1e-3;
  212. }
  213. sprintf (t, f, v);
  214. _numtext->set_text (t);
  215. }
  216. }