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.6KB

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