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.

501 lines
13KB

  1. /*
  2. * Carla Plugin Engine
  3. * Copyright (C) 2012-2013 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 GPL.txt file
  16. */
  17. #if 0 //def CARLA_ENGINE_PLUGIN
  18. #include "carla_engine_internal.hpp"
  19. #include "carla_backend_utils.hpp"
  20. #include "carla_midi.h"
  21. #include "DistrhoPlugin.h"
  22. CARLA_BACKEND_START_NAMESPACE
  23. // -----------------------------------------
  24. // Parameters
  25. static const unsigned char paramMap[] = {
  26. 0x01, 0x02, 0x03, 0x04, 0x05, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  27. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
  28. 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
  29. 0x50, 0x51, 0x52, 0x53, 0x54, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F
  30. };
  31. static const unsigned int paramVolume = 5;
  32. static const unsigned int paramBalance = 6;
  33. static const unsigned int paramPan = 8;
  34. static const unsigned int paramCount = sizeof(paramMap);
  35. static const unsigned int programCount = 128;
  36. // -----------------------------------------
  37. class CarlaEnginePlugin : public CarlaEngine,
  38. public DISTRHO::Plugin
  39. {
  40. public:
  41. short idZyn;
  42. CarlaEnginePlugin()
  43. : CarlaEngine(),
  44. DISTRHO::Plugin(paramCount, programCount, 0)
  45. {
  46. qDebug("CarlaEnginePlugin::CarlaEnginePlugin()");
  47. // init parameters
  48. for (unsigned int i=0; i < paramCount; i++)
  49. paramBuffers[i] = 0.0f;
  50. paramBuffers[paramVolume] = 100.0f;
  51. paramBuffers[paramBalance] = 63.5f;
  52. paramBuffers[paramPan] = 63.5f;
  53. carla_copyFloat(prevParamBuffers, paramBuffers, paramCount);
  54. // set-up engine
  55. fOptions.processMode = PROCESS_MODE_CONTINUOUS_RACK;
  56. fOptions.forceStereo = true;
  57. fOptions.preferPluginBridges = false;
  58. fOptions.preferUiBridges = false;
  59. init("Carla");
  60. // Force thread start so we get some OSC usage
  61. // (liblo locks otherwise)
  62. //startCheckThread();
  63. // testing
  64. idZyn = addPlugin(PLUGIN_DSSI, "/usr/lib/dssi/sineshaper.so", nullptr, "ll-sineshaper");
  65. }
  66. ~CarlaEnginePlugin()
  67. {
  68. qDebug("CarlaEnginePlugin::~CarlaEnginePlugin()");
  69. removeAllPlugins();
  70. close();
  71. }
  72. // -------------------------------------
  73. // CarlaEngine virtual calls
  74. bool init(const char* const clientName)
  75. {
  76. qDebug("CarlaEnginePlugin::init(\"%s\")", clientName);
  77. fBufferSize = d_bufferSize();
  78. fSampleRate = d_sampleRate();
  79. CarlaEngine::init(clientName);
  80. return true;
  81. }
  82. bool close()
  83. {
  84. qDebug("CarlaEnginePlugin::close()");
  85. CarlaEngine::close();
  86. return true;
  87. }
  88. bool isRunning() const
  89. {
  90. return true;
  91. }
  92. bool isOffline() const
  93. {
  94. return false;
  95. }
  96. EngineType type() const
  97. {
  98. return kEngineTypeRtAudio;
  99. }
  100. protected:
  101. // ---------------------------------------------
  102. // DISTRHO Plugin Information
  103. const char* d_label() const
  104. {
  105. return "Carla";
  106. }
  107. const char* d_maker() const
  108. {
  109. return "falkTX";
  110. }
  111. const char* d_license() const
  112. {
  113. return "GPL v2+";
  114. }
  115. uint32_t d_version() const
  116. {
  117. return 0x0500;
  118. }
  119. long d_uniqueId() const
  120. {
  121. return d_cconst('C', 'r', 'l', 'a');
  122. }
  123. // ---------------------------------------------
  124. // DISTRHO Plugin Init
  125. void d_initParameter(uint32_t index, DISTRHO::Parameter& parameter)
  126. {
  127. if (index >= paramCount)
  128. return;
  129. parameter.hints = DISTRHO::PARAMETER_IS_AUTOMABLE;
  130. parameter.ranges.def = 0.0f;
  131. parameter.ranges.min = 0.0f;
  132. parameter.ranges.max = 127.0f;
  133. if (index == paramVolume)
  134. parameter.ranges.def = 100.0f;
  135. else if (index == paramBalance)
  136. parameter.ranges.def = 63.5f;
  137. else if (index == paramPan)
  138. parameter.ranges.def = 63.5f;
  139. switch (paramMap[index])
  140. {
  141. case 0x01:
  142. parameter.name = "0x01 Modulation";
  143. break;
  144. case 0x02:
  145. parameter.name = "0x02 Breath";
  146. break;
  147. case 0x03:
  148. parameter.name = "0x03 (Undefined)";
  149. break;
  150. case 0x04:
  151. parameter.name = "0x04 Foot";
  152. break;
  153. case 0x05:
  154. parameter.name = "0x05 Portamento";
  155. break;
  156. case 0x07:
  157. parameter.name = "0x07 Volume";
  158. break;
  159. case 0x08:
  160. parameter.name = "0x08 Balance";
  161. break;
  162. case 0x09:
  163. parameter.name = "0x09 (Undefined)";
  164. break;
  165. case 0x0A:
  166. parameter.name = "0x0A Pan";
  167. break;
  168. case 0x0B:
  169. parameter.name = "0x0B Expression";
  170. break;
  171. case 0x0C:
  172. parameter.name = "0x0C FX Control 1";
  173. break;
  174. case 0x0D:
  175. parameter.name = "0x0D FX Control 2";
  176. break;
  177. case 0x0E:
  178. parameter.name = "0x0E (Undefined)";
  179. break;
  180. case 0x0F:
  181. parameter.name = "0x0F (Undefined)";
  182. break;
  183. case 0x10:
  184. parameter.name = "0x10 General Purpose 1";
  185. break;
  186. case 0x11:
  187. parameter.name = "0x11 General Purpose 2";
  188. break;
  189. case 0x12:
  190. parameter.name = "0x12 General Purpose 3";
  191. break;
  192. case 0x13:
  193. parameter.name = "0x13 General Purpose 4";
  194. break;
  195. case 0x14:
  196. parameter.name = "0x14 (Undefined)";
  197. break;
  198. case 0x15:
  199. parameter.name = "0x15 (Undefined)";
  200. break;
  201. case 0x16:
  202. parameter.name = "0x16 (Undefined)";
  203. break;
  204. case 0x17:
  205. parameter.name = "0x17 (Undefined)";
  206. break;
  207. case 0x18:
  208. parameter.name = "0x18 (Undefined)";
  209. break;
  210. case 0x19:
  211. parameter.name = "0x19 (Undefined)";
  212. break;
  213. case 0x1A:
  214. parameter.name = "0x1A (Undefined)";
  215. break;
  216. case 0x1B:
  217. parameter.name = "0x1B (Undefined)";
  218. break;
  219. case 0x1C:
  220. parameter.name = "0x1C (Undefined)";
  221. break;
  222. case 0x1D:
  223. parameter.name = "0x1D (Undefined)";
  224. break;
  225. case 0x1E:
  226. parameter.name = "0x1E (Undefined)";
  227. break;
  228. case 0x1F:
  229. parameter.name = "0x1F (Undefined)";
  230. break;
  231. case 0x46:
  232. parameter.name = "0x46 Control 1 [Variation]";
  233. break;
  234. case 0x47:
  235. parameter.name = "0x47 Control 2 [Timbre]";
  236. break;
  237. case 0x48:
  238. parameter.name = "0x48 Control 3 [Release]";
  239. break;
  240. case 0x49:
  241. parameter.name = "0x49 Control 4 [Attack]";
  242. break;
  243. case 0x4A:
  244. parameter.name = "0x4A Control 5 [Brightness]";
  245. break;
  246. case 0x4B:
  247. parameter.name = "0x4B Control 6 [Decay]";
  248. break;
  249. case 0x4C:
  250. parameter.name = "0x4C Control 7 [Vib Rate]";
  251. break;
  252. case 0x4D:
  253. parameter.name = "0x4D Control 8 [Vib Depth]";
  254. break;
  255. case 0x4E:
  256. parameter.name = "0x4E Control 9 [Vib Delay]";
  257. break;
  258. case 0x4F:
  259. parameter.name = "0x4F Control 10 [Undefined]";
  260. break;
  261. case 0x50:
  262. parameter.name = "0x50 General Purpose 5";
  263. break;
  264. case 0x51:
  265. parameter.name = "0x51 General Purpose 6";
  266. break;
  267. case 0x52:
  268. parameter.name = "0x52 General Purpose 7";
  269. break;
  270. case 0x53:
  271. parameter.name = "0x53 General Purpose 8";
  272. break;
  273. case 0x54:
  274. parameter.name = "0x54 Portamento Control";
  275. break;
  276. case 0x5B:
  277. parameter.name = "0x5B FX 1 Depth [Reverb]";
  278. break;
  279. case 0x5C:
  280. parameter.name = "0x5C FX 2 Depth [Tremolo]";
  281. break;
  282. case 0x5D:
  283. parameter.name = "0x5D FX 3 Depth [Chorus]";
  284. break;
  285. case 0x5E:
  286. parameter.name = "0x5E FX 4 Depth [Detune]";
  287. break;
  288. case 0x5F:
  289. parameter.name = "0x5F FX 5 Depth [Phaser]";
  290. break;
  291. }
  292. }
  293. void d_initProgramName(uint32_t index, d_string& programName)
  294. {
  295. programName = "Program #" + d_string(index);
  296. }
  297. void d_initStateKey(uint32_t index, d_string& stateKey)
  298. {
  299. Q_UNUSED(index);
  300. Q_UNUSED(stateKey);
  301. }
  302. // ---------------------------------------------
  303. // DISTRHO Plugin Internal data
  304. float d_parameterValue(uint32_t index)
  305. {
  306. if (index >= paramCount)
  307. return 0.0f;
  308. return paramBuffers[index];
  309. }
  310. void d_setParameterValue(uint32_t index, float value)
  311. {
  312. if (index >= paramCount)
  313. return;
  314. paramBuffers[index] = value;
  315. }
  316. void d_setProgram(uint32_t index)
  317. {
  318. if (index >= programCount)
  319. return;
  320. if (maxPluginNumber() == 0)
  321. return;
  322. #if 0
  323. if (CarlaPlugin* const plugin = getPlugin(0))
  324. {
  325. if (index > plugin->programCount())
  326. plugin->setProgram(index, true, true, false, true);
  327. }
  328. #endif
  329. }
  330. void d_setState(const char* key, const char* value)
  331. {
  332. Q_UNUSED(key);
  333. Q_UNUSED(value);
  334. }
  335. // ---------------------------------------------
  336. // DISTRHO Plugin Process
  337. void d_activate()
  338. {
  339. #if 0
  340. for (unsigned int i=0; i < fData->curPluginCount; i++)
  341. {
  342. CarlaPlugin* const plugin = getPluginUnchecked(i);
  343. if (plugin && plugin->enabled())
  344. plugin->setActive(true, true, false);
  345. }
  346. #endif
  347. carla_copyFloat(prevParamBuffers, paramBuffers, paramCount);
  348. }
  349. void d_deactivate()
  350. {
  351. #if 0
  352. for (unsigned int i=0; i < fData->curPluginCount; i++)
  353. {
  354. CarlaPlugin* const plugin = getPluginUnchecked(i);
  355. if (plugin && plugin->enabled())
  356. plugin->setActive(false, true, false);
  357. }
  358. #endif
  359. }
  360. void d_run(float** inputs, float** outputs, uint32_t frames, uint32_t midiEventCount, const DISTRHO::MidiEvent* midiEvents)
  361. {
  362. if (maxPluginNumber() == 0)
  363. return;
  364. // create audio buffers
  365. float* inBuf[2] = { inputs[0], inputs[1] };
  366. float* outBuf[2] = { outputs[0], outputs[1] };
  367. #if 0
  368. // initialize control input
  369. std::memset(rackControlEventsIn, 0, sizeof(CarlaEngineControlEvent)*CarlaEngine::MAX_CONTROL_EVENTS);
  370. {
  371. uint32_t carlaEventIndex = 0;
  372. for (unsigned int i=0; i < paramCount; i++)
  373. {
  374. if (prevParamBuffers[i] == paramBuffers[i])
  375. continue;
  376. CarlaEngineControlEvent* const carlaEvent = &rackControlEventsIn[carlaEventIndex++];
  377. carlaEvent->type = CarlaEngineParameterChangeEvent;
  378. carlaEvent->parameter = paramMap[i];
  379. carlaEvent->value = paramBuffers[i]/127;
  380. }
  381. }
  382. carla_copyFloat(prevParamBuffers, paramBuffers, paramCount);
  383. // initialize midi input
  384. std::memset(rackMidiEventsIn, 0, sizeof(CarlaEngineMidiEvent)*CarlaEngine::MAX_MIDI_EVENTS);
  385. {
  386. const DISTRHO::MidiEvent* event;
  387. for (uint32_t i=0, j=0; j < midiEventCount; j++)
  388. {
  389. if (i == CarlaEngine::MAX_MIDI_EVENTS)
  390. break;
  391. event = &midiEvents[j];
  392. rackMidiEventsIn[i].time = event->frame;
  393. rackMidiEventsIn[i].size = 3;
  394. std::memcpy(rackMidiEventsIn[i].data, event->buffer, 3);
  395. i += 1;
  396. }
  397. }
  398. #endif
  399. processRack(inBuf, outBuf, frames);
  400. }
  401. // ---------------------------------------------
  402. // Callbacks
  403. void d_bufferSizeChanged(uint32_t newBufferSize)
  404. {
  405. bufferSizeChanged(newBufferSize);
  406. }
  407. // ---------------------------------------------
  408. private:
  409. float paramBuffers[paramCount];
  410. float prevParamBuffers[paramCount];
  411. };
  412. CARLA_BACKEND_END_NAMESPACE
  413. // -------------------------------------------------
  414. START_NAMESPACE_DISTRHO
  415. Plugin* createPlugin()
  416. {
  417. return new CarlaBackend::CarlaEnginePlugin();
  418. }
  419. END_NAMESPACE_DISTRHO
  420. // -------------------------------------------------
  421. #include "DistrhoPluginMain.cpp"
  422. #endif // CARLA_ENGINE_PLUGIN