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

10 years ago
10 years ago
9 years ago
9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 "water/maths/MathsFunctions.h"
  21. using water::roundToIntAccurate;
  22. // -----------------------------------------------------------------------
  23. class BigMeterPlugin : public NativePluginAndUiClass
  24. {
  25. public:
  26. BigMeterPlugin(const NativeHostDescriptor* const host)
  27. : NativePluginAndUiClass(host, "bigmeter-ui"),
  28. fColor(1),
  29. fStyle(1),
  30. fOutLeft(0.0f),
  31. fOutRight(0.0f) {}
  32. protected:
  33. // -------------------------------------------------------------------
  34. // Plugin parameter calls
  35. uint32_t getParameterCount() const override
  36. {
  37. return 4;
  38. }
  39. const NativeParameter* getParameterInfo(const uint32_t index) const override
  40. {
  41. CARLA_SAFE_ASSERT_RETURN(index < 4, nullptr);
  42. static NativeParameter param;
  43. static NativeParameterScalePoint scalePoints[3];
  44. int hints = NATIVE_PARAMETER_IS_ENABLED|NATIVE_PARAMETER_IS_AUTOMABLE;
  45. param.name = nullptr;
  46. param.unit = nullptr;
  47. param.ranges.def = 0.0f;
  48. param.ranges.min = 0.0f;
  49. param.ranges.max = 1.0f;
  50. param.ranges.step = 1.0f;
  51. param.ranges.stepSmall = 1.0f;
  52. param.ranges.stepLarge = 1.0f;
  53. param.scalePointCount = 0;
  54. param.scalePoints = nullptr;
  55. switch (index)
  56. {
  57. case 0:
  58. hints |= NATIVE_PARAMETER_IS_INTEGER|NATIVE_PARAMETER_USES_SCALEPOINTS;
  59. param.name = "Color";
  60. param.ranges.def = 1.0f;
  61. param.ranges.min = 1.0f;
  62. param.ranges.max = 2.0f;
  63. scalePoints[0].value = 1.0f;
  64. scalePoints[0].label = "Green";
  65. scalePoints[1].value = 2.0f;
  66. scalePoints[1].label = "Blue";
  67. param.scalePointCount = 2;
  68. param.scalePoints = scalePoints;
  69. break;
  70. case 1:
  71. hints |= NATIVE_PARAMETER_IS_INTEGER|NATIVE_PARAMETER_USES_SCALEPOINTS;
  72. param.name = "Style";
  73. param.ranges.def = 1.0f;
  74. param.ranges.min = 1.0f;
  75. param.ranges.max = 3.0f;
  76. scalePoints[0].value = 1.0f;
  77. scalePoints[0].label = "Default";
  78. scalePoints[1].value = 2.0f;
  79. scalePoints[1].label = "OpenAV";
  80. scalePoints[2].value = 3.0f;
  81. scalePoints[2].label = "RNCBC";
  82. param.scalePointCount = 3;
  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 = roundToIntAccurate(value);
  121. break;
  122. case 1:
  123. fStyle = roundToIntAccurate(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. fOutLeft = carla_findMaxNormalizedFloat(inputs[0], frames);
  139. fOutRight = carla_findMaxNormalizedFloat(inputs[1], frames);
  140. }
  141. private:
  142. int fColor, fStyle;
  143. float fOutLeft, fOutRight;
  144. PluginClassEND(BigMeterPlugin)
  145. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(BigMeterPlugin)
  146. };
  147. // -----------------------------------------------------------------------
  148. static const NativePluginDescriptor bigmeterDesc = {
  149. /* category */ NATIVE_PLUGIN_CATEGORY_UTILITY,
  150. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE
  151. |NATIVE_PLUGIN_HAS_UI
  152. |NATIVE_PLUGIN_NEEDS_FIXED_BUFFERS),
  153. /* supports */ NATIVE_PLUGIN_SUPPORTS_NOTHING,
  154. /* audioIns */ 2,
  155. /* audioOuts */ 0,
  156. /* midiIns */ 0,
  157. /* midiOuts */ 0,
  158. /* paramIns */ 2,
  159. /* paramOuts */ 2,
  160. /* name */ "Big Meter",
  161. /* label */ "bigmeter",
  162. /* maker */ "falkTX",
  163. /* copyright */ "GNU GPL v2+",
  164. PluginDescriptorFILL(BigMeterPlugin)
  165. };
  166. // -----------------------------------------------------------------------
  167. CARLA_EXPORT
  168. void carla_register_native_plugin_bigmeter();
  169. CARLA_EXPORT
  170. void carla_register_native_plugin_bigmeter()
  171. {
  172. carla_register_native_plugin(&bigmeterDesc);
  173. }
  174. // -----------------------------------------------------------------------