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.1KB

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