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.

1413 lines
48KB

  1. /*
  2. * Carla LinuxSampler 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 doc/GPL.txt file.
  16. */
  17. /* TODO
  18. * - implement buffer size changes
  19. * - implement sample rate changes
  20. * - call outDev->ReconnectAll() after changing buffer size or sample rate
  21. * - use CARLA_SAFE_ASSERT_RETURN with err
  22. */
  23. #include "CarlaPluginInternal.hpp"
  24. #include "CarlaEngine.hpp"
  25. #ifdef WANT_LINUXSAMPLER
  26. #include "linuxsampler/EngineFactory.h"
  27. #include <linuxsampler/Sampler.h>
  28. #include <QtCore/QFileInfo>
  29. #include <QtCore/QStringList>
  30. namespace LinuxSampler {
  31. using CarlaBackend::CarlaEngine;
  32. using CarlaBackend::CarlaPlugin;
  33. // -----------------------------------------------------------------------
  34. // LinuxSampler static values
  35. static const float kVolumeMax = 3.16227766f; // +10 dB
  36. static const float kVolumeMin = 0.0f; // -inf dB
  37. // -----------------------------------------------------------------------
  38. // LinuxSampler AudioOutputDevice Plugin
  39. class AudioOutputDevicePlugin : public AudioOutputDevice
  40. {
  41. public:
  42. AudioOutputDevicePlugin(const CarlaEngine* const engine, const CarlaPlugin* const plugin, const bool uses16Outs)
  43. : AudioOutputDevice(std::map<String, DeviceCreationParameter*>()),
  44. fEngine(engine),
  45. fPlugin(plugin)
  46. {
  47. CARLA_ASSERT(engine != nullptr);
  48. CARLA_ASSERT(plugin != nullptr);
  49. AcquireChannels(uses16Outs ? 32 : 2);
  50. }
  51. ~AudioOutputDevicePlugin() override {}
  52. // -------------------------------------------------------------------
  53. // LinuxSampler virtual methods
  54. void Play() override
  55. {
  56. }
  57. bool IsPlaying() override
  58. {
  59. return (fEngine->isRunning() && fPlugin->isEnabled());
  60. }
  61. void Stop() override
  62. {
  63. }
  64. uint MaxSamplesPerCycle() override
  65. {
  66. return fEngine->getBufferSize();
  67. }
  68. uint SampleRate() override
  69. {
  70. return uint(fEngine->getSampleRate());
  71. }
  72. String Driver() override
  73. {
  74. return "AudioOutputDevicePlugin";
  75. }
  76. AudioChannel* CreateChannel(uint channelNr) override
  77. {
  78. return new AudioChannel(channelNr, nullptr, 0);
  79. }
  80. // -------------------------------------------------------------------
  81. // Give public access to the RenderAudio call
  82. int Render(const uint samples)
  83. {
  84. return RenderAudio(samples);
  85. }
  86. // -------------------------------------------------------------------
  87. private:
  88. const CarlaEngine* const fEngine;
  89. const CarlaPlugin* const fPlugin;
  90. };
  91. // -----------------------------------------------------------------------
  92. // LinuxSampler MidiInputPort Plugin
  93. class MidiInputPortPlugin : public MidiInputPort
  94. {
  95. public:
  96. MidiInputPortPlugin(MidiInputDevice* const device, const int portNumber)
  97. : MidiInputPort(device, portNumber)
  98. {
  99. }
  100. ~MidiInputPortPlugin() override {}
  101. };
  102. // -----------------------------------------------------------------------
  103. // LinuxSampler MidiInputDevice Plugin
  104. class MidiInputDevicePlugin : public MidiInputDevice
  105. {
  106. public:
  107. MidiInputDevicePlugin(Sampler* const sampler)
  108. : MidiInputDevice(std::map<String, DeviceCreationParameter*>(), sampler)
  109. {
  110. }
  111. // -------------------------------------------------------------------
  112. // LinuxSampler virtual methods
  113. void Listen() override
  114. {
  115. }
  116. void StopListen() override
  117. {
  118. }
  119. String Driver() override
  120. {
  121. return "MidiInputDevicePlugin";
  122. }
  123. MidiInputPort* CreateMidiPort() override
  124. {
  125. return new MidiInputPortPlugin(this, int(Ports.size()));
  126. }
  127. MidiInputPortPlugin* CreateMidiPortPlugin()
  128. {
  129. return new MidiInputPortPlugin(this, int(Ports.size()));
  130. }
  131. };
  132. } // namespace LinuxSampler
  133. // -----------------------------------------------------------------------
  134. CARLA_BACKEND_START_NAMESPACE
  135. #if 0
  136. }
  137. #endif
  138. class LinuxSamplerPlugin : public CarlaPlugin
  139. {
  140. public:
  141. LinuxSamplerPlugin(CarlaEngine* const engine, const unsigned int id, const char* const format, const bool use16Outs)
  142. : CarlaPlugin(engine, id),
  143. fUses16Outs(use16Outs),
  144. fFormat(carla_strdup(format)),
  145. fLabel(nullptr),
  146. fMaker(nullptr),
  147. fRealName(nullptr),
  148. fEngine(nullptr),
  149. fAudioOutputDevice(nullptr),
  150. fMidiInputDevice(nullptr),
  151. fMidiInputPort(nullptr),
  152. fInstrument(nullptr)
  153. {
  154. carla_debug("LinuxSamplerPlugin::LinuxSamplerPlugin(%p, %i, %s, %s)", engine, id, format, bool2str(use16Outs));
  155. for (int i=0; i < MAX_MIDI_CHANNELS; ++i)
  156. {
  157. fCurMidiProgs[0] = 0;
  158. fSamplerChannels[i] = nullptr;
  159. fEngineChannels[i] = nullptr;
  160. }
  161. }
  162. ~LinuxSamplerPlugin() override
  163. {
  164. carla_debug("LinuxSamplerPlugin::~LinuxSamplerPlugin()");
  165. pData->singleMutex.lock();
  166. pData->masterMutex.lock();
  167. if (pData->client != nullptr && pData->client->isActive())
  168. pData->client->deactivate();
  169. if (pData->active)
  170. {
  171. deactivate();
  172. pData->active = false;
  173. }
  174. if (fEngine != nullptr)
  175. {
  176. if (fMidiInputDevice != nullptr)
  177. {
  178. if (fMidiInputPort != nullptr)
  179. {
  180. for (int i=0; i < MAX_MIDI_CHANNELS; ++i)
  181. {
  182. if (fSamplerChannels[i] != nullptr)
  183. {
  184. if (fEngineChannels[i] != nullptr)
  185. {
  186. fMidiInputPort->Disconnect(fEngineChannels[i]);
  187. fEngineChannels[i]->DisconnectAudioOutputDevice();
  188. fEngineChannels[i] = nullptr;
  189. }
  190. fSampler.RemoveSamplerChannel(fSamplerChannels[i]);
  191. fSamplerChannels[i] = nullptr;
  192. }
  193. }
  194. delete fMidiInputPort;
  195. fMidiInputPort = nullptr;
  196. }
  197. delete fMidiInputDevice;
  198. fMidiInputDevice = nullptr;
  199. }
  200. if (fAudioOutputDevice != nullptr)
  201. {
  202. delete fAudioOutputDevice;
  203. fAudioOutputDevice = nullptr;
  204. }
  205. fInstrument = nullptr;
  206. LinuxSampler::EngineFactory::Destroy(fEngine);
  207. fEngine = nullptr;
  208. }
  209. fInstrumentIds.clear();
  210. if (fFormat != nullptr)
  211. {
  212. delete[] fFormat;
  213. fFormat = nullptr;
  214. }
  215. if (fLabel != nullptr)
  216. {
  217. delete[] fLabel;
  218. fLabel = nullptr;
  219. }
  220. if (fMaker != nullptr)
  221. {
  222. delete[] fMaker;
  223. fMaker = nullptr;
  224. }
  225. if (fRealName != nullptr)
  226. {
  227. delete[] fRealName;
  228. fRealName = nullptr;
  229. }
  230. clearBuffers();
  231. }
  232. // -------------------------------------------------------------------
  233. // Information (base)
  234. PluginType getType() const noexcept override
  235. {
  236. return getPluginTypeFromString(fFormat);
  237. }
  238. PluginCategory getCategory() const noexcept override
  239. {
  240. return PLUGIN_CATEGORY_SYNTH;
  241. }
  242. // -------------------------------------------------------------------
  243. // Information (count)
  244. // nothing
  245. // -------------------------------------------------------------------
  246. // Information (current data)
  247. // nothing
  248. // -------------------------------------------------------------------
  249. // Information (per-plugin data)
  250. unsigned int getOptionsAvailable() const noexcept override
  251. {
  252. unsigned int options = 0x0;
  253. options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES;
  254. options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES;
  255. options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
  256. options |= PLUGIN_OPTION_SEND_PITCHBEND;
  257. options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
  258. return options;
  259. }
  260. void getLabel(char* const strBuf) const noexcept override
  261. {
  262. if (fLabel != nullptr)
  263. std::strncpy(strBuf, fLabel, STR_MAX);
  264. else
  265. CarlaPlugin::getLabel(strBuf);
  266. }
  267. void getMaker(char* const strBuf) const noexcept override
  268. {
  269. if (fMaker != nullptr)
  270. std::strncpy(strBuf, fMaker, STR_MAX);
  271. else
  272. CarlaPlugin::getMaker(strBuf);
  273. }
  274. void getCopyright(char* const strBuf) const noexcept override
  275. {
  276. getMaker(strBuf);
  277. }
  278. void getRealName(char* const strBuf) const noexcept override
  279. {
  280. if (fRealName != nullptr)
  281. std::strncpy(strBuf, fRealName, STR_MAX);
  282. else
  283. CarlaPlugin::getRealName(strBuf);
  284. }
  285. // -------------------------------------------------------------------
  286. // Set data (state)
  287. void prepareForSave() override
  288. {
  289. char strBuf[STR_MAX+1];
  290. std::snprintf(strBuf, STR_MAX, "%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i", fCurMidiProgs[0], fCurMidiProgs[1], fCurMidiProgs[2], fCurMidiProgs[3],
  291. fCurMidiProgs[4], fCurMidiProgs[5], fCurMidiProgs[6], fCurMidiProgs[7],
  292. fCurMidiProgs[8], fCurMidiProgs[9], fCurMidiProgs[10], fCurMidiProgs[11],
  293. fCurMidiProgs[12], fCurMidiProgs[13], fCurMidiProgs[14], fCurMidiProgs[15]);
  294. CarlaPlugin::setCustomData(CUSTOM_DATA_TYPE_STRING, "midiPrograms", strBuf, false);
  295. }
  296. // -------------------------------------------------------------------
  297. // Set data (internal stuff)
  298. void setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback) noexcept override
  299. {
  300. if (channel < MAX_MIDI_CHANNELS)
  301. pData->midiprog.current = fCurMidiProgs[channel];
  302. CarlaPlugin::setCtrlChannel(channel, sendOsc, sendCallback);
  303. }
  304. // -------------------------------------------------------------------
  305. // Set data (plugin-specific stuff)
  306. void setCustomData(const char* const type, const char* const key, const char* const value, const bool sendGui) override
  307. {
  308. CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0',);
  309. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  310. CARLA_SAFE_ASSERT_RETURN(value != nullptr && value[0] != '\0',);
  311. carla_debug("LinuxSamplerPlugin::setCustomData(%s, \"%s\", \"%s\", %s)", type, key, value, bool2str(sendGui));
  312. if (std::strcmp(type, CUSTOM_DATA_TYPE_STRING) != 0)
  313. return carla_stderr2("LinuxSamplerPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - type is not string", type, key, value, bool2str(sendGui));
  314. if (std::strcmp(key, "midiPrograms") != 0)
  315. return carla_stderr2("LinuxSamplerPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - type is not string", type, key, value, bool2str(sendGui));
  316. if (fUses16Outs)
  317. {
  318. QStringList midiProgramList(QString(value).split(":", QString::SkipEmptyParts));
  319. if (midiProgramList.count() == MAX_MIDI_CHANNELS)
  320. {
  321. uint i = 0;
  322. foreach (const QString& midiProg, midiProgramList)
  323. {
  324. CARLA_SAFE_ASSERT_BREAK(i < MAX_MIDI_CHANNELS);
  325. bool ok;
  326. uint index = midiProg.toUInt(&ok);
  327. if (ok && index < pData->midiprog.count)
  328. {
  329. const uint32_t bank = pData->midiprog.data[index].bank;
  330. const uint32_t program = pData->midiprog.data[index].program;
  331. const uint32_t rIndex = bank*128 + program;
  332. /*if (pData->engine->isOffline())
  333. {
  334. fEngineChannels[i]->PrepareLoadInstrument(pData->filename, rIndex);
  335. fEngineChannels[i]->LoadInstrument();
  336. }
  337. else*/
  338. {
  339. fInstrument->LoadInstrumentInBackground(fInstrumentIds[rIndex], fEngineChannels[i]);
  340. }
  341. fCurMidiProgs[i] = index;
  342. if (pData->ctrlChannel == static_cast<int32_t>(i))
  343. {
  344. pData->midiprog.current = index;
  345. pData->engine->callback(ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED, pData->id, index, 0, 0.0f, nullptr);
  346. }
  347. }
  348. ++i;
  349. }
  350. CARLA_SAFE_ASSERT(i == MAX_MIDI_CHANNELS);
  351. }
  352. }
  353. CarlaPlugin::setCustomData(type, key, value, sendGui);
  354. }
  355. void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override
  356. {
  357. CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast<int32_t>(pData->midiprog.count),);
  358. if (index >= 0 && pData->ctrlChannel >= 0 && pData->ctrlChannel < MAX_MIDI_CHANNELS)
  359. {
  360. const uint32_t bank = pData->midiprog.data[index].bank;
  361. const uint32_t program = pData->midiprog.data[index].program;
  362. const uint32_t rIndex = bank*128 + program;
  363. LinuxSampler::EngineChannel* const engineChannel(fEngineChannels[pData->ctrlChannel]);
  364. const ScopedSingleProcessLocker spl(this, (sendGui || sendOsc || sendCallback));
  365. /*if (pData->engine->isOffline())
  366. {
  367. engineChannel->PrepareLoadInstrument(pData->filename, rIndex);
  368. engineChannel->LoadInstrument();
  369. }
  370. else*/
  371. {
  372. try {
  373. fInstrument->LoadInstrumentInBackground(fInstrumentIds[rIndex], engineChannel);
  374. } catch(...) {}
  375. }
  376. fCurMidiProgs[pData->ctrlChannel] = index;
  377. }
  378. CarlaPlugin::setMidiProgram(index, sendGui, sendOsc, sendCallback);
  379. }
  380. // -------------------------------------------------------------------
  381. // Set ui stuff
  382. // nothing
  383. // -------------------------------------------------------------------
  384. // Plugin state
  385. void reload() override
  386. {
  387. CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr,);
  388. CARLA_SAFE_ASSERT_RETURN(fInstrument != nullptr,);
  389. carla_debug("LinuxSamplerPlugin::reload() - start");
  390. const EngineProcessMode processMode(pData->engine->getProccessMode());
  391. // Safely disable plugin for reload
  392. const ScopedDisabler sd(this);
  393. if (pData->active)
  394. deactivate();
  395. clearBuffers();
  396. uint32_t aOuts;
  397. aOuts = fUses16Outs ? 32 : 2;
  398. pData->audioOut.createNew(aOuts);
  399. const int portNameSize(pData->engine->getMaxPortNameSize());
  400. CarlaString portName;
  401. // ---------------------------------------
  402. // Audio Outputs
  403. if (fUses16Outs)
  404. {
  405. for (int i=0; i < 32; ++i)
  406. {
  407. portName.clear();
  408. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  409. {
  410. portName = pData->name;
  411. portName += ":";
  412. }
  413. portName += "out-";
  414. if ((i+2)/2 < 9)
  415. portName += "0";
  416. portName += CarlaString((i+2)/2);
  417. if (i % 2 == 0)
  418. portName += "L";
  419. else
  420. portName += "R";
  421. portName.truncate(portNameSize);
  422. pData->audioOut.ports[i].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, false);
  423. pData->audioOut.ports[i].rindex = i;
  424. }
  425. }
  426. else
  427. {
  428. // out-left
  429. portName.clear();
  430. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  431. {
  432. portName = pData->name;
  433. portName += ":";
  434. }
  435. portName += "out-left";
  436. portName.truncate(portNameSize);
  437. pData->audioOut.ports[0].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, false);
  438. pData->audioOut.ports[0].rindex = 0;
  439. // out-right
  440. portName.clear();
  441. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  442. {
  443. portName = pData->name;
  444. portName += ":";
  445. }
  446. portName += "out-right";
  447. portName.truncate(portNameSize);
  448. pData->audioOut.ports[1].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, false);
  449. pData->audioOut.ports[1].rindex = 1;
  450. }
  451. // ---------------------------------------
  452. // Event Input
  453. {
  454. portName.clear();
  455. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  456. {
  457. portName = pData->name;
  458. portName += ":";
  459. }
  460. portName += "events-in";
  461. portName.truncate(portNameSize);
  462. pData->event.portIn = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, true);
  463. }
  464. // ---------------------------------------
  465. // plugin hints
  466. pData->hints = 0x0;
  467. pData->hints |= PLUGIN_IS_SYNTH;
  468. pData->hints |= PLUGIN_CAN_VOLUME;
  469. if (! fUses16Outs)
  470. pData->hints |= PLUGIN_CAN_BALANCE;
  471. // extra plugin hints
  472. pData->extraHints = 0x0;
  473. pData->extraHints |= PLUGIN_EXTRA_HINT_HAS_MIDI_IN;
  474. if (! fUses16Outs)
  475. pData->extraHints |= PLUGIN_EXTRA_HINT_CAN_RUN_RACK;
  476. bufferSizeChanged(pData->engine->getBufferSize());
  477. reloadPrograms(true);
  478. if (pData->active)
  479. activate();
  480. carla_debug("LinuxSamplerPlugin::reload() - end");
  481. }
  482. void reloadPrograms(bool init) override
  483. {
  484. carla_debug("LinuxSamplerPlugin::reloadPrograms(%s)", bool2str(init));
  485. // Delete old programs
  486. pData->midiprog.clear();
  487. // Query new programs
  488. uint32_t count = uint32_t(fInstrumentIds.size());
  489. // sound kits must always have at least 1 midi-program
  490. CARLA_SAFE_ASSERT_RETURN(count > 0,);
  491. pData->midiprog.createNew(count);
  492. // Update data
  493. LinuxSampler::InstrumentManager::instrument_info_t info;
  494. for (uint32_t i=0; i < pData->midiprog.count; ++i)
  495. {
  496. pData->midiprog.data[i].bank = i / 128;
  497. pData->midiprog.data[i].program = i % 128;
  498. try {
  499. info = fInstrument->GetInstrumentInfo(fInstrumentIds[i]);
  500. }
  501. catch (const LinuxSampler::InstrumentManagerException&)
  502. {
  503. continue;
  504. }
  505. pData->midiprog.data[i].name = carla_strdup(info.InstrumentName.c_str());
  506. }
  507. #ifndef BUILD_BRIDGE
  508. // Update OSC Names
  509. if (pData->engine->isOscControlRegistered())
  510. {
  511. pData->engine->oscSend_control_set_midi_program_count(pData->id, count);
  512. for (uint32_t i=0; i < count; ++i)
  513. pData->engine->oscSend_control_set_midi_program_data(pData->id, i, pData->midiprog.data[i].bank, pData->midiprog.data[i].program, pData->midiprog.data[i].name);
  514. }
  515. #endif
  516. if (init)
  517. {
  518. for (int i=0; i < MAX_MIDI_CHANNELS; ++i)
  519. {
  520. CARLA_SAFE_ASSERT_CONTINUE(fEngineChannels[i] != nullptr);
  521. /*fEngineChannels[i]->PrepareLoadInstrument(pData->filename, 0);
  522. fEngineChannels[i]->LoadInstrument();*/
  523. fInstrument->LoadInstrumentInBackground(fInstrumentIds[0], fEngineChannels[i]);
  524. fCurMidiProgs[i] = 0;
  525. }
  526. pData->midiprog.current = 0;
  527. }
  528. else
  529. {
  530. pData->engine->callback(ENGINE_CALLBACK_RELOAD_PROGRAMS, pData->id, 0, 0, 0.0f, nullptr);
  531. }
  532. }
  533. // -------------------------------------------------------------------
  534. // Plugin processing
  535. #if 0
  536. void activate() override
  537. {
  538. for (int i=0; i < MAX_MIDI_CHANNELS; ++i)
  539. {
  540. if (fAudioOutputDevices[i] != nullptr)
  541. fAudioOutputDevices[i]->Play();
  542. }
  543. }
  544. void deactivate() override
  545. {
  546. for (int i=0; i < MAX_MIDI_CHANNELS; ++i)
  547. {
  548. if (fAudioOutputDevices[i] != nullptr)
  549. fAudioOutputDevices[i]->Stop();
  550. }
  551. }
  552. #endif
  553. void process(float** const, float** const outBuffer, const uint32_t frames) override
  554. {
  555. // --------------------------------------------------------------------------------------------------------
  556. // Check if active
  557. if (! pData->active)
  558. {
  559. // disable any output sound
  560. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  561. FLOAT_CLEAR(outBuffer[i], frames);
  562. return;
  563. }
  564. // --------------------------------------------------------------------------------------------------------
  565. // Check if needs reset
  566. if (pData->needsReset)
  567. {
  568. if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  569. {
  570. for (uint i=0; i < MAX_MIDI_CHANNELS; ++i)
  571. {
  572. fMidiInputPort->DispatchControlChange(MIDI_CONTROL_ALL_NOTES_OFF, 0, i);
  573. fMidiInputPort->DispatchControlChange(MIDI_CONTROL_ALL_SOUND_OFF, 0, i);
  574. }
  575. }
  576. else if (pData->ctrlChannel >= 0 && pData->ctrlChannel < MAX_MIDI_CHANNELS)
  577. {
  578. for (uint8_t i=0; i < MAX_MIDI_NOTE; ++i)
  579. fMidiInputPort->DispatchNoteOff(i, 0, uint(pData->ctrlChannel));
  580. }
  581. pData->needsReset = false;
  582. }
  583. // --------------------------------------------------------------------------------------------------------
  584. // Event Input and Processing
  585. {
  586. // ----------------------------------------------------------------------------------------------------
  587. // MIDI Input (External)
  588. if (pData->extNotes.mutex.tryLock())
  589. {
  590. while (! pData->extNotes.data.isEmpty())
  591. {
  592. const ExternalMidiNote& note(pData->extNotes.data.getFirst(true));
  593. CARLA_SAFE_ASSERT_CONTINUE(note.channel >= 0 && note.channel < MAX_MIDI_CHANNELS);
  594. if (note.velo > 0)
  595. fMidiInputPort->DispatchNoteOn(note.note, note.velo, note.channel);
  596. else
  597. fMidiInputPort->DispatchNoteOff(note.note, note.velo, note.channel);
  598. }
  599. pData->extNotes.mutex.unlock();
  600. } // End of MIDI Input (External)
  601. // ----------------------------------------------------------------------------------------------------
  602. // Event Input (System)
  603. bool allNotesOffSent = false;
  604. bool sampleAccurate = (pData->options & PLUGIN_OPTION_FIXED_BUFFERS) == 0;
  605. uint32_t time, nEvents = pData->event.portIn->getEventCount();
  606. uint32_t startTime = 0;
  607. uint32_t timeOffset = 0;
  608. uint32_t nextBankIds[MAX_MIDI_CHANNELS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0 };
  609. if (pData->midiprog.current >= 0 && pData->midiprog.count > 0 && pData->ctrlChannel >= 0 && pData->ctrlChannel < MAX_MIDI_CHANNELS)
  610. nextBankIds[pData->ctrlChannel] = pData->midiprog.data[pData->midiprog.current].bank;
  611. for (uint32_t i=0; i < nEvents; ++i)
  612. {
  613. const EngineEvent& event(pData->event.portIn->getEvent(i));
  614. time = event.time;
  615. CARLA_SAFE_ASSERT_CONTINUE(time < frames);
  616. CARLA_SAFE_ASSERT_BREAK(time >= timeOffset);
  617. if (time > timeOffset && sampleAccurate)
  618. {
  619. if (processSingle(outBuffer, time - timeOffset, timeOffset))
  620. {
  621. startTime = 0;
  622. timeOffset = time;
  623. if (pData->midiprog.current >= 0 && pData->midiprog.count > 0 && pData->ctrlChannel >= 0 && pData->ctrlChannel < MAX_MIDI_CHANNELS)
  624. nextBankIds[pData->ctrlChannel] = pData->midiprog.data[pData->midiprog.current].bank;
  625. }
  626. else
  627. startTime += timeOffset;
  628. }
  629. // Control change
  630. switch (event.type)
  631. {
  632. case kEngineEventTypeNull:
  633. break;
  634. case kEngineEventTypeControl:
  635. {
  636. const EngineControlEvent& ctrlEvent = event.ctrl;
  637. switch (ctrlEvent.type)
  638. {
  639. case kEngineControlEventTypeNull:
  640. break;
  641. case kEngineControlEventTypeParameter:
  642. {
  643. #ifndef BUILD_BRIDGE
  644. // Control backend stuff
  645. if (event.channel == pData->ctrlChannel)
  646. {
  647. float value;
  648. if (MIDI_IS_CONTROL_BREATH_CONTROLLER(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_DRYWET) != 0)
  649. {
  650. value = ctrlEvent.value;
  651. setDryWet(value, false, false);
  652. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_DRYWET, 0, value);
  653. }
  654. if (MIDI_IS_CONTROL_CHANNEL_VOLUME(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_VOLUME) != 0)
  655. {
  656. value = ctrlEvent.value*127.0f/100.0f;
  657. setVolume(value, false, false);
  658. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_VOLUME, 0, value);
  659. }
  660. if (MIDI_IS_CONTROL_BALANCE(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_BALANCE) != 0)
  661. {
  662. float left, right;
  663. value = ctrlEvent.value/0.5f - 1.0f;
  664. if (value < 0.0f)
  665. {
  666. left = -1.0f;
  667. right = (value*2.0f)+1.0f;
  668. }
  669. else if (value > 0.0f)
  670. {
  671. left = (value*2.0f)-1.0f;
  672. right = 1.0f;
  673. }
  674. else
  675. {
  676. left = -1.0f;
  677. right = 1.0f;
  678. }
  679. setBalanceLeft(left, false, false);
  680. setBalanceRight(right, false, false);
  681. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_BALANCE_LEFT, 0, left);
  682. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_BALANCE_RIGHT, 0, right);
  683. }
  684. }
  685. #endif
  686. // Control plugin parameters
  687. for (uint32_t k=0; k < pData->param.count; ++k)
  688. {
  689. if (pData->param.data[k].midiChannel != event.channel)
  690. continue;
  691. if (pData->param.data[k].midiCC != ctrlEvent.param)
  692. continue;
  693. if (pData->param.data[k].hints != PARAMETER_INPUT)
  694. continue;
  695. if ((pData->param.data[k].hints & PARAMETER_IS_AUTOMABLE) == 0)
  696. continue;
  697. float value;
  698. if (pData->param.data[k].hints & PARAMETER_IS_BOOLEAN)
  699. {
  700. value = (ctrlEvent.value < 0.5f) ? pData->param.ranges[k].min : pData->param.ranges[k].max;
  701. }
  702. else
  703. {
  704. value = pData->param.ranges[k].getUnnormalizedValue(ctrlEvent.value);
  705. if (pData->param.data[k].hints & PARAMETER_IS_INTEGER)
  706. value = std::rint(value);
  707. }
  708. setParameterValue(k, value, false, false, false);
  709. pData->postponeRtEvent(kPluginPostRtEventParameterChange, static_cast<int32_t>(k), 0, value);
  710. }
  711. if ((pData->options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) != 0 && ctrlEvent.param <= 0x5F)
  712. {
  713. fMidiInputPort->DispatchControlChange(uint8_t(ctrlEvent.param), uint8_t(ctrlEvent.value*127.0f), event.channel, int32_t(sampleAccurate ? startTime : time));
  714. }
  715. break;
  716. }
  717. case kEngineControlEventTypeMidiBank:
  718. if (event.channel < MAX_MIDI_CHANNELS && (pData->options & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0)
  719. nextBankIds[event.channel] = ctrlEvent.param;
  720. break;
  721. case kEngineControlEventTypeMidiProgram:
  722. if (event.channel < MAX_MIDI_CHANNELS && (pData->options & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0)
  723. {
  724. const uint32_t bankId(nextBankIds[event.channel]);
  725. const uint32_t progId(ctrlEvent.param);
  726. const uint32_t rIndex = bankId*128 + progId;
  727. for (uint32_t k=0; k < pData->midiprog.count; ++k)
  728. {
  729. if (pData->midiprog.data[k].bank == bankId && pData->midiprog.data[k].program == progId)
  730. {
  731. LinuxSampler::EngineChannel* const engineChannel(fEngineChannels[pData->ctrlChannel]);
  732. /*if (pData->engine->isOffline())
  733. {
  734. engineChannel->PrepareLoadInstrument(pData->filename, rIndex);
  735. engineChannel->LoadInstrument();
  736. }
  737. else*/
  738. {
  739. fInstrument->LoadInstrumentInBackground(fInstrumentIds[rIndex], engineChannel);
  740. }
  741. fCurMidiProgs[event.channel] = k;
  742. if (event.channel == pData->ctrlChannel)
  743. pData->postponeRtEvent(kPluginPostRtEventMidiProgramChange, k, 0, 0.0f);
  744. break;
  745. }
  746. }
  747. }
  748. break;
  749. case kEngineControlEventTypeAllSoundOff:
  750. if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  751. {
  752. fMidiInputPort->DispatchControlChange(MIDI_CONTROL_ALL_SOUND_OFF, 0, event.channel, sampleAccurate ? startTime : time);
  753. }
  754. break;
  755. case kEngineControlEventTypeAllNotesOff:
  756. if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  757. {
  758. if (event.channel == pData->ctrlChannel && ! allNotesOffSent)
  759. {
  760. allNotesOffSent = true;
  761. sendMidiAllNotesOffToCallback();
  762. }
  763. fMidiInputPort->DispatchControlChange(MIDI_CONTROL_ALL_NOTES_OFF, 0, event.channel, sampleAccurate ? startTime : time);
  764. }
  765. break;
  766. }
  767. break;
  768. }
  769. case kEngineEventTypeMidi:
  770. {
  771. const EngineMidiEvent& midiEvent(event.midi);
  772. uint8_t status = uint8_t(MIDI_GET_STATUS_FROM_DATA(midiEvent.data));
  773. uint8_t channel = event.channel;
  774. // Fix bad note-off
  775. if (MIDI_IS_STATUS_NOTE_ON(status) && midiEvent.data[2] == 0)
  776. status = MIDI_STATUS_NOTE_OFF;
  777. if (MIDI_IS_STATUS_POLYPHONIC_AFTERTOUCH(status) && (pData->options & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH) == 0)
  778. continue;
  779. if (MIDI_IS_STATUS_CONTROL_CHANGE(status) && (pData->options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) == 0)
  780. continue;
  781. if (MIDI_IS_STATUS_CHANNEL_PRESSURE(status) && (pData->options & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE) == 0)
  782. continue;
  783. if (MIDI_IS_STATUS_PITCH_WHEEL_CONTROL(status) && (pData->options & PLUGIN_OPTION_SEND_PITCHBEND) == 0)
  784. continue;
  785. // put back channel in data
  786. uint8_t data[EngineMidiEvent::kDataSize];
  787. std::memcpy(data, event.midi.data, EngineMidiEvent::kDataSize);
  788. if (status < 0xF0 && channel < MAX_MIDI_CHANNELS)
  789. data[0] = uint8_t(data[0] + channel);
  790. fMidiInputPort->DispatchRaw(data, sampleAccurate ? startTime : time);
  791. if (status == MIDI_STATUS_NOTE_ON)
  792. pData->postponeRtEvent(kPluginPostRtEventNoteOn, channel, data[1], data[2]);
  793. else if (status == MIDI_STATUS_NOTE_OFF)
  794. pData->postponeRtEvent(kPluginPostRtEventNoteOff, channel,data[1], 0.0f);
  795. break;
  796. }
  797. }
  798. }
  799. pData->postRtEvents.trySplice();
  800. if (frames > timeOffset)
  801. processSingle(outBuffer, frames - timeOffset, timeOffset);
  802. } // End of Event Input and Processing
  803. }
  804. bool processSingle(float** const outBuffer, const uint32_t frames, const uint32_t timeOffset)
  805. {
  806. CARLA_SAFE_ASSERT_RETURN(outBuffer != nullptr, false);
  807. CARLA_SAFE_ASSERT_RETURN(frames > 0, false);
  808. // --------------------------------------------------------------------------------------------------------
  809. // Try lock, silence otherwise
  810. if (pData->engine->isOffline())
  811. {
  812. pData->singleMutex.lock();
  813. }
  814. else if (! pData->singleMutex.tryLock())
  815. {
  816. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  817. {
  818. for (uint32_t k=0; k < frames; ++k)
  819. outBuffer[i][k+timeOffset] = 0.0f;
  820. }
  821. return false;
  822. }
  823. // --------------------------------------------------------------------------------------------------------
  824. // Run plugin
  825. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  826. {
  827. if (LinuxSampler::AudioChannel* const outDev = fAudioOutputDevice->Channel(i))
  828. outDev->SetBuffer(outBuffer[i] + timeOffset);
  829. }
  830. fAudioOutputDevice->Render(frames);
  831. #ifndef BUILD_BRIDGE
  832. // --------------------------------------------------------------------------------------------------------
  833. // Post-processing (dry/wet, volume and balance)
  834. {
  835. const bool doVolume = (pData->hints & PLUGIN_CAN_VOLUME) > 0 && pData->postProc.volume != 1.0f;
  836. const bool doBalance = (pData->hints & PLUGIN_CAN_BALANCE) > 0 && (pData->postProc.balanceLeft != -1.0f || pData->postProc.balanceRight != 1.0f);
  837. float oldBufLeft[doBalance ? frames : 1];
  838. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  839. {
  840. // Balance
  841. if (doBalance)
  842. {
  843. if (i % 2 == 0)
  844. FLOAT_COPY(oldBufLeft, outBuffer[i], frames);
  845. float balRangeL = (pData->postProc.balanceLeft + 1.0f)/2.0f;
  846. float balRangeR = (pData->postProc.balanceRight + 1.0f)/2.0f;
  847. for (uint32_t k=0; k < frames; ++k)
  848. {
  849. if (i % 2 == 0)
  850. {
  851. // left
  852. outBuffer[i][k] = oldBufLeft[k] * (1.0f - balRangeL);
  853. outBuffer[i][k] += outBuffer[i+1][k] * (1.0f - balRangeR);
  854. }
  855. else
  856. {
  857. // right
  858. outBuffer[i][k] = outBuffer[i][k] * balRangeR;
  859. outBuffer[i][k] += oldBufLeft[k] * balRangeL;
  860. }
  861. }
  862. }
  863. // Volume
  864. if (doVolume)
  865. {
  866. for (uint32_t k=0; k < frames; ++k)
  867. outBuffer[i][k+timeOffset] *= pData->postProc.volume;
  868. }
  869. }
  870. } // End of Post-processing
  871. #endif
  872. // --------------------------------------------------------------------------------------------------------
  873. pData->singleMutex.unlock();
  874. return true;
  875. }
  876. #ifndef CARLA_OS_WIN // FIXME, need to update linuxsampler win32 build
  877. void bufferSizeChanged(const uint32_t) override
  878. {
  879. CARLA_SAFE_ASSERT_RETURN(fAudioOutputDevice != nullptr,);
  880. fAudioOutputDevice->ReconnectAll();
  881. }
  882. void sampleRateChanged(const double) override
  883. {
  884. CARLA_SAFE_ASSERT_RETURN(fAudioOutputDevice != nullptr,);
  885. fAudioOutputDevice->ReconnectAll();
  886. }
  887. #endif
  888. // -------------------------------------------------------------------
  889. // Plugin buffers
  890. // nothing
  891. // -------------------------------------------------------------------
  892. const void* getExtraStuff() const noexcept override
  893. {
  894. static const char xtrue[] = "true";
  895. static const char xfalse[] = "false";
  896. return fUses16Outs ? xtrue : xfalse;
  897. }
  898. bool init(const char* const filename, const char* const name, const char* const label)
  899. {
  900. CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr, false);
  901. // ---------------------------------------------------------------
  902. // first checks
  903. if (pData->client != nullptr)
  904. {
  905. pData->engine->setLastError("Plugin client is already registered");
  906. return false;
  907. }
  908. if (filename == nullptr || filename[0] == '\0')
  909. {
  910. pData->engine->setLastError("null filename");
  911. return false;
  912. }
  913. if (label == nullptr || label[0] == '\0')
  914. {
  915. pData->engine->setLastError("null label");
  916. return false;
  917. }
  918. // ---------------------------------------------------------------
  919. // Store format
  920. CarlaString cstype(fFormat);
  921. cstype.toLower();
  922. const char* const ctype(cstype.getBuffer());
  923. // ---------------------------------------------------------------
  924. // Create the LinuxSampler Engine
  925. try {
  926. fEngine = LinuxSampler::EngineFactory::Create(ctype);
  927. }
  928. catch (LinuxSampler::Exception& e)
  929. {
  930. pData->engine->setLastError(e.what());
  931. return false;
  932. }
  933. // ---------------------------------------------------------------
  934. // Init LinuxSampler stuff
  935. fAudioOutputDevice = new LinuxSampler::AudioOutputDevicePlugin(pData->engine, this, fUses16Outs);
  936. fMidiInputDevice = new LinuxSampler::MidiInputDevicePlugin(&fSampler);
  937. fMidiInputPort = fMidiInputDevice->CreateMidiPortPlugin();
  938. for (int i=0; i < MAX_MIDI_CHANNELS; ++i)
  939. {
  940. fSamplerChannels[i] = fSampler.AddSamplerChannel();
  941. CARLA_SAFE_ASSERT_CONTINUE(fSamplerChannels[i] != nullptr);
  942. fSamplerChannels[i]->SetEngineType(ctype);
  943. fSamplerChannels[i]->SetAudioOutputDevice(fAudioOutputDevice);
  944. fEngineChannels[i] = fSamplerChannels[i]->GetEngineChannel();
  945. CARLA_SAFE_ASSERT_CONTINUE(fEngineChannels[i] != nullptr);
  946. fEngineChannels[i]->Connect(fAudioOutputDevice);
  947. fEngineChannels[i]->Volume(LinuxSampler::kVolumeMax);
  948. if (fUses16Outs)
  949. {
  950. fEngineChannels[i]->SetOutputChannel(0, i*2);
  951. fEngineChannels[i]->SetOutputChannel(1, i*2 +1);
  952. }
  953. else
  954. {
  955. fEngineChannels[i]->SetOutputChannel(0, 0);
  956. fEngineChannels[i]->SetOutputChannel(1, 1);
  957. }
  958. fMidiInputPort->Connect(fEngineChannels[i], static_cast<LinuxSampler::midi_chan_t>(i));
  959. }
  960. // ---------------------------------------------------------------
  961. // Get the Engine's Instrument Manager
  962. fInstrument = fEngine->GetInstrumentManager();
  963. if (fInstrument == nullptr)
  964. {
  965. pData->engine->setLastError("Failed to get LinuxSampler instrument manager");
  966. return false;
  967. }
  968. // ---------------------------------------------------------------
  969. // Load the Instrument via filename
  970. try {
  971. fInstrumentIds = fInstrument->GetInstrumentFileContent(filename);
  972. }
  973. catch (const LinuxSampler::InstrumentManagerException& e)
  974. {
  975. pData->engine->setLastError(e.what());
  976. return false;
  977. }
  978. // ---------------------------------------------------------------
  979. // Get info
  980. if (fInstrumentIds.size() == 0)
  981. {
  982. pData->engine->setLastError("Failed to find any instruments");
  983. return false;
  984. }
  985. LinuxSampler::InstrumentManager::instrument_info_t info;
  986. try {
  987. info = fInstrument->GetInstrumentInfo(fInstrumentIds[0]);
  988. }
  989. catch (const LinuxSampler::InstrumentManagerException& e)
  990. {
  991. pData->engine->setLastError(e.what());
  992. return false;
  993. }
  994. CarlaString label2(label);
  995. if (fUses16Outs && ! label2.endsWith(" (16 outs)"))
  996. label2 += " (16 outs)";
  997. fLabel = label2.dup();
  998. fMaker = carla_strdup(info.Artists.c_str());
  999. fRealName = carla_strdup(info.InstrumentName.c_str());
  1000. pData->filename = carla_strdup(filename);
  1001. if (name != nullptr && name[0] != '\0')
  1002. pData->name = pData->engine->getUniquePluginName(name);
  1003. else if (fRealName[0] != '\0')
  1004. pData->name = pData->engine->getUniquePluginName(fRealName);
  1005. else
  1006. pData->name = pData->engine->getUniquePluginName(label);
  1007. // ---------------------------------------------------------------
  1008. // register client
  1009. pData->client = pData->engine->addClient(this);
  1010. if (pData->client == nullptr || ! pData->client->isOk())
  1011. {
  1012. pData->engine->setLastError("Failed to register plugin client");
  1013. return false;
  1014. }
  1015. // ---------------------------------------------------------------
  1016. // load plugin settings
  1017. {
  1018. // set default options
  1019. pData->options = 0x0;
  1020. pData->options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES;
  1021. pData->options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
  1022. pData->options |= PLUGIN_OPTION_SEND_PITCHBEND;
  1023. pData->options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
  1024. // set identifier string
  1025. CarlaString identifier(fFormat);
  1026. identifier += "/";
  1027. if (const char* const shortname = std::strrchr(filename, OS_SEP))
  1028. identifier += shortname+1;
  1029. else
  1030. identifier += label;
  1031. pData->identifier = identifier.dup();
  1032. // load settings
  1033. pData->options = pData->loadSettings(pData->options, getOptionsAvailable());
  1034. }
  1035. return true;
  1036. }
  1037. // -------------------------------------------------------------------
  1038. private:
  1039. const bool fUses16Outs;
  1040. const char* fFormat;
  1041. const char* fLabel;
  1042. const char* fMaker;
  1043. const char* fRealName;
  1044. int32_t fCurMidiProgs[MAX_MIDI_CHANNELS];
  1045. LinuxSampler::Sampler fSampler;
  1046. LinuxSampler::Engine* fEngine;
  1047. LinuxSampler::SamplerChannel* fSamplerChannels[MAX_MIDI_CHANNELS];
  1048. LinuxSampler::EngineChannel* fEngineChannels[MAX_MIDI_CHANNELS];
  1049. LinuxSampler::AudioOutputDevicePlugin* fAudioOutputDevice;
  1050. LinuxSampler::MidiInputDevicePlugin* fMidiInputDevice;
  1051. LinuxSampler::MidiInputPortPlugin* fMidiInputPort;
  1052. LinuxSampler::InstrumentManager* fInstrument;
  1053. std::vector<LinuxSampler::InstrumentManager::instrument_id_t> fInstrumentIds;
  1054. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LinuxSamplerPlugin)
  1055. };
  1056. CARLA_BACKEND_END_NAMESPACE
  1057. #endif // WANT_LINUXSAMPLER
  1058. CARLA_BACKEND_START_NAMESPACE
  1059. CarlaPlugin* CarlaPlugin::newLinuxSampler(const Initializer& init, const char* const format, const bool use16Outs)
  1060. {
  1061. carla_debug("LinuxSamplerPlugin::newLinuxSampler({%p, \"%s\", \"%s\", \"%s\"}, %s, %s)", init.engine, init.filename, init.name, init.label, format, bool2str(use16Outs));
  1062. #ifdef WANT_LINUXSAMPLER
  1063. if (init.engine->getProccessMode() == ENGINE_PROCESS_MODE_CONTINUOUS_RACK && use16Outs)
  1064. {
  1065. init.engine->setLastError("Carla's rack mode can only work with Stereo modules, please choose the 2-channel only sample-library version");
  1066. return nullptr;
  1067. }
  1068. // -------------------------------------------------------------------
  1069. // Check if file exists
  1070. {
  1071. QFileInfo file(init.filename);
  1072. if (! file.exists())
  1073. {
  1074. init.engine->setLastError("Requested file does not exist");
  1075. return nullptr;
  1076. }
  1077. if (! file.isFile())
  1078. {
  1079. init.engine->setLastError("Requested file is not valid");
  1080. return nullptr;
  1081. }
  1082. if (! file.isReadable())
  1083. {
  1084. init.engine->setLastError("Requested file is not readable");
  1085. return nullptr;
  1086. }
  1087. }
  1088. LinuxSamplerPlugin* const plugin(new LinuxSamplerPlugin(init.engine, init.id, format, use16Outs));
  1089. if (! plugin->init(init.filename, init.name, init.label))
  1090. {
  1091. delete plugin;
  1092. return nullptr;
  1093. }
  1094. plugin->reload();
  1095. return plugin;
  1096. #else
  1097. init.engine->setLastError("linuxsampler support not available");
  1098. return nullptr;
  1099. // unused
  1100. (void)format;
  1101. (void)use16Outs;
  1102. #endif
  1103. }
  1104. CARLA_BACKEND_END_NAMESPACE