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.

330 lines
9.1KB

  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 "CarlaNative.hpp"
  18. #include "CarlaMutex.hpp"
  19. #include "CarlaJuceUtils.hpp"
  20. #include "juce_audio_basics.h"
  21. #include "zita-bls1/source/png2img.cc"
  22. #include "zita-bls1/source/guiclass.cc"
  23. #include "zita-bls1/source/hp3filt.cc"
  24. #include "zita-bls1/source/jclient.cc"
  25. #include "zita-bls1/source/lfshelf2.cc"
  26. #include "zita-bls1/source/mainwin.cc"
  27. #include "zita-bls1/source/rotary.cc"
  28. #include "zita-bls1/source/shuffler.cc"
  29. #include "zita-bls1/source/styles.cc"
  30. using juce::FloatVectorOperations;
  31. using juce::ScopedPointer;
  32. // -----------------------------------------------------------------------
  33. // BLS1 Plugin
  34. class BLS1Plugin : public NativePluginClass
  35. {
  36. public:
  37. #if 0
  38. enum Parameters {
  39. kParameterInput = 0,
  40. kParameterCount
  41. };
  42. #endif
  43. BLS1Plugin(const NativeHostDescriptor* const host)
  44. : NativePluginClass(host),
  45. fJackClient(),
  46. fMutex(),
  47. xresman(),
  48. jclient(nullptr),
  49. display(nullptr),
  50. rootwin(nullptr),
  51. mainwin(nullptr),
  52. handler(nullptr),
  53. leakDetector_BLS1Plugin()
  54. {
  55. CARLA_SAFE_ASSERT(host != nullptr);
  56. carla_zeroStruct(fJackClient);
  57. gLastJackClient = &fJackClient;
  58. fJackClient.clientName = "bls1";
  59. fJackClient.bufferSize = getBufferSize();
  60. fJackClient.sampleRate = getSampleRate();
  61. int argc = 1;
  62. char* argv[] = { (char*)"bls1" };
  63. xresman.init(&argc, argv, (char*)"bls1", nullptr, 0);
  64. jclient = new Jclient(xresman.rname(), nullptr);
  65. //fParameters[kParameterInput] = 1.0f;
  66. }
  67. #if 0
  68. // -------------------------------------------------------------------
  69. // Plugin parameter calls
  70. uint32_t getParameterCount() const override
  71. {
  72. return kParameterCount;
  73. }
  74. const NativeParameter* getParameterInfo(const uint32_t index) const override
  75. {
  76. CARLA_SAFE_ASSERT_RETURN(index < kParameterCount, nullptr);
  77. static NativeParameter param;
  78. int hints = NATIVE_PARAMETER_IS_ENABLED|NATIVE_PARAMETER_IS_AUTOMABLE;
  79. // reset
  80. param.name = nullptr;
  81. param.unit = nullptr;
  82. param.ranges.def = 0.0f;
  83. param.ranges.min = 0.0f;
  84. param.ranges.max = 1.0f;
  85. param.ranges.step = 1.0f;
  86. param.ranges.stepSmall = 1.0f;
  87. param.ranges.stepLarge = 1.0f;
  88. param.scalePointCount = 0;
  89. param.scalePoints = nullptr;
  90. switch (index)
  91. {
  92. case kParameterInput:
  93. hints |= NATIVE_PARAMETER_IS_INTEGER;
  94. param.name = "Input";
  95. param.ranges.def = 1.0f;
  96. param.ranges.min = 1.0f;
  97. param.ranges.max = 8.0f;
  98. break;
  99. }
  100. param.hints = static_cast<NativeParameterHints>(hints);
  101. return &param;
  102. }
  103. float getParameterValue(const uint32_t index) const override
  104. {
  105. CARLA_SAFE_ASSERT_RETURN(index < kParameterCount, 0.0f);
  106. return fParameters[index];
  107. }
  108. // -------------------------------------------------------------------
  109. // Plugin state calls
  110. void setParameterValue(const uint32_t index, const float value) override
  111. {
  112. CARLA_SAFE_ASSERT_RETURN(index < kParameterCount,);
  113. fParameters[index] = value;
  114. }
  115. #endif
  116. // -------------------------------------------------------------------
  117. // Plugin process calls
  118. void process(float** const inBuffer, float** const outBuffer, const uint32_t frames, const NativeMidiEvent* const, const uint32_t) override
  119. {
  120. if (! fJackClient.active)
  121. {
  122. const int iframes(static_cast<int>(frames));
  123. for (int i=0; i<2; ++i)
  124. FloatVectorOperations::clear(outBuffer[i], iframes);
  125. return;
  126. }
  127. for (int i=0; i<2; ++i)
  128. fJackClient.portsAudioIn[i]->buffer = inBuffer[i];
  129. for (int i=0; i<2; ++i)
  130. fJackClient.portsAudioOut[i]->buffer = outBuffer[i];
  131. fJackClient.processCallback(frames, fJackClient.processPtr);
  132. }
  133. // -------------------------------------------------------------------
  134. // Plugin UI calls
  135. void uiShow(const bool show) override
  136. {
  137. const CarlaMutexLocker cml(fMutex);
  138. if (show)
  139. {
  140. if (display == nullptr)
  141. {
  142. display = new X_display(nullptr);
  143. if (display->dpy() == nullptr)
  144. return hostUiUnavailable();
  145. styles_init(display, &xresman);
  146. rootwin = new X_rootwin(display);
  147. mainwin = new Mainwin(rootwin, &xresman, 0, 0, jclient);
  148. rootwin->handle_event();
  149. handler = new X_handler(display, mainwin, EV_X11);
  150. if (const uintptr_t winId = getUiParentId())
  151. XSetTransientForHint(display->dpy(), mainwin->win(), static_cast<Window>(winId));
  152. }
  153. handler->next_event();
  154. XFlush(display->dpy());
  155. }
  156. else
  157. {
  158. handler = nullptr;
  159. mainwin = nullptr;
  160. rootwin = nullptr;
  161. display = nullptr;
  162. }
  163. }
  164. void uiIdle() override
  165. {
  166. if (display == nullptr)
  167. return;
  168. int ev;
  169. for (; (ev = mainwin->process()) == EV_X11;)
  170. {
  171. rootwin->handle_event();
  172. handler->next_event();
  173. }
  174. #if 0
  175. // check if parameters were updated
  176. if (mainwin->_input+1 != static_cast<int>(fParameters[kParameterInput]))
  177. {
  178. fParameters[kParameterInput] = mainwin->_input+1;
  179. uiParameterChanged(kParameterInput, fParameters[kParameterInput]);
  180. }
  181. #endif
  182. if (ev == EV_EXIT)
  183. {
  184. handler = nullptr;
  185. mainwin = nullptr;
  186. rootwin = nullptr;
  187. display = nullptr;
  188. uiClosed();
  189. }
  190. }
  191. #if 0
  192. void uiSetParameterValue(const uint32_t index, const float value) override
  193. {
  194. CARLA_SAFE_ASSERT_RETURN(index < kParameterCount,);
  195. const CarlaMutexLocker cml(fMutex);
  196. if (itcc == nullptr)
  197. return;
  198. switch (index)
  199. {
  200. case kParameterInput:
  201. mainwin->set_input(static_cast<int>(value)-1);
  202. break;
  203. }
  204. }
  205. #endif
  206. // -------------------------------------------------------------------
  207. // Plugin dispatcher calls
  208. void bufferSizeChanged(const uint32_t bufferSize) override
  209. {
  210. fJackClient.bufferSize = bufferSize;
  211. }
  212. void sampleRateChanged(const double sampleRate) override
  213. {
  214. fJackClient.sampleRate = sampleRate;
  215. }
  216. // -------------------------------------------------------------------
  217. private:
  218. // Fake jack client
  219. jack_client_t fJackClient;
  220. // Mutex just in case
  221. CarlaMutex fMutex;
  222. // Zita stuff (core)
  223. X_resman xresman;
  224. ScopedPointer<Jclient> jclient;
  225. ScopedPointer<X_display> display;
  226. ScopedPointer<X_rootwin> rootwin;
  227. ScopedPointer<Mainwin> mainwin;
  228. ScopedPointer<X_handler> handler;
  229. //float fParameters[kParameterCount];
  230. PluginClassEND(BLS1Plugin)
  231. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(BLS1Plugin)
  232. };
  233. // -----------------------------------------------------------------------
  234. static const NativePluginDescriptor bls1Desc = {
  235. /* category */ NATIVE_PLUGIN_CATEGORY_UTILITY,
  236. /* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE
  237. |NATIVE_PLUGIN_HAS_UI
  238. |NATIVE_PLUGIN_NEEDS_FIXED_BUFFERS
  239. |NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
  240. |NATIVE_PLUGIN_USES_PARENT_ID),
  241. /* supports */ static_cast<NativePluginSupports>(0x0),
  242. /* audioIns */ 2,
  243. /* audioOuts */ 2,
  244. /* midiIns */ 0,
  245. /* midiOuts */ 0,
  246. /* paramIns */ 0, //JaaaPlugin::kParameterCount,
  247. /* paramOuts */ 0,
  248. /* name */ "BLS1",
  249. /* label */ "bls1",
  250. /* maker */ "Fons Adriaensen",
  251. /* copyright */ "GPL v2+",
  252. PluginDescriptorFILL(BLS1Plugin)
  253. };
  254. // -----------------------------------------------------------------------
  255. CARLA_EXPORT
  256. void carla_register_native_plugin_zita_bls1();
  257. CARLA_EXPORT
  258. void carla_register_native_plugin_zita_bls1()
  259. {
  260. carla_register_native_plugin(&bls1Desc);
  261. }
  262. // -----------------------------------------------------------------------