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.

126 lines
3.4KB

  1. /*
  2. * DISTRHO BigMeter Plugin
  3. * Copyright (C) 2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #include "DistrhoPluginBigMeter.hpp"
  18. #include <cmath>
  19. START_NAMESPACE_DISTRHO
  20. // -----------------------------------------------------------------------
  21. DistrhoPluginBigMeter::DistrhoPluginBigMeter()
  22. : Plugin(1+DISTRHO_PLUGIN_NUM_INPUTS, 0, 0), // many parameters, 0 programs, 0 states
  23. fColor(0)
  24. {
  25. std::memset(fOuts, 0, sizeof(float)*DISTRHO_PLUGIN_NUM_INPUTS);
  26. }
  27. DistrhoPluginBigMeter::~DistrhoPluginBigMeter()
  28. {
  29. }
  30. // -----------------------------------------------------------------------
  31. // Init
  32. void DistrhoPluginBigMeter::d_initParameter(uint32_t index, Parameter& parameter)
  33. {
  34. switch (index)
  35. {
  36. case 0:
  37. parameter.hints = PARAMETER_IS_AUTOMABLE | PARAMETER_IS_INTEGER;
  38. parameter.name = "Color";
  39. parameter.symbol = "color";
  40. parameter.ranges.def = 0;
  41. parameter.ranges.min = 0;
  42. parameter.ranges.max = 1;
  43. parameter.ranges.step = 1;
  44. parameter.ranges.stepSmall = 1;
  45. parameter.ranges.stepLarge = 1;
  46. break;
  47. default:
  48. parameter.hints = PARAMETER_IS_AUTOMABLE | PARAMETER_IS_OUTPUT;
  49. parameter.name = "Out " + d_string(index);
  50. parameter.symbol = "out" + d_string(index);
  51. parameter.ranges.def = 0.0f;
  52. parameter.ranges.min = 0.0f;
  53. parameter.ranges.max = 1.0f;
  54. break;
  55. }
  56. }
  57. // -----------------------------------------------------------------------
  58. // Internal data
  59. float DistrhoPluginBigMeter::d_getParameterValue(uint32_t index) const
  60. {
  61. switch (index)
  62. {
  63. case 0:
  64. return (float)fColor;
  65. default:
  66. return fOuts[index-1];
  67. }
  68. }
  69. void DistrhoPluginBigMeter::d_setParameterValue(uint32_t index, float value)
  70. {
  71. switch (index)
  72. {
  73. case 0:
  74. fColor = (int)value;
  75. break;
  76. default:
  77. fOuts[index-1] = value;
  78. break;
  79. }
  80. }
  81. // -----------------------------------------------------------------------
  82. // Process
  83. void DistrhoPluginBigMeter::d_run(float** inputs, float**, uint32_t frames, const MidiEvent*, uint32_t)
  84. {
  85. float tmp, tmp32[DISTRHO_PLUGIN_NUM_INPUTS];
  86. std::memset(tmp32, 0, sizeof(float)*DISTRHO_PLUGIN_NUM_INPUTS);
  87. for (uint32_t i=0; i < frames; ++i)
  88. {
  89. for (int j=0; j < DISTRHO_PLUGIN_NUM_INPUTS; ++j)
  90. {
  91. tmp = std::abs(inputs[j][i]);
  92. if (tmp > tmp32[j])
  93. tmp32[j] = tmp;
  94. }
  95. }
  96. std::memcpy(fOuts, tmp32, sizeof(float)*DISTRHO_PLUGIN_NUM_INPUTS);
  97. }
  98. // -----------------------------------------------------------------------
  99. Plugin* createPlugin()
  100. {
  101. return new DistrhoPluginBigMeter();
  102. }
  103. // -----------------------------------------------------------------------
  104. END_NAMESPACE_DISTRHO