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.

200 lines
5.3KB

  1. /*
  2. * Carla Native Plugins
  3. * Copyright (C) 2012-2014 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 "CarlaDefines.h"
  18. #ifdef CARLA_OS_WIN
  19. # error This file should not be compiled for Windows
  20. #endif
  21. #include "CarlaNativeExtUI.hpp"
  22. #include <cmath>
  23. // -----------------------------------------------------------------------
  24. class BigMeterPlugin : public NativePluginAndUiClass
  25. {
  26. public:
  27. BigMeterPlugin(const NativeHostDescriptor* const host)
  28. : NativePluginAndUiClass(host, "/bigmeter-ui"),
  29. fColor(1),
  30. fOutLeft(0.0f),
  31. fOutRight(0.0f),
  32. leakDetector_BigMeterPlugin() {}
  33. protected:
  34. // -------------------------------------------------------------------
  35. // Plugin parameter calls
  36. uint32_t getParameterCount() const override
  37. {
  38. return 3;
  39. }
  40. const NativeParameter* getParameterInfo(const uint32_t index) const override
  41. {
  42. if (index >= 3)
  43. return nullptr;
  44. static NativeParameter param;
  45. static NativeParameterScalePoint scalePoints[2];
  46. int hints = PARAMETER_IS_ENABLED|PARAMETER_IS_AUTOMABLE;
  47. param.name = nullptr;
  48. param.unit = nullptr;
  49. param.ranges.def = 0.0f;
  50. param.ranges.min = 0.0f;
  51. param.ranges.max = 1.0f;
  52. param.ranges.step = 1.0f;
  53. param.ranges.stepSmall = 1.0f;
  54. param.ranges.stepLarge = 1.0f;
  55. param.scalePointCount = 0;
  56. param.scalePoints = nullptr;
  57. switch (index)
  58. {
  59. case 0:
  60. hints |= PARAMETER_IS_INTEGER|PARAMETER_USES_SCALEPOINTS;
  61. param.name = "Color";
  62. param.ranges.def = 1.0f;
  63. param.ranges.min = 1.0f;
  64. param.ranges.max = 2.0f;
  65. scalePoints[0].label = "Green";
  66. scalePoints[1].label = "Blue";
  67. scalePoints[0].value = 1.0f;
  68. scalePoints[1].value = 2.0f;
  69. param.scalePointCount = 2;
  70. param.scalePoints = scalePoints;
  71. break;
  72. case 1:
  73. hints |= PARAMETER_IS_OUTPUT;
  74. param.name = "Out Left";
  75. break;
  76. case 2:
  77. hints |= PARAMETER_IS_OUTPUT;
  78. param.name = "Out Right";
  79. break;
  80. }
  81. param.hints = static_cast<NativeParameterHints>(hints);
  82. return &param;
  83. }
  84. float getParameterValue(const uint32_t index) const override
  85. {
  86. switch (index)
  87. {
  88. case 0:
  89. return (float)fColor;
  90. case 1:
  91. return fOutLeft;
  92. case 2:
  93. return fOutRight;
  94. default:
  95. return 0.0f;
  96. }
  97. }
  98. // -------------------------------------------------------------------
  99. // Plugin state calls
  100. void setParameterValue(const uint32_t index, const float value) override
  101. {
  102. switch (index)
  103. {
  104. case 0:
  105. fColor = (int)value;
  106. break;
  107. case 1:
  108. fOutLeft = value;
  109. break;
  110. case 2:
  111. fOutRight = value;
  112. break;
  113. default:
  114. break;
  115. }
  116. }
  117. // -------------------------------------------------------------------
  118. // Plugin process calls
  119. void process(float** inputs, float**, const uint32_t frames, const NativeMidiEvent* const, const uint32_t) override
  120. {
  121. float tmp, tmpLeft, tmpRight;
  122. tmpLeft = tmpRight = 0.0f;
  123. for (uint32_t i=0; i < frames; ++i)
  124. {
  125. tmp = std::abs(inputs[0][i]);
  126. if (tmp > tmpLeft)
  127. tmpLeft = tmp;
  128. tmp = std::abs(inputs[1][i]);
  129. if (tmp > tmpRight)
  130. tmpRight = tmp;
  131. }
  132. fOutLeft = tmpLeft;
  133. fOutRight = tmpRight;
  134. }
  135. private:
  136. int fColor;
  137. float fOutLeft, fOutRight;
  138. PluginClassEND(BigMeterPlugin)
  139. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(BigMeterPlugin)
  140. };
  141. // -----------------------------------------------------------------------
  142. static const NativePluginDescriptor bigmeterDesc = {
  143. /* category */ PLUGIN_CATEGORY_UTILITY,
  144. /* hints */ static_cast<NativePluginHints>(PLUGIN_IS_RTSAFE|PLUGIN_HAS_UI),
  145. /* supports */ static_cast<NativePluginSupports>(0x0),
  146. /* audioIns */ 2,
  147. /* audioOuts */ 0,
  148. /* midiIns */ 0,
  149. /* midiOuts */ 0,
  150. /* paramIns */ 1,
  151. /* paramOuts */ 2,
  152. /* name */ "Big Meter",
  153. /* label */ "bigmeter",
  154. /* maker */ "falkTX",
  155. /* copyright */ "GNU GPL v2+",
  156. PluginDescriptorFILL(BigMeterPlugin)
  157. };
  158. // -----------------------------------------------------------------------
  159. CARLA_EXPORT
  160. void carla_register_native_plugin_bigmeter();
  161. CARLA_EXPORT
  162. void carla_register_native_plugin_bigmeter()
  163. {
  164. carla_register_native_plugin(&bigmeterDesc);
  165. }
  166. // -----------------------------------------------------------------------