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.

163 lines
4.5KB

  1. /*
  2. * XY Controller UI, taken from Cadence
  3. * Copyright (C) 2011-2020 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 "CarlaNativeExtUI.hpp"
  19. // -----------------------------------------------------------------------
  20. class XYControllerPlugin : public NativePluginAndUiClass
  21. {
  22. public:
  23. enum Parameters {
  24. kParamInX,
  25. kParamInY,
  26. kParamOutX,
  27. kParamOutY,
  28. kParamCount,
  29. };
  30. XYControllerPlugin(const NativeHostDescriptor* const host)
  31. : NativePluginAndUiClass(host, "xycontroller-ui"),
  32. fParams()
  33. {
  34. carla_fill(fParams, 50.0f, kParamCount);
  35. }
  36. protected:
  37. // -------------------------------------------------------------------
  38. // Plugin parameter calls
  39. uint32_t getParameterCount() const override
  40. {
  41. return kParamCount;
  42. }
  43. const NativeParameter* getParameterInfo(const uint32_t index) const override
  44. {
  45. CARLA_SAFE_ASSERT_RETURN(index < kParamCount, nullptr);
  46. static NativeParameter param;
  47. int hints = NATIVE_PARAMETER_IS_ENABLED|NATIVE_PARAMETER_IS_AUTOMABLE;
  48. param.name = nullptr;
  49. param.unit = "%";
  50. param.ranges.def = 50.0f;
  51. param.ranges.min = 0.0f;
  52. param.ranges.max = 100.0f;
  53. param.ranges.step = 1.0f;
  54. param.ranges.stepSmall = 0.01f;
  55. param.ranges.stepLarge = 10.0f;
  56. param.scalePointCount = 0;
  57. param.scalePoints = nullptr;
  58. switch (index)
  59. {
  60. case kParamInX:
  61. param.name = "X";
  62. break;
  63. case kParamInY:
  64. param.name = "Y";
  65. break;
  66. case kParamOutX:
  67. hints |= NATIVE_PARAMETER_IS_OUTPUT;
  68. param.name = "Out X";
  69. break;
  70. case kParamOutY:
  71. hints |= NATIVE_PARAMETER_IS_OUTPUT;
  72. param.name = "Out Y";
  73. break;
  74. }
  75. param.hints = static_cast<NativeParameterHints>(hints);
  76. return &param;
  77. }
  78. float getParameterValue(const uint32_t index) const override
  79. {
  80. CARLA_SAFE_ASSERT_RETURN(index < kParamCount, 0.0f);
  81. return fParams[index];
  82. }
  83. // -------------------------------------------------------------------
  84. // Plugin state calls
  85. void setParameterValue(const uint32_t index, const float value) override
  86. {
  87. switch (index)
  88. {
  89. case kParamInX:
  90. case kParamInY:
  91. fParams[index] = value;
  92. break;
  93. }
  94. }
  95. // -------------------------------------------------------------------
  96. // Plugin process calls
  97. void process(const float* const*, float**, const uint32_t,
  98. const NativeMidiEvent* const, const uint32_t) override
  99. {
  100. fParams[kParamOutX] = fParams[kParamInX];
  101. fParams[kParamOutY] = fParams[kParamInY];
  102. }
  103. private:
  104. float fParams[kParamCount];
  105. PluginClassEND(XYControllerPlugin)
  106. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(XYControllerPlugin)
  107. };
  108. // -----------------------------------------------------------------------
  109. static const NativePluginDescriptor notesDesc = {
  110. /* category */ NATIVE_PLUGIN_CATEGORY_UTILITY,
  111. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE
  112. |NATIVE_PLUGIN_HAS_UI),
  113. /* supports */ NATIVE_PLUGIN_SUPPORTS_NOTHING,
  114. /* audioIns */ 0,
  115. /* audioOuts */ 0,
  116. /* midiIns */ 0,
  117. /* midiOuts */ 1,
  118. /* paramIns */ 2,
  119. /* paramOuts */ 2,
  120. /* name */ "XY Controller",
  121. /* label */ "xycontroller",
  122. /* maker */ "falkTX",
  123. /* copyright */ "GNU GPL v2+",
  124. PluginDescriptorFILL(XYControllerPlugin)
  125. };
  126. // -----------------------------------------------------------------------
  127. CARLA_EXPORT
  128. void carla_register_native_plugin_xycontroller();
  129. CARLA_EXPORT
  130. void carla_register_native_plugin_xycontroller()
  131. {
  132. carla_register_native_plugin(&notesDesc);
  133. }
  134. // -----------------------------------------------------------------------