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.

244 lines
6.8KB

  1. // ----------------------------------------------------------------------
  2. //
  3. // Copyright (C) 2010 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 REV1 {
  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. _valuecb (valuecb)
  35. {
  36. X_hints H;
  37. char s [256];
  38. int i, x;
  39. _atom = XInternAtom (dpy (), "WM_DELETE_WINDOW", True);
  40. XSetWMProtocols (dpy (), win (), &_atom, 1);
  41. _atom = XInternAtom (dpy (), "WM_PROTOCOLS", True);
  42. sprintf (s, "%s", jclient->jname ());
  43. x_set_title (s);
  44. H.position (xp, yp);
  45. H.minsize (XSIZE, YSIZE);
  46. H.maxsize (XSIZE, YSIZE);
  47. H.rname (xres->rname ());
  48. H.rclas (xres->rclas ());
  49. x_apply (&H);
  50. _ambis = xres->getb (".ambisonic", false);
  51. x = 0;
  52. _rotary [R_DELAY] = new Rlinctl (this, this, &r_delay_img, x, 0, 160, 5, 0.02, 0.100, 0.04, R_DELAY);
  53. _rotary [R_XOVER] = new Rlogctl (this, this, &r_xover_img, x, 0, 200, 5, 50.0, 1000.0, 200.0, R_XOVER);
  54. _rotary [R_RTLOW] = new Rlogctl (this, this, &r_rtlow_img, x, 0, 200, 5, 1.0, 8.0, 3.0, R_RTLOW);
  55. _rotary [R_RTMID] = new Rlogctl (this, this, &r_rtmid_img, x, 0, 200, 5, 1.0, 8.0, 2.0, R_RTMID);
  56. _rotary [R_FDAMP] = new Rlogctl (this, this, &r_fdamp_img, x, 0, 200, 5, 1.5e3, 24.0e3, 6.0e3, R_FDAMP);
  57. x += 315;
  58. _rotary [R_EQ1FR] = new Rlogctl (this, this, &r_parfr_img, x, 0, 180, 5, 40.0, 2.5e3, 160.0, R_EQ1FR);
  59. _rotary [R_EQ1GN] = new Rlinctl (this, this, &r_pargn_img, x, 0, 150, 5, -15.0, 15.0, 0.0, R_EQ1GN);
  60. x += 110;
  61. _rotary [R_EQ2FR] = new Rlogctl (this, this, &r_parfr_img, x, 0, 180, 5, 160.0, 10e3, 2.5e3, R_EQ2FR);
  62. _rotary [R_EQ2GN] = new Rlinctl (this, this, &r_pargn_img, x, 0, 150, 5, -15.0, 15.0, 0.0, R_EQ2GN);
  63. x += 110;
  64. _rotary [R_OPMIX] = new Rlinctl (this, this, &r_opmix_img, x, 0, 180, 5, 0.0 , 1.0, 0.5, R_OPMIX);
  65. _rotary [R_RGXYZ] = new Rlinctl (this, this, &r_rgxyz_img, x, 0, 180, 5, -9.0 , 9.0, 0.0, R_RGXYZ);
  66. for (i = 0; i < R_OPMIX; i++) _rotary [i]->x_map ();
  67. if (_ambis) _rotary [R_RGXYZ]->x_map ();
  68. else _rotary [R_OPMIX]->x_map ();
  69. x_add_events (ExposureMask);
  70. x_map ();
  71. set_time (0);
  72. inc_time (250000);
  73. }
  74. Mainwin::~Mainwin (void)
  75. {
  76. }
  77. int Mainwin::process (void)
  78. {
  79. int e;
  80. if (_stop) handle_stop ();
  81. e = get_event_timed ();
  82. switch (e)
  83. {
  84. case EV_TIME:
  85. handle_time ();
  86. break;
  87. }
  88. return e;
  89. }
  90. void Mainwin::handle_event (XEvent *E)
  91. {
  92. switch (E->type)
  93. {
  94. case Expose:
  95. expose ((XExposeEvent *) E);
  96. break;
  97. case ClientMessage:
  98. clmesg ((XClientMessageEvent *) E);
  99. break;
  100. }
  101. }
  102. void Mainwin::expose (XExposeEvent *E)
  103. {
  104. if (E->count) return;
  105. redraw ();
  106. }
  107. void Mainwin::clmesg (XClientMessageEvent *E)
  108. {
  109. if (E->message_type == _atom) _stop = true;
  110. }
  111. void Mainwin::handle_time (void)
  112. {
  113. inc_time (500000);
  114. XFlush (dpy ());
  115. }
  116. void Mainwin::handle_stop (void)
  117. {
  118. put_event (EV_EXIT, 1);
  119. }
  120. void Mainwin::handle_callb (int type, X_window *W, XEvent *E)
  121. {
  122. RotaryCtl *R;
  123. int k;
  124. double v, v2;
  125. switch (type)
  126. {
  127. case RotaryCtl::PRESS:
  128. R = (RotaryCtl *) W;
  129. k = R->cbind ();
  130. switch (k)
  131. {
  132. default:
  133. ;
  134. }
  135. break;
  136. case RotaryCtl::DELTA:
  137. R = (RotaryCtl *) W;
  138. k = R->cbind ();
  139. switch (k)
  140. {
  141. case R_DELAY:
  142. v = _rotary [R_DELAY]->value ();
  143. _jclient->reverb ()->set_delay (v);
  144. _valuecb->valueChangedCallback (R_DELAY, v);
  145. break;
  146. case R_XOVER:
  147. v = _rotary [R_XOVER]->value ();
  148. _jclient->reverb ()->set_xover (v);
  149. _valuecb->valueChangedCallback (R_XOVER, v);
  150. break;
  151. case R_RTLOW:
  152. v = _rotary [R_RTLOW]->value ();
  153. _jclient->reverb ()->set_rtlow (v);
  154. _valuecb->valueChangedCallback (R_RTLOW, v);
  155. break;
  156. case R_RTMID:
  157. v = _rotary [R_RTMID]->value ();
  158. _jclient->reverb ()->set_rtmid (v);
  159. _valuecb->valueChangedCallback (R_RTMID, v);
  160. break;
  161. case R_FDAMP:
  162. v = _rotary [R_FDAMP]->value ();
  163. _jclient->reverb ()->set_fdamp (v);
  164. _valuecb->valueChangedCallback (R_FDAMP, v);
  165. break;
  166. case R_OPMIX:
  167. v = _rotary [R_OPMIX]->value ();
  168. _jclient->reverb ()->set_opmix (v);
  169. _valuecb->valueChangedCallback (R_OPMIX, v);
  170. break;
  171. case R_RGXYZ:
  172. v = _rotary [R_RGXYZ]->value ();
  173. _jclient->reverb ()->set_rgxyz (v);
  174. _valuecb->valueChangedCallback (R_RGXYZ, v);
  175. break;
  176. case R_EQ1FR:
  177. case R_EQ1GN:
  178. v = _rotary [R_EQ1FR]->value (), v2 = _rotary [R_EQ1GN]->value ();
  179. _jclient->reverb ()->set_eq1 (v, v2);
  180. _valuecb->valueChangedCallback (R_EQ1FR, v);
  181. _valuecb->valueChangedCallback (R_EQ1GN, v2);
  182. break;
  183. case R_EQ2FR:
  184. case R_EQ2GN:
  185. v = _rotary [R_EQ2FR]->value (), v2 = _rotary [R_EQ2GN]->value ();
  186. _jclient->reverb ()->set_eq2 (v, v2);
  187. _valuecb->valueChangedCallback (R_EQ2FR, v);
  188. _valuecb->valueChangedCallback (R_EQ2GN, v2);
  189. break;
  190. }
  191. break;
  192. }
  193. }
  194. void Mainwin::redraw (void)
  195. {
  196. int x;
  197. x = 0;
  198. XPutImage (dpy (), win (), dgc (), revsect_img, 0, 0, x, 0, 310, 75);
  199. x += 315;
  200. XPutImage (dpy (), win (), dgc (), eq1sect_img, 0, 0, x, 0, 110, 75);
  201. x += 110;
  202. XPutImage (dpy (), win (), dgc (), eq2sect_img, 0, 0, x, 0, 110, 75);
  203. x += 110;
  204. if (_ambis) XPutImage (dpy (), win (), dgc (), ambsect_img, 0, 0, x, 0, 70, 75);
  205. else XPutImage (dpy (), win (), dgc (), mixsect_img, 0, 0, x, 0, 70, 75);
  206. x += 70;
  207. }
  208. }