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.

284 lines
8.7KB

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