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.

DistrhoPluginBigMeter.cpp 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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(3, 0, 0), // 3 parameters, 0 programs, 0 states
  23. fColor(0),
  24. fOutLeft(0.0f),
  25. fOutRight(0.0f)
  26. {
  27. }
  28. DistrhoPluginBigMeter::~DistrhoPluginBigMeter()
  29. {
  30. }
  31. // -----------------------------------------------------------------------
  32. // Init
  33. void DistrhoPluginBigMeter::d_initParameter(uint32_t index, Parameter& parameter)
  34. {
  35. switch (index)
  36. {
  37. case 0:
  38. parameter.hints = PARAMETER_IS_AUTOMABLE | PARAMETER_IS_INTEGER;
  39. parameter.name = "Color";
  40. parameter.symbol = "color";
  41. parameter.ranges.def = 0;
  42. parameter.ranges.min = 0;
  43. parameter.ranges.max = 1;
  44. parameter.ranges.step = 1;
  45. parameter.ranges.stepSmall = 1;
  46. parameter.ranges.stepLarge = 1;
  47. break;
  48. case 1:
  49. parameter.hints = PARAMETER_IS_AUTOMABLE | PARAMETER_IS_OUTPUT;
  50. parameter.name = "Out Left";
  51. parameter.symbol = "outleft";
  52. parameter.ranges.def = 0.0f;
  53. parameter.ranges.min = 0.0f;
  54. parameter.ranges.max = 1.0f;
  55. break;
  56. case 2:
  57. parameter.hints = PARAMETER_IS_AUTOMABLE | PARAMETER_IS_OUTPUT;
  58. parameter.name = "Out Right";
  59. parameter.symbol = "outright";
  60. parameter.ranges.def = 0.0f;
  61. parameter.ranges.min = 0.0f;
  62. parameter.ranges.max = 1.0f;
  63. break;
  64. default:
  65. break;
  66. }
  67. }
  68. // -----------------------------------------------------------------------
  69. // Internal data
  70. float DistrhoPluginBigMeter::d_getParameterValue(uint32_t index) const
  71. {
  72. switch (index)
  73. {
  74. case 0:
  75. return (float)fColor;
  76. case 1:
  77. return fOutLeft;
  78. case 2:
  79. return fOutRight;
  80. default:
  81. return 0.0f;
  82. }
  83. }
  84. void DistrhoPluginBigMeter::d_setParameterValue(uint32_t index, float value)
  85. {
  86. switch (index)
  87. {
  88. case 0:
  89. fColor = (int)value;
  90. break;
  91. case 1:
  92. fOutLeft = value;
  93. break;
  94. case 2:
  95. fOutRight = value;
  96. break;
  97. default:
  98. break;
  99. }
  100. }
  101. // -----------------------------------------------------------------------
  102. // Process
  103. void DistrhoPluginBigMeter::d_run(float** inputs, float**, uint32_t frames, const MidiEvent*, uint32_t)
  104. {
  105. float tmp, tmpLeft, tmpRight;
  106. tmpLeft = tmpRight = 0.0f;
  107. for (uint32_t i=0; i < frames; ++i)
  108. {
  109. tmp = std::abs(inputs[0][i]);
  110. if (tmp > tmpLeft)
  111. tmpLeft = tmp;
  112. tmp = std::abs(inputs[1][i]);
  113. if (tmp > tmpRight)
  114. tmpRight = tmp;
  115. }
  116. fOutLeft = tmpLeft;
  117. fOutRight = tmpRight;
  118. }
  119. // -----------------------------------------------------------------------
  120. Plugin* createPlugin()
  121. {
  122. return new DistrhoPluginBigMeter();
  123. }
  124. // -----------------------------------------------------------------------
  125. END_NAMESPACE_DISTRHO