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.

259 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. set_time (0);
  61. inc_time (250000);
  62. }
  63. Mainwin::~Mainwin (void)
  64. {
  65. RotaryCtl::fini ();
  66. }
  67. int Mainwin::process (void)
  68. {
  69. int e;
  70. if (_stop) handle_stop ();
  71. e = get_event_timed ();
  72. switch (e)
  73. {
  74. case EV_TIME:
  75. handle_time ();
  76. break;
  77. }
  78. return e;
  79. }
  80. void Mainwin::handle_event (XEvent *E)
  81. {
  82. switch (E->type)
  83. {
  84. case Expose:
  85. expose ((XExposeEvent *) E);
  86. break;
  87. case ClientMessage:
  88. clmesg ((XClientMessageEvent *) E);
  89. break;
  90. }
  91. }
  92. void Mainwin::expose (XExposeEvent *E)
  93. {
  94. if (E->count) return;
  95. redraw ();
  96. }
  97. void Mainwin::clmesg (XClientMessageEvent *E)
  98. {
  99. if (E->message_type == _atom) _stop = true;
  100. }
  101. void Mainwin::handle_time (void)
  102. {
  103. if (_timeout)
  104. {
  105. if (--_timeout == 0) numdisp (-1);
  106. }
  107. if (_touch)
  108. {
  109. double v1 = _rotary [SHGAIN]->value (), v2 = _rotary [SHFREQ]->value ();
  110. _valuecb->valueChangedCallback (SHGAIN, v1);
  111. _valuecb->valueChangedCallback (SHFREQ, v2);
  112. _touch = 0;
  113. }
  114. inc_time (5000);
  115. XFlush (dpy ());
  116. }
  117. void Mainwin::handle_stop (void)
  118. {
  119. put_event (EV_EXIT, 1);
  120. }
  121. void Mainwin::handle_callb (int type, X_window *W, XEvent *E)
  122. {
  123. RotaryCtl *R;
  124. int k;
  125. double v, v2;
  126. switch (type)
  127. {
  128. case RotaryCtl::PRESS:
  129. R = (RotaryCtl *) W;
  130. k = R->cbind ();
  131. switch (k)
  132. {
  133. default:
  134. numdisp (-1);
  135. }
  136. break;
  137. case RotaryCtl::DELTA:
  138. R = (RotaryCtl *) W;
  139. k = R->cbind ();
  140. switch (k)
  141. {
  142. case INPBAL:
  143. v = _rotary [INPBAL]->value ();
  144. _valuecb->valueChangedCallback (INPBAL, v);
  145. break;
  146. case HPFILT:
  147. v = _rotary [HPFILT]->value ();
  148. _valuecb->valueChangedCallback (HPFILT, v);
  149. break;
  150. case SHGAIN:
  151. case SHFREQ:
  152. _touch++;
  153. break;
  154. case LFFREQ:
  155. case LFGAIN:
  156. v = _rotary [LFGAIN]->value ();
  157. v2 = _rotary [LFFREQ]->value ();
  158. _valuecb->valueChangedCallback (LFGAIN, v);
  159. _valuecb->valueChangedCallback (LFFREQ, v2);
  160. break;
  161. }
  162. break;
  163. }
  164. }
  165. void Mainwin::redraw (void)
  166. {
  167. XPutImage (dpy (), win (), dgc (), inputsect, 0, 0, 20, 0, 130, 75);
  168. XPutImage (dpy (), win (), dgc (), shuffsect, 0, 0, 190, 0, 170, 75);
  169. XPutImage (dpy (), win (), dgc (), lfshfsect, 0, 0, 410, 0, 105, 75);
  170. }
  171. void Mainwin::numdisp (int k)
  172. {
  173. int y = 0;
  174. _timeout = 10;
  175. if (k >= 0) fmtfreq (k);
  176. if (k == _parmind) return;
  177. if (k < 0)
  178. {
  179. _numtext->x_unmap ();
  180. _parmind = -1;
  181. }
  182. else
  183. {
  184. switch (k)
  185. {
  186. default:
  187. ;
  188. }
  189. _numtext->x_move (1, y + 3);
  190. _numtext->x_map ();
  191. _parmind = k;
  192. }
  193. }
  194. void Mainwin::fmtfreq (int k)
  195. {
  196. double v;
  197. char t [16];
  198. const char *f;
  199. v = _rotary [k]->value ();
  200. if (v <= 3e1) f = "%1.1lf";
  201. else if (v <= 1e3) f = "%1.0lf";
  202. else if (v <= 3e3)
  203. {
  204. f = "%1.2lfk";
  205. v *= 1e-3;
  206. }
  207. else
  208. {
  209. f = "%1.1lfk";
  210. v *= 1e-3;
  211. }
  212. sprintf (t, f, v);
  213. _numtext->set_text (t);
  214. }
  215. }