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.

bigmeter.cpp 6.3KB

10 years ago
10 years ago
9 years ago
9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Carla Native Plugins
  3. * Copyright (C) 2012-2017 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 "AppConfig.h"
  21. #include "juce_audio_basics/juce_audio_basics.h"
  22. using juce::roundToIntAccurate;
  23. using juce::FloatVectorOperations;
  24. using juce::Range;
  25. // -----------------------------------------------------------------------
  26. class BigMeterPlugin : public NativePluginAndUiClass
  27. {
  28. public:
  29. BigMeterPlugin(const NativeHostDescriptor* const host)
  30. : NativePluginAndUiClass(host, "bigmeter-ui"),
  31. fColor(1),
  32. fStyle(1),
  33. fOutLeft(0.0f),
  34. fOutRight(0.0f) {}
  35. protected:
  36. // -------------------------------------------------------------------
  37. // Plugin parameter calls
  38. uint32_t getParameterCount() const override
  39. {
  40. return 4;
  41. }
  42. const NativeParameter* getParameterInfo(const uint32_t index) const override
  43. {
  44. CARLA_SAFE_ASSERT_RETURN(index < 4, nullptr);
  45. static NativeParameter param;
  46. static NativeParameterScalePoint scalePoints[3];
  47. int hints = NATIVE_PARAMETER_IS_ENABLED|NATIVE_PARAMETER_IS_AUTOMABLE;
  48. param.name = nullptr;
  49. param.unit = nullptr;
  50. param.ranges.def = 0.0f;
  51. param.ranges.min = 0.0f;
  52. param.ranges.max = 1.0f;
  53. param.ranges.step = 1.0f;
  54. param.ranges.stepSmall = 1.0f;
  55. param.ranges.stepLarge = 1.0f;
  56. param.scalePointCount = 0;
  57. param.scalePoints = nullptr;
  58. switch (index)
  59. {
  60. case 0:
  61. hints |= NATIVE_PARAMETER_IS_INTEGER|NATIVE_PARAMETER_USES_SCALEPOINTS;
  62. param.name = "Color";
  63. param.ranges.def = 1.0f;
  64. param.ranges.min = 1.0f;
  65. param.ranges.max = 2.0f;
  66. scalePoints[0].value = 1.0f;
  67. scalePoints[0].label = "Green";
  68. scalePoints[1].value = 2.0f;
  69. scalePoints[1].label = "Blue";
  70. param.scalePointCount = 2;
  71. param.scalePoints = scalePoints;
  72. break;
  73. case 1:
  74. hints |= NATIVE_PARAMETER_IS_INTEGER|NATIVE_PARAMETER_USES_SCALEPOINTS;
  75. param.name = "Style";
  76. param.ranges.def = 1.0f;
  77. param.ranges.min = 1.0f;
  78. param.ranges.max = 3.0f;
  79. scalePoints[0].value = 1.0f;
  80. scalePoints[0].label = "Default";
  81. scalePoints[1].value = 2.0f;
  82. scalePoints[1].label = "OpenAV";
  83. scalePoints[2].value = 3.0f;
  84. scalePoints[2].label = "RNCBC";
  85. param.scalePointCount = 3;
  86. param.scalePoints = scalePoints;
  87. break;
  88. case 2:
  89. hints |= NATIVE_PARAMETER_IS_OUTPUT;
  90. param.name = "Out Left";
  91. break;
  92. case 3:
  93. hints |= NATIVE_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 = roundToIntAccurate(value);
  124. break;
  125. case 1:
  126. fStyle = roundToIntAccurate(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_maxLimited(std::abs(range.getStart()), std::abs(range.getEnd()), 1.0f);
  144. range = FloatVectorOperations::findMinAndMax(inputs[1], static_cast<int>(frames));
  145. fOutRight = carla_maxLimited(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 */ NATIVE_PLUGIN_CATEGORY_UTILITY,
  156. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE
  157. |NATIVE_PLUGIN_HAS_UI
  158. |NATIVE_PLUGIN_NEEDS_FIXED_BUFFERS),
  159. /* supports */ NATIVE_PLUGIN_SUPPORTS_NOTHING,
  160. /* audioIns */ 2,
  161. /* audioOuts */ 0,
  162. /* midiIns */ 0,
  163. /* midiOuts */ 0,
  164. /* paramIns */ 2,
  165. /* paramOuts */ 2,
  166. /* name */ "Big Meter",
  167. /* label */ "bigmeter",
  168. /* maker */ "falkTX",
  169. /* copyright */ "GNU GPL v2+",
  170. PluginDescriptorFILL(BigMeterPlugin)
  171. };
  172. // -----------------------------------------------------------------------
  173. CARLA_EXPORT
  174. void carla_register_native_plugin_bigmeter();
  175. CARLA_EXPORT
  176. void carla_register_native_plugin_bigmeter()
  177. {
  178. carla_register_native_plugin(&bigmeterDesc);
  179. }
  180. // -----------------------------------------------------------------------