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.

210 lines
6.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. #include "CarlaMathUtils.hpp"
  19. #include "CarlaNativeExtUI.hpp"
  20. #include "juce_audio_basics.h"
  21. using juce::FloatVectorOperations;
  22. using juce::Range;
  23. // -----------------------------------------------------------------------
  24. class BigMeterPlugin : public NativePluginAndUiClass
  25. {
  26. public:
  27. BigMeterPlugin(const NativeHostDescriptor* const host)
  28. : NativePluginAndUiClass(host, CARLA_OS_SEP_STR "bigmeter-ui"),
  29. fColor(1),
  30. fStyle(1),
  31. fOutLeft(0.0f),
  32. fOutRight(0.0f),
  33. leakDetector_BigMeterPlugin() {}
  34. protected:
  35. // -------------------------------------------------------------------
  36. // Plugin parameter calls
  37. uint32_t getParameterCount() const override
  38. {
  39. return 4;
  40. }
  41. const NativeParameter* getParameterInfo(const uint32_t index) const override
  42. {
  43. CARLA_SAFE_ASSERT_RETURN(index < 4, nullptr);
  44. static NativeParameter param;
  45. static NativeParameterScalePoint scalePoints[3];
  46. int hints = NATIVE_PARAMETER_IS_ENABLED|NATIVE_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 |= NATIVE_PARAMETER_IS_INTEGER|NATIVE_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].value = 1.0f;
  66. scalePoints[0].label = "Green";
  67. scalePoints[1].value = 2.0f;
  68. scalePoints[1].label = "Blue";
  69. param.scalePointCount = 2;
  70. param.scalePoints = scalePoints;
  71. break;
  72. case 1:
  73. hints |= NATIVE_PARAMETER_IS_INTEGER|NATIVE_PARAMETER_USES_SCALEPOINTS;
  74. param.name = "Style";
  75. param.ranges.def = 1.0f;
  76. param.ranges.min = 1.0f;
  77. param.ranges.max = 3.0f;
  78. scalePoints[0].value = 1.0f;
  79. scalePoints[0].label = "Default";
  80. scalePoints[1].value = 2.0f;
  81. scalePoints[1].label = "OpenAV";
  82. scalePoints[2].value = 3.0f;
  83. scalePoints[2].label = "RNCBC";
  84. param.scalePointCount = 3;
  85. param.scalePoints = scalePoints;
  86. break;
  87. case 2:
  88. hints |= NATIVE_PARAMETER_IS_OUTPUT;
  89. param.name = "Out Left";
  90. break;
  91. case 3:
  92. hints |= NATIVE_PARAMETER_IS_OUTPUT;
  93. param.name = "Out Right";
  94. break;
  95. }
  96. param.hints = static_cast<NativeParameterHints>(hints);
  97. return &param;
  98. }
  99. float getParameterValue(const uint32_t index) const override
  100. {
  101. switch (index)
  102. {
  103. case 0:
  104. return float(fColor);
  105. case 1:
  106. return float(fStyle);
  107. case 2:
  108. return fOutLeft;
  109. case 3:
  110. return fOutRight;
  111. default:
  112. return 0.0f;
  113. }
  114. }
  115. // -------------------------------------------------------------------
  116. // Plugin state calls
  117. void setParameterValue(const uint32_t index, const float value) override
  118. {
  119. switch (index)
  120. {
  121. case 0:
  122. fColor = int(value);
  123. break;
  124. case 1:
  125. fStyle = int(value);
  126. break;
  127. default:
  128. break;
  129. }
  130. }
  131. // -------------------------------------------------------------------
  132. // Plugin process calls
  133. void activate() override
  134. {
  135. fOutLeft = 0.0f;
  136. fOutRight = 0.0f;
  137. }
  138. void process(float** inputs, float**, const uint32_t frames, const NativeMidiEvent* const, const uint32_t) override
  139. {
  140. Range<float> range;
  141. range = FloatVectorOperations::findMinAndMax(inputs[0], static_cast<int>(frames));
  142. fOutLeft = carla_maxLimited(std::abs(range.getStart()), std::abs(range.getEnd()), 1.0f);
  143. range = FloatVectorOperations::findMinAndMax(inputs[1], static_cast<int>(frames));
  144. fOutRight = carla_maxLimited(std::abs(range.getStart()), std::abs(range.getEnd()), 1.0f);
  145. }
  146. private:
  147. int fColor, fStyle;
  148. float fOutLeft, fOutRight;
  149. PluginClassEND(BigMeterPlugin)
  150. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(BigMeterPlugin)
  151. };
  152. // -----------------------------------------------------------------------
  153. static const NativePluginDescriptor bigmeterDesc = {
  154. /* category */ NATIVE_PLUGIN_CATEGORY_UTILITY,
  155. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE
  156. |NATIVE_PLUGIN_HAS_UI
  157. |NATIVE_PLUGIN_NEEDS_FIXED_BUFFERS),
  158. /* supports */ static_cast<NativePluginSupports>(0x0),
  159. /* audioIns */ 2,
  160. /* audioOuts */ 0,
  161. /* midiIns */ 0,
  162. /* midiOuts */ 0,
  163. /* paramIns */ 1,
  164. /* paramOuts */ 2,
  165. /* name */ "Big Meter",
  166. /* label */ "bigmeter",
  167. /* maker */ "falkTX",
  168. /* copyright */ "GNU GPL v2+",
  169. PluginDescriptorFILL(BigMeterPlugin)
  170. };
  171. // -----------------------------------------------------------------------
  172. CARLA_EXPORT
  173. void carla_register_native_plugin_bigmeter();
  174. CARLA_EXPORT
  175. void carla_register_native_plugin_bigmeter()
  176. {
  177. carla_register_native_plugin(&bigmeterDesc);
  178. }
  179. // -----------------------------------------------------------------------