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.

208 lines
6.2KB

  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[2];
  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 = 2.0f;
  78. scalePoints[0].value = 1.0f;
  79. scalePoints[0].label = "Default";
  80. scalePoints[1].value = 2.0f;
  81. scalePoints[1].label = "OpenAV";
  82. param.scalePointCount = 2;
  83. param.scalePoints = scalePoints;
  84. break;
  85. case 2:
  86. hints |= NATIVE_PARAMETER_IS_OUTPUT;
  87. param.name = "Out Left";
  88. break;
  89. case 3:
  90. hints |= NATIVE_PARAMETER_IS_OUTPUT;
  91. param.name = "Out Right";
  92. break;
  93. }
  94. param.hints = static_cast<NativeParameterHints>(hints);
  95. return &param;
  96. }
  97. float getParameterValue(const uint32_t index) const override
  98. {
  99. switch (index)
  100. {
  101. case 0:
  102. return float(fColor);
  103. case 1:
  104. return float(fStyle);
  105. case 2:
  106. return fOutLeft;
  107. case 3:
  108. return fOutRight;
  109. default:
  110. return 0.0f;
  111. }
  112. }
  113. // -------------------------------------------------------------------
  114. // Plugin state calls
  115. void setParameterValue(const uint32_t index, const float value) override
  116. {
  117. switch (index)
  118. {
  119. case 0:
  120. fColor = int(value);
  121. break;
  122. case 1:
  123. fStyle = int(value);
  124. break;
  125. default:
  126. break;
  127. }
  128. }
  129. // -------------------------------------------------------------------
  130. // Plugin process calls
  131. void activate() override
  132. {
  133. fOutLeft = 0.0f;
  134. fOutRight = 0.0f;
  135. }
  136. void process(float** inputs, float**, const uint32_t frames, const NativeMidiEvent* const, const uint32_t) override
  137. {
  138. Range<float> range;
  139. range = FloatVectorOperations::findMinAndMax(inputs[0], static_cast<int>(frames));
  140. fOutLeft = carla_max(std::abs(range.getStart()), std::abs(range.getEnd()), 1.0f);
  141. range = FloatVectorOperations::findMinAndMax(inputs[1], static_cast<int>(frames));
  142. fOutRight = carla_max(std::abs(range.getStart()), std::abs(range.getEnd()), 1.0f);
  143. }
  144. private:
  145. int fColor, fStyle;
  146. float fOutLeft, fOutRight;
  147. PluginClassEND(BigMeterPlugin)
  148. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(BigMeterPlugin)
  149. };
  150. // -----------------------------------------------------------------------
  151. static const NativePluginDescriptor bigmeterDesc = {
  152. /* category */ NATIVE_PLUGIN_CATEGORY_UTILITY,
  153. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE
  154. |NATIVE_PLUGIN_HAS_UI
  155. |NATIVE_PLUGIN_NEEDS_FIXED_BUFFERS),
  156. /* supports */ static_cast<NativePluginSupports>(0x0),
  157. /* audioIns */ 2,
  158. /* audioOuts */ 0,
  159. /* midiIns */ 0,
  160. /* midiOuts */ 0,
  161. /* paramIns */ 1,
  162. /* paramOuts */ 2,
  163. /* name */ "Big Meter",
  164. /* label */ "bigmeter",
  165. /* maker */ "falkTX",
  166. /* copyright */ "GNU GPL v2+",
  167. PluginDescriptorFILL(BigMeterPlugin)
  168. };
  169. // -----------------------------------------------------------------------
  170. CARLA_EXPORT
  171. void carla_register_native_plugin_bigmeter();
  172. CARLA_EXPORT
  173. void carla_register_native_plugin_bigmeter()
  174. {
  175. carla_register_native_plugin(&bigmeterDesc);
  176. }
  177. // -----------------------------------------------------------------------