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.

237 lines
6.9KB

  1. /*
  2. * Carla Native Plugins
  3. * Copyright (C) 2012-2019 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(const float** inputs, float**, const uint32_t frames,
  137. const NativeMidiEvent* const, const uint32_t) override
  138. {
  139. fOutLeft = carla_findMaxNormalizedFloat(inputs[0], frames);
  140. fOutRight = carla_findMaxNormalizedFloat(inputs[1], frames);
  141. hostQueueDrawInlineDisplay();
  142. }
  143. // -------------------------------------------------------------------
  144. // Plugin dispatcher calls
  145. const NativeInlineDisplayImageSurface* renderInlineDisplay(const uint32_t width, const uint32_t height) override
  146. {
  147. CARLA_SAFE_ASSERT_RETURN(width > 0 && height > 0, nullptr);
  148. #if 0
  149. static unsigned char data[0xffff];
  150. for (uint i=0; i < 0xffff-4; i+=4)
  151. {
  152. data[i+0] = 200;
  153. data[i+1] = 0;
  154. data[i+2] = 0;
  155. data[i+3] = 255;
  156. }
  157. static const NativeInlineDisplayImageSurface nidims = {
  158. data, (int)width, (int)height, (int)width * 4,
  159. };
  160. carla_stdout("rendering bigmeter %u %u | %i %i %i %i", width, height, data[0], data[1], data[2], data[3]);
  161. return &nidims;
  162. #else
  163. return nullptr;
  164. #endif
  165. }
  166. private:
  167. int fColor, fStyle;
  168. float fOutLeft, fOutRight;
  169. PluginClassEND(BigMeterPlugin)
  170. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(BigMeterPlugin)
  171. };
  172. // -----------------------------------------------------------------------
  173. static const NativePluginDescriptor bigmeterDesc = {
  174. /* category */ NATIVE_PLUGIN_CATEGORY_UTILITY,
  175. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE
  176. |NATIVE_PLUGIN_HAS_INLINE_DISPLAY
  177. |NATIVE_PLUGIN_HAS_UI
  178. |NATIVE_PLUGIN_NEEDS_FIXED_BUFFERS),
  179. /* supports */ NATIVE_PLUGIN_SUPPORTS_NOTHING,
  180. /* audioIns */ 2,
  181. /* audioOuts */ 0,
  182. /* midiIns */ 0,
  183. /* midiOuts */ 0,
  184. /* paramIns */ 2,
  185. /* paramOuts */ 2,
  186. /* name */ "Big Meter",
  187. /* label */ "bigmeter",
  188. /* maker */ "falkTX",
  189. /* copyright */ "GNU GPL v2+",
  190. PluginDescriptorFILL(BigMeterPlugin)
  191. };
  192. // -----------------------------------------------------------------------
  193. CARLA_EXPORT
  194. void carla_register_native_plugin_bigmeter();
  195. CARLA_EXPORT
  196. void carla_register_native_plugin_bigmeter()
  197. {
  198. carla_register_native_plugin(&bigmeterDesc);
  199. }
  200. // -----------------------------------------------------------------------