Collection of tools useful for audio production
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.

1348 lines
45KB

  1. /*
  2. * Carla Backend
  3. * Copyright (C) 2011-2012 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * 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 COPYING file
  16. */
  17. #ifdef BUILD_BRIDGE
  18. # error Should not use fluidsynth for bridges!
  19. #endif
  20. #include "carla_plugin.h"
  21. #ifdef WANT_FLUIDSYNTH
  22. #include "carla_fluidsynth.h"
  23. CARLA_BACKEND_START_NAMESPACE
  24. /*!
  25. * @defgroup CarlaBackendFluidSynthPlugin Carla Backend FluidSynth Plugin
  26. *
  27. * The Carla Backend FluidSynth Plugin.\n
  28. * http://www.fluidsynth.org/
  29. * @{
  30. */
  31. class FluidSynthPlugin : public CarlaPlugin
  32. {
  33. public:
  34. FluidSynthPlugin(CarlaEngine* const engine, const unsigned short id)
  35. : CarlaPlugin(engine, id)
  36. {
  37. qDebug("FluidSynthPlugin::FluidSynthPlugin()");
  38. m_type = PLUGIN_SF2;
  39. m_label = nullptr;
  40. // create settings
  41. f_settings = new_fluid_settings();
  42. // define settings
  43. fluid_settings_setnum(f_settings, "synth.sample-rate", x_engine->getSampleRate());
  44. fluid_settings_setint(f_settings, "synth.threadsafe-api ", 0);
  45. // create synth
  46. f_synth = new_fluid_synth(f_settings);
  47. #ifdef FLUIDSYNTH_VERSION_NEW_API
  48. fluid_synth_set_sample_rate(f_synth, x_engine->getSampleRate());
  49. #endif
  50. // set default values
  51. fluid_synth_set_reverb_on(f_synth, 0);
  52. fluid_synth_set_reverb(f_synth, FLUID_REVERB_DEFAULT_ROOMSIZE, FLUID_REVERB_DEFAULT_DAMP, FLUID_REVERB_DEFAULT_WIDTH, FLUID_REVERB_DEFAULT_LEVEL);
  53. fluid_synth_set_chorus_on(f_synth, 0);
  54. fluid_synth_set_chorus(f_synth, FLUID_CHORUS_DEFAULT_N, FLUID_CHORUS_DEFAULT_LEVEL, FLUID_CHORUS_DEFAULT_SPEED, FLUID_CHORUS_DEFAULT_DEPTH, FLUID_CHORUS_DEFAULT_TYPE);
  55. fluid_synth_set_polyphony(f_synth, 64);
  56. for (int i=0; i < 16; i++)
  57. fluid_synth_set_interp_method(f_synth, i, FLUID_INTERP_DEFAULT);
  58. }
  59. ~FluidSynthPlugin()
  60. {
  61. qDebug("FluidSynthPlugin::~FluidSynthPlugin()");
  62. if (m_label)
  63. free((void*)m_label);
  64. delete_fluid_synth(f_synth);
  65. delete_fluid_settings(f_settings);
  66. }
  67. // -------------------------------------------------------------------
  68. // Information (base)
  69. PluginCategory category()
  70. {
  71. return PLUGIN_CATEGORY_SYNTH;
  72. }
  73. // -------------------------------------------------------------------
  74. // Information (count)
  75. uint32_t parameterScalePointCount(const uint32_t parameterId)
  76. {
  77. CARLA_ASSERT(parameterId < param.count);
  78. switch (parameterId)
  79. {
  80. case FluidSynthChorusType:
  81. return 2;
  82. case FluidSynthInterpolation:
  83. return 4;
  84. default:
  85. return 0;
  86. }
  87. }
  88. // -------------------------------------------------------------------
  89. // Information (per-plugin data)
  90. double getParameterValue(const uint32_t parameterId)
  91. {
  92. CARLA_ASSERT(parameterId < param.count);
  93. return paramBuffers[parameterId];
  94. }
  95. double getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId)
  96. {
  97. CARLA_ASSERT(parameterId < param.count);
  98. CARLA_ASSERT(scalePointId < parameterScalePointCount(parameterId));
  99. switch (parameterId)
  100. {
  101. case FluidSynthChorusType:
  102. switch (scalePointId)
  103. {
  104. case 0:
  105. return FLUID_CHORUS_MOD_SINE;
  106. case 1:
  107. return FLUID_CHORUS_MOD_TRIANGLE;
  108. default:
  109. return FLUID_CHORUS_DEFAULT_TYPE;
  110. }
  111. case FluidSynthInterpolation:
  112. switch (scalePointId)
  113. {
  114. case 0:
  115. return FLUID_INTERP_NONE;
  116. case 1:
  117. return FLUID_INTERP_LINEAR;
  118. case 2:
  119. return FLUID_INTERP_4THORDER;
  120. case 3:
  121. return FLUID_INTERP_7THORDER;
  122. default:
  123. return FLUID_INTERP_DEFAULT;
  124. }
  125. default:
  126. return 0.0;
  127. }
  128. }
  129. void getLabel(char* const strBuf)
  130. {
  131. if (m_label)
  132. strncpy(strBuf, m_label, STR_MAX);
  133. else
  134. CarlaPlugin::getLabel(strBuf);
  135. }
  136. void getMaker(char* const strBuf)
  137. {
  138. strncpy(strBuf, "FluidSynth SF2 engine", STR_MAX);
  139. }
  140. void getCopyright(char* const strBuf)
  141. {
  142. strncpy(strBuf, "GNU GPL v2+", STR_MAX);
  143. }
  144. void getRealName(char* const strBuf)
  145. {
  146. getLabel(strBuf);
  147. }
  148. void getParameterName(const uint32_t parameterId, char* const strBuf)
  149. {
  150. CARLA_ASSERT(parameterId < param.count);
  151. switch (parameterId)
  152. {
  153. case FluidSynthReverbOnOff:
  154. strncpy(strBuf, "Reverb On/Off", STR_MAX);
  155. break;
  156. case FluidSynthReverbRoomSize:
  157. strncpy(strBuf, "Reverb Room Size", STR_MAX);
  158. break;
  159. case FluidSynthReverbDamp:
  160. strncpy(strBuf, "Reverb Damp", STR_MAX);
  161. break;
  162. case FluidSynthReverbLevel:
  163. strncpy(strBuf, "Reverb Level", STR_MAX);
  164. break;
  165. case FluidSynthReverbWidth:
  166. strncpy(strBuf, "Reverb Width", STR_MAX);
  167. break;
  168. case FluidSynthChorusOnOff:
  169. strncpy(strBuf, "Chorus On/Off", STR_MAX);
  170. break;
  171. case FluidSynthChorusNr:
  172. strncpy(strBuf, "Chorus Voice Count", STR_MAX);
  173. break;
  174. case FluidSynthChorusLevel:
  175. strncpy(strBuf, "Chorus Level", STR_MAX);
  176. break;
  177. case FluidSynthChorusSpeedHz:
  178. strncpy(strBuf, "Chorus Speed", STR_MAX);
  179. break;
  180. case FluidSynthChorusDepthMs:
  181. strncpy(strBuf, "Chorus Depth", STR_MAX);
  182. break;
  183. case FluidSynthChorusType:
  184. strncpy(strBuf, "Chorus Type", STR_MAX);
  185. break;
  186. case FluidSynthPolyphony:
  187. strncpy(strBuf, "Polyphony", STR_MAX);
  188. break;
  189. case FluidSynthInterpolation:
  190. strncpy(strBuf, "Interpolation", STR_MAX);
  191. break;
  192. case FluidSynthVoiceCount:
  193. strncpy(strBuf, "Voice Count", STR_MAX);
  194. break;
  195. default:
  196. CarlaPlugin::getParameterName(parameterId, strBuf);
  197. break;
  198. }
  199. }
  200. void getParameterUnit(const uint32_t parameterId, char* const strBuf)
  201. {
  202. CARLA_ASSERT(parameterId < param.count);
  203. switch (parameterId)
  204. {
  205. case FluidSynthChorusSpeedHz:
  206. strncpy(strBuf, "Hz", STR_MAX);
  207. break;
  208. case FluidSynthChorusDepthMs:
  209. strncpy(strBuf, "ms", STR_MAX);
  210. break;
  211. default:
  212. CarlaPlugin::getParameterUnit(parameterId, strBuf);
  213. break;
  214. }
  215. }
  216. void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf)
  217. {
  218. CARLA_ASSERT(parameterId < param.count);
  219. CARLA_ASSERT(scalePointId < parameterScalePointCount(parameterId));
  220. switch (parameterId)
  221. {
  222. case FluidSynthChorusType:
  223. switch (scalePointId)
  224. {
  225. case 0:
  226. strncpy(strBuf, "Sine wave", STR_MAX);
  227. return;
  228. case 1:
  229. strncpy(strBuf, "Triangle wave", STR_MAX);
  230. return;
  231. }
  232. case FluidSynthInterpolation:
  233. switch (scalePointId)
  234. {
  235. case 0:
  236. strncpy(strBuf, "None", STR_MAX);
  237. return;
  238. case 1:
  239. strncpy(strBuf, "Straight-line", STR_MAX);
  240. return;
  241. case 2:
  242. strncpy(strBuf, "Fourth-order", STR_MAX);
  243. return;
  244. case 3:
  245. strncpy(strBuf, "Seventh-order", STR_MAX);
  246. return;
  247. }
  248. }
  249. CarlaPlugin::getParameterScalePointLabel(parameterId, scalePointId, strBuf);
  250. }
  251. // -------------------------------------------------------------------
  252. // Set data (plugin-specific stuff)
  253. void setParameterValue(const uint32_t parameterId, double value, const bool sendGui, const bool sendOsc, const bool sendCallback)
  254. {
  255. CARLA_ASSERT(parameterId < param.count);
  256. paramBuffers[parameterId] = fixParameterValue(value, param.ranges[parameterId]);
  257. switch (parameterId)
  258. {
  259. case FluidSynthReverbOnOff:
  260. value = value > 0.5 ? 1 : 0;
  261. fluid_synth_set_reverb_on(f_synth, value);
  262. break;
  263. case FluidSynthReverbRoomSize:
  264. case FluidSynthReverbDamp:
  265. case FluidSynthReverbLevel:
  266. case FluidSynthReverbWidth:
  267. fluid_synth_set_reverb(f_synth, paramBuffers[FluidSynthReverbRoomSize], paramBuffers[FluidSynthReverbDamp], paramBuffers[FluidSynthReverbWidth], paramBuffers[FluidSynthReverbLevel]);
  268. break;
  269. case FluidSynthChorusOnOff:
  270. {
  271. const ScopedDisabler m(this, ! x_engine->isOffline());
  272. value = value > 0.5 ? 1 : 0;
  273. fluid_synth_set_chorus_on(f_synth, value);
  274. break;
  275. }
  276. case FluidSynthChorusNr:
  277. case FluidSynthChorusLevel:
  278. case FluidSynthChorusSpeedHz:
  279. case FluidSynthChorusDepthMs:
  280. case FluidSynthChorusType:
  281. {
  282. const ScopedDisabler m(this, ! x_engine->isOffline());
  283. fluid_synth_set_chorus(f_synth, rint(paramBuffers[FluidSynthChorusNr]), paramBuffers[FluidSynthChorusLevel], paramBuffers[FluidSynthChorusSpeedHz], paramBuffers[FluidSynthChorusDepthMs], rint(paramBuffers[FluidSynthChorusType]));
  284. break;
  285. }
  286. case FluidSynthPolyphony:
  287. {
  288. const ScopedDisabler m(this, ! x_engine->isOffline());
  289. fluid_synth_set_polyphony(f_synth, rint(value));
  290. break;
  291. }
  292. case FluidSynthInterpolation:
  293. {
  294. const ScopedDisabler m(this, ! x_engine->isOffline());
  295. for (int i=0; i < 16; i++)
  296. fluid_synth_set_interp_method(f_synth, i, rint(value));
  297. break;
  298. }
  299. default:
  300. break;
  301. }
  302. CarlaPlugin::setParameterValue(parameterId, value, sendGui, sendOsc, sendCallback);
  303. }
  304. void setMidiProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block)
  305. {
  306. CARLA_ASSERT(index >= -1 && index < (int32_t)midiprog.count);
  307. if (index < -1)
  308. index = -1;
  309. else if (index > (int32_t)midiprog.count)
  310. return;
  311. if (m_ctrlInChannel < 0 || m_ctrlInChannel > 15)
  312. return;
  313. if (index >= 0)
  314. {
  315. if (x_engine->isOffline())
  316. {
  317. const CarlaEngine::ScopedLocker m(x_engine, block);
  318. fluid_synth_program_select(f_synth, m_ctrlInChannel, f_id, midiprog.data[index].bank, midiprog.data[index].program);
  319. }
  320. else
  321. {
  322. const ScopedDisabler m(this, block);
  323. fluid_synth_program_select(f_synth, m_ctrlInChannel, f_id, midiprog.data[index].bank, midiprog.data[index].program);
  324. }
  325. }
  326. CarlaPlugin::setMidiProgram(index, sendGui, sendOsc, sendCallback, block);
  327. }
  328. // -------------------------------------------------------------------
  329. // Plugin state
  330. void reload()
  331. {
  332. qDebug("FluidSynthPlugin::reload() - start");
  333. CARLA_ASSERT(f_synth);
  334. // Safely disable plugin for reload
  335. const ScopedDisabler m(this);
  336. if (x_client->isActive())
  337. x_client->deactivate();
  338. // Remove client ports
  339. removeClientPorts();
  340. // Delete old data
  341. deleteBuffers();
  342. uint32_t aOuts, params, j;
  343. aOuts = 2;
  344. params = FluidSynthParametersMax;
  345. aOut.ports = new CarlaEngineAudioPort*[aOuts];
  346. aOut.rindexes = new uint32_t[aOuts];
  347. param.data = new ParameterData[params];
  348. param.ranges = new ParameterRanges[params];
  349. const int portNameSize = CarlaEngine::maxPortNameSize() - 1;
  350. char portName[portNameSize];
  351. // ---------------------------------------
  352. // Audio Outputs
  353. #ifndef BUILD_BRIDGE
  354. if (carlaOptions.processMode != PROCESS_MODE_MULTIPLE_CLIENTS)
  355. {
  356. strcpy(portName, m_name);
  357. strcat(portName, ":out-left");
  358. }
  359. else
  360. #endif
  361. strcpy(portName, "out-left");
  362. aOut.ports[0] = (CarlaEngineAudioPort*)x_client->addPort(CarlaEnginePortTypeAudio, portName, false);
  363. aOut.rindexes[0] = 0;
  364. #ifndef BUILD_BRIDGE
  365. if (carlaOptions.processMode != PROCESS_MODE_MULTIPLE_CLIENTS)
  366. {
  367. strcpy(portName, m_name);
  368. strcat(portName, ":out-right");
  369. }
  370. else
  371. #endif
  372. strcpy(portName, "out-right");
  373. aOut.ports[1] = (CarlaEngineAudioPort*)x_client->addPort(CarlaEnginePortTypeAudio, portName, false);
  374. aOut.rindexes[1] = 1;
  375. // ---------------------------------------
  376. // MIDI Input
  377. #ifndef BUILD_BRIDGE
  378. if (carlaOptions.processMode != PROCESS_MODE_MULTIPLE_CLIENTS)
  379. {
  380. strcpy(portName, m_name);
  381. strcat(portName, ":midi-in");
  382. }
  383. else
  384. #endif
  385. strcpy(portName, "midi-in");
  386. midi.portMin = (CarlaEngineMidiPort*)x_client->addPort(CarlaEnginePortTypeMIDI, portName, true);
  387. // ---------------------------------------
  388. // Parameters
  389. #ifndef BUILD_BRIDGE
  390. if (carlaOptions.processMode != PROCESS_MODE_MULTIPLE_CLIENTS)
  391. {
  392. strcpy(portName, m_name);
  393. strcat(portName, ":control-in");
  394. }
  395. else
  396. #endif
  397. strcpy(portName, "control-in");
  398. param.portCin = (CarlaEngineControlPort*)x_client->addPort(CarlaEnginePortTypeControl, portName, true);
  399. #ifndef BUILD_BRIDGE
  400. if (carlaOptions.processMode != PROCESS_MODE_MULTIPLE_CLIENTS)
  401. {
  402. strcpy(portName, m_name);
  403. strcat(portName, ":control-out");
  404. }
  405. else
  406. #endif
  407. strcpy(portName, "control-out");
  408. param.portCout = (CarlaEngineControlPort*)x_client->addPort(CarlaEnginePortTypeControl, portName, false);
  409. // ----------------------
  410. j = FluidSynthReverbOnOff;
  411. param.data[j].index = j;
  412. param.data[j].rindex = j;
  413. param.data[j].type = PARAMETER_INPUT;
  414. param.data[j].hints = PARAMETER_IS_ENABLED | PARAMETER_IS_AUTOMABLE | PARAMETER_IS_BOOLEAN;
  415. param.data[j].midiChannel = 0;
  416. param.data[j].midiCC = -1;
  417. param.ranges[j].min = 0.0;
  418. param.ranges[j].max = 1.0;
  419. param.ranges[j].def = 0.0; // off
  420. param.ranges[j].step = 1.0;
  421. param.ranges[j].stepSmall = 1.0;
  422. param.ranges[j].stepLarge = 1.0;
  423. paramBuffers[j] = param.ranges[j].def;
  424. // ----------------------
  425. j = FluidSynthReverbRoomSize;
  426. param.data[j].index = j;
  427. param.data[j].rindex = j;
  428. param.data[j].type = PARAMETER_INPUT;
  429. param.data[j].hints = PARAMETER_IS_ENABLED | PARAMETER_IS_AUTOMABLE;
  430. param.data[j].midiChannel = 0;
  431. param.data[j].midiCC = -1;
  432. param.ranges[j].min = 0.0;
  433. param.ranges[j].max = 1.2;
  434. param.ranges[j].def = FLUID_REVERB_DEFAULT_ROOMSIZE;
  435. param.ranges[j].step = 0.01;
  436. param.ranges[j].stepSmall = 0.0001;
  437. param.ranges[j].stepLarge = 0.1;
  438. paramBuffers[j] = param.ranges[j].def;
  439. // ----------------------
  440. j = FluidSynthReverbDamp;
  441. param.data[j].index = j;
  442. param.data[j].rindex = j;
  443. param.data[j].type = PARAMETER_INPUT;
  444. param.data[j].hints = PARAMETER_IS_ENABLED | PARAMETER_IS_AUTOMABLE;
  445. param.data[j].midiChannel = 0;
  446. param.data[j].midiCC = -1;
  447. param.ranges[j].min = 0.0;
  448. param.ranges[j].max = 1.0;
  449. param.ranges[j].def = FLUID_REVERB_DEFAULT_DAMP;
  450. param.ranges[j].step = 0.01;
  451. param.ranges[j].stepSmall = 0.0001;
  452. param.ranges[j].stepLarge = 0.1;
  453. paramBuffers[j] = param.ranges[j].def;
  454. // ----------------------
  455. j = FluidSynthReverbLevel;
  456. param.data[j].index = j;
  457. param.data[j].rindex = j;
  458. param.data[j].type = PARAMETER_INPUT;
  459. param.data[j].hints = PARAMETER_IS_ENABLED | PARAMETER_IS_AUTOMABLE;
  460. param.data[j].midiChannel = 0;
  461. param.data[j].midiCC = MIDI_CONTROL_REVERB_SEND_LEVEL;
  462. param.ranges[j].min = 0.0;
  463. param.ranges[j].max = 1.0;
  464. param.ranges[j].def = FLUID_REVERB_DEFAULT_LEVEL;
  465. param.ranges[j].step = 0.01;
  466. param.ranges[j].stepSmall = 0.0001;
  467. param.ranges[j].stepLarge = 0.1;
  468. paramBuffers[j] = param.ranges[j].def;
  469. // ----------------------
  470. j = FluidSynthReverbWidth;
  471. param.data[j].index = j;
  472. param.data[j].rindex = j;
  473. param.data[j].type = PARAMETER_INPUT;
  474. param.data[j].hints = PARAMETER_IS_ENABLED | PARAMETER_IS_AUTOMABLE;
  475. param.data[j].midiChannel = 0;
  476. param.data[j].midiCC = -1;
  477. param.ranges[j].min = 0.0;
  478. param.ranges[j].max = 10.0; // should be 100, but that sounds too much
  479. param.ranges[j].def = FLUID_REVERB_DEFAULT_WIDTH;
  480. param.ranges[j].step = 0.01;
  481. param.ranges[j].stepSmall = 0.0001;
  482. param.ranges[j].stepLarge = 0.1;
  483. paramBuffers[j] = param.ranges[j].def;
  484. // ----------------------
  485. j = FluidSynthChorusOnOff;
  486. param.data[j].index = j;
  487. param.data[j].rindex = j;
  488. param.data[j].type = PARAMETER_INPUT;
  489. param.data[j].hints = PARAMETER_IS_ENABLED | PARAMETER_IS_BOOLEAN;
  490. param.data[j].midiChannel = 0;
  491. param.data[j].midiCC = -1;
  492. param.ranges[j].min = 0.0;
  493. param.ranges[j].max = 1.0;
  494. param.ranges[j].def = 0.0; // off
  495. param.ranges[j].step = 1.0;
  496. param.ranges[j].stepSmall = 1.0;
  497. param.ranges[j].stepLarge = 1.0;
  498. paramBuffers[j] = param.ranges[j].def;
  499. // ----------------------
  500. j = FluidSynthChorusNr;
  501. param.data[j].index = j;
  502. param.data[j].rindex = j;
  503. param.data[j].type = PARAMETER_INPUT;
  504. param.data[j].hints = PARAMETER_IS_ENABLED | PARAMETER_IS_INTEGER;
  505. param.data[j].midiChannel = 0;
  506. param.data[j].midiCC = -1;
  507. param.ranges[j].min = 0.0;
  508. param.ranges[j].max = 99.0;
  509. param.ranges[j].def = FLUID_CHORUS_DEFAULT_N;
  510. param.ranges[j].step = 1.0;
  511. param.ranges[j].stepSmall = 1.0;
  512. param.ranges[j].stepLarge = 10.0;
  513. paramBuffers[j] = param.ranges[j].def;
  514. // ----------------------
  515. j = FluidSynthChorusLevel;
  516. param.data[j].index = j;
  517. param.data[j].rindex = j;
  518. param.data[j].type = PARAMETER_INPUT;
  519. param.data[j].hints = PARAMETER_IS_ENABLED;
  520. param.data[j].midiChannel = 0;
  521. param.data[j].midiCC = 0; //MIDI_CONTROL_CHORUS_SEND_LEVEL;
  522. param.ranges[j].min = 0.0;
  523. param.ranges[j].max = 10.0;
  524. param.ranges[j].def = FLUID_CHORUS_DEFAULT_LEVEL;
  525. param.ranges[j].step = 0.01;
  526. param.ranges[j].stepSmall = 0.0001;
  527. param.ranges[j].stepLarge = 0.1;
  528. paramBuffers[j] = param.ranges[j].def;
  529. // ----------------------
  530. j = FluidSynthChorusSpeedHz;
  531. param.data[j].index = j;
  532. param.data[j].rindex = j;
  533. param.data[j].type = PARAMETER_INPUT;
  534. param.data[j].hints = PARAMETER_IS_ENABLED;
  535. param.data[j].midiChannel = 0;
  536. param.data[j].midiCC = -1;
  537. param.ranges[j].min = 0.29;
  538. param.ranges[j].max = 5.0;
  539. param.ranges[j].def = FLUID_CHORUS_DEFAULT_SPEED;
  540. param.ranges[j].step = 0.01;
  541. param.ranges[j].stepSmall = 0.0001;
  542. param.ranges[j].stepLarge = 0.1;
  543. paramBuffers[j] = param.ranges[j].def;
  544. // ----------------------
  545. j = FluidSynthChorusDepthMs;
  546. param.data[j].index = j;
  547. param.data[j].rindex = j;
  548. param.data[j].type = PARAMETER_INPUT;
  549. param.data[j].hints = PARAMETER_IS_ENABLED;
  550. param.data[j].midiChannel = 0;
  551. param.data[j].midiCC = -1;
  552. param.ranges[j].min = 0.0;
  553. param.ranges[j].max = 2048000.0 / x_engine->getSampleRate();
  554. param.ranges[j].def = FLUID_CHORUS_DEFAULT_DEPTH;
  555. param.ranges[j].step = 0.01;
  556. param.ranges[j].stepSmall = 0.0001;
  557. param.ranges[j].stepLarge = 0.1;
  558. paramBuffers[j] = param.ranges[j].def;
  559. // ----------------------
  560. j = FluidSynthChorusType;
  561. param.data[j].index = j;
  562. param.data[j].rindex = j;
  563. param.data[j].type = PARAMETER_INPUT;
  564. param.data[j].hints = PARAMETER_IS_ENABLED | PARAMETER_IS_INTEGER | PARAMETER_USES_SCALEPOINTS;
  565. param.data[j].midiChannel = 0;
  566. param.data[j].midiCC = -1;
  567. param.ranges[j].min = FLUID_CHORUS_MOD_SINE;
  568. param.ranges[j].max = FLUID_CHORUS_MOD_TRIANGLE;
  569. param.ranges[j].def = FLUID_CHORUS_DEFAULT_TYPE;
  570. param.ranges[j].step = 1;
  571. param.ranges[j].stepSmall = 1;
  572. param.ranges[j].stepLarge = 1;
  573. paramBuffers[j] = param.ranges[j].def;
  574. // ----------------------
  575. j = FluidSynthPolyphony;
  576. param.data[j].index = j;
  577. param.data[j].rindex = j;
  578. param.data[j].type = PARAMETER_INPUT;
  579. param.data[j].hints = PARAMETER_IS_ENABLED | PARAMETER_IS_INTEGER;
  580. param.data[j].midiChannel = 0;
  581. param.data[j].midiCC = -1;
  582. param.ranges[j].min = 1;
  583. param.ranges[j].max = 512; // max theoric is 65535
  584. param.ranges[j].def = fluid_synth_get_polyphony(f_synth);
  585. param.ranges[j].step = 1;
  586. param.ranges[j].stepSmall = 1;
  587. param.ranges[j].stepLarge = 10;
  588. paramBuffers[j] = param.ranges[j].def;
  589. // ----------------------
  590. j = FluidSynthInterpolation;
  591. param.data[j].index = j;
  592. param.data[j].rindex = j;
  593. param.data[j].type = PARAMETER_INPUT;
  594. param.data[j].hints = PARAMETER_IS_ENABLED | PARAMETER_IS_INTEGER | PARAMETER_USES_SCALEPOINTS;
  595. param.data[j].midiChannel = 0;
  596. param.data[j].midiCC = -1;
  597. param.ranges[j].min = FLUID_INTERP_NONE;
  598. param.ranges[j].max = FLUID_INTERP_HIGHEST;
  599. param.ranges[j].def = FLUID_INTERP_DEFAULT;
  600. param.ranges[j].step = 1;
  601. param.ranges[j].stepSmall = 1;
  602. param.ranges[j].stepLarge = 1;
  603. paramBuffers[j] = param.ranges[j].def;
  604. // ----------------------
  605. j = FluidSynthVoiceCount;
  606. param.data[j].index = j;
  607. param.data[j].rindex = j;
  608. param.data[j].type = PARAMETER_OUTPUT;
  609. param.data[j].hints = PARAMETER_IS_ENABLED | PARAMETER_IS_AUTOMABLE | PARAMETER_IS_INTEGER;
  610. param.data[j].midiChannel = 0;
  611. param.data[j].midiCC = -1;
  612. param.ranges[j].min = 0;
  613. param.ranges[j].max = 65535;
  614. param.ranges[j].def = 0;
  615. param.ranges[j].step = 1;
  616. param.ranges[j].stepSmall = 1;
  617. param.ranges[j].stepLarge = 1;
  618. paramBuffers[j] = param.ranges[j].def;
  619. // ---------------------------------------
  620. aOut.count = aOuts;
  621. param.count = params;
  622. // plugin checks
  623. m_hints &= ~(PLUGIN_IS_SYNTH | PLUGIN_USES_CHUNKS | PLUGIN_CAN_DRYWET | PLUGIN_CAN_VOLUME | PLUGIN_CAN_BALANCE | PLUGIN_CAN_FORCE_STEREO);
  624. m_hints |= PLUGIN_IS_SYNTH;
  625. m_hints |= PLUGIN_CAN_VOLUME;
  626. m_hints |= PLUGIN_CAN_BALANCE;
  627. m_hints |= PLUGIN_CAN_FORCE_STEREO;
  628. reloadPrograms(true);
  629. x_client->activate();
  630. qDebug("FluidSynthPlugin::reload() - end");
  631. }
  632. void reloadPrograms(const bool init)
  633. {
  634. qDebug("FluidSynthPlugin::reloadPrograms(%s)", bool2str(init));
  635. // Delete old programs
  636. if (midiprog.count > 0)
  637. {
  638. for (uint32_t i=0; i < midiprog.count; i++)
  639. free((void*)midiprog.data[i].name);
  640. delete[] midiprog.data;
  641. }
  642. midiprog.count = 0;
  643. midiprog.data = nullptr;
  644. // Query new programs
  645. fluid_sfont_t* f_sfont;
  646. fluid_preset_t f_preset;
  647. bool hasDrums = false;
  648. f_sfont = fluid_synth_get_sfont_by_id(f_synth, f_id);
  649. // initial check to know how much midi-programs we have
  650. f_sfont->iteration_start(f_sfont);
  651. while (f_sfont->iteration_next(f_sfont, &f_preset))
  652. midiprog.count += 1;
  653. // soundfonts must always have at least 1 midi-program
  654. CARLA_ASSERT(midiprog.count > 0);
  655. if (midiprog.count > 0)
  656. midiprog.data = new MidiProgramData[midiprog.count];
  657. // Update data
  658. uint32_t i = 0;
  659. f_sfont->iteration_start(f_sfont);
  660. while (f_sfont->iteration_next(f_sfont, &f_preset))
  661. {
  662. CARLA_ASSERT(i < midiprog.count);
  663. midiprog.data[i].bank = f_preset.get_banknum(&f_preset);
  664. midiprog.data[i].program = f_preset.get_num(&f_preset);
  665. midiprog.data[i].name = strdup(f_preset.get_name(&f_preset));
  666. if (midiprog.data[i].bank == 128)
  667. hasDrums = true;
  668. i++;
  669. }
  670. //f_sfont->free(f_sfont);
  671. #ifndef BUILD_BRIDGE
  672. // Update OSC Names
  673. if (x_engine->isOscControlRegisted())
  674. {
  675. x_engine->osc_send_control_set_midi_program_count(m_id, midiprog.count);
  676. for (i=0; i < midiprog.count; i++)
  677. x_engine->osc_send_control_set_midi_program_data(m_id, i, midiprog.data[i].bank, midiprog.data[i].program, midiprog.data[i].name);
  678. }
  679. #endif
  680. if (init)
  681. {
  682. fluid_synth_program_reset(f_synth);
  683. for (i=0; i < 16 && i != 9; i++)
  684. {
  685. fluid_synth_program_select(f_synth, i, f_id, midiprog.data[0].bank, midiprog.data[0].program);
  686. #ifdef FLUIDSYNTH_VERSION_NEW_API
  687. fluid_synth_set_channel_type(f_synth, i, CHANNEL_TYPE_MELODIC);
  688. #endif
  689. }
  690. if (hasDrums)
  691. {
  692. fluid_synth_program_select(f_synth, 9, f_id, 128, 0);
  693. #ifdef FLUIDSYNTH_VERSION_NEW_API
  694. fluid_synth_set_channel_type(f_synth, 9, CHANNEL_TYPE_DRUM);
  695. #endif
  696. }
  697. else
  698. {
  699. fluid_synth_program_select(f_synth, 9, f_id, midiprog.data[0].bank, midiprog.data[0].program);
  700. #ifdef FLUIDSYNTH_VERSION_NEW_API
  701. fluid_synth_set_channel_type(f_synth, 9, CHANNEL_TYPE_MELODIC);
  702. #endif
  703. }
  704. setMidiProgram(0, false, false, false, true);
  705. }
  706. else
  707. {
  708. x_engine->callback(CALLBACK_RELOAD_PROGRAMS, m_id, 0, 0, 0.0);
  709. }
  710. }
  711. // -------------------------------------------------------------------
  712. // Plugin processing
  713. void process(float** const, float** const outBuffer, const uint32_t frames, const uint32_t framesOffset)
  714. {
  715. uint32_t i, k;
  716. uint32_t midiEventCount = 0;
  717. double aOutsPeak[2] = { 0.0 };
  718. CARLA_PROCESS_CONTINUE_CHECK;
  719. // --------------------------------------------------------------------------------------------------------
  720. // Parameters Input [Automation]
  721. if (m_active && m_activeBefore)
  722. {
  723. bool allNotesOffSent = false;
  724. const CarlaEngineControlEvent* cinEvent;
  725. uint32_t time, nEvents = param.portCin->getEventCount();
  726. unsigned char nextBankIds[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0 };
  727. if (midiprog.current >= 0 && midiprog.count > 0 && m_ctrlInChannel >= 0 && m_ctrlInChannel < 16)
  728. nextBankIds[m_ctrlInChannel] = midiprog.data[midiprog.current].bank;
  729. for (i=0; i < nEvents; i++)
  730. {
  731. cinEvent = param.portCin->getEvent(i);
  732. if (! cinEvent)
  733. continue;
  734. time = cinEvent->time - framesOffset;
  735. if (time >= frames)
  736. continue;
  737. // Control change
  738. switch (cinEvent->type)
  739. {
  740. case CarlaEngineEventNull:
  741. break;
  742. case CarlaEngineEventControlChange:
  743. {
  744. double value;
  745. // Control backend stuff
  746. if (cinEvent->channel == m_ctrlInChannel)
  747. {
  748. if (MIDI_IS_CONTROL_BREATH_CONTROLLER(cinEvent->controller) && (m_hints & PLUGIN_CAN_DRYWET) > 0)
  749. {
  750. value = cinEvent->value;
  751. setDryWet(value, false, false);
  752. postponeEvent(PluginPostEventParameterChange, PARAMETER_DRYWET, 0, value);
  753. continue;
  754. }
  755. if (MIDI_IS_CONTROL_CHANNEL_VOLUME(cinEvent->controller) && (m_hints & PLUGIN_CAN_VOLUME) > 0)
  756. {
  757. value = cinEvent->value*127/100;
  758. setVolume(value, false, false);
  759. postponeEvent(PluginPostEventParameterChange, PARAMETER_VOLUME, 0, value);
  760. continue;
  761. }
  762. if (MIDI_IS_CONTROL_BALANCE(cinEvent->controller) && (m_hints & PLUGIN_CAN_BALANCE) > 0)
  763. {
  764. double left, right;
  765. value = cinEvent->value/0.5 - 1.0;
  766. if (value < 0.0)
  767. {
  768. left = -1.0;
  769. right = (value*2)+1.0;
  770. }
  771. else if (value > 0.0)
  772. {
  773. left = (value*2)-1.0;
  774. right = 1.0;
  775. }
  776. else
  777. {
  778. left = -1.0;
  779. right = 1.0;
  780. }
  781. setBalanceLeft(left, false, false);
  782. setBalanceRight(right, false, false);
  783. postponeEvent(PluginPostEventParameterChange, PARAMETER_BALANCE_LEFT, 0, left);
  784. postponeEvent(PluginPostEventParameterChange, PARAMETER_BALANCE_RIGHT, 0, right);
  785. continue;
  786. }
  787. }
  788. // Control plugin parameters
  789. for (k=0; k < param.count; k++)
  790. {
  791. if (param.data[k].midiChannel != cinEvent->channel)
  792. continue;
  793. if (param.data[k].midiCC != cinEvent->controller)
  794. continue;
  795. if (param.data[k].type != PARAMETER_INPUT)
  796. continue;
  797. if (param.data[k].hints & PARAMETER_IS_AUTOMABLE)
  798. {
  799. if (param.data[k].hints & PARAMETER_IS_BOOLEAN)
  800. {
  801. value = cinEvent->value < 0.5 ? param.ranges[k].min : param.ranges[k].max;
  802. }
  803. else
  804. {
  805. value = cinEvent->value * (param.ranges[k].max - param.ranges[k].min) + param.ranges[k].min;
  806. if (param.data[k].hints & PARAMETER_IS_INTEGER)
  807. value = rint(value);
  808. }
  809. setParameterValue(k, value, false, false, false);
  810. postponeEvent(PluginPostEventParameterChange, k, 0, value);
  811. }
  812. }
  813. break;
  814. }
  815. case CarlaEngineEventMidiBankChange:
  816. if (cinEvent->channel < 16)
  817. nextBankIds[cinEvent->channel] = rint(cinEvent->value);
  818. break;
  819. case CarlaEngineEventMidiProgramChange:
  820. if (cinEvent->channel < 16)
  821. {
  822. uint32_t bankId = nextBankIds[cinEvent->channel];
  823. uint32_t progId = rint(cinEvent->value);
  824. for (k=0; k < midiprog.count; k++)
  825. {
  826. if (midiprog.data[k].bank == bankId && midiprog.data[k].program == progId)
  827. {
  828. if (cinEvent->channel == m_ctrlInChannel)
  829. {
  830. setMidiProgram(k, false, false, false, false);
  831. postponeEvent(PluginPostEventMidiProgramChange, k, 0, 0.0);
  832. }
  833. else
  834. fluid_synth_program_select(f_synth, cinEvent->channel, f_id, bankId, progId);
  835. break;
  836. }
  837. }
  838. }
  839. break;
  840. case CarlaEngineEventAllSoundOff:
  841. if (cinEvent->channel == m_ctrlInChannel)
  842. {
  843. if (! allNotesOffSent)
  844. sendMidiAllNotesOff();
  845. postponeEvent(PluginPostEventParameterChange, PARAMETER_ACTIVE, 0, 0.0);
  846. postponeEvent(PluginPostEventParameterChange, PARAMETER_ACTIVE, 0, 1.0);
  847. allNotesOffSent = true;
  848. }
  849. break;
  850. case CarlaEngineEventAllNotesOff:
  851. if (cinEvent->channel == m_ctrlInChannel)
  852. {
  853. if (! allNotesOffSent)
  854. sendMidiAllNotesOff();
  855. allNotesOffSent = true;
  856. }
  857. break;
  858. }
  859. }
  860. } // End of Parameters Input
  861. CARLA_PROCESS_CONTINUE_CHECK;
  862. // --------------------------------------------------------------------------------------------------------
  863. // MIDI Input
  864. if (m_active && m_activeBefore)
  865. {
  866. // ----------------------------------------------------------------------------------------------------
  867. // MIDI Input (External)
  868. {
  869. engineMidiLock();
  870. for (i=0; i < MAX_MIDI_EVENTS && midiEventCount < MAX_MIDI_EVENTS; i++)
  871. {
  872. if (extMidiNotes[i].channel < 0)
  873. break;
  874. if (extMidiNotes[i].velo)
  875. fluid_synth_noteon(f_synth, m_ctrlInChannel, extMidiNotes[i].note, extMidiNotes[i].velo);
  876. else
  877. fluid_synth_noteoff(f_synth, m_ctrlInChannel, extMidiNotes[i].note);
  878. extMidiNotes[i].channel = -1; // mark as invalid
  879. midiEventCount += 1;
  880. }
  881. engineMidiUnlock();
  882. } // End of MIDI Input (External)
  883. CARLA_PROCESS_CONTINUE_CHECK;
  884. // ----------------------------------------------------------------------------------------------------
  885. // MIDI Input (System)
  886. {
  887. const CarlaEngineMidiEvent* minEvent;
  888. uint32_t time, nEvents = midi.portMin->getEventCount();
  889. for (i=0; i < nEvents && midiEventCount < MAX_MIDI_EVENTS; i++)
  890. {
  891. minEvent = midi.portMin->getEvent(i);
  892. if (! minEvent)
  893. continue;
  894. time = minEvent->time - framesOffset;
  895. if (time >= frames)
  896. continue;
  897. uint8_t status = minEvent->data[0];
  898. uint8_t channel = status & 0x0F;
  899. // Fix bad note-off
  900. if (MIDI_IS_STATUS_NOTE_ON(status) && minEvent->data[2] == 0)
  901. status -= 0x10;
  902. if (MIDI_IS_STATUS_NOTE_OFF(status))
  903. {
  904. uint8_t note = minEvent->data[1];
  905. fluid_synth_noteoff(f_synth, channel, note);
  906. postponeEvent(PluginPostEventNoteOff, channel, note, 0.0);
  907. }
  908. else if (MIDI_IS_STATUS_NOTE_ON(status))
  909. {
  910. uint8_t note = minEvent->data[1];
  911. uint8_t velo = minEvent->data[2];
  912. fluid_synth_noteon(f_synth, channel, note, velo);
  913. postponeEvent(PluginPostEventNoteOn, channel, note, velo);
  914. }
  915. else if (MIDI_IS_STATUS_POLYPHONIC_AFTERTOUCH(status))
  916. {
  917. // TODO, not in fluidsynth API?
  918. }
  919. else if (MIDI_IS_STATUS_AFTERTOUCH(status))
  920. {
  921. uint8_t pressure = minEvent->data[1];
  922. fluid_synth_channel_pressure(f_synth, channel, pressure);
  923. }
  924. else if (MIDI_IS_STATUS_PITCH_WHEEL_CONTROL(status))
  925. {
  926. uint8_t lsb = minEvent->data[1];
  927. uint8_t msb = minEvent->data[2];
  928. fluid_synth_pitch_bend(f_synth, channel, (msb << 7) | lsb);
  929. }
  930. else
  931. continue;
  932. midiEventCount += 1;
  933. }
  934. } // End of MIDI Input (System)
  935. } // End of MIDI Input
  936. CARLA_PROCESS_CONTINUE_CHECK;
  937. // --------------------------------------------------------------------------------------------------------
  938. // Plugin processing
  939. if (m_active)
  940. {
  941. if (! m_activeBefore)
  942. {
  943. for (int c=0; c < MAX_MIDI_CHANNELS; c++)
  944. {
  945. #ifdef FLUIDSYNTH_VERSION_NEW_API
  946. fluid_synth_all_notes_off(f_synth, c);
  947. fluid_synth_all_sounds_off(f_synth, c);
  948. #else
  949. fluid_synth_cc(f_synth, c, MIDI_CONTROL_ALL_SOUND_OFF, 0);
  950. fluid_synth_cc(f_synth, c, MIDI_CONTROL_ALL_NOTES_OFF, 0);
  951. #endif
  952. }
  953. }
  954. fluid_synth_process(f_synth, frames, 0, nullptr, 2, outBuffer);
  955. }
  956. CARLA_PROCESS_CONTINUE_CHECK;
  957. // --------------------------------------------------------------------------------------------------------
  958. // Post-processing (balance and volume)
  959. if (m_active)
  960. {
  961. bool do_balance = (x_balanceLeft != -1.0 || x_balanceRight != 1.0);
  962. double bal_rangeL, bal_rangeR;
  963. float oldBufLeft[do_balance ? frames : 0];
  964. for (i=0; i < aOut.count; i++)
  965. {
  966. // Balance
  967. if (do_balance)
  968. {
  969. if (i%2 == 0)
  970. memcpy(&oldBufLeft, outBuffer[i], sizeof(float)*frames);
  971. bal_rangeL = (x_balanceLeft+1.0)/2;
  972. bal_rangeR = (x_balanceRight+1.0)/2;
  973. for (k=0; k < frames; k++)
  974. {
  975. if (i%2 == 0)
  976. {
  977. // left output
  978. outBuffer[i][k] = oldBufLeft[k]*(1.0-bal_rangeL);
  979. outBuffer[i][k] += outBuffer[i+1][k]*(1.0-bal_rangeR);
  980. }
  981. else
  982. {
  983. // right
  984. outBuffer[i][k] = outBuffer[i][k]*bal_rangeR;
  985. outBuffer[i][k] += oldBufLeft[k]*bal_rangeL;
  986. }
  987. }
  988. }
  989. // Volume, using fluidsynth internals
  990. fluid_synth_set_gain(f_synth, x_volume);
  991. // Output VU
  992. for (k=0; i < 2 && k < frames; k++)
  993. {
  994. if (abs(outBuffer[i][k]) > aOutsPeak[i])
  995. aOutsPeak[i] = abs(outBuffer[i][k]);
  996. }
  997. }
  998. }
  999. else
  1000. {
  1001. // disable any output sound if not active
  1002. for (i=0; i < aOut.count; i++)
  1003. zeroF(outBuffer[i], frames);
  1004. aOutsPeak[0] = 0.0;
  1005. aOutsPeak[1] = 0.0;
  1006. } // End of Post-processing
  1007. CARLA_PROCESS_CONTINUE_CHECK;
  1008. // --------------------------------------------------------------------------------------------------------
  1009. // Control Output
  1010. if (m_active)
  1011. {
  1012. k = FluidSynthVoiceCount;
  1013. paramBuffers[k] = fluid_synth_get_active_voice_count(f_synth);
  1014. fixParameterValue(paramBuffers[k], param.ranges[k]);
  1015. if (param.data[k].midiCC > 0)
  1016. {
  1017. double value = (paramBuffers[k] - param.ranges[k].min) / (param.ranges[k].max - param.ranges[k].min);
  1018. param.portCout->writeEvent(CarlaEngineEventControlChange, framesOffset, param.data[k].midiChannel, param.data[k].midiCC, value);
  1019. }
  1020. } // End of Control Output
  1021. CARLA_PROCESS_CONTINUE_CHECK;
  1022. // --------------------------------------------------------------------------------------------------------
  1023. // Peak Values
  1024. x_engine->setOutputPeak(m_id, 0, aOutsPeak[0]);
  1025. x_engine->setOutputPeak(m_id, 1, aOutsPeak[1]);
  1026. m_activeBefore = m_active;
  1027. }
  1028. // -------------------------------------------------------------------
  1029. bool init(const char* const filename, const char* const name, const char* const label)
  1030. {
  1031. // ---------------------------------------------------------------
  1032. // open soundfont
  1033. f_id = fluid_synth_sfload(f_synth, filename, 0);
  1034. if (f_id < 0)
  1035. {
  1036. setLastError("Failed to load SoundFont file");
  1037. return false;
  1038. }
  1039. // ---------------------------------------------------------------
  1040. // get info
  1041. m_filename = strdup(filename);
  1042. m_label = strdup(label);
  1043. if (name)
  1044. m_name = x_engine->getUniqueName(name);
  1045. else
  1046. m_name = x_engine->getUniqueName(label);
  1047. // ---------------------------------------------------------------
  1048. // register client
  1049. x_client = x_engine->addClient(this);
  1050. if (! x_client->isOk())
  1051. {
  1052. setLastError("Failed to register plugin client");
  1053. return false;
  1054. }
  1055. return true;
  1056. }
  1057. private:
  1058. enum FluidSynthInputParameters {
  1059. FluidSynthReverbOnOff = 0,
  1060. FluidSynthReverbRoomSize = 1,
  1061. FluidSynthReverbDamp = 2,
  1062. FluidSynthReverbLevel = 3,
  1063. FluidSynthReverbWidth = 4,
  1064. FluidSynthChorusOnOff = 5,
  1065. FluidSynthChorusNr = 6,
  1066. FluidSynthChorusLevel = 7,
  1067. FluidSynthChorusSpeedHz = 8,
  1068. FluidSynthChorusDepthMs = 9,
  1069. FluidSynthChorusType = 10,
  1070. FluidSynthPolyphony = 11,
  1071. FluidSynthInterpolation = 12,
  1072. FluidSynthVoiceCount = 13,
  1073. FluidSynthParametersMax = 14
  1074. };
  1075. fluid_settings_t* f_settings;
  1076. fluid_synth_t* f_synth;
  1077. int f_id;
  1078. double paramBuffers[FluidSynthParametersMax];
  1079. const char* m_label;
  1080. };
  1081. /**@}*/
  1082. CARLA_BACKEND_END_NAMESPACE
  1083. #else // WANT_FLUIDSYNTH
  1084. # warning fluidsynth not available (no SF2 support)
  1085. #endif
  1086. CARLA_BACKEND_START_NAMESPACE
  1087. CarlaPlugin* CarlaPlugin::newSF2(const initializer& init)
  1088. {
  1089. qDebug("CarlaPlugin::newSF2(%p, \"%s\", \"%s\", \"%s\")", init.engine, init.filename, init.name, init.label);
  1090. #ifdef WANT_FLUIDSYNTH
  1091. short id = init.engine->getNewPluginId();
  1092. if (id < 0 || id > CarlaEngine::maxPluginNumber())
  1093. {
  1094. setLastError("Maximum number of plugins reached");
  1095. return nullptr;
  1096. }
  1097. if (! fluid_is_soundfont(init.filename))
  1098. {
  1099. setLastError("Requested file is not a valid SoundFont");
  1100. return nullptr;
  1101. }
  1102. FluidSynthPlugin* const plugin = new FluidSynthPlugin(init.engine, id);
  1103. if (! plugin->init(init.filename, init.name, init.label))
  1104. {
  1105. delete plugin;
  1106. return nullptr;
  1107. }
  1108. plugin->reload();
  1109. plugin->registerToOscControl();
  1110. return plugin;
  1111. #else
  1112. setLastError("fluidsynth support not available");
  1113. return nullptr;
  1114. #endif
  1115. }
  1116. CARLA_BACKEND_END_NAMESPACE