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.

290 lines
8.8KB

  1. /*
  2. * Carla Native Plugins
  3. * Copyright (C) 2012-2015 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 "CarlaNativeExtUI.hpp"
  18. #include "CarlaJuceUtils.hpp"
  19. #include "juce_audio_basics.h"
  20. #include "zita-bls1/hp3filt.cc"
  21. #include "zita-bls1/jclient.cc"
  22. #include "zita-bls1/lfshelf2.cc"
  23. #include "zita-bls1/shuffler.cc"
  24. using juce::FloatVectorOperations;
  25. using juce::ScopedPointer;
  26. using namespace BLS1;
  27. // -----------------------------------------------------------------------
  28. // BLS1 Plugin
  29. class BLS1Plugin : public NativePluginAndUiClass
  30. {
  31. public:
  32. static const uint32_t kNumInputs = 2;
  33. static const uint32_t kNumOutputs = 2;
  34. enum Parameters {
  35. kParameterINPBAL,
  36. kParameterHPFILT,
  37. kParameterSHGAIN,
  38. kParameterSHFREQ,
  39. kParameterLFFREQ,
  40. kParameterLFGAIN,
  41. kParameterNROTARY
  42. };
  43. BLS1Plugin(const NativeHostDescriptor* const host)
  44. : NativePluginAndUiClass(host, "bls1-ui"),
  45. fJackClient(),
  46. jclient(nullptr),
  47. leakDetector_BLS1Plugin()
  48. {
  49. CARLA_SAFE_ASSERT(host != nullptr);
  50. carla_zeroStruct(fJackClient);
  51. fJackClient.clientName = "bls1";
  52. fJackClient.bufferSize = getBufferSize();
  53. fJackClient.sampleRate = getSampleRate();
  54. // set initial values
  55. fParameters[kParameterINPBAL] = 0.0f;
  56. fParameters[kParameterHPFILT] = 40.0f;
  57. fParameters[kParameterSHGAIN] = 15.0f;
  58. fParameters[kParameterSHFREQ] = 5e2f;
  59. fParameters[kParameterLFFREQ] = 80.0f;
  60. fParameters[kParameterLFGAIN] = 0.0f;
  61. _recreateZitaClient();
  62. }
  63. // -------------------------------------------------------------------
  64. // Plugin parameter calls
  65. uint32_t getParameterCount() const override
  66. {
  67. return kParameterNROTARY;
  68. }
  69. const NativeParameter* getParameterInfo(const uint32_t index) const override
  70. {
  71. CARLA_SAFE_ASSERT_RETURN(index < kParameterNROTARY, nullptr);
  72. static NativeParameter param;
  73. int hints = NATIVE_PARAMETER_IS_ENABLED|NATIVE_PARAMETER_IS_AUTOMABLE;
  74. // reset
  75. param.name = nullptr;
  76. param.unit = nullptr;
  77. param.ranges.def = 0.0f;
  78. param.ranges.min = 0.0f;
  79. param.ranges.max = 1.0f;
  80. param.ranges.step = 1.0f;
  81. param.ranges.stepSmall = 1.0f;
  82. param.ranges.stepLarge = 1.0f;
  83. param.scalePointCount = 0;
  84. param.scalePoints = nullptr;
  85. switch (index)
  86. {
  87. case kParameterINPBAL:
  88. param.name = "Input balance";
  89. //param.unit = "dB";
  90. param.ranges.def = 0.0f;
  91. param.ranges.min = -3.0f;
  92. param.ranges.max = 3.0f;
  93. break;
  94. case kParameterHPFILT:
  95. hints |= NATIVE_PARAMETER_IS_LOGARITHMIC;
  96. param.name = "Highpass filter";
  97. param.ranges.def = 40.0f;
  98. param.ranges.min = 10.0f;
  99. param.ranges.max = 320.0f;
  100. break;
  101. case kParameterSHGAIN:
  102. param.name = "Shuffler gain";
  103. param.ranges.def = 15.0f;
  104. param.ranges.min = 0.0f;
  105. param.ranges.max = 24.0f;
  106. break;
  107. case kParameterSHFREQ:
  108. hints |= NATIVE_PARAMETER_IS_LOGARITHMIC;
  109. param.name = "Shuffler frequency";
  110. param.ranges.def = 5e2f;
  111. param.ranges.min = 125.0f;
  112. param.ranges.max = 2e3f;
  113. break;
  114. case kParameterLFFREQ:
  115. hints |= NATIVE_PARAMETER_IS_LOGARITHMIC;
  116. param.name = "LF shelf filter frequency";
  117. param.ranges.def = 80.0f;
  118. param.ranges.min = 20.0f;
  119. param.ranges.max = 320.0f;
  120. break;
  121. case kParameterLFGAIN:
  122. param.name = "LF shelf filter gain";
  123. param.ranges.def = 0.0f;
  124. param.ranges.min = -9.0f;
  125. param.ranges.max = 9.0f;
  126. break;
  127. }
  128. param.hints = static_cast<NativeParameterHints>(hints);
  129. return &param;
  130. }
  131. float getParameterValue(const uint32_t index) const override
  132. {
  133. CARLA_SAFE_ASSERT_RETURN(index < kParameterNROTARY, 0.0f);
  134. return fParameters[index];
  135. }
  136. // -------------------------------------------------------------------
  137. // Plugin state calls
  138. void setParameterValue(const uint32_t index, const float value) override
  139. {
  140. CARLA_SAFE_ASSERT_RETURN(index < kParameterNROTARY,);
  141. fParameters[index] = value;
  142. switch (index)
  143. {
  144. case kParameterINPBAL:
  145. jclient->set_inpbal(value);
  146. break;
  147. case kParameterHPFILT:
  148. jclient->set_hpfilt(value);
  149. break;
  150. case kParameterSHGAIN:
  151. jclient->shuffler()->prepare(value, fParameters[kParameterSHFREQ]);
  152. break;
  153. case kParameterSHFREQ:
  154. jclient->shuffler()->prepare(fParameters[kParameterSHGAIN], value);
  155. break;
  156. case kParameterLFFREQ:
  157. jclient->set_loshelf(fParameters[kParameterLFGAIN], value);
  158. break;
  159. case kParameterLFGAIN:
  160. jclient->set_loshelf(value, fParameters[kParameterLFFREQ]);
  161. break;
  162. }
  163. }
  164. // -------------------------------------------------------------------
  165. // Plugin process calls
  166. void process(float** const inBuffer, float** const outBuffer, const uint32_t frames, const NativeMidiEvent* const, const uint32_t) override
  167. {
  168. if (! fJackClient.active)
  169. {
  170. const int iframes(static_cast<int>(frames));
  171. for (uint32_t i=0; i<kNumInputs; ++i)
  172. FloatVectorOperations::clear(outBuffer[i], iframes);
  173. return;
  174. }
  175. for (uint32_t i=0; i<kNumInputs; ++i)
  176. fJackClient.portsAudioIn[i].buffer.audio = inBuffer[i];
  177. for (uint32_t i=0; i<kNumOutputs; ++i)
  178. fJackClient.portsAudioOut[i].buffer.audio = outBuffer[i];
  179. fJackClient.processCallback(frames, fJackClient.processPtr);
  180. }
  181. // -------------------------------------------------------------------
  182. // Plugin dispatcher calls
  183. void bufferSizeChanged(const uint32_t bufferSize) override
  184. {
  185. fJackClient.bufferSize = bufferSize;
  186. _recreateZitaClient();
  187. }
  188. void sampleRateChanged(const double sampleRate) override
  189. {
  190. fJackClient.sampleRate = sampleRate;
  191. _recreateZitaClient();
  192. }
  193. // -------------------------------------------------------------------
  194. private:
  195. // Fake jack client
  196. jack_client_t fJackClient;
  197. // Zita stuff (core)
  198. ScopedPointer<Jclient> jclient;
  199. // Parameters
  200. float fParameters[kParameterNROTARY];
  201. void _recreateZitaClient()
  202. {
  203. jclient = new Jclient(&fJackClient);
  204. jclient->set_inpbal(fParameters[kParameterINPBAL]);
  205. jclient->set_hpfilt(fParameters[kParameterHPFILT]);
  206. jclient->shuffler()->prepare(fParameters[kParameterSHGAIN], fParameters[kParameterSHFREQ]);
  207. jclient->set_loshelf(fParameters[kParameterLFGAIN], fParameters[kParameterLFFREQ]);
  208. }
  209. PluginClassEND(BLS1Plugin)
  210. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(BLS1Plugin)
  211. };
  212. // -----------------------------------------------------------------------
  213. static const NativePluginDescriptor bls1Desc = {
  214. /* category */ NATIVE_PLUGIN_CATEGORY_FILTER,
  215. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE
  216. |NATIVE_PLUGIN_HAS_UI
  217. |NATIVE_PLUGIN_NEEDS_FIXED_BUFFERS),
  218. /* supports */ static_cast<NativePluginSupports>(0x0),
  219. /* audioIns */ BLS1Plugin::kNumInputs,
  220. /* audioOuts */ BLS1Plugin::kNumOutputs,
  221. /* midiIns */ 0,
  222. /* midiOuts */ 0,
  223. /* paramIns */ BLS1Plugin::kParameterNROTARY,
  224. /* paramOuts */ 0,
  225. /* name */ "BLS1",
  226. /* label */ "bls1",
  227. /* maker */ "falkTX, Fons Adriaensen",
  228. /* copyright */ "GPL v2+",
  229. PluginDescriptorFILL(BLS1Plugin)
  230. };
  231. // -----------------------------------------------------------------------
  232. CARLA_EXPORT
  233. void carla_register_native_plugin_zita_bls1();
  234. CARLA_EXPORT
  235. void carla_register_native_plugin_zita_bls1()
  236. {
  237. carla_register_native_plugin(&bls1Desc);
  238. }
  239. // -----------------------------------------------------------------------