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.

1364 lines
45KB

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