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.

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