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.

mainwin.cc 5.8KB

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