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.

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