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 5.3KB

10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 "CarlaNativeExtUI.hpp"
  22. #include <cmath>
  23. // -----------------------------------------------------------------------
  24. class BigMeterPlugin : public NativePluginAndUiClass
  25. {
  26. public:
  27. BigMeterPlugin(const NativeHostDescriptor* const host)
  28. : NativePluginAndUiClass(host, "/bigmeter-ui"),
  29. fColor(1),
  30. fOutLeft(0.0f),
  31. fOutRight(0.0f)
  32. {
  33. }
  34. protected:
  35. // -------------------------------------------------------------------
  36. // Plugin parameter calls
  37. uint32_t getParameterCount() const override
  38. {
  39. return 3;
  40. }
  41. const NativeParameter* getParameterInfo(const uint32_t index) const override
  42. {
  43. if (index >= 3)
  44. return nullptr;
  45. static NativeParameter param;
  46. static NativeParameterScalePoint scalePoints[2];
  47. int hints = PARAMETER_IS_ENABLED|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 |= PARAMETER_IS_INTEGER|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].label = "Green";
  67. scalePoints[1].label = "Blue";
  68. scalePoints[0].value = 1.0f;
  69. scalePoints[1].value = 2.0f;
  70. param.scalePointCount = 2;
  71. param.scalePoints = scalePoints;
  72. break;
  73. case 1:
  74. hints |= PARAMETER_IS_OUTPUT;
  75. param.name = "Out Left";
  76. break;
  77. case 2:
  78. hints |= PARAMETER_IS_OUTPUT;
  79. param.name = "Out Right";
  80. break;
  81. }
  82. param.hints = static_cast<NativeParameterHints>(hints);
  83. return &param;
  84. }
  85. float getParameterValue(const uint32_t index) const override
  86. {
  87. switch (index)
  88. {
  89. case 0:
  90. return (float)fColor;
  91. case 1:
  92. return fOutLeft;
  93. case 2:
  94. return fOutRight;
  95. default:
  96. return 0.0f;
  97. }
  98. }
  99. // -------------------------------------------------------------------
  100. // Plugin state calls
  101. void setParameterValue(const uint32_t index, const float value) override
  102. {
  103. switch (index)
  104. {
  105. case 0:
  106. fColor = (int)value;
  107. break;
  108. case 1:
  109. fOutLeft = value;
  110. break;
  111. case 2:
  112. fOutRight = value;
  113. break;
  114. default:
  115. break;
  116. }
  117. }
  118. // -------------------------------------------------------------------
  119. // Plugin process calls
  120. void process(float** inputs, float**, const uint32_t frames, const NativeMidiEvent* const, const uint32_t) override
  121. {
  122. float tmp, tmpLeft, tmpRight;
  123. tmpLeft = tmpRight = 0.0f;
  124. for (uint32_t i=0; i < frames; ++i)
  125. {
  126. tmp = std::abs(inputs[0][i]);
  127. if (tmp > tmpLeft)
  128. tmpLeft = tmp;
  129. tmp = std::abs(inputs[1][i]);
  130. if (tmp > tmpRight)
  131. tmpRight = tmp;
  132. }
  133. fOutLeft = tmpLeft;
  134. fOutRight = tmpRight;
  135. }
  136. private:
  137. int fColor;
  138. float fOutLeft, fOutRight;
  139. PluginClassEND(BigMeterPlugin)
  140. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(BigMeterPlugin)
  141. };
  142. // -----------------------------------------------------------------------
  143. static const NativePluginDescriptor bigmeterDesc = {
  144. /* category */ PLUGIN_CATEGORY_UTILITY,
  145. /* hints */ static_cast<NativePluginHints>(PLUGIN_IS_RTSAFE|PLUGIN_HAS_UI),
  146. /* supports */ static_cast<NativePluginSupports>(0x0),
  147. /* audioIns */ 2,
  148. /* audioOuts */ 0,
  149. /* midiIns */ 0,
  150. /* midiOuts */ 0,
  151. /* paramIns */ 1,
  152. /* paramOuts */ 2,
  153. /* name */ "Big Meter",
  154. /* label */ "bigmeter",
  155. /* maker */ "falkTX",
  156. /* copyright */ "GNU GPL v2+",
  157. PluginDescriptorFILL(BigMeterPlugin)
  158. };
  159. // -----------------------------------------------------------------------
  160. CARLA_EXPORT
  161. void carla_register_native_plugin_bigmeter()
  162. {
  163. carla_register_native_plugin(&bigmeterDesc);
  164. }
  165. // -----------------------------------------------------------------------