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.

zita-bls1.cpp 8.7KB

9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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 */ NATIVE_PLUGIN_SUPPORTS_NOTHING,
  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. // -----------------------------------------------------------------------