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.

87 lines
2.2KB

  1. /*
  2. Copyright (C) 2009-2010 Fons Adriaensen <fons@linuxaudio.org>
  3. Modified by falkTX on Jan-Apr 2015 for inclusion in Carla
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #include <math.h>
  17. #include "tmeter.h"
  18. namespace AT1 {
  19. XImage *Tmeter::_scale = 0;
  20. XImage *Tmeter::_imag0 = 0;
  21. XImage *Tmeter::_imag1 = 0;
  22. Tmeter::Tmeter (X_window *parent, int xpos, int ypos) :
  23. X_window (parent, xpos, ypos, XS + 2 * XM, YS + 2 * YM, 0),
  24. _k0 (86),
  25. _k1 (86)
  26. {
  27. if (!_imag0 || !_imag1 || !_scale) return;
  28. x_add_events (ExposureMask);
  29. }
  30. Tmeter::~Tmeter (void)
  31. {
  32. }
  33. void Tmeter::handle_event (XEvent *E)
  34. {
  35. switch (E->type)
  36. {
  37. case Expose:
  38. expose ((XExposeEvent *) E);
  39. break;
  40. }
  41. }
  42. void Tmeter::expose (XExposeEvent *E)
  43. {
  44. if (E->count) return;
  45. XSetFunction (dpy (), dgc (), GXcopy);
  46. XPutImage (dpy (), win (), dgc (), _imag0, 0, 0, XM, YM, XS, Y1);
  47. XPutImage (dpy (), win (), dgc (), _imag1, _k0 - 2, 0, XM + _k0 - 2, YM, 5 + _k1 - _k0, Y1);
  48. XPutImage (dpy (), win (), dgc (), _scale, 0, 0, XM, YM + Y1, XS, Y2);
  49. }
  50. void Tmeter::update (float v0, float v1)
  51. {
  52. int k0, k1;
  53. k0 = (int)(floorf (86.0f + 80.0f * v0 + 0.5f));
  54. k1 = (int)(floorf (86.0f + 80.0f * v1 + 0.5f));
  55. if (k0 < 4) k0 = 4;
  56. if (k0 > 168) k0 = 168;
  57. if (k1 < 4) k1 = 4;
  58. if (k1 > 168) k1 = 168;
  59. XSetFunction (dpy (), dgc (), GXcopy);
  60. XPutImage (dpy (), win (), dgc (), _imag0, _k0 - 2, 0, XM + _k0 - 2, YM, 5 + _k1 - _k0, Y1);
  61. _k0 = k0;
  62. _k1 = k1;
  63. XPutImage (dpy (), win (), dgc (), _imag1, _k0 - 2, 0, XM + _k0 - 2, YM, 5 + _k1 - _k0, Y1);
  64. }
  65. }