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.

289 lines
8.8KB

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