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.

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