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.

267 lines
5.9KB

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